MHB Can we achieve linear time with groups of 7 in the SELECT algorithm?

  • Thread starter Thread starter evinda
  • Start date Start date
  • Tags Tags
    Linear Time
AI Thread Summary
The SELECT algorithm efficiently finds the $i$th smallest element in an array of distinct elements by dividing the array into groups, finding medians, and recursively partitioning. The process begins by grouping elements into sets of five, determining the median of each group through insertion sort, and then finding the median of these medians. The algorithm partitions the array around this median and recursively searches the appropriate side based on the desired index. A discussion point is whether using groups of seven could still yield linear execution time, prompting consideration of a recurrence relation to analyze time complexity. It is noted that using groups of three would not achieve linear time, leading to inquiries about the time complexity of each step, particularly regarding the cost of insertion sort on small groups and the overall cost in step five. The insertion sort is confirmed to be applied to fixed-length groups of five, raising questions about how this affects the algorithm's efficiency and complexity calculations.
evinda
Gold Member
MHB
Messages
3,741
Reaction score
0
Hello! (Wave)

The [m]SELECT[/m] algorithm determines the $i$th smallest element of an input array of $n>1$
distinct elements by executing the following steps.


  • 1. Divide the $n$ elements of the input array into $\lfloor \frac{n}{5} \rfloor $ groups of $5$ elements each and at most one group made up of the remaining $n \mod 5$ elements.
    2. Find the median of each of the $\lfloor \frac{n}{5} \rfloor $ groups by first insertion-sorting the elements
    of each group (of which there are at most $5$) and then picking the median
    from the sorted list of group elements.
    3. Use SELECT recursively to find the median $x$ of the $\lfloor \frac{n}{5} \rfloor $ medians found in step $2$. (If there are an even number of medians, then by our convention, $x$ is the lower median.)
    4. Partition the input array around the median-of-medians $x$ using the modified
    version of PARTITION. Let $k$ be one more than the number of elements on the
    low side of the partition, so that $x$ is the $k$th smallest element and there are $n-$k
    elements on the high side of the partition.
    5. If $i=k$, then return $x$. Otherwise, use SELECT recursively to find the $i$th
    smallest element on the low side if $i<k$, or the $i-k$ th smallest element on
    the high side if $i>k$.
At the algorithm [m]SELECT[/m], the input elements are divided into groups of $5$.

Can the algorithm achieve linear execution time if the elements get divided into groups of $7$?

Show that if groups of $3$ are used , linear execution time cannot be achieved.
How can we deduce if the algorithm can achieve linear execution time if the elements get divided into groups of $7$? (Thinking)
 
Last edited:
Technology news on Phys.org
We could find a recurrence relation that describes the algorithm, right? (Thinking)

Could you help me to find the time complexity of each of the steps?
 
Do you understand the proof when the length is divided by 5 ?
 
I saw that for the second step, the cost should be $c \cdot \lceil \frac{n}{5} \rceil$. How can this be the cost, although we apply Insertion sort? Also how can we find the cost for the step $5$? :confused:
 
evinda said:
I saw that for the second step, the cost should be $c \cdot \lceil \frac{n}{5} \rceil$. How can this be the cost, although we apply Insertion sort? Also how can we find the cost for the step $5$? :confused:

The insertion sort is done on lists with fixed length equal to 5 , right ?
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top