In the worst case of Randomized Quicksort, the random number generator Random is called Θ(n) times, as Randomized-Partition is called n-1 times in the worst case. In the best case, Random is called Θ(n) times as well, as Randomized-Partition is called approximately n/2 times.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as ODP, PDF, TXT or read online from Scribd
In the worst case of Randomized Quicksort, the random number generator Random is called Θ(n) times, as Randomized-Partition is called n-1 times in the worst case. In the best case, Random is called Θ(n) times as well, as Randomized-Partition is called approximately n/2 times.
In the worst case of Randomized Quicksort, the random number generator Random is called Θ(n) times, as Randomized-Partition is called n-1 times in the worst case. In the best case, Random is called Θ(n) times as well, as Randomized-Partition is called approximately n/2 times.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as ODP, PDF, TXT or read online from Scribd
In the worst case of Randomized Quicksort, the random number generator Random is called Θ(n) times, as Randomized-Partition is called n-1 times in the worst case. In the best case, Random is called Θ(n) times as well, as Randomized-Partition is called approximately n/2 times.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as ODP, PDF, TXT or read online from Scribd
Download as odp, pdf, or txt
You are on page 1of 1
During the running of the procedure Randomized-
Quicksort, how many calls are made to the
random-number generator Random in the worst case? How about in the best case? Give your answer in terms of Θ-notation. 演算法如下 Randomized-Partition(A,p,r) 1 i ← Random(p, r) 2 exchange A[r] ↔ A[i] 3 return Partition(A,p,r) Randomized_Quicksort(A,p,r) 1 if p < r 2 then q ← Randomized-Partition(A, p, r) 3 Randomized_Quicksort(A,p,q) 4 Randomized_Quicksort(A,q+1,r) 每次 Randomized-Partition 都會呼叫一次 Random,因此這個問題 等於在問 Randomized-Partition會被呼叫幾次,顯然 worst case 是會呼叫 n-1 次,best case 會呼叫 ⌊n/2⌋ 次,只是題目要用 來 表示,因此都是 (n)。