# lec02 - 6.006 Introduction to Algorithms Lecture 2: Peak...

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

6.006 Introduction to Algorithms Lecture 2: Peak Finding Prof. Erik Demaine

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

View Full Document
Today Peak finding (new problem) 1D algorithms 2D algorithms (new technique)
Finding Water… IN SPACE You are Geordi LaForge Trapped on alien mountain range Need to find a pool where water accumulates Can teleport, but can’t see http://en.wikipedia.org/wiki/File:GeordiLaForge.jpg photo by Erik Demaine Banff, Canada

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

View Full Document
Finding Water… IN SPACE Problem: Find a local minimum or maximum in a terrain by sampling photo by Erik Demaine Banff, Canada
1D Peak Finding Given an array : is a peak if it is not smaller than its neighbor(s): where we imagine Goal: Find any peak 1 2 6 5 3 7 4 0123456 :

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

View Full Document
“Brute Force” Algorithm Test all elements for peakyness for in : if : return 1 2 6 5 3 7 4 0123456 :
Algorithm 1½ Global maximum is a local maximum for in : if : return 1 2 6 5 3 7 4 0123456 :

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

View Full Document
Cleverer Idea Look at any element and its neighbors If peak: return Otherwise: locally rising on some side
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 11/11/2011 for the course MATH 180 taught by Professor Byrns during the Spring '11 term at Montgomery College.

### Page1 / 23

lec02 - 6.006 Introduction to Algorithms Lecture 2: Peak...

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

View Full Document
Ask a homework question - tutors are online