Computer Science
Linear Search
Linear search is a simple search algorithm that checks each element in a list or array until the desired element is found. It is a brute-force approach that is easy to implement but can be inefficient for large datasets.
Written by Perlego with AI-assistance
Related key terms
1 of 5
10 Key excerpts on "Linear Search"
- No longer available |Learn more
Data Structures and Program Design Using Java
A Self-Teaching Introduction
- D. Malhotra, N. Malhotra(Authors)
- 2020(Publication Date)
- Mercury Learning and Information(Publisher)
6SEARCHING AND SORTING
6.1 Introduction to Searching
As we all know, computer systems are often used to store large numbers. We require some search mechanism to retrieve a specific record from the large amounts of data stored in our computer system. Searching means to find whether a particular data item exists in an array/list or not. The process of finding a particular value in a list or an array is called searching.If that particular value is present in the array, then the search is said to be successful and the location of that particular value is returned by the searching process. However, if the value does not exist, then searching is said to be unsuccessful. There are many different searching algorithms, but three of the popular searching techniques are as follows:- Linear Search or Sequential Search
- Binary Search
- Interpolation Search
6.2 Linear Search or Sequential Search
A Linear Search is also called a sequential search. This is a very simple technique used to search for a particular value in an array. A Linear Search works by comparing the value of the key being searched for with every element of the array in a linear sequence until a match is found. A search will be unsuccessful if all the data elements are readand the desired element is not found. The following are some important points:- It is the simplest way to search an element in a list.
- It searches the data element sequentially, no matter whether the array is sorted or unsorted.
For example: Let us take an array of ten elements, which is declared as follows:int array[10] = {87, 25, 14, 39, 74, 1, 99, 12, 30, 67};and the value to be searched for in the array is VALUE = 74, and then search to find whether 74 exists in the array or not. If the value is present, then its position is returned. Here the position of VAL = 74 is POS = 4 (index starting from zero), which has been shown by the following figures: - No longer available |Learn more
Data Structures and Program Design Using Python
A Self-Teaching Introduction
- D. Malhotra, N. Malhotra, Dheeraj Malhotra, Neha Malhotra(Authors)
- 2020(Publication Date)
- Mercury Learning and Information(Publisher)
CHAPTER 6SEARCHING AND SORTING6.1 INTRODUCTION TO SEARCHINGComputer systems are often used to store large numbers. We require some search mechanism to retrieve a specific record from the large amounts of data stored in our computer system. Searching means to find whether a particular data item exists in an array/list or not. The process of finding a particular value in a list or an array is called searching. If that particular value is present in the array, then the search is said to be successful and the location of that particular value is returned by the searching process. However, if the value does not exist, then searching is said to be unsuccessful. There are many different search algorithms, but three of the popular searching techniques are as follows:• Linear Search or Sequential Search• Binary Search• Interpolation SearchHere, we will discuss all these methods in detail.6.2 Linear Search OR SEQUENTIAL SEARCHA Linear Search is also called a sequential search. This is a very simple technique used to search for a particular value in an array. A Linear Search works by comparing the value of the key being searched for with every element of the array in a linear sequence until a match is found. A search will be unsuccessful if all the data elements are read and the desired element is not found. The following are some important points:• It is the simplest way to search an element in a list.• It searches the data element sequentially, no matter whether the array is sorted or unsorted.For Example – let us take an array/list of ten elements, which is declared as follows:array = [87, 25, 14, 39, 74, 1, 99, 12, 30, 67]The value to be searched for in the array is VALUE = 74, and then we search to find whether 74 exists in the array. If the value is present, then its position is returned. Here, the position of VAL = 74 is POS = 4 (index starting from zero), which is shown in the following figures.Pass 1 - No longer available |Learn more
- D. Malhotra, N. Malhotra(Authors)
- 2019(Publication Date)
- Mercury Learning and Information(Publisher)
6SEARCHING AND SORTING
In This Chapter• Introduction to searching• Linear Search or sequential search• Binary search• Interpolation search• Introduction to sorting• External sorting• Summary• Exercises6.1Introduction to Searching
As we all know, computer systems are often used to store large numbers. We require some search mechanism to retrieve a specific record from the large amounts of data stored in our computer system. Searching means to find whether a particular data item exists in an array/list or not. The process of finding a particular value in a list or an array is called searching . If that particular value is present in the array, then the search is said to be successful and the location of that particular value is returned by the searching process. However, if the value does not exist then searching is said to be unsuccessful. There are many different searching algorithms, but three of the popular searching techniques are as follows:•Linear Search or Sequential Search •Binary Search •Interpolation Search Here, we will discuss all these methods in detail.6.2Linear Search or Sequential Search
A Linear Search is also called a sequential search. This is a very simple technique used to search for a particular value in an array. A Linear Search works by comparing the value of the key being searched for with every element of the array in a linear sequence until a match is found . A search will be unsuccessful if all the data elements are read and the desired element is not found. The following are some important points:•It is the simplest way to search an element in a list. •It searches the data element sequentially, no matter whether the array is sorted or unsorted.For example – Let us take an array of ten elements, which is declared as follows:int array[10] = {87, 25, 14, 39, 74, 1, 99, 12, 30, 67};and the value to be searched for in the array is VALUE = 74, and then search to find whether 74 exists in the array or not. If the value is present, then its position is returned. Here the position of VAL = 74 is POS = 4 (index starting from zero), which has been shown by the following figures: - No longer available |Learn more
Data Structures and Program Design Using C
A Self-Teaching Introduction
- D. Malhotra, N. Malhotra(Authors)
- 2018(Publication Date)
- Mercury Learning and Information(Publisher)
C H A P T E R 6 SEARCHING AND SORTING In This Chapter ● ● Introduction to searching ● ● Linear Search or sequential search ● ● Binary search ● ● Interpolation search ● ● Introduction to sorting ● ● External sorting ● ● Summary ● ● Exercises 6.1 Introduction to Searching As we all know, computer systems are often used to store large num- bers. We require some search mechanism to retrieve a specific record from the large amounts of data stored in our computer system. Searching means to find whether a particular data item exists in an array/list or not. The process of finding a particular value in a list or an array is called search- ing. If that particular value is present in the array, then the search is said to be successful and the location of that particular value is returned by the searching process. However, if the value does not exist or we can say that if 250 • DATA STRUCTURES AND PROGRAM DESIGN USING C the value is not present in the array, then searching is said to be unsuccess- ful. There are many different searching algorithms, but three of the popular searching techniques are as follows: • Linear Search or Sequential Search • Binary Search • Interpolation Search Hence, we will discuss all these methods in detail. 6.2 Linear Search or Sequential Search A Linear Search is also called a sequential search. This is a very sim- ple technique used to search a particular value in an array. A Linear Search works by comparing the value of the key being searched for with every element of the array in a linear sequence until a match is found. A search will be unsuccessful if all the data elements are read and the desired element is not found. The following are some important points: • It is the simplest way to search an element in the list. • It searches the data element sequentially, no matter whether the array is sorted or unsorted. - eBook - PDF
A Textbook of Data Structures and Algorithms, Volume 3
Mastering Advanced Data Structures and Algorithm Design Strategies
- G. A. Vijayalakshmi Pai(Author)
- 2022(Publication Date)
- Wiley-ISTE(Publisher)
16 Searching 16.1. Introduction Search (or searching) is a commonplace occurrence in everyday life. Searching for a book in the library, searching for a subscriber’s telephone number in the telephone directory and searching for one’s name in the electoral rolls are some examples. In the discipline of computer science, the problem of search has assumed enormous significance. It spans a variety of applications or rather disciplines, beginning from searching for a key in a list of data elements to searching for a solution to a complex problem in its search space amidst constraints. Innumerable problems exist where one searches for patterns – images, voice, text, hypertext, photographs and so forth – in a repository of data or patterns, for the solution of the problems concerned. A variety of search algorithms and procedures appropriate to the problem and the associated discipline exist in the literature. In this chapter, we enumerate search algorithms pertaining to the problem of looking for a key K in a list of data elements. When the list of data elements is represented as a linear list, the search procedures of Linear Search or sequential search, transpose sequential search, interpolation search, binary search and Fibonacci search are applicable. When the list of data elements is represented using nonlinear data structures such as binary search trees or AVL trees or B trees and so forth, the appropriate tree search techniques unique to the data structure representation may be applied. Hash tables also promote efficient searching. Search techniques such as breadth first search and depth first search are applicable on graph data structures. In the case of data representing an index of a file or a group of ordered elements, indexed 94 A Textbook of Data Structures and Algorithms 3 sequential search may be employed. This chapter discusses all the above-mentioned search procedures. - eBook - PDF
- Rex Porbasas Flejoles(Author)
- 2019(Publication Date)
- Arcler Press(Publisher)
FUNDAMENTALS OF Linear Search ALGORITHM CHAPTER 2 CONTENTS 2.1. Introduction ...................................................................................... 36 2.2. Theory of The Linear Search Algorithm .............................................. 38 2.3. Modified Linear Search Technique With One Middle Component ..... 39 2.4. Modified Linear Search Technique With Two Middle Components .... 41 2.5. Two-Way Linear Search ..................................................................... 45 2.6. Proof of Accuracy for Two-Way Linear Search .......... ................ ......... 45 2.7. Analysis And Comparison of Performance ......................................... 46 References ............................................................................................... 48 Introduction to Search Algorithms 36 2.1. INTRODUCTION Search methods such as ternary search, Linear Search and binary search play a vital role in numerous engineering and scientific fields. From last few decades searching method has a substantial interest in Data Structure. Designing an algorithm to improve the searching methods is a significant task now a day. Searching the component in a considerable lesser time from the group of data accumulated in the system has an enormous importance in Computer Applications (McGraw-Hill, 2005; Arora et al., 2012). Out of all the search methods the Linear Search also called the sequential search is the very basic and uncomplicated search algorithm. Sequential search algorithm is created over all the items individually until each item is checked, if the match exists then that specific item is returned or else the search goes on till the data collection concludes (Knuth, 1998; Cormen et al., 2009). The most terrible performance situation for the Linear Search algorithm is that it requires to loop throughout the whole data collection because either the item is not found or it is the last one. - eBook - PDF
- Kyla McMullen, Elizabeth Matthews, June Jamrich Parsons, , Kyla McMullen, Kyla McMullen, Elizabeth Matthews, June Jamrich Parsons(Authors)
- 2021(Publication Date)
- Cengage Learning EMEA(Publisher)
However, as you add more contacts to the list, the task gets more difficult because the search space, or the amount of data you are searching, gets larger. Figure 23-1 Contacts in a cell phone Kikinunchi/Shutterstock.com, Sapann Design/Shutterstock.com Copyright 2022 Cengage Learning. All Rights Reserved. May not be copied, scanned, or duplicated, in whole or in part. Due to electronic rights, some third party content may be suppressed from the eBook and/or eChapter(s). Editorial review has deemed that any suppressed content does not materially affect the overall learning experience. Cengage Learning reserves the right to remove additional content at any time if subsequent rights restrictions require it. Module 23 Search algorithMS 413 23.2 PERFORMING A Linear Search Looking for a Needle in a Haystack (23.2.1, 23.2.2) Sometimes, searching for data seems like you are looking for a needle in a haystack. The search space contains a huge amount of information and you need to find the one value that you need. Consider the unordered list of contacts shown in Figure 23-2. Figure 23-2 Unordered contact list Sapann Design/ Shutterstock.com Suppose you need to call Sandra Taylor but you have no idea where her name is located within your unor- dered list of contacts. Your first instinct might be to scroll through the entire list, looking at each name one at a time to find Sandra Taylor. This type of search algorithm is called Linear Search, where you look at each item in a list one by one to find what you are looking for. Linear Search is the simplest search algorithm when the information you are searching is in a random order. You typically use a Linear Search algorithm when your data is stored in an array or a list. Generally, Linear Search can be used for any contiguous data structure. When coding a Linear Search algorithm, a loop is often used. Following is the algorithm for Linear Search: Specify a cursor variable to start searching at the beginning of the search space. - eBook - ePub
Data Structures using C
A Practical Approach for Beginners
- Amol M. Jagtap, Ajit S. Mali(Authors)
- 2021(Publication Date)
- Chapman and Hall/CRC(Publisher)
Sorting is an important step to speed up the subsequent operations on a data structure, like comparing two lists, assigning processes to the processor based on priority, etc. It is easier and faster to search the position of elements in a sorted list than unsorted. Sorting algorithms can be used in a program to sort an array for later searching or writing out of an ordered file or report. Computers spend more time in sorting than any other operation, historically 25% on mainframes. Sorting is the best-studied problem in computer science, with a variety of different algorithms known. Sorting is important because once a set of elements is sorted, many more other problems become easy to solve.7.2 Sequential Search or Linear Search
7.2.1 Linear Search or Sequential Search Basics
In Linear Search, we access each element of an array one by one sequentially and see whether or not it is desired element. A search will be unsuccessful if all the elements are accessed, and the desired element is not found.7.2.2 Efficiency of Linear Search
- Best-case time complexity:
Searched element is available at the first or almost first place that is at a [0].
T(n) = Ω (1)
- Worst-case time complexity:
Searched element is available at the end of array that is at a [n – 1] or it is not available in the array.
T(n) = O(n)
- Average-case time complexity:
Searched element is present nearly at the middle of the list is called as average case in Linear Search.
Average case = (Best case + Worst case)/2 = (1+n) /2T(n) = Θ (n)
Time complexity:Best-case time complexity T(n) = Ω (1) Average-case time complexity T(n) = Θ (n) Worst-case time complexity T(n) = O(n) 7.2.3 Algorithm of Linear Search
- Start.
- Traverse the array using any other loop.
- In every iteration, compare the key element value with the current value of the array.
- If the value gets a match, then print the current position or location of the array element.
- If the value does not match, move on to the next array element by incrementing the array index by one.
- If the last element in the array is checked with key elements and no match is found, then print the key element that is not present in your array or list.
- eBook - PDF
- Sourabh Pal(Author)
- 2023(Publication Date)
- Arcler Press(Publisher)
To confirm the presence of a specific object, you must search the whole collection. Let’s have a look at the following array: i I II III IV V VI VII VIII A 35 17 26 34 8 23 49 9 For example, if we require to look for the value x = 34 in this array (A). We require a comparison of x with (35, 17, 26, 34), with every element being compared just once each. Position 4 contains the required number (34) which is present. Thus, after four comparisons have been performed, we return 4. If the search for the value x = 19 in this specific array is necessary. To complete this task, we must compare x with every one of the following elements: (35, 17, 26, 34, 8, 23, 49, 9), every element once. After going Fundamentals of Search Algorithms 63 through all of the objects in this array, we are unable to locate number 19. Hence, we return “18 not found.” In this particular situation, we have carried out a total of eight comparisons. Most of the time, it is necessary to do a determination (search) of x in an array of unordered objects that has n entries. It may be necessary to search through the entire array to find the appropriate response in some cases. It entails the implementation of a set of n contrasts. It is possible to create the following equation to express the number (n) of executed comparisons: T (n) = n (Brin, 1995; Bozkaya and Ozsoyoglu, 1999). 3.3. ORDERED Linear Search Assume that the array you’re given is sorted. In these circumstances, a search across the entire list to identify a specific object or enquire about its existence in the collection of objects is not required. For example, if a collection of test results is sorted by name, it is not necessary to look beyond the “J”s to see if the exam score for “Jacob” is included in the collection or not included. The ordered Linear Search algorithms are the outcome of a simple modification of the algorithm (Brusoni et al., 1995; Console et al., 1995; Buneman et al., 1998). - eBook - ePub
Data Structures Through C++
Experience Data Structures C++ through animations
- Yashavant Kanetkar(Author)
- 2020(Publication Date)
- BPB Publications(Publisher)
Chapter 09Searching and Sorting
Seek Me Out, Sort Me Out
Why This Chapter Matters?
It would be an interesting statistic to find out how much time pre-computer-age generations spent in searching things and arranging them in an order. What a colossal waste it must have been to do these things manually! When history of computing is written ‘searching’ and ‘sorting’ would be right there at the top, as entities responsible for changing the way people do work.W e often spend time in searching some thing or the other. If the data is kept properly in some sorted order then searching becomes very easy. Think of searching a word's meaning from an unordered list of words and then you will appreciate the way a dictionary is designed. In this chapter we are going to discuss different types of searching and sorting methods. Let us start with searching methods.Searching
Searching is an operation that finds the location of a given element in a list. The search is said to be successful or unsuccessful depending on whether the element that is to be searched is found or not. Here, we will discuss two standard searching methods—Linear Search and Binary search.Linear Search
This is the simplest method of searching. In this method, an element is searched in the list sequentially. This method can be applied to a sorted or an unsorted list. Searching in unsorted list starts from the 0th element and continues until the element is found or the end of list is reached. As against this, searching in an ascending order sorted list starts from 0th element and continues until the element is found or an element whose value is greater than the value being searched is reached.Following program implements Linear Search method for an unsorted as well as a sorted array.Honest Solid Code
Program 9-1. Implementation of Linear Search algorithm
Index pages curate the most relevant extracts from our library of academic textbooks. They’ve been created using an in-house natural language model (NLM), each adding context and meaning to key research topics.









