kodecocodes / swift-algorithm-club

Algorithms and data structures in Swift, with explanations!
MIT License
28.78k stars 5k forks source link

Visualization of Algorithms in Playgrounds / Cocoa / Swift #171

Closed timarnold closed 7 years ago

timarnold commented 8 years ago

Love the repository, it's been very useful in my recent learning endeavors. Being a professional iOS developer without a CS background, I've been looking to increase my understanding of foundational CS topics like algorithms and data structures.

I really like the Algorithm Visualizer linked in the README, and also really like the images and visualizations that accompany many of the algorithms or data structures in the repository.

A couple questions: • Have folks thought about a way to visualize algorithms right inside the playground, a la the Algorithm Visualizer? • What tools do you all use to generate your static visualizations of arrays, graphs, etc.?

I'm interested in a task to improve my understanding of these topics and I'd be really interested in creating visualizations of these algorithms that were accessible right in the playground. Has anyone thought about or started this task?

kelvinlauKL commented 8 years ago

Glad you're liking it!

I've thought of building a visual tool for the club, but have been swamped lately. I think you're the first to suggest to work on it. If you're up for the task of visualizing an algorithm using playgrounds, I think we'd all be grateful 👍.

Playgrounds are pretty powerful and I can see it being a great tool for visualizing the algorithms. I'll try to see what I can come up with in a future SAC article at www.raywenderlich.com.

//cc @chris-pilcher

timarnold commented 8 years ago

I may or may not have time but it's definitely something that interests me!

What tools are used (generally) to create the static visualizations in the README files for the files in the repository?

hollance commented 8 years ago

A while ago I've done some visualizations in playgrounds for sorting algorithms. What I did was draw stuff into an NSView. As you dragging the timeline scroller, the NSView would get updated. I'm not sure this is still possible since the timeline scroller has since disappeared from playgrounds?!

A simple visualization is to put values into an array and then let the playground draw the array. One trick is a.map { $0 } (where a is an array) and then click on the eye icon to show a graph with the array's values.