filmov
tv
Median of medians Algorithm - [Linear Time O(n)] #PART-2
Показать описание
Median of medians can be used as a pivot strategy in quicksort, yielding an optimal algorithm.
10, 1, 67, 20, 56, 8 ,43, 90, 54, 34, 0
for this array the median will be 34.
0 1 8 10 20 34 43 54 56 67 90
Now the naive solution for this problem would be something like, first you sort the array, and then get the middle index element. But that approach does more work than required, as you just need to find the median, there's no need to know the sorted position of each element in the array.
and the worst time complexity for this solution is O(nlogn)
There's another solution for this problem that has complexity O(n), which is based on quick sort algorithm. so what we do,
we choose a pivot element,
then rearrange numbers exactly like we used to do in quick sort
then we return the pivot index.
Now we check if the index is the middle index.
if it is, we have found the median
if pivot index is less than median index, we recursively search for the median in right subarray.
else if pivot index is greater than median index, we recursively search in the left subarray.
10, 1, 67, 20, 56, 8 ,43, 90, 54, 34, 0
for this array the median will be 34.
0 1 8 10 20 34 43 54 56 67 90
Now the naive solution for this problem would be something like, first you sort the array, and then get the middle index element. But that approach does more work than required, as you just need to find the median, there's no need to know the sorted position of each element in the array.
and the worst time complexity for this solution is O(nlogn)
There's another solution for this problem that has complexity O(n), which is based on quick sort algorithm. so what we do,
we choose a pivot element,
then rearrange numbers exactly like we used to do in quick sort
then we return the pivot index.
Now we check if the index is the middle index.
if it is, we have found the median
if pivot index is less than median index, we recursively search for the median in right subarray.
else if pivot index is greater than median index, we recursively search in the left subarray.
Median of medians Algorithm - [Linear Time Complexity O(n)] #PART-1
What is Median of Medians algorithm for Selection Problem?
Illustration of Linear Time Median of Medians Algorithm
2.2 - Linear Time Selection (Median of Medians Algorithm)
Quick-Select Algorithm and Median-of-Medians Lecture
UIUC CS 374 FA 20: 11.4.3. Median of medians
14 - Median using quick select algo
Median of Medians - Order Statistics
2. Divide & Conquer: Convex Hull, Median Finding
Median of medians Algorithm - [Linear Time O(n)] #PART-2
Linear-Time Median Algorithm (Making Quicksort go Fast!)
UIUC CS 374 FA 20: 11.4.4. Median of medians is a good median
Blum on median finding in linear time
UIUC CS 374 FA 20: 11.4.5. Running time analysis of the median of medians algorithm
Median Selection Algorithm (Part #1 - Concepts)
Adaptive Median-of-Medians Quick Sort
[Algo 11] Finding the median value without sorting. Apply divide and conquer algorithm
Median of Medians Puzzle
Time complexity to find Median of Medians
Array : Not understanding median of medians algorithm to find k-th element
Is median of medians optimal?
Why in BFPRT (median of medians) algorithm the partition of the array by $7$ blocks would work...
Lecture 8: Median of Medians and Randomized Algorithms
Median Selection Algorithm (Part #2 - Improving Effeciency)
Комментарии