0% found this document useful (0 votes)
3 views

Search Algo

Presentation on searching algorithm
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Search Algo

Presentation on searching algorithm
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 8

Introduction to search

techniques, essential
of search
Introduction to searching
Searching is the fundamental process of locating a specific element or item within a
collection of data. This collection of data can take various forms, such as arrays,
lists, or other structured representations.

The primary objective of searching is to determine whether the desired element


exists within the data, and if so, to identify its precise location or retrieve it.

Essential of searching
 Efficiency: Efficient searching algorithms improve program
performance.
 Data Retrieval: Quickly find and retrieve specific data from large
datasets.
 Problem Solving: Used in a wide range of problem-solving tasks.

 Search Analysis: Analyze the right searching approach as your


requirement.
Some of the types of searching algorithms:
Linear Search
Binary search
Ternary search
Jump search
Interpolation search, etc

In this presentation, we are going to discuss two important types of


search algorithms:

 Linear Search
 Binary Search
Linear Search
Linear Search or Sequential Search, is one of the simplest searching algorithms is which the algorithm
works by sequentially iterating through the whole array or list from one end until the target element is
found.

Pseudo Code:
LinearSearch(Array, key){
for each element in Array{
if element == key{
return the index of element
}
}
return “Not Found”
}
Binary Search
Binary Search is defined as a searching algorithm used in a sorted array by repeatedly
dividing the search interval in half.

Approach for Binary Search:


(In Ascending Sorted Array)
 Compare the target element with the middle element of the array.
 If the target element is greater than the middle element, then the search continues in the right
half.
 Else if the target element is less than the middle value, the search continues in the left half.
 This process is repeated until the middle element is equal to the target element, or the target
element is not in the array.
 If the target element is found, its index is returned, else -1 is returned.
Pseudo Code:

binarySearch(Array, key){
Low = 0
High = Array.length – 1
while (Low <= High) {
mid = (Low +High) / 2
if (Array[mid] == key)
return mid
else if (Array[mid] < key)
Low = mid + 1
else
High = mid – 1
}
return “Not found”
}
Time complexity of linear search:
 Best Case: O(1) – When the key is found at the middle element.
 Worst Case: O(N) – When the key is not present, and the search
space is
continuously halved.

Time complexity of binary search:


 Best Case: O(1) – When the key is found at the middle element.
 Worst Case: O(log N) – When the key is not present, and the search
space is continuously
halved.

You might also like