Assignment 03 Solution: TUESDAY 06/12/2022. Warning
Assignment 03 Solution: TUESDAY 06/12/2022. Warning
Assignment 03 Solution: TUESDAY 06/12/2022. Warning
ASSIGNMENT 03
SOLUTION
Marks: 10
NAME: ______________________________________________
CLASS:_______________________________________________
REG. NO. ____________________________________________
COURSE:_____________________________________________
COURSE CODE:________________________________________
Theoretical Assignment
Read Carefully:
• The deadline for this assignment is before or on TUESDAY 06/12/2022.
WARNING: This is an individual assignment; you must solve it by yourself. Any form of plagiarism
will result in receiving a zero on the assignment.
WARNING: Late submissions will not be accepted. Any assignment submitted after the cutoff
time will receive zero.
• You have to answer and submit your solution in the SOFTCOPY form on LMS.
Level of problem Is outside problems encompassed by standards and standard practice for professional
computing
The solution must be designed by applying the following attributes/characteristics
1|Page
CS Department, BUKC 2 Semester 05 (Fall 2022)
CSC-321: DAA Assignment 03
Binary search is a classical algorithm. Given an array A[1..n] sorted in ascending order, binary search
can find whether an element b is in array A. The algorithm works as follows:
binary_search(A[1..n], b)
If n <= 2 then check whether b is in A by looking through all elements.
Let k = n/2
Partition A into B, C where B contains A [1...k-1], and C contains A[k+1..n]
If A[k] == b then b is in array A
If A[k] > b then call binary_search(B, b)
If A[k] < b then call binary_search(C, b)
(Note: you can also describe this algorithm as: When length of A is at least 3, compare b against the
middle element in A, if b is larger than search in the right half of A, if b is smaller than search in the
left half of A.)
Answer:
Given an arbitrary number of inputs (n), it will only require the algorithm to perform one action to
With (n) number of inputs the algorithm will still need to perform more than 1 step, however, with
each new step it performs, the ratio of inputs to remaining steps decreases, with the number of
Taking in (n) number of inputs the algorithm will perform (n) steps to completion.
***********************************