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
5
votes
3 answers

Matrix Multiplication using Divide and Conquer, Time Complexity

I understand that the algorithm uses 8 multiplications and 4 additions with time-complexity: The multiplication is done on every n/2 * n/2 matrices. I have few questions on this : Does every n * nmatrix finally gets reduced to n=1 size by…
5
votes
2 answers

python merge sort issue

Not sure where I am going wrong with my implementation of merge sort in python. import sys sequence = [6, 5, 4, 3, 2, 1] def merge_sort(A, first, last): if first < last: middle = (first + last) / 2 merge_sort(A, first, middle) …
nuce
  • 53
  • 4
5
votes
3 answers

Forward Edge in an Undirected Graph

CLRS - Chapter 22 Theorem 22.10 In a depth-first search of an undirected graph G, every edge of G is either a tree edge or a back edge. Proof Let (u,v) be an arbitrary edge of G, and suppose without loss of generality that u.d < v.d. Then the…
p0lAris
  • 4,750
  • 8
  • 45
  • 80
5
votes
3 answers

What does this passage from CLRS mean?

I came across this passage on page 47 of Introduction to Algorithms by Cormen et al.: The number of anonymous functions in an expression is understood to be equal to the number of times the asymptotic notation appearrs. For example in the…
Programming Noob
  • 1,755
  • 5
  • 19
  • 28
4
votes
2 answers

Difference in running time of insertion sort using CLRS's code and Robert Sedgewick's code

So, very recently, just out of curiosity, I bought the book 'Introduction to Algorithms' By CLRS. As I started going through the book, I noticed that some very typical algorithms in the book are implemented in very different way. The implementation…
Suyash Shetty
  • 513
  • 3
  • 8
  • 17
4
votes
1 answer

Can we prove correctness of algorithms using loop invariants in which we prove that it is true after the first iteration rather than before?

CLRS says that We must show three things about a loop invariant: Initialization: It is true prior to the first iteration of the loop. Maintenance: If it is true before an iteration of the loop, it remains true before the next…
Garima
  • 53
  • 5
4
votes
1 answer

Why isn't heapsort lg(n!)?

I'm reading CLRS and it says heapsort is HEAPSORT(A): BUILD-MAX-HEAP(A); for (i = A.length; i >= 1; i++) { exchange A[1] with A[i]; A.heap-size = A.heap-size - 1; MAX-HEAPIFY(A,1); } MAX_HEAPIFY is O(lg n). The book says it runs…
4
votes
2 answers

Maximum and minimum depth of quicksort

This was a problem of CLR (Introduction to Algorithms) The question goes as follow: Suppose that the splits at every level of quicksort are in the proportion 1 - α to α, where 0 < α ≤ 1/2 is a constant. Show that the minimum depth of a leaf in the…
meteors
  • 1,747
  • 3
  • 20
  • 40
4
votes
1 answer

Point of Maximum Overlap

Suppose that we wish to keep track of a point of maximum overlap in a set of intervals—a point that has the largest number of intervals in the database overlapping it. a. Show that there will always be a point of maximum overlap which is an endpoint…
city
  • 2,036
  • 2
  • 32
  • 40
3
votes
1 answer

Median select algorithm - does it find the absolute median, or a "median of medians" close to the absolute median?

Section 9.3 in CLRS 3rd edition "Selection in worst-case linear time" talks about the "Select" algorithm (sometimes called the BFPRT algorithm due to Blum, Floyd, Pratt, Rivest, and Tarjan) for finding the median of a list in O(n) time at worst…
Jordan
  • 4,928
  • 4
  • 26
  • 39
3
votes
1 answer

How to prove that lower bound of a sorting networks depth is lgn?

I'm trying to answer clrs intro to alg edition2 exercises. in chapter 27.1-4 there is an exercise which says: "Prove that any sorting network on n inputs has depth at least lg n". so I think that we can use at most (n/2) comparators in each depth…
Libnist
  • 45
  • 5
3
votes
1 answer

Confused on claim in CLRS randomly built binary search tree proof

Not sure if I should put this on math stackexchange instead, but oh well. On page 300 of CLRS... Theorem 12.4 The expected height of a randomly built binary search tree on n distinct keys is O(lgn). They define 3 random variables... 'Xn' is the…
confused
  • 213
  • 2
  • 6
3
votes
1 answer

What's the purpose of having Grey color in DFS and BFS implementation in CLRS?

In implementation of DFS and BFS, CLRS authors distinguish 3 colors for each vertex -- grey, black and white. I understand that black and white signify whether node was visited or not. Why do we need grey color? My guess is to detect cycles, but can…
3
votes
3 answers

How to find a node's predecessor in a BST with each node having 3 attributes--succ,left and right?

A problem from CLRS ,3ed. 12.3-5 Suppose that instead of each node x keeping the attribute x.p, pointing to x’s parent, it keeps x.succ, pointing to x’s successor. Give pseudocode for SEARCH,INSERT, and DELETE on a binary search tree T using this…
yjcdll
  • 51
  • 5
3
votes
1 answer

MIT Lecture WRONG? Analysis of open addressing in hashing

In the following MIT lecture: https://www.youtube.com/watch?v=JZHBa-rLrBA at 1:07:00 ,professor taught to calculate number of probes in unsuccessful search. But my method of calculating doesn't matches his. My answer is: Number of probes= m= no. of…
1
2
3
11 12