Discrete Math List all the steps used to search for 10 in th
Discrete Math
List all the steps used to search for 10 in the sequence 1, 3, 4, 5, 6, 8, 9, 11 using
a. a linear search
b. a binary search
Solution
a) We compare 10 with 1 as it is not equal we move on
We compare 10 with 3 as it is not equal we move on
We compare 10 with 4 as it is not equal we move on
We compare 10 with 5 as it is not equal we move on
We compare 10 with 6 as it is not equal we move on
We compare 10 with 8 as it is not equal we move on
We compare 10 with 8 as it is not equal we move on
We compare 10 with 11 as it is not equal we end the process as we reached the end of the sequence.
b) We compare 10 with 5 as it is less than 10 we move forward
We compare 10 with 8 as it is less than 10 we move forward
We compare 10 with 9 as it is less than 10 we move forward
We compare 10 with 11 as it is less than 10, so now we need to move forward but we already reached the end so we end the process.
