An algorithm is a set of steps for accomplishing a task. For example, a recipe for baking a cake is an algorithm - because a recipe is a series of steps for transforming the input to the desired output.
In code, even a simple function (doubleNumbers(array)
) can be considered an algorithm. On this page, we highlight some of the more useful and commonly known algorithms.
Before you dive in, check out this 5-minute video which gives a nice introduction to algorithms.
- Reduce traffic jam
- Find your best match in speed-dating event
- Improve operational efficiency in PSA port
- The secret behind blockchain
Algorithms are everywhere in our lives! Checkout this podcast
Well known searching algorithms on arrays
- Binary Search
- Breadth-First Search
- Depth-First Search
- Shortest Path Search
- Travelling Salesman Problem
Common Sorting Algorithms
https://codility.com/media/train/4-Sorting.pdf
- https://www.cs.usfca.edu/~galles/visualization/ComparisonSort.html
- https://www.toptal.com/developers/sorting-algorithms
- http://sorting.at/
- http://pythontutor.com/javascript.html#mode=edit
- http://algo-visualizer.jasonpark.me/
- https://visualgo.net/en
https://codility.com/media/train/1-TimeComplexity.pdf
The most well-known one is Big-O notation
:
In computer science, big O notation is used to classify algorithms according to how their running time or space requirements grow as the input size grows.
It describes upper bound of time/space complexity of an algorithm.
There are similar notations:
- big-Omega, for lower bound
- big-Theta, for both lower bound and upper bound
Short Explanation: https://stackoverflow.com/questions/10376740/what-exactly-does-big-Ө-notation-represent
Long Explanation: https://www.khanacademy.org/computing/computer-science/algorithms/asymptotic-notation/a/asymptotic-notation
More Explanation:
Big-O cheatsheet of common algorithms
- Take a set of 10 numbers in random and write code to sort these numbers using selection sort. Write another program to sort this list of 10 numbers using merge sort. If that's too easy for you, implement quick sort
Sample list of numbers (7, 5, 34, 565, 232, 9, 0, 342, 31, 1411)
- Create a binary search tree and given any list of 10 numbers and an input. The program should be able to tell if the number exists in the original list given. Number list (7, 5, 34, 565, 232, 9, 0, 342, 31, 1411) First input 232, Second input 99
- Implement breath first search, depth first search on a binary tree. Hint: you can implement breath first search using a queue, and implement depth first search using a stack.
More Exercises
- https://app.codility.com/programmers/lessons/1-iterations/
- https://github.com/Vintharas/AlgorithmsAndDataStructuresInJavaScript
- What are algorithms
- Recursion
countdown(n)
recursiveSum(n)
factorial(n)
isPalindrome(str)
- binary search (vs. simple search)
binarySearch(sortedArr, target)
- intro to big O notation - O(n) and O(log n)
- Sorting
- selection sort (video)
- How you can change the world by learning Data Structures and Algorithms
- An intuitive introduction to algorithmic efficiency
- Grokking Algorithms
- Once Upon an Algorithm: How Stories Explain Computing (MIT Press)
- Algorithms Illuminated: Part 1: The Basics
- Real-World Algorithms: A Beginner's Guide (MIT Press)
- The algorithm design manual
- Algorithms, by Jeff Erickson
- Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne
https://www.khanacademy.org/computing/computer-science/algorithms https://www.manning.com/livevideo/algorithms-in-motion