Question: Searching unsorted array with duplicate data items. Given array int B[10] = {10, 70, 20, 30, 25, 70 , 10, 25, 70, 50}; Design algorithm

  1. Searching unsorted array with duplicate data items.

Given array int B[10] = {10, 70, 20, 30, 25, 70 , 10, 25, 70, 50};

  1. Design algorithm int SearchUnsorted_First(int L[], int n, int k) that finds and returns the index of the first occurrence of k in L. If k is not found, -1 is returned. For example, the call SearchUnsorted_First(B, 10, 70); should return 1 (index of the first occurrence of 70 in the above array B).

The call: SearchUnsorted_First(B, 10, 15); should return -1.

  1. Design algorithm int SearchUnsorted_L(int L[], int n, int k) that finds and returns the index of the last occurrence of k in L. If k is not found, -1 is returned. For example, the call SearchUnsorted_L(B, 10, 70); should return 8 (index of the last occurrence of 70 in the above array B).

The call: SearchUnsorted_L(B, 10, 20); should return 2.

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!