Question: An integer array is one-repeating if it contains at most one integer that occurs more than once. For example, (5,3,2,5, 1,5) is one-repeating as 5

 An integer array is one-repeating if it contains at most one

An integer array is one-repeating if it contains at most one integer that occurs more than once. For example, (5,3,2,5, 1,5) is one-repeating as 5 is the only entry repeating (3 times). Let A be an integer array of size n containing integers between 1 and n. Our goal is to determine a longest one-repeating subarray of A. For example, A = (3,1,5, 3, 2,5, 1,5, 3, 4] is not one-repeating (5, 3, and 1 appear more than once). The longest one-repeating subarray of A is [5, 3, 2,5,1, 5]. No one-repeating subarray of size 7 exists. (a) Describe an O(n) time algorithm that finds the longest one-repeating subarray which starts at position i > 1, i.e., entry A[i] is the i-th element of the subarray. Recall that all integers in A are between 1 and n. For the given example A and i = 2, the algorithm should return (1,5, 3, 2,5]. (b) Design and describe an O(na) time algorithm that finds a longest one-repeating sub- array in A by using (a). (c) Suppose subarray A[...], j

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!