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

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 3PE
icon
Related questions
Question
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.
Transcribed Image Text: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.
Expert Solution
steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage