Introduction To Algorithms, Third Edition (international Edition)
Introduction To Algorithms, Third Edition (international Edition)
3rd Edition
ISBN: 9780262533058
Author: Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, Clifford Stein
Publisher: TRILITERAL
Question
Book Icon
Chapter 2, Problem 1P

(a)

Program Plan Intro

To show that the insertion sort can sort the n/k sub lists, each of length k in Θ(nk) time.

(a)

Expert Solution
Check Mark

Explanation of Solution

The procedure of insertion sort in non-increasing order is as below:

INSERTION-SORT(A)

For j=2 to A .length

  key=A[j]

  i=j1

while i>0 and A[i]<key

  A[i+1]=A[i]

  i=i1

  A[i+1]=key

The j loop is running from 2 to the length of the array and then value in the index of array is stored in the key variable. After that the variable j is decreased by 1 and stored in the variable i.

Now, while loop is used in which two conditions are given: first condition is variable i is greater than 0 and the value of the array at index i must be less than key value.

The value at index i is swapped at the index i1 . The variable i is decreased by 1 and the key value is stored at the index i+1 . The only change in the insertion sort of non-decreasing order to non-increasing order is flip the condition.

Analysis:

The worst case running time of the insertion sort to sort a list of length n is Θ(n2) . Therefore, for sorting the n/k

sub lists of length k , the time taken by insertion sort is calculated as follows:

  Θ(k2nk)=Θ(nk)

Hence, the worst case running time of insertion sort to sort the n/k sub lists, each of length k is Θ(nk) .

(b)

Program Plan Intro

To show that the worst case running time to merge the sub lists is Θ(nlg(n/k)) .

(b)

Expert Solution
Check Mark

Explanation of Solution

There are n/k sub lists of length k and then merge the n/k sorted sub lists in a list of length n .

For this, take two sublists and merge them simultaneously. The time taken by this process is lg(n/k) steps. Now, compare n elements in each step.

Hence, the worst case running time to merge the sub listsis Θ(nlg(n/k)) .

(c)

Program Plan Intro

To find the largest value of k as a function of n so that the modified algorithm has same running time as standard merge sort.

(c)

Expert Solution
Check Mark

Explanation of Solution

Merge sort is a sorting algorithm that uses divide and conquer method. In merge sort, divide the input sequence in two halves and then sort them, Finally, merge the sorted halves.

The modified algorithm has same running time as standard merge sort if Θ(nlg(n/k))=Θ(nlgn) and consider that k=Θ(lgn) .

  Θ(nlg( n/k ))=Θ(nk+nlgnnlgk)=Θ(nlgn+nlgnnlg( lgn))=Θ(2nlgnnlg( lgn))=Θ(nlgn)

Hence, the running time of the modified algorithm has same as standard merge sort if Θ(nlg(n/k))=Θ(nlgn) and k=Θ(lgn) .

(d)

Program Plan Intro

To choose the value of k in practice.

(d)

Expert Solution
Check Mark

Explanation of Solution

Merge sort is a sorting algorithm that uses the divide and conquer method. In merge sort, divide the input sequence in two halves and then sort them. Finally, merge the sorted halves.

For considering the value of k, choose the largest length of sub list as kso that insertion sort becomes faster than merge sort.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
I need help creating the network diagram and then revising it for the modified activity times.
Activity No. Activity Time (weeks) Immediate Predecessors 1 Requirements collection 3 2 Requirements structuring 4 1 3 Process analysis 3 2 4 Data analysis 3 2 5 Logical design 50 3,4 6 Physical design 5 5 7 Implementation 6 6 c. Using the information from part b, prepare a network diagram. Identify the critical path.
Given the following Extended-BNF grammar of the basic mathematical expressions:  Show the derivation steps for the expression: ( 2 + 3 ) * 6 – 20 / ( 3 + 1 ) Draw the parsing tree of this expression. SEE IMAGE
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
Publisher:Cengage Learning