0% found this document useful (0 votes)
13 views6 pages

LINEAR and BINARY SEARCH

The document explains two search algorithms: Linear Search and Binary Search. Linear Search checks each element sequentially and can be used on both sorted and unsorted lists, while Binary Search is more efficient but requires a sorted list and divides the search interval in half repeatedly. It also compares the two methods in terms of efficiency and complexity.

Uploaded by

ayeshasabir724
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

LINEAR and BINARY SEARCH

The document explains two search algorithms: Linear Search and Binary Search. Linear Search checks each element sequentially and can be used on both sorted and unsorted lists, while Binary Search is more efficient but requires a sorted list and divides the search interval in half repeatedly. It also compares the two methods in terms of efficiency and complexity.

Uploaded by

ayeshasabir724
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

LINEAR and BINARY SEARCH

AYESHA SABIR 8-D


SEARCH ALGORITHMS:
A search algorithm is a method used to locate specific information within a
data structure or a problem's search space. It can retrieve information from
a data structure like an array or a tree, or it can help solve problems by
exploring the possible solutions in a search space. An algorithm set s out the
steps to solve a problem or complete a task. An algorithm can be used to
plan a program.

− There are two ways to search using search algorithm:

− Linear search algorithm

− Binary search algorithm

LINEAR SEARCH ALGORITHM:


A linear search is the simplest approach employed to search for an element
in a data set. It examines each element until it finds a match, starting at the
beginning of the data set, until the end. The search is finished and
terminated once the target element is located.it has four main steps:

1. Count through the list from the first item


2. Compare each item to the search term
3. If there is a match, the item is in the list

The computer has to look through every item in the list which a little bit
time taking but the easiest to find a search term.

PAGE 1 THANK YOU!!!


search??

Binary search algorithm:


Binary search is an efficient algorithm for finding an item from a sorted list
of items. It works by repeatedly dividing in half the portion of the list that
could contain the item, until you've narrowed down the possible locations to
just one.

A faster way to search a list is called Binary search. binary means “made of
two parts” or “divided into two”.

HOW IT WORKS?
1. Sort the list into order.
2. Find the midpoint of the list.
3. Compare the search term to the midpoint. Is it higher or lower?
4. Split the list in half and keep the higher or lower half
5. Keeps splitting the list in half only one item.

ATTENTION!!!
You can only use the binary search when the list you have is sorted.

The procedure in detail…


Let’s take the example of a list of students.

PAGE 2 THANK YOU!!!


First count the number of total students in the list then find the middle
student. The student in the middle position in a list is called the midpoint.
Now you have to split the list in two halves. One half will have the values
smaller than the midpoint and the other half will have the midpoint value
and all the bigger values. As the list is sorted it will be in the alphabetical
order so the student you want to find just check the alphabet of his/her name
and then just go though that which half contains that alphabet. Keep the half
with that alphabet. Now you have to repeat the process until only one
student remains. The work looks time taking but the computer can do it in a
few minutes.

RESULT!!!
If the search term is founded it displays you have found it and if not found
it displays the search term is not in the list.

“Comparing the searches”

LINEAR BINARY
Can be used on both sorted and Can only be used if the list is sorted
unsorted lists

Checks each element sequentially Divides the search interval in half


repeatedly

Less efficient for large data sets More efficient to large data sets

Simpler to implement More complex to implement

PAGE 3 THANK YOU!!!


PAGE 4 THANK YOU!!!
PAGE 5 THANK YOU!!!

You might also like