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.
Questions tagged [clrs]
170 questions
1
vote
1 answer
Insertion Sort Algorithm in CLRS and Robert Sedgewick
In Online Course of Algorithms by Robert Sedgewick, Insertion sort is described as -
for(i = 0; i< length of array ; i++) // *i represents pointer which increments uniformly*
for( j = i ; j > 0 ; j--) // *j is subpart of i which compares…

HIMANSHU NARAYAN
- 41
- 7
1
vote
1 answer
How can a never-ending recursive function have a time complexity?
In the book "Introduction to Algorithms" by CLRS we are asked to find the time complexity of a recursive function:
4.4-8
Use a recursion tree to give an asymptotically tight solution to the recurrence T(n) = T(n - a) + T(a) + cn where a ≥ 1 and c >…

Viktor Skarve
- 129
- 1
- 8
1
vote
1 answer
Recursive relation for the MAX_HEAPIFY algorithm and the worst case
I came upon the recursive relation for the max-heapify algorithm when going through CLRS. My teacher had justified, quite trivially in fact, that the time complexity of the max-heapify process was O(logn), simply because the worst case is when the…

booma vijay
- 113
- 3
1
vote
1 answer
Big theta notation in substitution proofs for recurrences
Often in CLRS, when proving recurrences via substitution, Ө(f(n)) is replaced with cf(n).
For example,on page 91, the recurrence
T(n) = 3T(⌊n/4⌋) + Ө(n^2)
is written like so in the proof
T(n) <= 3T(⌊n/4⌋) + cn^2
But can't Ө(n^2) stand for, let's…

Cirrus86
- 336
- 4
- 13
1
vote
1 answer
Deletion time of items in a hashtables linked list
I am currently reading the CLRS book and looking at how hashtables are defined there, when talking about open hashing and using chaining for collision resolution there is a piece of text that reads:
If the hash table supports deletion, then its…

berimbolo
- 3,319
- 8
- 43
- 78
1
vote
1 answer
CLRS Red-Black Tree deletion
I copied pseudocode from CLRS chapter on red-black trees, also based on this implementation. My copied code doesn't properly work when deleting root nodes (root node doesn't change before fixup, which I assume is due to a faulty transplant), and I…

skeytrek
- 53
- 3
1
vote
1 answer
Why is the cost in a recursion tree shown as an addition?
I'm taking introduction to Algorithms and trying to understand recursion trees a bit more (I'm using the CLRS textbook).
Here is an example algorithm:
T(n) = 3T(n/4) + cn^2
My understanding of this is that 3T(n/4) represents the number of…

sdub0800
- 139
- 1
- 9
1
vote
1 answer
How I solve the recurrence error of FindMaximumSubarray using divide and conquer approach?
This is my solution to findMaximumSubarray, I follow CLRS Pseudo code algorithm and I get this recursion error I tried to figure out why, but I reach nothing !
I can't understand this part of recursion, the first line is to find divide left array…

Kotoz
- 47
- 4
1
vote
3 answers
What's wrong with this Pollard Rho implementation
#include
#include
typedef unsigned long long int ULL;
ULL gcd(ULL a, ULL b)
{
for(; b >0 ;)
{
ULL rem = a % b;
a = b;
b = rem;
}
return a;
}
void pollard_rho(ULL n)
{
ULL i = 0,y,k,d;
ULL…

Pointer
- 11
- 2
1
vote
1 answer
any linear function an + b is O(n^2) CLRS
In 3rd edition of CLRS specifically section 3.1 (page 47 in my book) they say
when a > 0, any linear function an + b is in O(n^2), which is easily verified by taking c = a + |b| and n0 = max(1,-b/a).
where n0 is the value such that when n >= n0…

Alphaus
- 13
- 3
1
vote
1 answer
Can someone explain me what are X, I and Pr in this proof ? and also why first sigma start from j=i+1?
I am reading CLRS Algorithm and i saw this Theorem.
Theorem 11.2: In a hash table in which collisions are resolved by chaining, a successful search
takes average-case time: theta(1+n/m) under the assumption of simple uniform hashing.
in this…

Ali Abbasifard
- 398
- 4
- 22
1
vote
0 answers
coarsening of merge sort
I just started CLRS. The first problem of the 2nd chapter involves coarsening the merge sort algorithm by using insertion sort when the subarray reaches a specified minimum size. I have written the modified code and i think it is correct as I have…

CeNiEi
- 97
- 1
- 5
1
vote
1 answer
Merge sort based on CLRS Introduction to algorithms, with inversion count, on C++
I have implemented a merge sort that counts inversions, based on CLRS Merge Sort pseudo-code, but the answer is not correct, doesn't sort the array and neither does it count the inversions correctly.
Definition of inversion: Let A[1..n] be an array…

diegof59
- 29
- 8
1
vote
1 answer
Which has a higher order of growth, c.n.(log (base 1.5) n) or d.(n^(log (base 1.5) 2))
I was looking at an example from a book. The final equation comes to ( c⋅n log (base 1.5) n)+ d.(n^(log (base 1.5) 2)) . I assume that the second function has a higher order of growth. As it evaluates to roughly n ^ 1.71, but the example…

Ahsen Waqar
- 7
- 4
1
vote
1 answer
Is this loop invariant and its informal proof correct? (CLRS 3rd ed. exercise 2-1-3)
Given the following algorithm for linear-search (referring to index 1 as the index of the first element in an array of elements):
found_idx = nil
for i = 1 to A.length
if A[i] == value
found_idx = i
return found_idx
…

Wilfred Tannr Allard
- 473
- 2
- 9