clrs

Maximum and minimum depth of quicksort

北城以北 提交于 2019-12-21 19:16:10
问题 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 recursion tree is approximately - lg n/ lg α and the maximum depth is approximately -lg n/ lg(1 - α). (Don't worry about integer round-off.)http://integrator-crimea.com/ddu0043.html I'm not getting how to reach this solution. as per the link they

what is meaning expected value(math) and what reason behind it in quickSort?

浪尽此生 提交于 2019-12-12 03:22:44
问题 I need help interpreting the formulas from the Quicksort algorithm description in the Clrs book, page 157 My questions are overlayed in the page screenshot. This formula is about QiuckSort Algorithm. what is behind(logic) E[X] ... I mean what is happening in quickstart that the authors wrote this formula? given n=3, the result is 8, ok, but what does 8 mean semanitcally in quicksort? 回答1: In order to understand the analysis in the book you cited, you need to understand some concepts from

Red-Black Tree Delete Fixup in CLRS Second Edition, in Clojure

穿精又带淫゛_ 提交于 2019-12-11 02:44:09
问题 I am implementing red-black tree deletion for interval trees following CLRS 2nd edition, fourth printing, pg 288-9. Summary of bug: RB-Delete-Fixup If x and w are the sentinel nodes, which is a possible consequence of RB-Delete, then the evaluation of color(left(w)) resp. color(right(w)) in RB-Delete-Fixup suffers a null pointer exception on the first iteration of the while loop. (if (and (= (get-color (get-left @w)) black) (= (get-color (get-right @w)) black)) ;; Bug here! All of the code

Is a node in a tree considered its own ancestor?

为君一笑 提交于 2019-12-05 19:21:52
问题 I'm wondering what the consensus is on the definition of "ancestor" in a computer science context. I only ask because in Introduction to Algorithms, Second Edition, p. 259 there is a description of the algorithm Tree-Successor(x) that seems odd. In finding the successor of node x , [...] if the right subtree of node x is empty and x has a successor y , then y is the lowest ancestor of x whose left child is also an ancestor of x . In a binary search tree with a root having key 2 and children 1

Printing out nodes in a disjoint-set data structure in linear time

风流意气都作罢 提交于 2019-12-04 11:43:33
I'm trying to do this exercise in Introduction to Algorithms by Cormen et al that has to do with the Disjoin Set data structure: Suppose that we wish to add the operation PRINT-SET(x) , which is given a node x and prints all the members of x 's set, in any order. Show how we can add just a single attribute to each node in a disjoint-set forest so that PRINT-SET(x) takes time linear in the number of members of x 's set , and the asymptotic running times of the other operations are unchanged. Assume that we can print each member of the set in O(1) time. Now, I'm quite sure that the attribute

Maximum and minimum depth of quicksort

谁说我不能喝 提交于 2019-12-04 09:03:59
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 recursion tree is approximately - lg n/ lg α and the maximum depth is approximately -lg n/ lg(1 - α). (Don't worry about integer round-off.) http://integrator-crimea.com/ddu0043.html I'm not getting how to reach this solution. as per the link they show that for a ratio of 1:9 the max depth is log n/log(10/9) and minimum log n/log(10). Then how can

Is a node in a tree considered its own ancestor?

偶尔善良 提交于 2019-12-04 03:21:03
I'm wondering what the consensus is on the definition of "ancestor" in a computer science context. I only ask because in Introduction to Algorithms , Second Edition, p. 259 there is a description of the algorithm Tree-Successor(x) that seems odd. In finding the successor of node x , [...] if the right subtree of node x is empty and x has a successor y , then y is the lowest ancestor of x whose left child is also an ancestor of x . In a binary search tree with a root having key 2 and children 1 and 3 , the successor of 1 is its parent 2 . In this case, x is the left child of x 's successor, y .

asymptotic tight bound for quadratic functions

跟風遠走 提交于 2019-12-03 06:01:25
问题 In CLRS (Introduction to Algorithms by Cormen, Leiserson, Rivest, and Stein), for a function f ( n ) = an 2 + bn + c they said Suppose we take the constants c 1 = a /4, c 2 = 7 a /4, and n 0 = 2·max(| b |/ a , √(| c |/ a )). Then 0 ≤ c 1 n 2 ≤ an 2 + bn + c ≤ c 2 n 2 for all n ≥ n 0 . Therefore f ( n ) is Θ( n 2 ). But they didn't specify how values of these constants came ? I tried to prove it but couldn't. Please tell me how these constants came ? 回答1: There's nothing special about those

Unbiased random number generator using a biased one

混江龙づ霸主 提交于 2019-11-28 23:26:25
You have a biased random number generator that produces a 1 with a probability p and 0 with a probability (1-p). You do not know the value of p. Using this make an unbiased random number generator which produces 1 with a probability 0.5 and 0 with a probability 0.5. Note : this problem is an exercise problem from Introduction to Algorithms by Cormen, Leiserson, Rivest, Stein.(clrs) pau.estalella The events (p)(1-p) and (1-p)(p) are equiprobable. Taking them as 0 and 1 respectively and discarding the other two pairs of results you get an unbiased random generator. In code this is done as easy

worst case in MAX-HEAPIFY: “the worst case occurs when the bottom level of the tree is exactly half full”

六眼飞鱼酱① 提交于 2019-11-28 21:27:29
In CLRS , third Edition, on page 155, it is given that in MAX-HEAPIFY, "the worst case occurs when the bottom level of the tree is exactly half full" I guess the reason is that in this case, Max-Heapify has to "float down" through the left subtree. But the thing I couldn't get is "why half full" ? Max-Heapify can also float down if left subtree has only one leaf. So why not consider this as the worst case ? Read the entire context: The children's subtrees each have size at most 2n/3 - the worst case occurs when the last row of the tree is exactly half full Since the running time T(n) is