02 - Maximum Contiguous Subarray

# 02 - Maximum Contiguous Subarray - Part I Divide and...

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

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

View Full Document

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

View Full Document

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.

Unformatted text preview: Part I: Divide and Conquer Lecture 2: Maximum Contiguous Subarray Problem Lecture 2: Maximum Contiguous Subarray Problem Part I: Divide and Conquer Introduction to Part I Divide and conquer (D&C) is an important algorithm design paradigm. It works by recursively breaking down a problem into two or more sub-problems of the same (or related) type, until these become simple enough to be solved directly. The solutions to the sub-problems are then combined to give a solution to the original problem. In Part I, we will illustrate Divide-and-Conquer using several examples: Maximum contiguous subarray Polynomial Multiplication Partition and Selection Lecture 2: Maximum Contiguous Subarray Problem Part I: Divide and Conquer Objective and Outline Objective : Discuss first example of divide-and-conquer Reference : Chapter 8 in Programming Pearls, (2nd ed) by Jon Bentley Outline: Problem definition A brute force algorithm A data-reuse algorithm A divide-and-conquer algorithm Analysis of the divide-and-conquer algorithm Summary Lecture 2: Maximum Contiguous Subarray Problem Part I: Divide and Conquer Maximum Contiguous Subarray Problem ACME CORP 1 – PROFIT HISTORY Year 1 2 3 4 5 6 7 8 9 Profit M\$-3 2 1-4 5 2-1 3-1 Between years 1 and 9: ACME earned- 3 + 2 + 1- 4 + 5 + 2- 1 + 3- 1 = 4 M\$ Between years 2 and 6: ACME earned 2 + 1- 4 + 5 + 2 = 6 M\$ Betweeen years 5 and 8: ACME earned 5 + 2- 1 + 3 = 9 M\$ Problem: Find the span of years in which ACME earned the most Answer: Year 5-8 , 9 M\$ 1 A Company that Makes Everything Lecture 2: Maximum Contiguous Subarray Problem Part I: Divide and Conquer Formal Definition Input : An array of reals A [1 . . . N ] The value of sub array A [ i . . . j ] is V ( i , j ) = j X x = i A ( x ) Definition (Maximum Contiguous Subarray Problem) Find i ≤ j such that V ( i...
View Full Document

{[ snackBarMessage ]}

### Page1 / 22

02 - Maximum Contiguous Subarray - Part I Divide and...

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

View Full Document
Ask a homework question - tutors are online