Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Searching sequentially a sorted array with duplicate items . Design algorithm int SearchSorted_Asc_Du(int L[], int n, int k) that finds and returns the index of

  1. Searching sequentially a sorted array with duplicate items.

    1. Design algorithm int SearchSorted_Asc_Du(int L[], int n, int k) that finds and returns the index of the first occurrence of k in L sorted in ascending order. If k is not found, -1 is returned. For example, given array int F[10] = {20, 30, 30, 50, 60, 60 , 60, 90, 100, 110}; sorted in ascending order. The call SearchSorted_ Asc_Du(F, 10, 60); should return 4 (index of the first occurrence of 60 in the above array F).

The call: SearchSorted_ Asc_Du (F, 10, 55); should return -1(not found).

  1. Design algorithm int SearchSorted_Des_Du(int L[], int n, int k) that finds and returns the index of the last occurrence of k in L sorted in descending order. If k is not found, -1 is returned. For example, given array int G[12] = {120, 110, 110, 110, 80, 70 , 70, 50, 40, 30, 30, 30}; sorted in descending order. The call SearchSorted_ Dec_Du(G, 12, 70); should return 6 (index of the last occurrence of 90 in the above array G).

The call: SearchSorted_ Dec_Du(G, 12, 10); should return -1(not found).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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