Introduction to Algorithms
Introduction to Algorithms
3rd Edition
ISBN: 9780262033848
Author: Thomas H. Cormen, Ronald L. Rivest, Charles E. Leiserson, Clifford Stein
Publisher: MIT Press
Question
Book Icon
Chapter 2.3, Problem 5E
Program Plan Intro

To write the pseudo code of either recursive or iterative binary search and also explain that the worst case running time complexity of binary search is θ(lgn) .

Blurred answer
Students have asked these similar questions
4. Consider the function IndexEqual(A,i.j) that returns true if there exists an index x (i sx sj) such that A[x] = x; otherwise, retums false. You may assume A is a sorted integer array in which every element is unique. a. Write an efficient recursive algorithm for IndexEqual(A,i.j). b. What is the situation resulting in the best-case running time of your function, and give an expression for that running time? c. What is the situation resulting in the worst-case running time of your function, and give an expression for that running time in terms of n, where n=j-i+1?
The recursive algorithm below takes as input an array A of distinct integers, indexed between s andf, and an integer k. The algorithm returns the index of the integer k in the array A, or ?1 if the integerk is not contained within A. Complete the missing portion of the algorithm in such a way that you makethree recursive calls to subarrays of approximately one third the size of A.• Write and justify a recurrence for the runtime T(n) of the above algorithm.• Use the recursion tree to show that the algorithm runs in time O(n).FindK(A,s,f,k)if s < fif f = s + 1if k = A[s] return sif k = A[f] return felseq1 = b(2s + f)=3cq2 = b(q1 + 1 + f)=2c... to be continued.else... to be continued.
Question 2: Implement sequential search and binary search algorithms on your computer. Note down run time for each algorithm on arrays of size (1, 250, 500, 750, 1000, 1250, 1500, 5000). For both algorithms, store the values 0 through n - 1 in order in the array, and use a variety of random search values in the range 0 to n - 1 on each size n. Graph the resulting times. When is sequential search faster than binary search for a sorted array? Solution: Input Size(N) Search Element Execution Time for Execution Time for Sequential Search(n) Binary Search(logn)
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education