emory-courses / dsa-java

Data Structures and Algorithms in Java
https://emory.gitbook.io/dsa-java/
42 stars 55 forks source link

[HW#1] Unknown error #103

Closed Bksimon closed 4 years ago

Bksimon commented 4 years ago

So I've been staring at this code for a couple hours now adding in various print statements, but can't seem to find the reason behind my error. It has to do with line 66, when leaving it as "row < input.length-1" it will correctly combine all but the last row. So the error of different array sizes is expected.

However, when I switch it to "row < input.length" to include the last row I get a crazy error. The output array overflows and produces negative numbers and for some reason unknown to me it will re-run my sort algorithm like there's no tomorrow with an infinite loop.

https://github.com/Bksimon/dsa-java/blob/master/src/main/java/edu/emory/cs/sort/hybrid/HybridSortHW.java

@lujiaying @marvinquiet

lujiaying commented 4 years ago

Please considering remove all print statements, and then test it again. I tested the code in textbook testRobutness(), nothing special happens.

Bksimon commented 4 years ago

Ahh you're right. Thanks for the speedy response and your s tier analysis. Idk why those print statements did that.

lujiaying commented 4 years ago

print statements just slow down the speed significantly. Even keeping them, if you waiting enough time you can still get correct results.