Skip to content

Commit

Permalink
Updated exercise 1.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
reneargento committed May 21, 2024
1 parent 0e7ead4 commit 62da660
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/chapter1/section5/Exercise4.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sz[]
0 1 2 3 4 5 6 7 8 9
1 1 1 1 3 1 1 1 1 1

Array accesses: 4 (2 for find(3), 1 for find(8) and 1 for updating parent)
Array accesses: 5 (3 for find(3), 1 for find(8) and 1 for updating parent)

6-5

Expand Down Expand Up @@ -82,7 +82,7 @@ sz[]
0 1 2 3 4 5 6 7 8 9
1 1 2 1 4 1 2 1 1 1

Array accesses: 4 (2 for find(8) and 2 for find(9))
Array accesses: 6 (3 for find(8) and 3 for find(9))

5-0

Expand All @@ -94,7 +94,7 @@ sz[]
0 1 2 3 4 5 6 7 8 9
1 1 2 1 4 1 3 1 1 1

Array accesses: 4 (1 for find(0), 2 for find(5) and 1 for updating parent)
Array accesses: 5 (3 for find(5), 1 for find(0) and 1 for updating parent)

7-2

Expand All @@ -118,7 +118,7 @@ sz[]
0 1 2 3 4 5 6 7 8 9
1 1 3 1 4 1 6 1 1 1

Array accesses: 4 (1 for find(6), 2 for find(1) and 1 for updating parent)
Array accesses: 5 (1 for find(6), 3 for find(1) and 1 for updating parent)

1-0

Expand All @@ -130,7 +130,7 @@ sz[]
0 1 2 3 4 5 6 7 8 9
1 1 3 1 4 1 6 1 1 1

Array accesses: 5 (3 for find(1) and 2 for find(0))
Array accesses: 8 (5 for find(1) and 3 for find(0))

6-7

Expand All @@ -142,7 +142,7 @@ sz[]
0 1 2 3 4 5 6 7 8 9
1 1 3 1 4 1 6 1 1 1

Array accesses: 4 (1 for find(6) and 3 for find(7))
Array accesses: 6 (1 for find(6) and 5 for find(7))

Worst-case input

Expand Down Expand Up @@ -241,4 +241,6 @@ sz[]
Array accesses: 3 (1 for find(0), 1 for find(4) and 1 for updating parent)

Thanks to sergiovasquez122 (https://github.com/sergiovasquez122) for noticing that there were extra array fields in the worst case:
https://github.com/reneargento/algorithms-sedgewick-wayne/issues/168
https://github.com/reneargento/algorithms-sedgewick-wayne/issues/168
Thanks to xzy2022 (https://github.com/xzy2022) for reporting an issue with the array access count in the find() method:
https://github.com/reneargento/algorithms-sedgewick-wayne/issues/307

0 comments on commit 62da660

Please sign in to comment.