Questions tagged [clrs]

CLRS refers to the textbook "Introduction to Algorithms" by Thomas H. Cormen, Charles E. Leiserson, Ronald R. Rivest, and Clifford Stein. It is a standard textbook in algorithms and data structures.

170 questions
2
votes
1 answer

Loop Invariants with Breaks

I am trying to understand how loop invariants interact with breaks. CLRS 3e (pg19) describes a loop invariant as requiring that If it is true before an iteration of the loop, it remains true before the next iteration. So given the following…
frog
  • 165
  • 2
  • 9
2
votes
1 answer

Im trying to implement queue from clrs book ,but its not working as expected ? whats wrong with my code

I am trying to implement queue from clrs book, but it's not working as expected. What is wrong with my code? Could it be a problem with queue size or enqueue operation? However, it is very clear that enqueue operation on queue is not working as…
chan
  • 23
  • 1
  • 4
2
votes
2 answers

calculate n for nlog(n) and n! when time is 1 second. (algorithm takes f(n) microseconds)

given the following problem from CLRS algo book. For each function f (n) and time t in the following table, determine the largest size n of a problem that can be solved in time t, assuming that the algorithm to solve the problem takes f(n)…
user119020
  • 413
  • 1
  • 3
  • 13
2
votes
1 answer

Applying Case 3 Of The Master Theorem

Introduction to Algorithms CLRS 4.3 (b) has the problem T(n) = 3*T(n/3) + n/lg(n) Note that n^(log a/ log b) = n^(log 3/ log 3) = 1 The book states that here the master theorem case 3 cannot be applied since n/log (n) is not polynomially larger i.e.…
2
votes
2 answers

Which definition of complete k-ary tree should I consider as more appropiate?

Consider the following definition of a complete k-ary tree from the CLRS book: Definition: A complete k-ary tree is a k-ary tree in which all leaves have the same depth and all internal nodes have degree k. (p.1179) Because of this definition I…
mayhem9891
  • 21
  • 1
2
votes
1 answer

What exctly is "cn" while calculating the complexity of Merge Sort?

I was reading CLRS today to understand the complexity of Merge sort in a better way. I came across a line that says "where the constant c represents the time required to solve problems of size 1 as well as the time per array element of the divide…
Sarthak
  • 75
  • 1
  • 7
2
votes
1 answer

What is the reason behind calculating GCD in Pollard rho integer factorisation?

This is the pseudo code for calculating integer factorisation took from CLRS. But what is the point in calculating GCD involved in Line 8 and the need for doubling k when i == k in Line 13.? Help please.
2
votes
1 answer

Red-Black Tree Delete Fixup in CLRS Second Edition, in Clojure

I am implementing red-black tree deletion for interval trees following CLRS 2nd edition, fourth printing, pg 288-9. Summary of bug: RB-Delete-Fixup If x and w are the sentinel nodes, which is a possible consequence of RB-Delete, then the…
David Williams
  • 8,388
  • 23
  • 83
  • 171
2
votes
1 answer

Why don't we add a black node instead of a red node in Red Black tree insertion?

In red black tree insertion, we always choose to add a new node as red so that we can avoid changing the black height of the tree. Why this is more desirable than adding a black node?
Minh Pham
  • 948
  • 12
  • 22
2
votes
1 answer

What is the intuition behing an optimal substructure?

This question is related to dynamic programming and specifically rod cutting problem from CLRS Pg 362 The overall optimal solution incorporates optimal solutions to two related subproblems. The overall optimal solution is obtained by finding…
hershey92
  • 783
  • 2
  • 6
  • 17
2
votes
3 answers

Recursive matrix multiplication

I am reading Introduction to Algorithms by CLRS. Book shows pseudocode for simple divide and conquer matrix multiplication: n = A.rows let c be a new n x n matrix if n == 1 c11 = a11 * b11 else partition A, B, and C C11 =…
Mislav Blažević
  • 268
  • 1
  • 3
  • 9
2
votes
2 answers

Recurrence in analysis of SELECT algorithm

In CLRS (2/e, page 191, section 9.3) the analysis of the SELECT algorithm for finding the ith smallest element in an array is presented with the following induction proof: 1. T(n) <= c celing(n/5) + c(7n/10 + 6) + an 2. <= cn/5 + c + 7cn/10 +…
1
vote
1 answer

In Push Relabel algorithms for max flow why is there not path from source s to sink t?

I have difficulty understanding the following lemma from CLRS: Let G be a flow network, s and t be source and sink nodes, f be a preflow from s to t, and h be a height function on G. Then there is no augmenting path from s to t in the residual…
user494461
1
vote
1 answer

CLRS's Fibonacci Heap size(x) analysis has a flaw?

In CLRS's Introduction to Algorithms 3rd edition P.525, when it analyzes the size(x)'s lower bound, there is a sentence that I quote as "because adding children to a node cannot decrease the node’s size, the value of Sk increases monotonically with…
jscoot
  • 2,019
  • 3
  • 24
  • 27
1
vote
1 answer

Mergesort resulting in error in CLRS (3rd edition)

According to CLRS(3rd edition) ch2 pages 31-34, here's the pseudocode and respective code for merge and merge_sort. def merge(a, p, q, r): n1 = q - p + 1 n2 = r - q left, right = [], [] for i in range(1, n1): left.append(a[p…
user12690225