Question
I want a visual studio c++ programming code for the following task. Q1. If you have a sorted array you can use a very efficient
I want a visual studio c++ programming code for the following task.
Q1. If you have a sorted array you can use a very efficient (in terms of time!) algorithm to find any element of your interest in the array.
The array is sorted so you begin your search by comparing the search number with the middle index of the array. How will you get to the middle index? Since the array is sorted if the search number is smaller than the middle index value then it can only be in the first half of the array and you need not look at any element in the last half of the array. Again you compare the search number with the middle index of the first half of the array and check if it is larger or smaller. You repeat these steps, discarding one half of the array everytime. You will stop this algorithm only when either you have found the number you are looking for OR when the portion of the array you are searching from is only the size of a single element.
You may look at youtube for a pictorial explanantion of the binary search algorithm. You are expected to implement Binary Search Algorithm over a sorted list.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started