Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this problem, you are given a sorted int array data of size N (sorted in ascending order), where each element of data is some

In this problem, you are given a sorted int array data of size N (sorted in ascending order), where each element of data is some value between 0 and M 1, along with an int array counts of size N. You must write a recursive method that counts the number of occurrences of each element in the data array. For example, if you are given the array data = { 0, 1, 1, 1, 2, 2, 3, 4, 4, 4 }, with N = 10 and M = 5, then after your recursive method returns, the counts array should look like this: counts = { 1, 3, 2, 1, 3 }. You may assume that M = counts.length. (a) Give the most efficient recursive algorithm that you can think of that solves this problem. Give your solution in the form of an implementation of the following method:

image text in transcribed

b)Give the recurrence formula for the worst-case running time of your countsRec algorithm, assuming N = 2k, where k is a non-negative integer.

static void countsRec(int[] data, int low, int high, int[] counts) { // Counts the occurrences of the elements in // data[low), ..., data [high] // Returns with counts [0] = # occurrences of 0 in data, // counts [1] # occurrences of 1 in data, etc. // If you leave this part blank, you will automatically earn // 6 points and I will ignore your answers on the next page

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

Students also viewed these Databases questions

Question

What do Dimensions represent in OLAP Cubes?

Answered: 1 week ago