04 - CIS 121 Spring 2010 Data Structures and Introduction...

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

View Full Document Right Arrow Icon
1 1/29/10 Lecture Notes 4 1 CIS 121 Spring 2010 Data Structures and Introduction to Algorithms using JAVA Lecture Notes 4: Maximum contiguous subsequence sum © 1999-2009 S.Kannan, V.Tannen, S.Guha & K.Daniilidis © 2006 M.Goodrich & R.Tamassia (with permission) 1/29/10 Lecture Notes 4 2 Improving asymptotic running time Next we look at a problem (finding the maximum contiguous subsequence sum) that can be solved by several algorithms. We will see that additional thinking and clever ideas can lead to algorithms that run in better asymptotic bounds!
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 1/29/10 Lecture Notes 4 3 Maximum Contiguous Subsequence Sum: One Problem, Many Solutions Problem : Given a sequence of (possibly negative) integers find the maximum value of the sum of a subsequence: The maximum subsequence sum is 0 if all the integers are negative. , ,..., , 2 1 N A A A = j i k k A . Example: The input is [ -2, 11, -4, 13, -5, 2 ] The answer is 20, by summing [ 11, -4, 13 ] . 1/29/10 Lecture Notes 4 4 Solution 1 --- ruminations. .. Consider all possibilities for where the answer might come from. .. ... 0 1 2 i j N-1 add Is sum larger? Yes: remember it! No: move on ...
Background image of page 2
3 1/29/10 Lecture Notes 4 5 Analysis of solution 1 When we are sufficiently clear in our ruminations we should be able to analyze the program even before we write it! In fact, we are analyzing the algorithm , not the details of the program. To add up the interval of length
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

04 - CIS 121 Spring 2010 Data Structures and Introduction...

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

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