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

CLRS 18-2.4 Suppose that we insert the keys {1,2,…,n} into an empty B-tree with minimum degree 2. How many nodes does the final B-tree have?

Suppose that we insert the keys {1,2,…,n} into an empty B-tree with minimum degree 2. How many nodes does the final B-tree have?
0
votes
1 answer

Can an m-way B-Tree have m odd?

I read on book CLRS that we have m-way B-tree where m is even. But is there is B-Tree where m is odd, if there is then how can we make changes in the code given in this book.
suleman
  • 65
  • 12
0
votes
1 answer

Probability and Asymptotics

Consider the case when we have n identical inputs, for a binary search tree. We randomly select from x.left and x.right, while inserting the node. There's a question in clrs (12-1-(d)), which asks us to derive the expected running time of this…
Mooncrater
  • 4,146
  • 4
  • 33
  • 62
0
votes
1 answer

Runtime of R-Select vs Select in average case?

In worst case R-select is O(n^2) where as select is O(n). Can someone explain and contrast their behavior in average cases. P.s. - I am not sure if its a repetitive question. I can delete if its the case! Thanks!!
polyglot
  • 57
  • 11
0
votes
0 answers

Maximum Subarray (BRUTE)

I was trying to implement the Brute method of Maximum Subarray problem, (clrs 4.1-2) and I thought I got it( quite easily ) as : PSEUDO-CODE: BRUTE-MAX-SUB-ARR(A) 1. from = -1 , to = -1, TSUM = -infinity 2. for i=0 to A.length-2 3. sum = 0 4. …
Mooncrater
  • 4,146
  • 4
  • 33
  • 62
0
votes
2 answers

big O in algorithm

I have read the definition of big O in the introduction to algorithm which book doesn't talk about my confusion. According to its definition, everybody knows the function T(n) = 3n belongs to O(n),my confusion is whether all functions what belongs…
Dr.Shiki
  • 3
  • 4
0
votes
1 answer

Is this a correct invariant for this loop?

This is pseudocode for a linear search in an array, returning an index i if the desired element e in an array A is found, NIL otherwise (this is from the CLRS book, 3rd edition, exercise 2.1-3): LINEAR_SEARCH (A, e) for i = 1 to A.length …
pr0gma
  • 577
  • 3
  • 8
  • 18
0
votes
1 answer

Master Theorem: comparing two versions of the theorem

I have generally seen two versions of the Master theorem. Version 1: (from Tim Roughgarden's course) for recurrence relations of the form, T(n) <= aT(n/b)+O(n^d) where a >= 1, b > 1, and d >= 0 there are 3 cases, case 1: if a=b^d, then T(n) =…
jkarimi
  • 1,247
  • 2
  • 15
  • 27
0
votes
1 answer

Why won't this merge sort implementation work?

I am following along with the CLRS book and am implementing all the algorithms in python as I go along, this is the merge sort algorithm. I tested the merge function on a test array and it works, so it must be the merge_sort function, however it's…
Jamal Moir
  • 66
  • 9
0
votes
2 answers

CLRS Insertion Sort Implmentation

I was going through Insertion Sort algo in CLRS. I am not sure which is the right implementation - Algo from CLRS - Implementation 1 : def Insertion_sort(): list = [3,5,1,7,2,4] for j in xrange(1,len(list)): i = j-1 while i>=0 and list[i] >…
Fox
  • 9,384
  • 13
  • 42
  • 63
0
votes
2 answers

When would it be important to be able to calculate order of growth?

I'm reading the chapter 2 and 3 of CLRS, and get stuck so often, especially in the problems provided at the end of each chapter, that I wonder if it'll ever be worthwhile for this much effort. I can't understand the solution online like this one:…
stacko
  • 237
  • 1
  • 7
0
votes
1 answer

Why the weight of a critical path provides a lower bound on the total time to perform all the jobs?

In Introduction to Algorithms P657, 3rd edition, it says: A critical path is a longest path through the dag, corresponding to the longest time to perform any sequence of jobs. Thus, the weight of a critical path provides a lower bound on the…
fuiiii
  • 1,359
  • 3
  • 17
  • 33
0
votes
1 answer

CLRS exercise 3.2-4 Big-Oh vs Little Oh

I'm self studying CLRS, and I've hit this point - the question I'm answering is: Is the function ⌈lglgn⌉! polynomially bounded? And I've reduced it down to =Θ(lglgn⋅lglglgn) Now, all the solutions manuals seem to use little oh at this point to…
Verlet64
  • 67
  • 1
  • 8
0
votes
2 answers

Lazy propagation for Segmented Tree

There is something unclear to me in the lazy propagation algorithm for segmented trees. According to the code below, upon completely overlap of the query interval, the update value is just added to the parent node and the children are marked for…
mkmostafa
  • 3,071
  • 2
  • 18
  • 47
0
votes
2 answers

Where am I going wrong in this python code for CLRS exercise 2.1-4

So the problem is: "Consider a problem of adding two n-bit binary integers, stored in two n-element arrays A and B. The sum of the two integers should be stored in binary form in an (n+1)-element array C. State the problem formally and write…