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

CLASS PARTICIPATION (Search Algorithms)

A linear search checks each item in a list sequentially until it finds the target or reaches the end, making it slower for large lists. In contrast, a binary search operates on a sorted list by repeatedly dividing the search interval in half, resulting in faster performance. For the given array with a target value of 34, the linear search required 5 comparisons while the binary search only needed 1 comparison.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

CLASS PARTICIPATION (Search Algorithms)

A linear search checks each item in a list sequentially until it finds the target or reaches the end, making it slower for large lists. In contrast, a binary search operates on a sorted list by repeatedly dividing the search interval in half, resulting in faster performance. For the given array with a target value of 34, the linear search required 5 comparisons while the binary search only needed 1 comparison.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Answer the following questions based on what you have learned in our

discussion.

1. What is a linear search?

Answer: A linear search checks each item in a list one by one until it finds the target
or reaches the end. It’s easy to understand but can be slow if the target is far
down the list.

2. What is a binary search?

Answer: A binary search is a faster way to find something in a sorted list. It starts
by checking the middle item, then decides to search in either the left or right half.
It keeps splitting the list in half until it finds the target. This makes it quicker than
linear search for large lists.

3. Use linear and binary search algorithm to the following array and compare their
performance based on the number of comparisons (Target Value is 34).

54 45 12 67 34 27 78 91 83 8

Linear Search:
54 ≠ 34
45 ≠ 34
12 ≠ 34
67 ≠ 34
34 = 34 (Found!)

Linear Search Comparisons: 5

Binary Search:
mid = low+(high-low)/2
= 0+(9-0)/2
=4.5/4
34=34
The index 4 is 34 and the number that should get.
Binary Search Comparisons: 1

You might also like