Consider the following pseudocode for finding an element in a sorted array A[1..n]: 1: BINARY SEARCH(A[1..n],...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Consider the following pseudocode for finding an element in a sorted array A[1..n]: 1: BINARY SEARCH(A[1..n], x) 2: left = 1 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: right = n while (right left) mid=left + right-left 2 if x== A[mid] return mid else if x < A[mid] right mid-1 else if > A[mid] left = mid + 1 return NOTFOUND (a) State precisely the loop invariant for the while loop in lines 4-11 and prove that this loop invariant holds. Your proof should use the structure of the loop invariant proof presented in Chapter 2 of CLRS. Conclude that if x is present in the sorted array A, correctly returns the index of z. (b) Prove by induction that the while loop in lines 4-11 will execute 1+log n times in the worst case. (Hint: observe what happens to the size of the subarray Alleft..right] after each iteration.) Conclude that the running time of the BINARYSEARCH algorithm is (logn). Consider the following pseudocode for finding an element in a sorted array A[1..n]: 1: BINARY SEARCH(A[1..n], x) 2: left = 1 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: right = n while (right left) mid=left + right-left 2 if x== A[mid] return mid else if x < A[mid] right mid-1 else if > A[mid] left = mid + 1 return NOTFOUND (a) State precisely the loop invariant for the while loop in lines 4-11 and prove that this loop invariant holds. Your proof should use the structure of the loop invariant proof presented in Chapter 2 of CLRS. Conclude that if x is present in the sorted array A, correctly returns the index of z. (b) Prove by induction that the while loop in lines 4-11 will execute 1+log n times in the worst case. (Hint: observe what happens to the size of the subarray Alleft..right] after each iteration.) Conclude that the running time of the BINARYSEARCH algorithm is (logn).
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
Mary is 30 years old and married to Mark, age 36. Mark passed away on January 30, 2021. Mark was unemployed and had no income in 2021 due to his illness. Marys seven-year-old daughter, Jenny, lived...
-
Joan is the operations manager at Dark Light Communications, a services company. She has been told that the Operations function needs to pay more attention to the "service package" in order to be...
-
What major organic product would you expect to obtain when acetyl chloride reacts with each of the following? (a) H2O (b) BuLi (excess) (c) (d) NH3 (excess) (e) (f) LiAlH(t-BuO)3 (g) NaOH/H2O (h)...
-
Briefly discuss the strengths and limitations associated with this approach and the specific design . Develop a hypothetical research scenario that would necessitate the use of the Action Research...
-
Navajo Corporation traded a used truck (cost $20,000, accumulated depreciation $18,000) for a small computer worth $3,300. Navajo also paid $500 in the transaction. Prepare the journal entry to...
-
A swimmer wants to cross a river, from point A to point B, as shown in the figure. The distance di (from A to C) is 200 m, the distance d (from C to B) is 150 m, and the speed vr of the current in...
-
For the case The WM. Wrigley Jr. Company: Capital Structure, Valuation, and the Cost of Capital(Darden Case: UVAF1482) please answer the following questions and explain your reasoningwhere...
-
The Steveston Hotel operates a pub in Richmond, B.C. On June 12, 1999, Harry Thomas McWilliams was drinking at the pub and was grossly intoxicated. He was permitted to consume alcohol while in the...
-
1. Calculate f for a nachannel MOSFET whose T Cas 6.1 f F, C=1.7fF capacitances are given given as Cgs gd Assume operation current at 100 A, and that Kn= 160 A/V, W = 10m, L= 1m.
-
Answer: Bad debt and doubtful debt are terms used in accounting to classify debts that a company is unlikely to collect from its customers. Here's how they differ: Bad Debts: This alludes to the...
-
Image transcription text Role Play- SKILLS ASSESSMENT Please complete this by videoing yourself and sending the video to dised @fit edulau When undertaking your role play please be organised and...
-
find A such that M8 k = 2 (1+A) k = 5
-
Consider a closed economy described with a Keynesian cross. The consumption is C = 500 + .75 (Y T). Planned investment is 400, government spending is 300, and taxes are 300. 1. If Y is 2000, what is...
-
Question 4: You are the financial controller of Fresco Ltd, and its financial statements for the year ended 30 April 2020 are being prepared. Fresco Ltd, applied for a government grant in October...
-
What are the 5 Cs of marketing channel structure?
-
The relationship between the number of decibels and the intensity of a sound I (in watts per square meter) is = 10 log(I/1012). Find the intensity I for each decibel level (a) = 60 (b) = 135 (c)...
-
1. The graph of a polynomial function is ________, which means that the graph has no breaks, holes, or gaps. 2. The ________ ________ ________ is used to determine the left-hand and right-hand...
-
In Exercises 1-4, use a calculator to evaluate each function. Round your answers to four decimal places. (Be sure the calculator is in the correct mode.) 1. (a) sin 20.2 (b) csc 69.8 2. (a) tan 12.75...
-
A diploid organism has a total of 14 chromosomes and about 20,000 genes per haploid genome. Approximately how many genes are in each linkage group?
-
By conducting testcrosses, researchers have found that the sweet pea plant has seven linkage groups. How many chromosomes would you expect to find in leaf cells of sweet pea plants?
-
Describe the unique features of ascomycetes that facilitate genetic analysis of these fungi.
Study smarter with the SolutionInn App