GithubHelp home page GithubHelp logo

hhy5277 / illustrated-algorithms Goto Github PK

View Code? Open in Web Editor NEW

This project forked from skidding/illustrated-algorithms

0.0 2.0 0.0 2.39 MB

Interactive algorithm visualizations

Home Page: https://illustrated-algorithms.now.sh/

License: MIT License

JavaScript 100.00%

illustrated-algorithms's Introduction

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

illustrated-algorithms's People

Contributors

mathiasbynens avatar radvalentin avatar skidding avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.