Skip to content

Latest commit

 

History

History
136 lines (86 loc) · 6.59 KB

introduction-algorithms.md

File metadata and controls

136 lines (86 loc) · 6.59 KB

Introduction: Algorithms

What is an algorithm?

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.

Use cases of 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

Examples

Searching on arrays

Well known searching algorithms on arrays

  • Binary Search

Searching on a graph

  • Breadth-First Search
  • Depth-First Search
  • Shortest Path Search
  • Travelling Salesman Problem

Sorting an array

Common Sorting Algorithms

https://codility.com/media/train/4-Sorting.pdf

Visualization of Algorithms

Complexity of an algorithm

https://codility.com/media/train/1-TimeComplexity.pdf

Asymptotic notation

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

Exercises

Sorting

  • 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)

Searching

  • 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

jumpstart-2 algos learning roadmap

  • 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

Resources

Tutorials

Books

Courses

https://www.khanacademy.org/computing/computer-science/algorithms https://www.manning.com/livevideo/algorithms-in-motion