Knowee
Questions
Features
Study Tools

Suppose following numbers are sorted in an array A:32,51,26,84,63,21,11,54Using Binary search find the location of item  26,11 and 99.Answer text

Question

Suppose following numbers are sorted in an array A:

32, 51, 26, 84, 63, 21, 11, 54

Using Binary search find the location of item
26, 11 and 99.

Answer text

🧐 Not the exact question you are looking for?Go ask a question

Solution

Sure, let's start with the binary search process. But first, we need to make sure that the array is sorted in ascending order. The given array is: 32, 51, 26, 84, 63, 21, 11, 54. Let's sort it first:

Sorted array: 11, 21, 26, 32, 51, 54, 63, 84

Now, let's find the items using binary search:

  1. Finding 26:

    • Start with the middle element: 32. 26 is less than 32, so we will continue our search in the left half of the array.
    • Now, the middle element is 21. 26 is greater than 21, so we will continue our search in the right half of the remaining array.
    • Now, the middle element is 26, which is the number we are looking for. So, 26 is at the 3rd position in the sorted array.
  2. Finding 11:

    • Start with the middle element: 32. 11 is less than 32, so we will continue our search in the left half of the array.
    • Now, the middle element is 21. 11 is less than 21, so we will continue our search in the left half of the remaining array.
    • Now, the middle element is 11, which is the number we are looking for. So, 11 is at the 1st position in the sorted array.
  3. Finding 99:

    • Start with the middle element: 32. 99 is greater than 32, so we will continue our search in the right half of the array.
    • Now, the middle element is 54. 99 is greater than 54, so we will continue our search in the right half of the remaining array.
    • Now, the middle element is 84. 99 is greater than 84, so we will continue our search in the right half of the remaining array.
    • Now, we have no more elements left in the array. This means that 99 is not present in the array.

This problem has been solved

Similar Questions

Program to demonstrate the use of Binary Search to search a given element in a sorted array in ascending order.

What is the maximum number of comparisons required to find an element in a sorted array of size 31 using Binary Search?4567

In a binary search, the elements of the array must be in which order?Group of answer choicesAll options are correctAscending orderRandom orderDescending order

Given an input a[]={5,3,2,1,0}, key=1, what is position of key element ( assume binary search)102Error

Write a program to read and store n+ve numbers in array and search a number k provided by the user using a. Linear Searchb. Binary Search

1/2

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.