Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Linear Search (LS)

Md. Mehedi Hassan


ID: IT 19603, Session: 2018-2019, M.Sc. (Engg.) student,
Department of Information and Communication Technology (ICT),
Mawlana Bhashani Science and Technology University
Santosh, Tangail-1902, Bangladesh.

28 January
Md. Mehedi Hassan 1
2022
Searching

 Searching is the process of finding the location of


the specified element in a list.

 Searching in data structure refers to the process of


finding the required information from a collection
of items stored as elements in the computer
memory. These sets of items are in different forms,
such as an array, linked list, graph, or tree.

Md. Mehedi Hassan 2


Searching

 Types of searching:

 Array search
 Linear search/Sequential search
 Binary search/Interval search

 Tree or graph search


 BFS (Breadth First Search)
 DFS (Depth First Search)

Md. Mehedi Hassan 3


Linear Searching

 A linear search or sequential search is a method


for finding an element within a list. It
sequentially checks each element of the list until
a match is found or the whole list has been
searched.

Md. Mehedi Hassan 4


Start
A [] = Input Array
Svalue = Search Value
max size = Maximum size of input array Read (Svalue), i = 0
i = Starting index
Count = Number of elements
No Yes
Count = -1

No Yes
A[i]=Svalue Array is empty

No Yes
i >= max size Value is found

i = i+1
Value is not found

Stop
Flowchart of Linear Search
Linear Searching

Md. Mehedi Hassan 6


Linear Searching Complexity

 Worst-case complexity: O(n) – This case occurs when the


search element is not present in the array.

 Best case complexity: O(1) – This case occurs when the


first element is the element to be searched.

 Average complexity: O(n) – This means when an


element is present somewhere in the middle of the
array.

Md. Mehedi Hassan 7


Thank You
Any Question ?

28 January
Md. Mehedi Hassan 8
2022

You might also like