Discuss all kind of algorithms and data structures from their mathematical and programming sides.
Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard
Consider an array containing positive and negative integers.Define contigsum(i,j) as the sum of the contiguous elements a[i] through a[j] for all array indexes i<=j.Develop a recursive procedure that determines i and j such that contigsum(i,j) is maximized.The recursion should consider the two halves of the array a.
- Posts: 1
- Joined: Fri Feb 27, 2009 10:09 pm
I leave this problem as an exercise to the reader. If you have a question I'll answer that, though.
Need information on a function I've posted? Chances are it's at the MSDN
- Posts: 6506
- Joined: Mon Sep 22, 2003 5:27 pm
This could very easily (and more efficiently) be done with a single loop. Your instructor will probably show you that implementation later on.
The recursive solution is also pretty straight forward. Remember that contigsum(i,i) is i.
- Posts: 2810
- Joined: Mon Sep 22, 2003 5:25 pm
- Location: MD USA
Return to Algorithms & Data Structures
Who is online
Users browsing this forum: No registered users and 1 guest