gzc / CLRS

:notebook:Solutions to Introduction to Algorithms
MIT License
9.44k stars 2.75k forks source link

Wrong answer #340

Open ghost opened 2 years ago

ghost commented 2 years ago

It seems that the answer to the 10.1.4 is wrong. Checking for tail[Q]+1 == head[Q] is not enough in the case where we have tail[Q] = length[Q] and head[Q] == 1 which will result on an overflow but it will not be detected by the offered solution. A better solution would be to check if head[Q] == tail[Q] + 1 or ( tail[Q] == length[Q] and head[Q] == 1 ).