[SOLVED] CECS328 Programming assignment 4

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Lab_4-pnqtcq.zip (152.5 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (2 votes)

Part A.

Implement a function called Quick_select to find the kth least element on a given array. (The average running time of your algorithm should be O(n)) (Hint: Use partitioning algorithm)

  1. Request the user to enter a positive integer, and call it n.
  2. Generate n random integers between -100 to 100 and save them in array a.
  3. Print the generated array.
  4. Request the user to enter a number between 1 to n (as the kth least element).
  5. Call your Quick_select function to find and print the kth least element.

Part B.

Modify your algorithm to return the max k numbers from an unsorted array. (The average running time of your algorithm should be O(n)) (Example: a = [4 2 0 10 1 6], k = 3 ➔ output = [4 10 6])

 

  • Lab_4-pnqtcq.zip