Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

Describe the steps involved in the installment method.

Answered: 1 week ago

Question

1. Identify what positions are included in the plan.

Answered: 1 week ago

Question

2. Identify the employees who are included in the plan.

Answered: 1 week ago