Question: Question 3 - Finding a missing element in an array [30%] You are given an array A[0,1,,n2,n1] of n entries that contains n distinct integers

 Question 3 - Finding a missing element in an array [30\%]

Question 3 - Finding a missing element in an array [30\%] You are given an array A[0,1,,n2,n1] of n entries that contains n distinct integers within the range p to p+n (where p is a positive integer). Since there are n+1 integers in the range and there are only n entries in the array A, exactly one integer in the range is missing in the array. In this question, your mission is to find the missing nymber. (a) [10\%] Design a brute-force algorithm that searches all possible integers from p to p+n, and returns the missing integer. Determine the time complexity of your algorithm. (Note: Describe your algorithm in pseudo code, not verbally.) (b) [10%] Design an algorithm that considers the sum of the entries A[0..n1] and compares that to the sum of the range [pp+n] to deduce the missing integer. Determine the time complexity of your algorithm. (c) [10\%] Algorithm 3.1 iterates through the array entries A[0,1,,n2,n1]. The algorithm splits the array into two halves, with elements in the first half smaller than any in the second half. Assume each swap takes O(1) time. The algorithm then determines which half is missing an element and re-applies the algorithm on that half. Analyze the time complexity of this algorithm. Note; you may assume n=2k1 for some integer k

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!