Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in c++ AIM: Write a program to do Linear Search using a given Search Key in an un- sorted Linear Array A which has N

in c++

image text in transcribed

image text in transcribed

AIM: Write a program to do Linear Search using a given Search Key in an un- sorted Linear Array A which has N values in it. Description: The linear search compares each element of the array with the search key until the search key is found. To determine that a value is not in the array, the program must compare the search key to every element in the array A'. It is also called "Sequential Search" because it traverses the data sequentially to locate the element. Algorithm: (Linear Search) LINEAR_SEARCH (A, N, SKEY) Here A is a Linear Array with N elements and SKEY is a given item of information to search. This algorithm finds the location of SKEY in A and if successful, it returns its location otherwise it returns -1 for unsuccessful. 1. Repeat step-2 for K = 0 to N-1 2. if(A [K] = SKEY) return K [Successful Search] [ End of loop of step-1 ] 3. return -1 [Un-Successful] 4. End. AIM: _Write a program to do Binary Search using a given Search Key in a Sorted Linear Array A which has N values in it. Description: The binary search algorithm can only be used with sorted array and eliminates one half of the elements in the array being searched after each comparison. The binary search algorithm applied to our array A works as follows: Algorithm: (Binary Search) Here is a sorted Linear Array with N elements stored in it in sorted order and SKEY is a given item of information to search. This algorithm finds the location of SKEY in A and if successful, it returns its location otherwise it returns -1 for unsuccessful. Binary Search (A, N, SKEY) [Initialize segment variables.] 1. Set START=0, END=N-1 and MID=int((START+END)/2). 2. Repeat Steps 3 and 4 while START

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

Recommended Textbook for

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions

Question

What is an interface? What keyword is used to define one?

Answered: 1 week ago