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

Searching Algorithms 4

This document discusses different searching algorithms. It begins by defining searching algorithms as processes for finding the location of an element in a data structure. There are two main categories of searching algorithms: sequential search and interval search. Sequential search involves linearly traversing an unsorted list or array and checking each element. Interval search algorithms like binary search are more efficient and work by repeatedly dividing the search space in half when the data is sorted. The document provides examples of linear search, binary search, and jump search algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

Searching Algorithms 4

This document discusses different searching algorithms. It begins by defining searching algorithms as processes for finding the location of an element in a data structure. There are two main categories of searching algorithms: sequential search and interval search. Sequential search involves linearly traversing an unsorted list or array and checking each element. Interval search algorithms like binary search are more efficient and work by repeatedly dividing the search space in half when the data is sorted. The document provides examples of linear search, binary search, and jump search algorithms.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

150

LESSON 1 SEARCHING ALGORITHM


Searching in data structure refers to the process of finding location LOC of an element in a list. This is
one of the important parts of many data structures algorithms, as one operation can be performed on an element
if and only if we find it. Various algorithms have been defined to find whether an element is present in the
collection of items or not. This algorithm can be executed on both internal as well as external data structures.
The efficiency of searching an element increases the efficiency of any algorithm.

Lesson Objectives:
At the end of this lesson, you will be able to:
• Learn what is searching algorithm.
• Identify the categories of searching algorithm.
• Analysed different searching algorithm.

WHAT IS SEARCHING ALGORITHM


• Searching Algorithms are designed to check for an element or
retrieve an element from any data structure where it is stored.

TWO CATEGORIES
1. SEQUENTIAL SEARCH
The list or array is traversed sequentially and every element is
checked.

Learning Module on PROG 201


151

ALGORITHM

LINEAR SEARCH C++ IMPLEMENTATION

OUTPUT

Learning Module on PROG 201


152

2. INTERVAL SEARCH
• These algorithms are specifically designed for searching in sorted data-structures. These type of
searching algorithms are much more efficient than Linear Search as they repeatedly target the center of
the search structure and divide the search space in half.
• Binary search is a fast search algorithm with run-time complexity of Ο(log n). This search algorithm
works on the principle of divide and conquer. For this algorithm to work properly, the data collection
should be in the sorted form.
• Binary search looks for a particular item by comparing the middle most item of the collection. If a match
occurs, then the index of item is returned. If the middle item is greater than the item, then the item is
searched in the sub-array to the left of the middle item. Otherwise, the item is searched for in the sub-
array to the right of the middle item. This process continues on the sub-array as well until the size of the
subarray reduces to zero.

Learning Module on PROG 201


153

Learning Module on PROG 201


154

Learning Module on PROG 201


155

Learning Module on PROG 201


156

OUTPUT

Learning Module on PROG 201


157

JUMP SEARCH

• Jump Search is a searching algorithm for sorted arrays.


• The basic idea is to check fewer elements (than linear search) by jumping ahead by fixed steps or
skipping some elements in place of searching all elements.
• Let’s consider the following array: (0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610). Length of
the array is 16. Jump search will find the value of 55 with the following steps assuming that the block
size to be jumped is 4.
Note: To get the block size to be jumped is by getting the square root of the

ALGORITHM

SUMMARY
• Searching Algorithms are designed to check for an element or retrieve an element from any data
structure where it is stored.
• In sequential search the list or array is traversed sequentially and every element is checked.
• In interval search algorithms are specifically designed for searching in sorted data-structures. These type
of searching algorithms are much more efficient than Linear Search as they repeatedly target the center
of the search structure and divide the search space in half.
• Binary search looks for a particular item by comparing the middle most item of the collection

Learning Module on PROG 201

You might also like