Algorithm
Algorithm
Divide and Conquer Breaking down a problem Sorting algorithms, Merge sort,
into smaller subproblems, binary search. Quicksort.
solving each subproblem
independently, and
combining their solutions
to solve the original
problem.
Pivot
38 27 43 10
<=10 10 <
Pivot
10 38 27 43
<=43 43 <
Pivot
10 38 27 43
<=27 27<
10 27 38 43
10 27 38 43
Algorithms-CS101
• Bottom-Up Approach
◦ Definition: Building a system from the smallest subsystems up to the overall system.
◦ Illustration: Combining solutions to subproblems to solve the main problem (e.g., Merge sort).
38 27 43 10
38 27 43 10
38 27 43 10
27 38 10 43
10 27 38 43
Breadth- Exploring all O(V + E) Useful for Ideal for finding Source Node
First neighbors at finding the the shortest
Layer 0 0
Search the present shortest path path or Layer 1
(BFS) depth before in unweighted level-order 1 2 3
moving on to graphs; explores traversal
nodes at the all neighbors in graphs or
next depth before moving trees. 4 5 6 7
level. on to the next Layer 2
level. Output: 0, 1, 2, 3, 4, 5, 6, 7
Preorder Visit the root O(n) Used to create a Useful for prefix 1
node, then copy of the tree notation
traverse the or to get a prefix expressions 2 3
left subtree, expression of and when you
followed by an expression need to process
the right 4 5 6 7
tree. the root node
subtree. before the Preorder Traversal
subtrees.
1 2 4 5 3 6 7