Question: need a main.cpp , SelectionAlgotihm.cpp and TestBed.cpp In this assignment, you will write a C++ program that finds the k th largest number among a

need a main.cpp , SelectionAlgotihm.cpp and TestBed.cpp

 need a main.cpp , SelectionAlgotihm.cpp and TestBed.cpp In this assignment, you

In this assignment, you will write a C++ program that finds the kth largest number among a set of N numbers. However, this time, you will use a variation of the quicksort algorithm to implement the program. The details can be found below.

1) The Input and Expected Output

The program will take the type of algorithm to be applied, k (a number less than or equal to N). Then it will take N followed by a list of N numbers. As output, it will print out the kth largest number and the total elapsed time for the completion of the algorithm.

2) The Algorithm: quickselect

You will implement a variation of the quicksort algorithm to find the kth largest number among a set of numbers S in O(N) time on average, where N is the total amount of numbers, i.e., |S|. The outline of the algorithm, quickselect is as follows.

  1. If N , sort all the numbers (using insertion sort) and return the kth number.
  2. Else, pick a pivot number, v S.
    1. Partition S {v} into S1 and S2, as done in quicksort.
    2. If k 1|, then the kth largest number must be in S1. Return quickselect(S1, k).
    3. If k = 1 + | S1|, then the pivot, v is the kth largest number. Return v.
    4. Otherwise, the kth largest number lies in |S2|, and it is the (k |S1| 1)st largest number in S2. Return quickselect(S2, k |S1| 1).

main.cpp main / modification/extension if(type == 4) algorithm = new Algorithm SortQuick (k); cu ses TestBed / -* algorithm: Selection Algorithm +execute():void +set Algorithmink: int, in type : int) : void +TestBed() + TestBed) ! Selection Algorithm #k: int +select(): int +Selection Algorithm (ink: int) AgorithmSortal AlgorithmSortk +select(): int +AlgorithmsortAllink: int) +select(): int +AlgorithmSortKink: int) extension AlgorithmSortQuick I select(): int +quickselect/in numbers * : int, in left : int, in right : int, in k : int): int I AlgorithmsortQuick(ink: int)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!