Timeline for Maximum subarray problem solved with divide and conquer also for the all negative element case
Current License: CC BY-SA 3.0
5 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 2, 2016 at 19:14 | comment | added | JS1 |
@windlessStorm The easiest way is to use a larger type than int for your sum. For example, if your ints are 32-bit, use int64_t for your sum. If your ints are 64-bit, then you would need to do something more tricky (custom 128-bit math). For any size int, you can detect overflow from sign changes, but just detecting the overflow doesn't allow you to continue finding the max subarray (you need to actually hold the total sum)
|
|
| Feb 2, 2016 at 11:22 | vote | accept | windlessStorm | ||
| Feb 2, 2016 at 10:38 | comment | added | windlessStorm | What is the good way to avoid and handle overflow like that as you mentioned in #1. Should I put checks on values attained by the variables so its sum doesn't overflow the sum? or some better way? thanks :) | |
| Feb 2, 2016 at 10:35 | vote | accept | windlessStorm | ||
| Feb 2, 2016 at 10:35 | |||||
| Feb 2, 2016 at 7:39 | history | answered | JS1 | CC BY-SA 3.0 |