1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
vitfil [10]
4 years ago
9

Suppose we are performing a binary search on a sorted array called numbers initialized as follows: // index 0 1 2 3 4 5 6 7 8 9

10 11 12 13 14 int[] numbers = {-5, -1, 0, 3, 9, 14, 19, 24, 33, 41, 56, 62, 70, 88, 99}; int index = binarySearch(numbers, 18); Write the indexes of the elements that would be examined by the binary search (the mid values in our algorithm's code).
Computers and Technology
1 answer:
konstantin123 [22]4 years ago
6 0

Answer:

The indexes of the elements that would be examined by the binary search are

7 11 9

numbers[7] = 39

numbers[11] = 57

numbers[9] = 42

The values that would be returned from the search are    

39 57 42

Explanation:

The complexity of searching a value in an array using binary search is O (log n). It follows divide and conquer principle. First we have to sort the elements in the array. Here in our case the array is already sorted.

   target = (search for the value) =42

numbers[] 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14    

min max

here assign min= 0 (minimum index)

max= 14 (maximum index)    

Instead of searching for the target in a sequential manner we are searching by examining the middle term in the array by using the following formula. middle = ( min + max )/2

step 1) middle = (0 + 14)/2 = 7 numbers[middle]=numbers[7] = 39

compare target value with numbers[middle]

i.e target = 42 > 39 , the target value is greater than the numbers[middle]. so we have to move to upper part of the array.

Then min= middle+1 = 7+1 = 8

max= (unchanged) 14

 

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14    

min max

step 2) middle = (8+ 14)/2 = 11 numbers[middle]=numbers[11] = 57

compare target value with numbers[middle]

i.e target =  42 < 57 ,the target value is lesser than the numbers[middle] .

Then min= (unchanged) 8

max= middle -1 =11-1 =10

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14    

min max

step 3) middle = (8+10)/2 = 9   numbers[middle]=numbers[9] = 42

i.e target =  42 = 42

Here stop the process. In this way we found our target using binary search.

You might be interested in
For C++ (please make sure it runs properly)
Jlenok [28]

Answer:

The C code is below.

Explanation:

#define amplitude 1

02     #define b 1

03     #define c 200

04     class Sinewave

05     {

06     protected:

07

08                 double freq;

09                 int y;

10

11     public:

12                 Sinewave()

13                 {

14

15                 }              

16                 void generateSinewave()

17                 {

18                     COLORREF yellow = RGB(255,255,0);

19                     COLORREF lightblue = RGB(173,216,230);

20

21                     // make sure the names match

22                     SetConsoleTitle(L"ConGraphics");

23                     HWND hWnd = FindWindow(NULL, L"ConGraphics");

24                     HDC hDC = GetDC(hWnd);

25

26                     //for(int x = 0; x < freq; x++)

27                     for(int x = 0;; x++)

28                     {

29                         // center at y = 200 pixels

30                          

31                         y = amplitude*(int)(sin(x/100.0)*100 + 150);

32                         SetPixel(hDC, x, y, lightblue);

33                          

34                          

35                     }

36                      

37                 }

38 };

7 0
3 years ago
A(n) ___________________________ is a pl/sql block that executes in place of a dml action on a database view.
Zinaida [17]

A(n)<u> Instead Of trigger </u>is a pl/sql block that manages in place of a dml action on a database view.

<h3>Why instead of triggers are used?</h3>

INSTEAD OF triggers describe how to perform insert, update, and delete functions against complex views. INSTEAD OF triggers permit applications to use a view as the sole interface for all SQL operations.

<h3>What are the after triggers?</h3>

An after trigger runs after the connected insert, update, or delete changes are involved to the table. The WHEN condition can be used in an SQL trigger to specify a state. If the condition evaluates to true, the SQL views in the SQL trigger routine body are run.

To learn more about Instead Of trigger, refer

brainly.com/question/21564232

#SPJ4

6 0
2 years ago
What report indicates the last page users viewed before leaving a website?.
Serhud [2]

Answer:

You can find the last page users viewed before leaving the website on the “Exit Pages” report under “Site Content”

Explanation:

This can also give you a percentage of exits as well as the number of exits from a page.

If you have an important page, (using a silly example, a picture of your dog) that you really want people to see, you can check the exit pages and see how many people are actually seeing this <em>great</em> picture of your dog, or adjust your site if needed.

Have a nice day!

     I hope this is what you are looking for, but if not - comment! I will edit and update my answer accordingly.

- Heather

3 0
2 years ago
Define and test a function myRange. This function should behave like Python’s standard range function, with the required and opt
Cerrena [4.2K]

Answer:

Study Python’s help on range to determine the names, positions, and what to do with your function’s parameters.

Use a default value of None for the two optional parameters. If these parameters both equal None, then the function has been called with just the stop value. If just the third parameter equals None, then the function has been called with a start value as well. Thus, the first part of the function’s code establishes what the values of the parameters are or should be. The rest of the code uses those values to build a list by counting up or down.

6 0
3 years ago
Read 2 more answers
What indicator displays in a cell that contains a comment? red indicator triangle blue indicator triangle green triangle red squ
mixer [17]
Are you talking about like a notification??

if so it is a red square
3 0
3 years ago
Other questions:
  • What is value parameter and reference parameter while things are passed by Also, do a c code to show it
    13·1 answer
  • Hands-On Project 15-4 Make Network Cables
    8·1 answer
  • which statement is true? O A Future games will be more context oriented. OB. Future games will be more product driven. Future ga
    13·2 answers
  • An employee sets up an automation that transfers files in a specific folder on their PC to a remote drive for archiving, provide
    11·1 answer
  • Font size means the height of characters.<br>True<br>False​
    11·1 answer
  • Question # 2 Multiple Select You wrote a program to compare the portion of drivers who were on the phone. Which statements are t
    15·1 answer
  • When two well-informed people have different perspectives on a problem, it is often because they are focusing on a different app
    12·1 answer
  • Which of the following is adoptable in Mindanao only?​
    5·1 answer
  • Write a program that ask a user to input radius of a circle and display circumference of a circle
    13·1 answer
  • Your program has a loop. You want to exit the loop completely if the user guesses the correct word.
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!