資料結構›Ch7 搜尋與排序
第 56 題/共 76 題
◀ DS 56/76
56. Quicksort、Algorithm Analysis
#DS-07-056中QuicksortAlgorithm Analysis
  1. Following is the quicksort algorithm from Wikipedia (https://en.wikipedia.org/wiki/Quicksort). Assume that the input array A has n elements. Which of the following statements are true?
// Sorts a (portion of an) array, divides it into partitions, then sorts those
algorithm quicksort(A, lo, hi) is
  if lo >= 0 && hi >= 0 && lo < hi then
    p := partition(A, lo, hi)
    quicksort(A, lo, p - 1)
    quicksort(A, p + 1, hi)

// Divides array into two partitions
algorithm partition(A, lo, hi) is
  pivot := A[hi]

  i := lo - 1

  for k := lo to hi do
    if A[k] <= pivot then
      i := i + 1
      swap A[i] with A[k]
  return i
📄 交大111
跳轉到第題
▤完整推導請見《WH 資工筆記 · 資料結構》Ch7 搜尋與排序
本章題號 · 41–60 / 76