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
3
votes
1 answer

Singly connected directed graphs

According to the definition available in CLRS 3rd edition, a singly connected directed graph is the one where for every pair of vertices (u,v) there is at most 1 unique path from u->v. Now most of the answers that I have read, state that we run DFS…
Sachin Malhotra
  • 1,211
  • 2
  • 11
  • 24
3
votes
1 answer

Greedy Algorithm for activity selection with activity value (CLRS 16.1-5)

Is there a greedy algorithm possible for this problem. I have worked out a DP algorithm for it but am not sure of a Greedy Algorithm for it. Please Explain if a greedy algorithm exists for it. For those who are not familiar with the problem: There…
KayEs
  • 135
  • 8
3
votes
2 answers

binary prefix code in huffman algorithm

In the huffman coding algorithm, there's a lemma that says: The binary tree corresponding to an optimal binary prefix code is full But I can't figure out why. How can you prove this lemma?
Kadaj13
  • 1,423
  • 3
  • 17
  • 41
3
votes
2 answers

Minimize set of edges in a directed graph keeping connected components

Here is the full question: Assume we have a directed graph G = (V,E), we want to find a graph G' = (V,E') that has the following properties: G' has same connected components as G G' has same component graph as G E' is minimized. That is, E' is as…
user678392
  • 1,981
  • 3
  • 28
  • 50
3
votes
2 answers

Why the 14 most significant bits of 17612864 is 67?

At the bottom of Page 264 of CLRS, the authors say after obtaining r0 = 17612864, the 14 most significant bits of r0 yield the hash value h(k) = 67. I do not understand why it gives 67 since 67 in binary is 1000011 which is 7 bits. EDIT In the…
zxia31
  • 43
  • 5
3
votes
2 answers

The significance of "word" in analyzing computer algorithms

I am reading "Introduction to Algorithms", third edition. In there under the section "Analyzing Algorithms" it is written that: We also assume a limit on the size of each word of data. For example when working with inputs of size n, we typically…
Geek
  • 26,489
  • 43
  • 149
  • 227
3
votes
1 answer

encoding of the input (time complexity)

Not sure if this is the right place to ask this. In Cormen page 1056 I read that if the running time of an algorithm is O(k) and "k" is represented in unary i.e. a string of k 1s then running time of the algorithm is 0(n) where "n" is the input-size…
code4fun
  • 2,661
  • 9
  • 25
  • 39
2
votes
2 answers

understanding Universal hashing chapter on CLRS

Hi I am reading the chapter about universal hashing on CLRS. On page 234 Corollary 11.4 Using universal hashing and collision resolution by chaining in a table with m slots, it takes expected time Theta(n) to handle any sequence of n INSERT,…
Alfred Zhong
  • 6,773
  • 11
  • 47
  • 59
2
votes
1 answer

Average time complexity of open addressing

From CLRS book analysis: 11.6: Given an open-address hash table with load factor α=n/m<1 the expected number of probes in an unsuccessful search is at most 1/1-α assuming uniform hashing. 11.7: Inserting an element into an open-address hash table…
Spyromancer
  • 435
  • 1
  • 3
  • 10
2
votes
1 answer

Worst and average case of open addressing

I read chapter 11 of CLRS and there are three theorems provided regarding the analysis of open addressing: 11.6: Given an open-address hash table with load factor α=n/m<1 the expected number of probes in an unsuccessful search is at most 1/1-α…
Spyromancer
  • 435
  • 1
  • 3
  • 10
2
votes
1 answer

Do we consider recursive method calls or other method calls inside a method for that method/function's time complexity?

If I had a function call itself, meaning it is recursive, would that factor into the time complexity of the function? Or if I had a function call another function, would that factor into the total complexity of the outside function? I did find some…
2
votes
1 answer

How to solve a problem on relative asymptotic growth (table) from CLRS?

I struggle to fill this table in even though I took calculus recently and good at math. It is only specified in the chapter how to deal with lim(n^k/c^n), but I have no idea how to compare other functions. I checked the solution manual and no info…
Iaroslav Baranov
  • 1,100
  • 9
  • 17
2
votes
1 answer

Modifying merge sort to count the number of inversions

Please read this before you rush to mark this as duplicate! - This is not about the actual modification, this is about checking if a particular inversion has been counted or not. So there is this question in the popular CLRS' Introduction to…
MrProgrammer
  • 443
  • 3
  • 13
2
votes
1 answer

Implementing Prim's MST in Java

I'm having trouble getting my code to follow CLRS's example of a Minimum Spanning Tree (MST) in page 635. I'm also implementing CLRS's pseudo-code for MST-Prim quite literally, which is In particular, I'm implementing the following graph using an…
2
votes
1 answer

Can I compute closest split pair of points where distance is strictly less than delta

The Closest Pair of Points Problem has been intriguing me lately. More specifically, the divide and conquer algorithm. This recursive algorithm requires me to split a set of points into two chunks, a and b and compute the closest pair of points for…
Danilo Souza Morães
  • 1,481
  • 13
  • 18
1 2
3
11 12