Algorithms:

Algorithms Time Complexity
Euclid’s Algorithm O(logmin(a,b))O(log_{min(a, b)})
Middle-school procedure O(n)O(\sqrt{n})
Maximum Element O(n)O(n)
Matrix Multiplication O(n3)O(n^3)
Conventional Matrix Multiplication O(n3)O(n^3)
Strassen’s Matrix Multiplication O(nlog2(7))O(n^{log_2(7)})O(n2.8)O(n ^ {2.8})
Counting binary digits O(log(n))O(log(n))
Counting bits O(log(n))O(log(n))
The Tower of Hanoi Puzzle 2n2^n
String Matching O(n×m)O(n \times m)
Closest-Pair by Brute-force O(n2)O(n ^ 2)
Closest-Pair by devide and conquer O(n×log2(n))O(n \times log^2(n))
Convex-hull Problem by Brute-force O(n2)O(n ^ 2)
Convex-hull Problem by devide and conquer O(n×log2(n))O(n \times log^2(n))
Traveling Salesman Problem O(n!)O(n!)
The Assignment Problem O(n!)O(n!)
Knapsack Problem 2n2 ^ n
Decrease by constant factor O(log(n))O(log(n))
Multiplication à la russe O(log(n))O(log(n))
Exponentiation by Squaring O(log(n))O(log(n))
Lumoto Partition O(n)O(n) or O(rl)O(r - l)
Pre-Order O(n)O(n)
In-Order O(n)O(n)
Pre-Order O(n)O(n)
First Multiplication of Large Integers O(n2)O(n^2)
Second Multiplication of Large Integers O(n1.585)O(n^{1.585})
BFS O(v)O(v) or O(bd)O(b ^ d)
DFS O(bm)O(b ^ m)

Sorting Algorithms Best Case Average Case Worst Case Stable In-place
Selection Sort O(n2)O(n^2) O(n2)O(n^2) O(n2)O(n^2) ✔️
Bubble Sort O(n)O(n) O(n2)O(n ^ 2) O(n2)O(n ^ 2) ✔️ ✔️
Insertion Sort O(n)O(n) O(n2)O(n ^ 2) O(n2)O(n ^ 2) ✔️ ✔️
Merge Sort O(nlog(n))O(nlog(n)) O(nlog(n))O(nlog(n)) O(nlog(n))O(nlog(n)) ✔️
Quick Sort O(nlog(n))O(nlog(n)) O(nlog(n))O(nlog(n)) O(n2)O(n ^ 2) ✔️
Topology Sort O(V2+E)O(V^2 + E) O(V2+E)O(V^2 + E) O(V2+E)O(V^2 + E)
Median Selection O(n)O(n) O(n)O(n) O(n2)O(n ^ 2)
Quick Select O(n)O(n) O(n)O(n) O(n2)O(n ^ 2)
Binary Search O(1)O(1) O(log(n))O(log(n)) O(log(n))O(log(n))
Sequential Search O(1)O(1) O(n)O(n) O(n)O(n)

Note:

In The Exam Choose O(N2)O(N^2) or O(V2+E)O(V^2 + E)


BFS & DFS Time explanation:

bfs

How O(V+E)O(V+E) and O(bd)O(b^d) are equal the first one looks like a linear complexity and second one is exponential.

In the first, the graph is the input, so it is linear in the size of the input - the graph.
The second is also linear in the size of the graph - and exponential in the depth of the solution - a different factor, still - no need to traverse a vertex more then once, so still linear in the graph’s size.
So, in here - basically O(bd)O(b^d) is a subset of O(V+E)O(V+E), and is more informative then it, if you can ‘suffer’ the fact that your complexity is a function of dd, which is not part of the input.

When we talk about big OO notation it means that upper bound whatsoever the input may be it should remains the same because its an upper bound. whether Big OO only deals with some finite data input?


Sorting key

Two properties of sorting algorithms:


String matching:


DEFINITION: A set of points in the plane is called convex if, for any two points pp and qq in the set, the entire line segment with the endpoints at pp and qq belongs to the set.


Graph:

Paths

Connected graphs

Connected component

Cycle

Acyclic graph

Cyclic graph

Degree of a vertex

graph


Trees

Properties of trees:

Rooted Trees

Ordered trees

Binary trees

Binary search trees


Tree search terminology


The differences between Tree and Graph

Basis For Comparison Tree Graph
Path Only one between two vertices more than one path is allowed
Root node It has exactly one root node Graph doesn’t have a root node
Loops no loops are permitted Graph can have loops
Complexity Less Complex More Complex
Traversal technique Pre-order, In-order, Post-order BFS, DFS
Number of edges n1n - 1 (nn is the number of node) not defined
Model type Hierarchical Network

Uniformed search strategies


Breadth First Search (BFS) (Shortest path first)


Depth First Search (DFS) (Longest path first)


Comparing DFS and BFS:

A quick explanation of DFS & BFS (Depth First Search & Breadth-First Search)  | by Sebastian De Lima | Analytics Vidhya | Medium

Tree Traverse:


Arrays

Linked List

Stacks

Queues

Priority queues (implemented using heaps)


Comp Array Linked Lists
Length fixed length dynamic length
Memory contiguous memory locations arbitrary memory locations
Access direct access access by following links

Comparing Orders of Growth (Limit)


Useful summation formulas and rules


What is Brute Force?


Exhaustive Search


Measuring problem-solving performance


Decrease-and-Conquer

  1. Reduce problem instance to smaller instance of the same problem
  2. Solve smaller instance
  3. Extend solution of smaller instance to obtain solution to original instance

Divide-and-Conquer

  1. Divide instance of problem into two or more smaller instances
  2. Solve smaller instances recursively
  3. Obtain solution to original (larger) instance by combining these solutions

Examples:


Notes:


Code icon with heart icon by Ahmed Hossam