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

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

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!

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

View Full Document
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 ...
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

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

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

## This note was uploaded on 02/19/2010 for the course CIS 121 taught by Professor Tannen during the Spring '09 term at UPenn.

### 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
Ask a homework question - tutors are online