jeffgerickson / algorithms

Bug-tracking for Jeff's algorithms book, notes, etc.
7.92k stars 1.02k forks source link

[Oops.] Errors in MomSelect pseudocode #168

Open emilykfox opened 5 years ago

emilykfox commented 5 years ago

Please verify that the error is present in the most recent revision before reporting. Downloaded today.

Chapter number or note title: Chapter 1: Recursion

Page number: 37

Error description:

1) You pass floor{m / 2} as the second parameter to the first call recursive call of MomSelect (the Approximate Median Fairy). So, you're not really selecting the median of the medians, and you're contradicting your figures on the next page.

2) You pass mom as the second parameter of Partition, but partition is supposed to take an element index.

Suggested fix (if any):

1) Pass ceil{m / 2}.

2) Either a) add a line like "p <- index of mom" and pass p to Partition, or b) write a for loop to compute such a p.