clrs4e-solutions icon indicating copy to clipboard operation
clrs4e-solutions copied to clipboard

6.5-5

Open wojtask opened this issue 3 years ago • 3 comments

wojtask avatar Jan 01 '23 01:01 wojtask

Migratable from CLRS2e's 6.5-4. Note, that the code of Max-Heap-Insert is updated.

wojtask avatar Apr 13 '23 15:04 wojtask

While I was arguing before that temporarily updating the key of the new object to $-\infty$ is necessary, now I am not so sure about it. We can simply leave $x.key$ unchanged in $MaxHeapInsert$ and call $MaxHeapIncreaseKey(A, x, x.key)$ at the end. This call is safe, because it won't generate the error, and will correctly get rid of the max-heap property violation that adding $x$ may have caused.

It could have been done in the CLRS2e's version of the procedure as well, by assigning $A[heapsize[A]]\leftarrow key$ before increasing the key of the new element.

Anyone would like to share their opinion on it?

wojtask avatar Mar 02 '25 13:03 wojtask

I got a confirmation that the Authors agreed that line 5 in Max-Heap-Insert is redundant, and that Exercise 6.5-5 is not valid (thanks to @evarga who spoke to Tom Cormen). The Authors aren't going to fix that though, so I'm leaving this exercise unsolved, with a clarification note instead.

wojtask avatar Mar 15 '25 21:03 wojtask