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 6E
Program Plan Intro

To observe that the while loop of lines 5-7 of the insertion sort uses the linear search to sort the sub-array and also state whether the binary search can be used instead of linear search to improve the running time complexity.

Blurred answer
Students have asked these similar questions
Although merge sort runs in (n lg n) worst-case time and insertion sort runs in (n²) worst-case time, the constant factors in insertion sort can make it faster in practice for small problem sizes on many machines. Thus, it makes sense to coarsen the leaves of the recursion by using insertion sort within merge sort when Chapter 2 Getting Started subproblems become sufficiently small. Consider a modification to merge sort in which n/k sublists of length k are sorted using insertion sort and then merged using the standard merging mechanism, where k is a value to be determined. a. Show that insertion sort can sort the n/k sublists, each of length k, in (nk) worst-case time. b. Show how to merge the sublists in (n lg(n/k)) worst-case time. c. Given that the modified algorithm runs in (nk + n lg(n/k)) worst-case time, what is the largest value of k as a function of n for which the modified algorithm has the same running time as standard merge sort, in terms of -notation? d. How should we…
Write a bottom-up mergesort that makes use of the array's order by carrying out the following steps each time it needs to locate two arrays to merge: locate the first entry in an array that is smaller than its predecessor, then locate the next, and finally merge them to form a sorted subarray. Consider the array size and the number of maximal ascending sequences in the array while analysing the running time of this algorithm.
Observe that the while loop of lines 6–8 of the Insertion-Sort procedure given in class uses a linear search to scan (backward) through the sorted subarray A[1..j − 1]. Can we use a binary searh instead to im- prove the overall worst-case running time of insertion sort to Θ(n lg n)?
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