-
Big O:
Divide-and-Conquer
- Divide-and-Conquer:
The divide-and-conquer strategy solves a problem by:- Breaking it into subproblems that are themselves smaller instances of the same type of problem
- Recursively solving these subproblems
- Appropriately combining their answers
The real work is done piecemeal, in three different places:
- in the partitioning of problems into subproblems
- at the very tail end of the recursion, when the subproblems are so small that they are solved outright
- and in the gluing together of partial answers.
These are held together and coordinated by the algorithm’s core recursive structure.
-
Asynchronous:
-
Asynchronous:
-
Binary Search:
img1 -
Mergesort:
The problem of sorting a list of numbers lends itself immediately to a divide-and-conquer strategy: split the list into two halves, recursively sort each half, and then merge the two sorted sublists.img2
Merge Function:
Given two sorted arrays \(x[1 . . . k]\) and \(y[1 . . . l]\), how do we efficiently merge them into a single sorted array \(z[1 . . . k + l]\)?
img3Here ◦ denotes concatenation.
Run-Time:
This merge procedure does a constant amount of work per recursive call (provided the required array space is allocated in advance), for a total running time of \(O(k + l)\). Thus merge’s are linear, and the overall time taken by mergesort is:$$T(n)=2 T(n / 2)+O(n) = O(n \log n)$$
☹️
Iterative MergeSort:
img4 -
\(n \log n\) Lower Bound for (comparison-based) Sorting (Proof):
img5 -
Medians:
-
Asynchronous:
SECOND
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
THIRD
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
FOURTH
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
FIFTH
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
Sixth
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:{: .bodyContents6 #bodyContents68
Seven
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous:
-
Asynchronous: