Dsa Lab 03
Dsa Lab 03
Instructions:
Take snapshots of both input and output and provide a brief summary explaining what you
have learned in this lab.
Lab Tasks:
a. Write a C++ program that performs a Binary search
algorithm to find a target element in an array. Prompt the user to
enter the target value and output whether the element is found
in the array or not with target value location.
b. Modify the above program to count and display the number of
iterations performed during the binary search.
c. Create an array containing multiples of 5, starting from 5, up to a
reasonable size (e.g., 100). Then, use the binary search algorithm to find
the index of the element 35. Output whether 35 is present in the array
and, if present, the index of its first occurrence.
Instructions:
Take snapshots of both input and output and provide a brief summary explaining what you
have learned in this lab.
Lab Tasks:
a. Write a C++ program that performs a Binary search
algorithm to find a target element in an array. Prompt the user to
enter the target value and output whether the element is found
in the array or not with target value location.
INPUT:
OUPUT:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering
b. Modify the above program to count and display the number of
iterations performed during the binary search.
INPUT:
OUPUT:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering
c. Create an array containing multiples of 5, starting from 5, up to a
reasonable size (e.g., 100). Then, use the binary search algorithm to find
the index of the element 35. Output whether 35 is present in the array
and, if present, the index of its first occurrence.
INPUT:
OUPUT:
ZIAUDDIN UNIVERSITY
Faculty Of Engineering Science & Technology
(ZUFEST)
Department of Software Engineering
SUMMARY:
Three binary search-related tasks make up the given code. To locate a target value in an array in the first task, a
simple binary search technique is used. The same algorithm is used in the second task, but it also counts and
displays the number of iterations. In the third task, a target value is located within an array containing the first 100
multiples of 5 by using the binary search algorithm. In each job requests the user to input a target value and then
searches for it inside the array using the binary search method. After the search, the code displays whether the
element was found or not, along with the index of the element if it was found.