Based in: thewilly/uniovi.ed.
Here you'll find implementations of popular algorithms and data structures in everyone's favorite new language, Java, with detailed explanations of how they work.
If you're a computer science student who needs to learn this stuff for exams -- or if you're a self-taught programmer who wants to brush up on the theory behind your craft -- you've come to the right place!
The goal of this project is to explain how algorithms work. The focus is on clarity and readability of the code, not on making a reusable library that you can drop into your own projects. That said, most of the code should be ready for production use but you may need to tweak it to fit into your own codebase.
Code is compatible Eclipse Oxigen, Maven and Java 1.8. We'll keep this updated with the latest version of Java.
π Suggestions and contributions are welcome! π
The choice of data structure for a particular task depends on a few things.
First, there is the shape of your data and the kinds of operations that you'll need to perform on it. If you want to look up objects by a key you need some kind of dictionary; if your data is hierarchical in nature you want a tree structure of some sort; if your data is sequential you want a stack or queue.
Second, it matters what particular operations you'll be performing most, as certain data structures are optimized for certain actions. For example, if you often need to find the most important object in a collection, then a heap or priority queue is more optimal than a plain array.
Most of the time using just the built-in Array, Dictionary, and Set types is sufficient, but sometimes you may want something more fancy...
Remember that on each package you have a detailed explanation of its content, theory most of it.
- Heap. A binary tree stored in an array, so it doesn't use pointers. Makes a great priority queue. Fibonacci Heap
- B-Tree. A B-tree is a balanced tree, but it is not a binary tree. Nodes have more children, which increases per-node search time but decreases the number of nodes the search needs to visit
- AVL Tree. An AVL tree is a self-balancing binary search tree, balanced to maintain O(log n) height.
- Hash Table. Allows you to store and retrieve objects by a key. This is how the dictionary type is usually implemented.
- Graph.
For more information, check out these great books:
- Introduction to Algorithms by Cormen, Leiserson, Rivest, Stein
- The Algorithm Design Manual by Skiena
- Elements of Programming Interviews by Aziz, Lee, Prakash
- Algorithms by Sedgewick
- Grokking Algorithms by Aditya Bhargava
The following books are available for free online:
- Algorithms by Dasgupta, Papadimitriou, Vazirani
- Algorithms, Etc. by Erickson
- Algorithms + Data Structures = Programs by Wirth
- Algorithms and Data Structures: The Basic Toolbox by Mehlhorn and Sanders
- Open Data Structures by Pat Morin
- Wikibooks: Algorithms and Implementations
Other algorithm repositories:
- EKAlgorithms. A great collection of algorithms in Objective-C.
- @lorentey. Production-quality Swift implementations of common algorithms and data structures.
- Rosetta Code. Implementations in pretty much any language you can think of.
- AlgorithmVisualizer. Visualize algorithms on your browser.
- Swift Structures Data Structures with directions on how to use them here