Starting Out with C++ from Control Structures to Objects (9th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 8, Problem 1RQE

Explanation of Solution

Linear search:

  • Linear search or sequential search is the process of searching for a particular element that is present in the array one by one till the last element in the search element is found.
  • The search uses a loop that iterates from the beginning till the last element to find the search element.
  • The search continues for all the elements present in the array until the last element.
  • The search of the target element is made after comparing it with each and every element that is present in the array.
  • The search process continues until the target value or search value is found.
  • If the search element is not found, the search gets returned unsuccessfully.

Number of comparisons in linear search:

To search the target element that is present in the array, the search element is compared with the number of elements present in the array. Even if the array contains 500 elements, the search process continues 500 times if the search element is present at the end of the array.

Maximum number of comparison = N

Average number of the comparison = N/2

Therefore, linear search is called sequential search because the search element is found by comparing each element present in the array using a loop one after the other, until the search element is found.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
There are two advantages of utilizing linear search in comparison to binary search?
Is there a reason why binary search is faster than linear search? Put out a defense of your actions.
In what ways does binary search outperform sequential search?

Chapter 8 Solutions

Starting Out with C++ from Control Structures to Objects (9th Edition)

Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning