Given the following code for binary search, binarySearch () and the content of the list below,...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Given the following code for binary search, binarySearch () and the content of the list below, fill Table 1 below with the values of first, last, mid and list[mid] when calling the function binarySearch (81) ie. when searching for 81 in the list, until 81 is found in the list. int binarysearch (int item) { int first = 0; int last = length bool found - false; while (first <= last && !found) { mid = (first + last) / 2; if (list [mid] 1; int mid; %3D item) == found - true; else if(list [mid] > item) last = mid - 1; else first = mid + 13; if (found) return mid; else return -1; 0 1 2 3 2 5 7 15 21 28 29 37 45 51 57 4 5 6 7 8 9 10 11 12 61 13 14 81 15 16 17 List= 72 78 87 91 97 Table 1 Iteration first last mid List[mid] 1 2 3 4 6 せト Given the following code for binary search, binarySearch () and the content of the list below, fill Table 1 below with the values of first, last, mid and list[mid] when calling the function binarySearch (81) ie. when searching for 81 in the list, until 81 is found in the list. int binarysearch (int item) { int first = 0; int last = length bool found - false; while (first <= last && !found) { mid = (first + last) / 2; if (list [mid] 1; int mid; %3D item) == found - true; else if(list [mid] > item) last = mid - 1; else first = mid + 13; if (found) return mid; else return -1; 0 1 2 3 2 5 7 15 21 28 29 37 45 51 57 4 5 6 7 8 9 10 11 12 61 13 14 81 15 16 17 List= 72 78 87 91 97 Table 1 Iteration first last mid List[mid] 1 2 3 4 6 せト
Expert Answer:
Answer rating: 100% (QA)
binarySearch81 Iteration first last mid listmid Exp... View the full answer
Related Book For
Intermediate Accounting
ISBN: 978-0324300987
10th Edition
Authors: Loren A Nikolai, D. Bazley and Jefferson P. Jones
Posted Date:
Students also viewed these algorithms questions
-
Given the following code letters and components of financial statements indicate where each item would most likely be reported in the financial statements by inserting the corresponding code letters....
-
Finish the following code for a method that converts an image into its red channel; that is, removing any green or blue from each pixel and keeping only the red component. public static void...
-
(i) 8 9 10 11 12 (ii) 7 9 10 11 13 (iii) 7 8 10 12 13 (a) Without doing any computations, order the data sets according to increasing value of standard deviations. (b) Why do you expect the...
-
Which statement about cylindrical coordinates is correct? (a) If = 0, then P lies on the z-axis. (b) If = 0, then P lies in the xz-plane.
-
Only 75 of the 250 people interviewed were able to name the vice president of the United States. Find the values for x, n, p, and q.
-
What is interest rate parity? Currently, you can exchange 1 euro for 0.8100 dollars in the 180-day forward market, and the risk-free rate on 180-day securities is 6 percent in the United States and 4...
-
Which account does a merchandiser use that a service company does not use? a. Cost of goods sold b. Inventory C. Sales revenue d. All of the above
-
From the following, calculate the dividends for common and preferred stock: 8% fully participating preferred stock. The board declared a $210,000 dividend. Preferred stock 5,000 shares, $50 par...
-
What do customers want from quick service restaurants during lunch, in the afternoon, and in the evening? What outcomes are they looking for when they eat or drink during those times? How do these...
-
Can you come up with a scenario where the hotel could stay in business and still address the mayor offices environmental concerns?
-
research all about the following: 1) LINUX SYSTEM 2) LINUX COMPONENTS 3) LINUX DISTRIBUTIONS
-
Initial Post: How can reason and utility apply to modern society? Does equality of opportunity still exist? Give an example to support your position on both questions. You are required to make at...
-
( A horizontal curve is designed for a two-lane road in a level terrain. The following data are known: Central angle (A): 50 degrees Design speed of 80 km/h Side friction factor = 0.12 Superelevation...
-
What might be some risk factors involved in migrating to a new country? What are the three different push/pull factors that generally influence decisions on whether to migrate? How does each of these...
-
8. A loan is being repaid with a series of payments at the end of each quarter for five years. If the amount of principal in the third payment is $100, find the amount of principal in the last five...
-
If a firm has a profit function where p=-120+ 200q-5q what output should it produce to maximize profit? What are profits for that q?
-
Based on the following information, create a proposed budget for year 2: Recent merit pay increases (usually 0-5% provided annually) have resulted in the following salaries: 2 coders each at $15/hour...
-
Why is it necessary to study the diffusion of molecules in biological systems?
-
Define liquidity, financial flexibility, and operating capability.
-
On January 1, 2007 the Stimpson Company sells land to Barker Company for $2.5 million, then immediately leases it back. The relevant information is as follows: 1. The land was carried on Stimpsons...
-
Define gain contingency. Describe the accounting requirements for a gain contingency.
-
Find the flexibility and stiffness influence coefficients of the system shown in Fig. 6.29. Also, derive the equations of motion of the system. k1 k3 k4 000 /711 000 m2 000 my 000 FIGURE 6.29...
-
Find the flexibility and stiffness influence coefficients of the torsional system shown in Fig. 6.28. Also write the equations of motion of the system. (GJ)1 01 Compressor (GJ)2 (Jan) Turbine (142)...
-
Derive the stiffness matrix of the system shown in Fig. 5.39. mo e(t) ellee k1 k2 lllll m x(t) FIGURE 5.39 Mass hanging from a pulley.
Study smarter with the SolutionInn App