• 沒有找到結果。

# Course information

N/A
N/A
Protected

Share "Course information"

Copied!
26
0
0

(1)

## Course information

### 14.Collaboration policy

September 7, 2005 Introduction to Algorithms L1.2

(2)

## Analysis of algorithms

### •reliability

September 7, 2005

Introduction to Algorithms L1.3

## Why study algorithms and performance?

### ‧Speed is fun!

September 7, 2005

Introduction to Algorithms L1.4

(3)

## The problem of sorting

### Input: 8 2 4 9 3 6Output: 2 3 4 6 8 9

September 7, 2005 L1.5

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

## INSERTION-SORT

NSERTION

ORT

### i ← i –1A[i+1] = key

Introduction to Algorithms L1.6

September 7, 2005

### “pseudocode”

(4)

Introduction to Algorithms L1.7

September 7, 2005

NSERTION

ORT

## INSERTION-SORT

i

n 1 j

### 8 2 4 9 3 6

Introduction to Algorithms L1.8

September 7, 2005

(5)

## Example of insertion sort

### 8 2 4 9 3 6

September 7, 2005 L1.9

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.10

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

## Example of insertion sort

(6)

September 7, 2005

Introduction to Algorithms L1.11

## Example of insertion sort

### 8 2 4 9 3 6 2 8 4 9 3 6

September 7, 2005

Introduction to Algorithms L1.12

## Example of insertion sort

### 2 4 8 9 3 6

(7)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.13

## Example of insertion sort

### 8 2 4 9 3 6 2 8 4 9 3 6 2 4 8 9 3 6

September 7, 2005

Introduction to Algorithms L1.14

## Example of insertion sort

### 2 4 8 9 3 6

(8)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.15

## Example of insertion sort

### 8 2 4 9 3 6 2 8 4 9 3 6 2 4 8 9 3 6 2 4 8 9 3 6

September 7, 2005 L1.16

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

### 2 3 4 8 9 6

(9)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.17

### 8 2 4 9 3 6 2 8 4 9 3 6 2 4 8 9 3 6 2 4 8 9 3 6 2 3 4 8 9 6

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.18

(10)

## Running time

### •Generally, we seek upper bounds on the running time, because everybody likes a guarantee.

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.19

## Kinds of analyses

### • Cheat with a slow algorithm that works fast on some input.

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.20

(11)

## Machine-independent time

### “Asymptotic Analysis”

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.21

### •Example: 3n 3 + 90n 2 –5n+ 6046 = Θ(n 3 )

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.22

(12)

### When n gets large enough, a Θ(n 2 )algorithm always beats a Θ(n 3 )algorithm.

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.23

0

### •Not at all, for large n.

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.24

2

2

n

j

=

2

2

n

j

=

(13)

### Key subroutine: MERGE

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.25

### 20 12 13 11 7 9 2 1

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.26

(14)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1. 27

### 1

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.28

### 2

(15)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.29

### 2

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.30

### 7 9

(16)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.31

### 27

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.32

### 9

(17)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.33

### 279

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.34

### 1279

(18)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.35

### 127911

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.36

### 7911

(19)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.37

### 12791112

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.37

(20)

## Analyzing merge sort

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.38

### • CLRS and Lecture 2 provide several ways to find a good upper bound on T(n).

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.39

(21)

## Recursion tree

### Solve T(n) = 2T(n/2) + cn, where c > 0 is constant.

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.40

### T(n)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.41

(22)

## Recursion tree

### T(n/2)T(n/2)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.42

## Recursion tree

### T(n/4) T(n/4) T(n/4) T(n/4)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.43

(23)

## Recursion tree

### Θ(1)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.44

## Recursion tree

### Θ(1)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.44

(24)

## Recursion tree

### Θ(1)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.44

## Recursion tree

### Θ(1)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.44

(25)

## Recursion tree

### Θ(1)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.44

## Recursion tree

### Θ(1)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.44

(26)

## Recursion tree

### Θ(1)

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.44

## Conclusions

### • Go test it out for yourself!

Copyright © 2001-5 Erik D. Demaine and Charles E. Leiserson Introduction to Algorithms

September 7, 2005 L1.48

• By definition, a pseudo-polynomial-time algorithm becomes polynomial-time if each integer parameter is limited to having a value polynomial in the input length.. • Corollary 42

• Suppose, instead, we run the algorithm for the same running time mkT (n) once and rejects the input if it does not stop within the time bound.. • By Markov’s inequality, this

Too good security is trumping deployment Practical security isn’ t glamorous... USENIX Security

Since we use the Fourier transform in time to reduce our inverse source problem to identification of the initial data in the time-dependent Maxwell equations by data on the

Reading Task 6: Genre Structure and Language Features. • Now let’s look at how language features (e.g. sentence patterns) are connected to the structure

This kind of algorithm has also been a powerful tool for solving many other optimization problems, including symmetric cone complementarity problems [15, 16, 20–22], symmetric

x=spawn P-FIB(n-1)

 Corollary: Let be the running time of a multithreaded computation produced by a g reedy scheduler on an ideal parallel comp uter with P processors, and let and be the work