A programmer writes a program to find an element


Asked by admin @ in Computer Science viewed by 802 People


A programmer writes a program to find an element in the array A[5] with the elements:8 30 40 45 70 the program is run to find a number X,that is found in the first iteration of binary search.what is the value of X?

Answered by admin @



Binary Search is performed on a sorted array.

For each iteration,

1. It first finds the mid element's value.

2. Comparison of X and mid values.
If value(X) = value(mid) then
You've found the number. EXIT.
If value(X) > value(mid) then
Perform Binary Search on second half of array.
If value(X) < value(mid) then
Perform Binary Search on first half of array.

The answer is 40.

Similar Questions

Write a program to find average of three numbers

Asked by admin @ in Computer Science viewed by 321 persons

Write a program to find average of three numbers.

How to find the amount of neutrons in an element

Asked by admin @ in Chemistry viewed by 299 persons

How can you calculate the number of neutrons in an atom?

Where do you find the molar mass of an element

Asked by admin @ in Chemistry viewed by 310 persons

How is the molar mass of an element determined?

Write a program to calculate area of circle in c++

Asked by admin @ in Computers and Technology viewed by 299 persons

I want to write a C++ program to read the diameter of a circle. The program should find and display the area and circumference of the circle. Define a constant …

How to find how many protons are in an element

Asked by admin @ in Physics viewed by 356 persons

How many protons are in an element with an atomic number of eight and a mass number of 18

How do i find the oxidation number of an element

Asked by admin @ in Chemistry viewed by 328 persons

What is the oxidation number of an element? A. The group number for the element O B. The number of valence electrons an element has O C. The charge an …

How to find how many atoms are in an element

Asked by admin @ in Chemistry viewed by 374 persons

Which number in a chemical formula tells you how many atoms of element you have

How do you find the atomic mass of an element

Asked by admin @ in Biology viewed by 302 persons

What does the atomic mass of an element represent? A) The total number of its protons and electrons. B) The average total mass of its neutrons, protons, and electrons. C) …

A programmer mistakenly writes gor instead of for

Asked by admin @ in Computer Science viewed by 18992 persons

Class brush{ private:integer size,rcodefunction getdata() { ... }// Statement 1public:integer name // Statement 2function putdata() { ... }}function main{brush b1,b2 …

To write the correct and effective program we much first

Asked by admin @ in Computer Science viewed by 1008 persons

To write the correct and effective program we must first

Find the last element of a list in prolog

Asked by admin @ in Computer Science viewed by 290 persons

How to find first and last element in a list in prolog

How to find the group number of an element

Asked by admin @ in Chemistry viewed by 319 persons

How to find the group and period of a given element

How to find period and group of an element

Asked by admin @ in Chemistry viewed by 303 persons

How to find the group and period of a given element

How to find group number of d block elements

Asked by admin @ in Chemistry viewed by 352 persons

(a) How is group, period and block of elements predicted. (b) Give the electronic configuration and in terms of period group and block where would you locate the elements with …

How to find the electronic configuration of an element

Asked by admin @ in Chemistry viewed by 341 persons

How to find out the electronic configuration of an element?

Most viewed questions in Computer Science


A programmer mistakenly writes gor instead of for

Asked by admin @ in Computer Science viewed by 18992 persons


Domestic data entry operator ncert book class 9 solutions

Asked by admin @ in Computer Science viewed by 15734 persons


Information technology code 402 class 9 solutions chapter 1

Asked by admin @ in Computer Science viewed by 10931 persons



Ncert solutions for class 8 computer chapter 1 computer system

Asked by admin @ in Computer Science viewed by 10375 persons


A scrum team works on a 4 weeks sprint

Asked by admin @ in Computer Science viewed by 8698 persons


Which of the following occupies more memory in c

Asked by admin @ in Computer Science viewed by 8108 persons



A database of motor vehicles has the base entity

Asked by admin @ in Computer Science viewed by 7820 persons


The network architecture can be termed as a mcq

Asked by admin @ in Computer Science viewed by 6453 persons


Cat5 and cat6 cabling refer to which reference model layer

Asked by admin @ in Computer Science viewed by 5755 persons



Class 7 computer chapter 3 questions and answers

Asked by admin @ in Computer Science viewed by 5660 persons


Choose the correct options about usability and user experience

Asked by admin @ in Computer Science viewed by 5445 persons


Which advocates daily team meetings for coordination and integration

Asked by admin @ in Computer Science viewed by 4954 persons



Which three security features match the database security level

Asked by admin @ in Computer Science viewed by 4946 persons


Which of the dbms package is not available

Asked by admin @ in Computer Science viewed by 4663 persons


________ aid a business grow and attain its objectives

Asked by admin @ in Computer Science viewed by 4464 persons