Question: In this assignment, you are required to come up with a (nlogn) algorithm (that would make use of the binary search algorithms to determine the

In this assignment, you are required to come up with a (nlogn) algorithm (that would make use of the binary search algorithms to determine the indexes of first and last occurrence of any search key) to print the number of occurrences of each unique key/integer in a sorted array. You are given a startup code that inputs the number of elements and the maximum value for any element in the array, generates a random array of that many elements and gets it sorted.In this assignment, you are required to come up with a (nlogn)

(T-1) Implement the functions findIndexOfFirstOccurrence (..)andfindIndexOfLastOccurrence(...)that would make use of the binary search approach to determine the indexes of first and last occurrence for any key in a sorted array. (T-2) In the main function, you will then develop and implement a (nlogn) algorithm that would make use of the functions implemented in T-1 and determine and print the count (number of occurrences) of each unique integer/key in the sorted array. (T-3) Provide a theoretical time complexity analysis of the algorithm you implemented in task T-2 to determine and print the number of occurrences of each unique integer/key in the sorted array by making use of the (logn) algorithms implemented in task T-1. Show that the total number of times the binary search algorithms of T-1 are called is (n) so that the overall time complexity of the algorithm implemented in T-2 is ( nlogn ). (T-4) Run your code for an array/list size of 20 integers and maximum value for any integer being 5

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!