Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Binary Search 1. Suppose that that we have an array called list initialized as follows: int[] list = {-2, 8, 13, 22, 25, 25, 38,

Binary Search

1. Suppose that that we have an array called list initialized as follows:

int[] list = {-2, 8, 13, 22, 25, 25, 38, 42, 51, 103};

This would construct the following array:

[0] [1] [2] [3] [4] [5] [6] [7] [8] [9]

+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+

| -2 | 8 | 13 | 22 | 25 | 25 | 38 | 42 | 51 | 103 |

+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+

Note that the method calls below is of the form: binarySearch(int[] a, int low, int high, int target)

a) What values would low, high and mid take on for the following call:

binarySearch(list, 103, 0, 9, 103)

and what value would be returned?

b) What values would low, high and mid take on for the following call:

binarySearch(list, 2, 8, 30)

and what value would be returned?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

3rd Edition

978-1119907466

More Books

Students also viewed these Databases questions

Question

which muscle were use to extend and splay your finger outward?

Answered: 1 week ago

Question

What attracts you about this role?

Answered: 1 week ago

Question

How many states in India?

Answered: 1 week ago

Question

HOW IS MARKETING CHANGING WITH ARTIFITIAL INTELIGENCE

Answered: 1 week ago

Question

Different types of Grading?

Answered: 1 week ago