tsiege / Tech-Interview-Cheat-Sheet

Studying for a tech interview sucks. Here's an open source cheat sheet to help
MIT License
4.29k stars 983 forks source link

Tech Interview Cheat Sheet

This list is meant to be both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth.

Contributing

This is an open source, community project, and I am grateful for all the help I can get. If you find a mistake make a PR and please have a source so I can confirm the correction. If you have any suggestions feel free to open an issue.

Challenges

This project now has actual code challenges! This challenges are meant to cover the topics you'll read below. Maybe you'll see them in an interview and maybe you won't. Either way you'll probably learn something new. Click here for more

Table of Content

Asymptotic Notation

Definition:

Asymptotic Notation is the hardware independent notation used to tell the time and space complexity of an algorithm. Meaning it's a standardized way of measuring how much memory an algorithm uses or how long it runs for given an input.

Complexities

The following are the Asymptotic rates of growth from best to worst:

(source: Soumyadeep Debnath, Analysis of Algorithms | Big-O analysis)

Visualized below; the x-axis representing input size and the y-axis representing complexity:

#

(source: Wikipedia, Computational Complexity of Mathematical Operations)

Big-O notation

Big-O refers to the upper bound of time or space complexity of an algorithm, meaning it worst case runtime scenario. An easy way to think of it is that runtime could be better than Big-O but it will never be worse.

Big-Ω (Big-Omega) notation

Big-Omega refers to the lower bound of time or space complexity of an algorithm, meaning it is the best runtime scenario. Or runtime could worse than Big-Omega, but it will never be better.

Big-θ (Big-Theta) notation

Big-Theta refers to the tight bound of time or space complexity of an algorithm. Another way to think of it is the intersection of Big-O and Big-Omega, or more simply runtime is guaranteed to be a given complexity, such as n log n.

What you need to know

Data Structures

Array

Definition

What you need to know

Time Complexity

Linked List

Definition

What you need to know

Time Complexity

Hash Table or Hash Map

Definition

What you need to know

Time Complexity

Binary Tree

Definition

For a full binary-tree reference see Here

What you need to know

Time Complexity

Algorithms

Algorithm Basics

Recursive Algorithms

Definition

What you need to know

Iterative Algorithms

Definition

What you need to know

Recursion Vs. Iteration

Pseudo Code of Moving Through an Array

Recursion                         | Iteration
----------------------------------|----------------------------------
recursive method (array, n)       | iterative method (array)
  if array[n] is not nil          |   for n from 0 to size of array
    print array[n]                |     print(array[n])
    recursive method(array, n+1)  |
  else                            |
    exit loop                     |

Greedy Algorithms

Definition

What you need to know

Pseudo Code of a Greedy Algorithm to Find Largest Difference of any Two Numbers in an Array.

greedy algorithm (array)
  var largest difference = 0
  var new difference = find next difference (array[n], array[n+1])
  largest difference = new difference if new difference is > largest difference
  repeat above two steps until all differences have been found
  return largest difference

This algorithm never needed to compare all the differences to one another, saving it an entire iteration.

Search Algorithms

Breadth First Search

Definition

What you need to know

Time Complexity

Depth First Search

Definition

What you need to know

Time Complexity

Breadth First Search Vs. Depth First Search

Nuances

Sorting Algorithms

Selection Sort

Definition

What you need to know

Time Complexity

Space Complexity

Visualization

#

(source: Wikipedia, Selection Sort)

Insertion Sort

Definition

What you need to know

Time Complexity

Space Complexity

Visualization

#

(source: Wikipedia, Insertion Sort)

Merge Sort

Definition

What you need to know

Time Complexity

Space Complexity

Visualization

#

(source: Wikipedia, Merge Sort)

Quicksort

Definition

What you need to know

Time Complexity

Space Complexity

Visualization

#

(source: Wikipedia, Quicksort)

Merge Sort Vs. Quicksort

Additional Resources

Khan Academy's Algorithm Course Graph Data Structure & Algorithms Data Structure Interview Questions Data Structure MCQ With Answers 10 Best Data Structures and Algorithms Books