edited by
365 views
1 votes
1 votes

I implemented maximum sub-array problem with Divide and Conquer approach in c++ and python. I got little bit of confusion in the implementation.Below are the implementations. I got different results when I change the for loop of both c++ and python code.in first I implemented something like that.

I used vector A={13,-3,-25,20,-3,-16,-23,18,20,-7,12,-5,-22}

and in python I used list A=[13,-3,-25,20,-3,-16,-23,18,20,-7,12,-5,-22]

(1) for i = mid downto low

     and 

(2) for i =low upto mid

(1) C++ Source Code: https://ideone.com/SxbJOe (check line 13 (for loop))

(2) C++ Source Code: https://ideone.com/hThJgI (check line 13 (for loop))

(1) Python Source Code: https://ideone.com/Ovg6bl (check line 4(for loop))

(2) Python Source Code: https://ideone.com/7YS8OT (check line 4(for loop))

In first case I am getting right output i.e 43 but in 2nd I am getting 56 as the output! Please help!

edited by

Please log in or register to answer this question.

Related questions

0 votes
0 votes
0 answers
4
akash.dinkar12 asked Apr 5, 2019
293 views
Write pseudo code for the brute-force method of solving the $maximum-subarray$ problem. Your procedure should run in $\Theta(n^2)$ time.