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
0
votes
2 answers

Cannot understand CLRS Problem 4-2 case 2

The question: 4-2 Parameter-passing costs Throughout this book, we assume that parameter passing during procedure calls takes constant time, even if an N-element array is being passed. This assumption is valid in most systems because a pointer to…
Xazy
  • 9
  • 3
0
votes
2 answers

Why does the "for" loop execute one more time than the body of the loop?

In the book Introduction to Algorithms, there is a line under the heading Analysis of Insertion Sort that reads: "When a for or while loop exits in the usual way (i.e., due to the test in the loop header), the test is executed one time more than…
0
votes
1 answer

Solving Negative coefficients in linear program

I am trying to solve a assignment problem using linear programming. I am using the simplex algorithm mentioned in CLRS. Consider the below example: --(1/1)--->|a|---(10/1)------>|d|-----------> | | ^ …
Abis
  • 155
  • 8
0
votes
1 answer

Explanation to Rabin Karp from CLRS

I've been reading the Rabin Karp algorithm from Introduction To Algorithms. Everything makes sense except the following. In general, with a d-ary alphabet {0, 1, . . ., d - 1}, we choose q so that dq fits within a computer word I don't understand…
Rajat Saxena
  • 3,834
  • 5
  • 45
  • 63
0
votes
1 answer

Use Floyd-Warshall algorithm to find negative-weight circles

To judge whether a graph contains negative-circles, after running the Floyd-Warshall algorithm, can I deal with the problem only by scanning the diagonal elements of the matrix to find whether it has negative elements. I dont't know how to prove…
NiaBie
  • 55
  • 1
  • 9
0
votes
1 answer

Result calculation in rod cutting

I am learning the rod cutting algorithm from CLRS book. I believe I understand the logic and my below solution was accepted on this OJ. #include #include using namespace std; int prices[101]; int result[101]; int…
0
votes
1 answer

implementing priority queues and heaps

I am trying to implement a min priority queue using a binary min heap based on the description from "Introduction to Algorithms, Third Edition" and have a couple of questions. The book says that we often need to store a handle (pointer or integer)…
James Miller
  • 25
  • 1
  • 4
0
votes
1 answer

Confused about a convention in pseudocode from Introduction to Algorithms

I have the follwoing convention in pseudocode, from the Introduction to Algorithims textbook: Parameters are passed to a procedure by value: the called procedure receives its own copy of the parameters, and if it assigns a value to a parameter,…
Jake Wright
  • 373
  • 1
  • 8
0
votes
1 answer

Worst case in Max-Heapify - Why can you get 2n/3?

I have figured out how to get 2n/3 from the following question: Worst case in Max-Heapify - How do you get 2n/3? "In CLRS, third Edition, on page 155, it is given that in MAX-HEAPIFY: 'The children’s subtrees each have size at most 2n/3—the worst…
fatpanda2049
  • 483
  • 1
  • 4
  • 9
0
votes
1 answer

Modular arithmatic in Rabin-karp algorithm

I am studying Rabin-karp algotithm for string matching from CLRS in which modular arithmetic is used for hashing which i haven't studied so what I don't understand is that how does (7 – 3·3)·10 + 2 (mod 13) evaluate to 8 (mod 13)
0
votes
0 answers

Python: AND operator in IF statement

It is a heap sort. def Parent(i): return i / 2 def Left(i): return 2 * i def Right(i): return 2 * i + 1 def MAX_HEAPIFY(A, i): # A.heapSize == A[0] l = Left(i) r = Right(i) Here is the problem. if l <= A[0] and A[l] >…
Belent
  • 1
0
votes
1 answer

Regarding subsequences - CLRS

I am reading chapter 15 from CLRS and came across this definition of a subsequence: A subsequence of a given sequence is just the given sequence with zero or more elements left out. Later it is said that: Each subsequence of X corresponds to a…
babon
  • 3,615
  • 2
  • 20
  • 20
0
votes
1 answer

solving the recurrance by the method of substitution

While learning the algorithms and referring to CLRS, I came across a problem T(n) = T(n-a) + T(a) + cn ; a >= 1 and c > 0 it is Big-theta(n^2), can be easily proved by recursion tree method I can solve it by the method of recursion tree. While…
Adorn
  • 1,403
  • 1
  • 23
  • 46
0
votes
1 answer

Red Black Tree in C

I am trying to implement red black tree in C. For reference I am using CLRS. But when I run the code I am getting "Segmentation fault (core dumped)" error message. I can't figure out what's wrong in my code so, could anyone tell me what's wrong in…
0
votes
1 answer

Understanding BELLMAN-FORD algorithm from CLRS

Consider this simple graph: S -> A -> B -> C In CLRS, the authors have implemented a loop which goes for |V|-1. But according to path-relaxation property a simple path P can be < s,a,b,c >. Using the path-relaxation property we are going to relax…
Rajat Saxena
  • 3,834
  • 5
  • 45
  • 63