Login
Register
Dark Mode
Brightness
Profile
Edit Profile
Messages
My favorites
My Updates
Logout
Recent questions tagged cormen
0
votes
0
answers
61
Cormen Edition 3 Exercise 6.5 Question 5 (Page No. 166)
Argue the correctness of HEAP-INCREASE-KEY using the following loop invariant: At the start of each iteration of the while loop of lines $4-6$, the subarray $A[1..A.heapsize]$ satisfies the max-heap property, except that there ... assume that the subarray $A[a..heapsize]$ satisfies the max-heap property at the time HEAP-INCREASE-KEY is called.
Argue the correctness of HEAP-INCREASE-KEY using the following loop invariant:At the start of each iteration of the while loop of lines $4–6$, the subarray $A[1..A.heap...
akash.dinkar12
280
views
akash.dinkar12
asked
Jun 27, 2019
Algorithms
cormen
algorithms
binary-heap
descriptive
+
–
0
votes
0
answers
62
Cormen Edition 3 Exercise 6.5 Question 4 (Page No. 165)
Why do we bother setting the key of the inserted node to $-\infty$ in line $2$ of MAX-HEAP-INSERT when the next thing we do is increase its key to the desired value?
Why do we bother setting the key of the inserted node to $-\infty$ in line $2$ of MAX-HEAP-INSERT when the next thing we do is increase its key to the desired value?
akash.dinkar12
280
views
akash.dinkar12
asked
Jun 27, 2019
Algorithms
cormen
algorithms
binary-heap
descriptive
+
–
1
votes
0
answers
63
Cormen Edition 3 Exercise 6.5 Question 3 (Page No. 165)
Write pseudo code for the procedures HEAP-MINIMUM, HEAP-EXTRACT-MIN, HEAP-DECREASE-KEY, and MIN-HEAP-INSERT that implement a min-priority queue with a min-heap.
Write pseudo code for the procedures HEAP-MINIMUM, HEAP-EXTRACT-MIN, HEAP-DECREASE-KEY, and MIN-HEAP-INSERT that implement a min-priority queue with a min-heap.
akash.dinkar12
362
views
akash.dinkar12
asked
Jun 27, 2019
Algorithms
cormen
algorithms
binary-heap
descriptive
+
–
0
votes
0
answers
64
Cormen Edition 3 Exercise 6.5 Question 2 (Page No. 165)
HEAP-INCREASE-KEY(A,i,key) 1 if key < A[i] 2 error new key is smaller than current key 3 A[i] = key 4 while i > 1 and A[parent(i)] < A[i] 5 exchange A[i] with A[parent(i)] 6 i=parent(i) MAX-HEAP-INSERT(A,key) 1 A ... ,key) Illustrate the operation of MAX-HEAP-INSERT$(A,10)$ on the heap $A=\langle 15,13,9,5,12,8,7,4,0,6,2,1 \rangle$.
HEAP-INCREASE-KEY(A,i,key) 1 if key < A[i] 2 error “new key is smaller than current key” 3 A[i] = key 4 while i 1 and A[parent(i)] < A[i] 5 exchange A[i] with A[pare...
akash.dinkar12
291
views
akash.dinkar12
asked
Jun 27, 2019
Algorithms
cormen
algorithms
binary-heap
descriptive
+
–
0
votes
0
answers
65
Cormen Edition 3 Exercise 6.5 Question 1 (Page No. 164)
HEAP-EXTRACT-MAX(A) 1 if A.heap-size < 1 2 error “heap underflow” 3 max=A[1] 4 A[1]=A[A.heapsize] 5 A.heapsize=A.heapsize-1 6 MAX-HEAPIFY(A,1) 7 return max Illustrate the operation of HEAP-EXTRACT-MAX on the heap $A=\langle 15,13,9,5,12,8,7,4,0,6,2,1 \rangle$.
HEAP-EXTRACT-MAX(A) 1 if A.heap-size < 1 2 error “heap underflow” 3 max=A 4 A =A[A.heapsize] 5 A.heapsize=A.heapsize-1 6 MAX-HEAPIFY(A,1) 7 return max Illustrat...
akash.dinkar12
605
views
akash.dinkar12
asked
Jun 27, 2019
Algorithms
cormen
algorithms
binary-heap
descriptive
+
–
0
votes
0
answers
66
Cormen Edition 3 Exercise 6.4 Question 5 (Page No. 161)
Show that when all elements are distinct, the best-case running time of HEAPSORT is $\Omega(n\lg\ n)$.
Show that when all elements are distinct, the best-case running time of HEAPSORT is $\Omega(n\lg\ n)$.
akash.dinkar12
328
views
akash.dinkar12
asked
Jun 27, 2019
Algorithms
cormen
algorithms
binary-heap
heap-sort
descriptive
difficult
+
–
0
votes
0
answers
67
Cormen Edition 3 Exercise 6.4 Question 4 (Page No. 160)
Show that the worst-case running time of HEAPSORT is $\Omega(n\lg\ n)$.
Show that the worst-case running time of HEAPSORT is $\Omega(n\lg\ n)$.
akash.dinkar12
322
views
akash.dinkar12
asked
Jun 27, 2019
Algorithms
cormen
algorithms
binary-heap
heap-sort
descriptive
+
–
0
votes
0
answers
68
Cormen Edition 3 Exercise 6.4 Question 3 (Page No. 160)
What is the running time of HEAPSORT on an array $A$ of length $n$ that is already sorted in increasing order? What about decreasing order?
What is the running time of HEAPSORT on an array $A$ of length $n$ that is already sorted in increasing order? What about decreasing order?
akash.dinkar12
267
views
akash.dinkar12
asked
Jun 27, 2019
Algorithms
cormen
algorithms
binary-heap
heap-sort
descriptive
+
–
0
votes
0
answers
69
Cormen Edition 3 Exercise 6.4 Question 2 (Page No. 160)
Argue the correctness of HEAPSORT using the following loop invariant: At the start of each iteration of the for loop of lines $2–5$,the subarray $A[1..i]$ is a max-heap containing the $i$ smallest elements of $A[1..n] $, and the subarray $A[i+1..n]$ contains the $n- i$ largest elements of $A[1..n]$, sorted.
Argue the correctness of HEAPSORT using the following loop invariant:At the start of each iteration of the for loop of lines $2–5$,the subarray $A[1..i]$ is a max-heap ...
akash.dinkar12
388
views
akash.dinkar12
asked
Jun 27, 2019
Algorithms
cormen
algorithms
binary-heap
heap-sort
descriptive
+
–
0
votes
0
answers
70
Cormen Edition 3 Exercise 6.4 Question 1 (Page No. 160)
HEAPSORT(A) 1 BUILD-MAX-HEAP(A) 2 for i = A.length down to 2 3 exchange A[1] with A[i] 4 A.heapsize=A.heapsize – 1 5 MAX-HEAPIFY(A,1) illustrate the operation of HEAPSORT on the array $A=\langle 5,13,2,25,7,17,20,8,4 \rangle$
HEAPSORT(A) 1 BUILD-MAX-HEAP(A) 2 for i = A.length down to 2 3 exchange A with A[i] 4 A.heapsize=A.heapsize – 1 5 MAX-HEAPIFY(A,1)illustrate the operation of HEAPSORT ...
akash.dinkar12
341
views
akash.dinkar12
asked
Jun 27, 2019
Algorithms
cormen
algorithms
binary-heap
heap-sort
descriptive
+
–
0
votes
0
answers
71
Cormen Edition 3 Exercise 6.3 Question 3 (Page No. 159)
Show that there are at most $\lceil n/2^{h+1}\rceil$ nodes of height $h$ in any $n-$element heap.
Show that there are at most $\lceil n/2^{h+1}\rceil$ nodes of height $h$ in any $n-$element heap.
akash.dinkar12
246
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
binary-heap
descriptive
+
–
0
votes
0
answers
72
Cormen Edition 3 Exercise 6.3 Question 2 (Page No. 159)
Why do we want the loop index $i$ in line $2$ of BUILD-MAX-HEAP to decrease from $\lfloor A.length/2 \rfloor$ to 1 rather than increase from 1 to $\lfloor A.length/2 \rfloor$?
Why do we want the loop index $i$ in line $2$ of BUILD-MAX-HEAP to decrease from $\lfloor A.length/2 \rfloor$ to 1 rather than increase from 1 to $\lfloor A.length/2 \rfl...
akash.dinkar12
238
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
binary-heap
descriptive
+
–
0
votes
0
answers
73
Cormen Edition 3 Exercise 6.3 Question 1 (Page No. 159)
BUILD-MAX-HEAP(A) 1 A.heapsize=A.length 2 for i=A.length/2 downto 1 3 MAX-HEAPIFY(A,i) Using Figure $6.3$ as a model, illustrate the operation of BUILD-MAX-HEAP on the array $A=\langle 5,3,17,10,84,19,6,22,9 \rangle $
BUILD-MAX-HEAP(A) 1 A.heapsize=A.length 2 for i=A.length/2 downto 1 3 MAX-HEAPIFY(A,i)Using Figure $6.3$ as a model, illustrate the operation of BUILD-MAX-HEAP on the arr...
akash.dinkar12
545
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
binary-heap
descriptive
+
–
0
votes
0
answers
74
Cormen Edition 3 Exercise 6.2 Question 6 (Page No. 156)
Show that the worst-case running time of MAX-HEAPIFY on a heap of size $n$ is $\Omega(lg\ n)$.(Hint: For a heap with $n$ nodes, give node values that cause MAXHEAPIFY to be called recursively at every node on a simple path from the root down to a leaf).
Show that the worst-case running time of MAX-HEAPIFY on a heap of size $n$ is $\Omega(lg\ n)$.(Hint: For a heap with $n$ nodes, give node values that cause MAXHEAPIFY to ...
akash.dinkar12
260
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
binary-heap
descriptive
+
–
0
votes
0
answers
75
Cormen Edition 3 Exercise 6.2 Question 5 (Page No. 156)
The code for MAX-HEAPIFY is quite efficient in terms of constant factors, except possibly for the recursive call in line 10, which might cause some compilers to produce inefficient code. Write an efficient MAX-HEAPIFY that uses an iterative control construct (a loop) instead of recursion.
The code for MAX-HEAPIFY is quite efficient in terms of constant factors, except possibly for the recursive call in line 10, which might cause some compilers to produce i...
akash.dinkar12
296
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
binary-heap
descriptive
+
–
0
votes
0
answers
76
Cormen Edition 3 Exercise 6.2 Question 4 (Page No. 156)
What is the effect of calling MAX-HEAPIFY$(A,i)$ for $i > A.heapsize/2$.
What is the effect of calling MAX-HEAPIFY$(A,i)$ for $i A.heapsize/2$.
akash.dinkar12
180
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
binary-heap
descriptive
+
–
0
votes
0
answers
77
Cormen Edition 3 Exercise 6.2 Question 3 (Page No. 156)
What is the effect of calling MAX-HEAPIFY$(A, i)$ when the element $A[i]$ is larger than its children?
What is the effect of calling MAX-HEAPIFY$(A, i)$ when the element $A[i]$ is larger than its children?
akash.dinkar12
174
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
binary-heap
descriptive
+
–
0
votes
0
answers
78
Cormen Edition 3 Exercise 6.2 Question 2 (Page No. 156)
Starting with the procedure MAX-HEAPIFY, write pseudocode for the procedure MIN-HEAPIFY$(A, i )$, which performs the corresponding manipulation on a minheap. How does the running time of MIN-HEAPIFY compare to that of MAXHEAPIFY?
Starting with the procedure MAX-HEAPIFY, write pseudocode for the procedure MIN-HEAPIFY$(A, i )$, which performs the corresponding manipulation on a minheap. How does the...
akash.dinkar12
333
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
binary-heap
descriptive
+
–
0
votes
0
answers
79
Cormen Edition 3 Exercise 6.2 Question 1 (Page No. 156)
MAX-HEAPIFY(A,i) 1 l=Left(i) 2 r=Right(i) 3 if l <= A.heapsize and A[l] > A[i] 4 largest=l 5 else largest = i 6 if r <= A.heapsize and A[r] > A[largest] 7 largest=r 8 if largest!=i 9 exchange A[i] with A[ ... model, illustrate the operation of MAX-HEAPIFY(A,3) on the array $A=\langle 27,17,3,16,13,10, 1,5,7,12,4,8,9,0 \rangle$
MAX-HEAPIFY(A,i) 1 l=Left(i) 2 r=Right(i) 3 if l <= A.heapsize and A[l] A[i] 4 largest=l 5 else largest = i 6 if r <= A.heapsize and A[r] A[largest] 7 largest=r...
akash.dinkar12
404
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
binary-heap
descriptive
+
–
0
votes
2
answers
80
Cormen Edition 3 Exercise 3.2 Question 3 (Page No. 60)
Prove that $n!=\omega(2^n)$ and $n!=o(n^n)$.
Prove that $n!=\omega(2^n)$ and $n!=o(n^n)$.
akash.dinkar12
374
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
asymptotic-notation
descriptive
+
–
0
votes
0
answers
81
Cormen Edition 3 Exercise 2.4 Question 4 (Page No. 42)
Give an algorithm that determines the number of inversions in any permutation on $n$ elements in $\Theta (n\ lg\ n)$ worst-case time. (Hint: Modify merge sort.)
Give an algorithm that determines the number of inversions in any permutation on $n$ elements in $\Theta (n\ lg\ n)$ worst-case time. (Hint: Modify merge sort.)
akash.dinkar12
219
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
algorithm-design-technique
inversion
descriptive
+
–
0
votes
0
answers
82
Cormen Edition 3 Exercise 2.4 Question 3 (Page No. 42)
What is the relationship between the running time of insertion sort and the number of inversions in the input array? Justify your answer.
What is the relationship between the running time of insertion sort and the number of inversions in the input array? Justify your answer.
akash.dinkar12
159
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
inversion
descriptive
+
–
0
votes
1
answer
83
Cormen Edition 3 Exercise 2.4 Question 2 (Page No. 42)
What array with elements from the set $\{1,2,\dots n\}$ has the most inversions? How many does it have?
What array with elements from the set $\{1,2,\dots n\}$ has the most inversions? How many does it have?
akash.dinkar12
326
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
inversion
descriptive
+
–
0
votes
1
answer
84
Cormen Edition 3 Exercise 2.4 Question 1 (Page No. 41)
List the five inversions of the array $\langle 2,3,8,6,1\rangle$
List the five inversions of the array $\langle 2,3,8,6,1\rangle$
akash.dinkar12
243
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
inversion
descriptive
+
–
0
votes
1
answer
85
Cormen Edition 3 Exercise 2.3 Question 3 (Page No. 39)
Use mathematical induction to show that when $n$ is an exact power of $2$, the solution of the recurrence $T(n) = \begin{cases} 2 \text{, if n=2, } \\2T(n/2)+n \text{, if n=$2^k$,for k >1} \end{cases}$ is $T(n) = n\ lg\ n$.
Use mathematical induction to show that when $n$ is an exact power of $2$, the solution of the recurrence$T(n) = \begin{cases} 2 \text{, if n=2, } ...
akash.dinkar12
611
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
recurrence-relation
time-complexity
descriptive
+
–
0
votes
1
answer
86
Cormen Edition 3 Exercise 2.3 Question 7 (Page No. 39)
Describe a $\Theta(n\ lg\ n)$ time algorithm that, given a set $S$ of $n$ integers and another integer $x$, determines whether or not there exist two elements in $S$ whose sum is exactly $x$.
Describe a $\Theta(n\ lg\ n)$ time algorithm that, given a set $S$ of $n$ integers and another integer $x$, determines whether or not there exist two elements in $S$ whos...
akash.dinkar12
373
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
algorithm-design-technique
descriptive
difficult
+
–
0
votes
1
answer
87
Cormen Edition 3 Exercise 2.3 Question 6 (Page No. 39)
Observe that the while loop of the INSERTION-SORT procedure uses a linear search to scan (backward) through the sorted subarray $A[i\dots j-1]$ Can we use a binary search (see Exercise 2.3-5) instead to improve the overall worst-case running time of insertion sort to $\Theta(n\ lg\ n)$?
Observe that the while loop of the INSERTION-SORT procedure uses a linear search to scan (backward) through the sorted subarray $A[i\dots j-1]$ Can we use a binary search...
akash.dinkar12
821
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
algorithms
cormen
searching
descriptive
+
–
0
votes
0
answers
88
Cormen Edition 3 Exercise 2.3 Question 5 (Page No. 39)
Referring back to the searching problem (see Exercise 2.1-3), observe that if the sequence $A$ is sorted, we can check the midpoint of the sequence against $v$ and eliminate half of the sequence from further consideration. The binary ... recursive, for binary search. Argue that the worst-case running time of binary search is $\Theta (lg\ n)$.
Referring back to the searching problem (see Exercise 2.1-3), observe that if the sequence $A$ is sorted, we can check the midpoint of the sequence against $v$ and elimin...
akash.dinkar12
350
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
searching
descriptive
+
–
0
votes
1
answer
89
Cormen Edition 3 Exercise 2.3 Question 4 (Page No. 38)
We can express the insertion sort as a recursive procedure as follows.In order to sort $A[1\dots n]$, we recursively sort $A[1 \dots n-1]$ and then insert $A[n]$ into the sorted array $A[1 \dots n-1]$. Write a recurrence for the running time of this recursive version of insertion sort.
We can express the insertion sort as a recursive procedure as follows.In order to sort $A[1\dots n]$, we recursively sort $A[1 \dots n-1]$ and then insert $A[n]$ into the...
akash.dinkar12
509
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
sorting
time-complexity
descriptive
+
–
0
votes
0
answers
90
Cormen Edition 3 Exercise 2.3 Question 2 (Page No. 37)
Rewrite the MERGE procedure so that it does not use sentinels, instead of stopping once either array $L$ or $R$ has had all its elements copied back to $A$ and then copying the remainder of the other array back into $A$.
Rewrite the MERGE procedure so that it does not use sentinels, instead of stopping once either array $L$ or $R$ has had all its elements copied back to $A$ and then copyi...
akash.dinkar12
606
views
akash.dinkar12
asked
Jun 26, 2019
Algorithms
cormen
algorithms
sorting
merge-sort
descriptive
+
–
Page:
« prev
1
2
3
4
5
6
7
next »
Email or Username
Show
Hide
Password
I forgot my password
Remember
Log in
Register