Skip to content

Commit

Permalink
The code of O(2^n) isn't correct which is O(n)
Browse files Browse the repository at this point in the history
Need solve two smaller problems in one recursive call
  • Loading branch information
markgz authored Aug 8, 2019
1 parent 667d265 commit 762de52
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Big-O Notation.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,8 @@ Below are some examples for each category of performance:
func solveHanoi(n: Int, from: String, to: String, spare: String) {
guard n >= 1 else { return }
if n > 1 {
solveHanoi(n: n - 1, from: from, to: spare, spare: to)
} else {
solveHanoi(n: n - 1, from: spare, to: to, spare: from)
solveHanoi(n: n - 1, from: from, to: spare, spare: to)
solveHanoi(n: n - 1, from: spare, to: to, spare: from)
}
}
```
Expand Down

0 comments on commit 762de52

Please sign in to comment.