-
- peek(): see the very top element or node of the Stack
- push(value): add a node (or element to the top of the Stack
- pop(): remove an element or node from the top of the Stack
- isEmpty(): check if Stack is empty
-
- peek(): get the very fist element or node in the Queue
- enqueue(value): add a node or element to the Queue
- dequeue(): remove an element or node from the Queue
- isEmpty(): check if the Queue is empty
-
-
- lookup: O(log N)
- insert: O(log N)
- delete: O(log N)
-
- lookup: O(N)
- insert: O(N)
- delete: O(N)
-
- Sorting
- Dynamic Programming
- BFS + DFS (Searching)
- Recursion
Anatomy of recursion
- 1- Identify the base case
- 2- Identify the recursive case
- 3- Get closer and closer and return when needed. Usually you have 2 returns (1 for the base case and 1 for the recursive case).
Sorting What sorting algorithm to choose based on the problem? How to make the right decision?
- Bubble Sort
- Insertion Sort
- Selection Sort
- Merge Sort
- Quick Sort
Elementary sort
- Bubble Sort - O(n^2)
- Insertion Sort
- Selection Sort - O(n^2)
NB::
- When the data set is small or data is nearly sorted, use insertion sort over other sorting algorithms.
- O(1) Constant - no loops
- O(log N) Logarithmic - usually searching algorithms have log(n) if they are sorted (Binary Search)
- O(N) Linear - for loops while loops
- Know Thy Complexities
- Sorting Algorithms Animations
- Visualize data structures and algorithms through animation
- Linear Search
- Binary Search
- Depth First Search (DFS)
- Breadth First search (BFS)
- All traverals are O(n)
- BFS is good for
- Finding the shortest path
- Closer Nodes
- Require more memory (downside)
- DFS
- Less memory
- Does Path Exist?
- Can Get Slow
Divide and Conquer + Memmoization
- Can be divided into subproblem
- Recursive solution
- Are there repetitive subproblems?
- Memoize subproblems