MaxSumTest - public final class MaxSumTest START Fig02_05...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public final class MaxSumTest { /* START: Fig02_05.txt */ /** * Cubic maximum contiguous subsequence sum algorithm. */ public static int maxSubSum1( int [ ] a ) { /* 1*/ int maxSum = 0; / /* 2*/ for( int i = 0; i < a.length; i++ ) /* 3*/ for( int j = i; j < a.length; j++ ) { /* 4*/ int thisSum = 0; / /* 5*/ for( int k = i; k <= j; k++ ) /* 6*/ thisSum += a[ k ]; / /* 7*/ if( thisSum > maxSum ) /* 8*/ maxSum = thisSum; } /* 9*/ return maxSum; } /* END */ / /* START: Fig02_06.txt */ /** * Quadratic maximum contiguous subsequence sum algorithm. */ public static int maxSubSum2( int [ ] a ) { /* 1*/ int maxSum = 0; / /* 2*/ for( int i = 0; i < a.length; i++ ) { /* 3*/ int thisSum = 0; /* 4*/ for( int j = i; j < a.length; j++ ) { /* 5*/ thisSum += a[ j ]; / /* 6*/ if( thisSum > maxSum ) /* 7*/ maxSum = thisSum; } } /* 8*/ return maxSum; } /* END */ / /* START: Fig02_07.txt */ /** * Recursive maximum contiguous subsequence sum algorithm....
View Full Document

{[ snackBarMessage ]}

Page1 / 3

MaxSumTest - public final class MaxSumTest START Fig02_05...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online