• This repository has been archived on 28/Mar/2023
  • Stars
    star
    2,770
  • Rank 16,441 (Top 0.4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 8 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Interactive algorithm visualizations

Illustrated Algorithms

Algorithm → AST → CSS (3 x JavaScript)

Binary search

Inspired by Grokking Algorithms and python-execution-trace, this project aims to reveal the mechanics behind algorithms via interactive visualizations of their execution.

Visual representations of variables and operations augment the control flow, alongside actual source code. You can fast forward and rewind the execution to closely observe how an algorithm works.

Disclaimer ✌️

Edge cases and optimizations are beyond the scope of this project. The featured implementations are chosen for their simplicity and do not promise to work for data sets different from the illustrated ones. Please rely on other resources for learning algorithms in depth, from Wikipedia to other visualization projects. Also see community-driven Footnotes. Thanks.

Principles

  • The same code that is displayed next to the illustration is also decorated using babel-plugin-trace-execution and executed to record the context at every step. Literally the same source file.
  • Going back and forth between function execution (and call stack when algorithm uses recursion) is effortless. So is pausing and resuming.
  • Visualizations are easy to follow, fun to play with and simple enough to fit inside the screen of any modern phone.

Work in progress

Dynamic styles

This project uses styled-jsx, but takes the idea of CSS-in-JS even further. Sizing, positioning and transition offsets are computed by JS, all before elements hit the DOM. This provides complete control over layout (e.g. font scaling relative to container width, rounded to a multiplier of 2) and animation (e.g. pausing in the middle of a transition and rewinding). It's a wild concept that hopefully gets mainstream someday.

How to contribute

Consider the following actions if you want to advance this project:

  • Find and/or fix bugs
  • Add tests to babel-plugin-trace-execution
  • Improve rendering perf (already decent, but not ideal due to how styles are applied)
  • Propose algorithms to add (that can fit in a func <=25 lines of ES6)
  • Create elegant illustrations (sketches/wireframes do) – Hello graphic designers and people who draw!

Before submitting a PR, make sure to:

  • Briefly describe the value of your contribution
  • Stay in line with the project's mission (i.e. to make algorithms easy, see above sections)
  • Test code before committing it via npm run test
  • Thoroughly test the visual experience you're creating (e.g. algorithms must fit nicely on the screen)

Development

npm i
# Start Next.js server (localhost:3000)
npm run dev
# Run tests
npm test
# Start React Cosmos playground (localhost:8989)
npm run cosmos

Footnotes

While this project doesn't focus on algorithm implementation specifics, here's a list of valuable insights brought up by the community which serves to complement the visuals.

Binary Search

  • #21 Calculating mid can be improved to avoid overflow when list is sufficiently large enough (@mhaji)

Quicksort


Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

More Repositories

1

flatris

Fast-paced two-player web game
JavaScript
1,446
star
2

dragdealer

Drag-based vanilla JS component
JavaScript
1,051
star
3

jobs-done

Ritual app for ending the work day inspired by Deep Work
JavaScript
943
star
4

react-testing-examples

Searchable library of React testing examples
JavaScript
387
star
5

react-mock

Declarative mocks for React state and global APIs
JavaScript
368
star
6

react-component-tree

Serialize and reproduce the state of an entire tree of React components.
JavaScript
87
star
7

aufond

A résumé for the modern age
JavaScript
77
star
8

react-component-playground

Minimal frame for loading and testing React components in isolation.
JavaScript
76
star
9

obvious-buttons

Almost flat CSS buttons
CSS
62
star
10

babel-plugin-trace-execution

Trace execution context of JS functions
JavaScript
61
star
11

async-hacker-handbook

The Asynchronous Hacker Handbook
35
star
12

github-issue-template

BDD Issue Template for Github (with Chrome Extension)
JavaScript
18
star
13

chrome-imdb-ratings

Chrome extension for displaying IMDB ratings in listings
JavaScript
16
star
14

async-until

Wait until a given callback returns true
TypeScript
10
star
15

cosmos-example

Example of loading components and fixtures using Cosmos.
JavaScript
10
star
16

react-data-fetch

A good-enough data fetching mixin for React components.
JavaScript
8
star
17

react-querystring-router

Bare router for React components, using query string as props.
JavaScript
8
star
18

play

Agnostic frame-skipping animation library
JavaScript
6
star
19

react-redux-layout

Unleash your creativity with dynamic layouts!
JavaScript
4
star
20

react-cosmos-redux

Redux mock for React Cosmos fixtures
TypeScript
4
star
21

chrome-hide-facebook-sponsored-posts

A Chrome extension for automatically hiding sponsored posts from your Facebook News Feed.
JavaScript
4
star
22

ui-development-made-simple

My JSHeroes talk on how to build a scalable UI architecture
JavaScript
4
star
23

gutenHashTag

Dynamic Twitter background
PHP
3
star
24

mode

A node.js web framework for real-world applications
JavaScript
3
star
25

stoic-guide-to-good-life

Notes from William B. Irvine's book, A Guide to the Good Life: The Ancient Art of Stoic Joy.
3
star
26

berlinjs-2017

Code used for my BerlinJS talk
JavaScript
2
star
27

hacker-comments

A browser hack for hackers
JavaScript
2
star
28

react-animation-loop

React mixin for running a callback at 60fps with frame skipping
JavaScript
2
star
29

react-test-useeffect

JavaScript
2
star
30

react-testing-talk

Slides and resources for my React testing talk
JavaScript
2
star
31

linked-list

Turn an array into a stateless linked list
TypeScript
2
star
32

react-plugin

API for composable 3rd party React plugins
TypeScript
1
star
33

YOH2011

1
star
34

flux-dispatcher-game

Fun with Flux
CSS
1
star
35

chrome-mozaic-profiler

JavaScript
1
star
36

after-pending-promises

Wait for pending promises to resolve
JavaScript
1
star
37

jLaid

JavaScript
1
star
38

async-retry

Wait until cb doesn't throw or time out
TypeScript
1
star