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
1
vote
1 answer

why the depth of stack can be O(lgn) in quick sort in introduction to algorithms book

Now I was reading introduction to algorithms, Quicksort chapter. It said that tail recursion can be used for optimization. QUICKSORT'(A, p, r) while p < r do ▸ Partition and sort left subarray. q ← PARTITION(A, p, r) QUICKSORT'(A,…
liumilan
  • 365
  • 1
  • 4
  • 13
1
vote
1 answer

CLRS Algorithms: Merge n/k sublists each of size k in O(n*lg(n/k))

This is a problem 2-1.b from CLRS. I don't understand how to merge n/k arrays of size k each in n*lg(n/k). The best solution I can come up with is to fill each entry of a final array of size n by searching for the min element amongst min elements of…
user1745356
  • 4,462
  • 7
  • 42
  • 70
1
vote
1 answer

Operations on bits when doing binary long division

This is from the number theory chapter in CLRS. We are asked to prove that binary "paper and pencil" long division a/b with result q and reminder r does O((1+lgq)lgb) operations on bits. The way I see it is we do 1 subtraction of b for each bit in…
daramasala
  • 3,040
  • 2
  • 26
  • 33
1
vote
3 answers

CLRS Depth First Search Theorem 22.10

Theorem 22.10 in CLRS - Introduction to Algorithms says that In a depth first search of an undirected graph G, every edge of G is either a tree edge or a back edge. Now in this the explanation for tree edge portion is obvious, but I didn't get…
Akshay Jindal
  • 115
  • 3
  • 11
1
vote
1 answer

analysis of push relabel algorithm

I am reading push flow algorithm in Introduction to Algorithms by Cormen etc. I am having difficulaty in understanding lemma 26.20 which is mentioned as below: Let G = (V, E) be a flow network with source s and sink t, and let f be a preflow in…
venkysmarty
  • 11,099
  • 25
  • 101
  • 184
0
votes
2 answers

Why Hashtable's load factor is not consistent with the one described in CLRS book?

From the doc of Java about Hashtable class, it says As a general rule, the default load factor (.75) offers a good tradeoff between time and space costs So the load factor for Hashtable is 0.75, which means if there are N keys, Hashtable will use…
Jackson Tale
  • 25,428
  • 34
  • 149
  • 271
0
votes
1 answer

Finding the loop invariant of selection sort

I am trying to find then loop invariant of selection sort Pseudo code SELECTION SORT (A,n) for i= 1 to n-1 smallest=i for j=i+1 to n if A[j]
laltubantu
  • 13
  • 3
0
votes
0 answers

RBTree deletion : what if sibling is nil(sentinel)

I am implementing red-black tree by c. I'm referring to pseudo codes in CLRS. pseudo code: I wonder why there is no error handling in deletion's fixup when sibling is nil(Null). currently, there's no error handling when checking sibling's child, so…
YSEO
  • 101
  • 7
0
votes
1 answer

I get "index out of range" error in a function when an ensure makes this impossible

I am trying to implement the KMP algorithm in Dafny according to CLRS [sec. 32.4], and I am having trouble implementing the *[q]: function FuncStarIter(func: seq, q: nat, count: nat): nat requires 0 <= q < |func| requires forall i :: 0…
roydbt
  • 91
  • 1
  • 8
0
votes
0 answers

CLRS red black tree deletion

01 void RedBlackTree::deleteNode(Node *z) 02 { 03 Node *y = z; 04 Color yOriginalColor = y->color; 05 Node *x; 06 if (z->left == sentinel) 07 { 08 x = z->right; 09 transplant(z, z->right); 10 } 11 else if…
Zack
  • 1
  • 2
0
votes
1 answer

Hashtable with chaining efficiency if linked list are sorted

I am currently working on an exercise from the CLRS, here is the problem: 11.2-3 Professor Marley hypothesizes that he can obtain substantial performance gains by modifying the chaining scheme to keep each list in sorted order. How does the…
0
votes
1 answer

Is saying that search have a θ(1+a) complexity in hash table ( with chaining ) implying that it is also θ(a)?

I am looking at these snippets from CLRS: Description of the hash table search time: Definition of as /: Explanation of θ ( removing constant factors and only keeping the order of growth ): I do not understand this usage of the theta notation.…
0
votes
0 answers

Quickselect algorithm condition

So I am going through the Quick select algorithm from the CLRS book and I understand the whole concept of the algorithm. But one thing that I am not able to grasp is the initial condition they have at the top. Following is my implementation of the…
0
votes
1 answer

Max subarray sum in CLRS (3rd edition) resulting in error

This is a continuation to my early complaints about CLRS(3rd edition) if you're looking to learn about algorithms, this is by far the worst book that you can ever use. All the pseudocode examples up to chapter 4 that I've seen so far have mistakes…
user12690225
0
votes
1 answer

Time complexity of recursive Longest Common Subsequence which uses a map

I was reading 'Algorithms Unlocked' by Thomas H Corman and came across an approach to finding the Longest Common Subsequence which ran in O(n * m). This approach can be seen in this article too:…
60q
  • 35
  • 5