演算法›Ch1 Introduction
第 3 題/共 4 題
◀ AL 3/4
3. 隨機演算法、期望值分析、遞迴
#AL-01-003中隨機演算法期望值分析遞迴

Consider the following randomized recursive algorithm, which prints out some number of exclamation marks (!) and some number of asterisks (*). Assume that the size of AA is nn initially. What are the expected numbers of !'s and *'s that the algorithm prints out. Choose the tightest possible answers.

RandomizedPrint(A): n = length(A) if n <= 1: print "!" return for i in {0,...,n-1}: print "*" Choose a uniformly random integer p in {1,...,n-1} RandomizedPrint(A[:p]) RandomizedPrint(A[p:])

📄 台大114
跳轉到第題
▤完整推導請見《WH 資工筆記 · 演算法》Ch1 Introduction
本章題號 · 1–4 / 4