+ All Categories
Home > Documents > Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

Date post: 08-Jan-2018
Category:
Upload: peregrine-riley
View: 217 times
Download: 0 times
Share this document with a friend
Description:
Time efficiency: How much time does a program take to run? Time complexity of a solution: How much more time will a program take to run if given more bytes as input? How Fast Is a Solution?
21
Complexity © 2014 Project Lead The Way, Inc. Computer Science and Software Engineering
Transcript
Page 1: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

Complexity

© 2014 Project Lead The Way, Inc.Computer Science and Software Engineering

Page 2: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• Constraints:–Limited time to execute–Limited bandwidth –Limited memory to store the

program–Limited memory for input/output

data• These constraints trade off against

each other• Often readability is more important

than any of these

Computers Have Finite Resources

Page 3: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• Time efficiency: How much time does a program take to run?

• Time complexity of a solution: How much more time will a program take to run if given more bytes as input?

How Fast Is a Solution?

Page 4: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• Time complexity described by the type of curve showing time vs. input bytes

• Brute force, an algorithm in which you try all possibilities, takes exponentially longer with longer passwords

How Fast Is a Solution?

Page 5: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• Consider passwords with a-z,A-Z,0-9 which allows 26+26+10=62 characters

Why Is Brute Force Exponential?

bytes passwords to try

1 622 622

3 623

4 624

n 62n

Page 6: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• Exponential growth will outpace any other kind of growth

• Make brute force impractical by using long passwords

Exponential Curve Gets Ahead of Others

Page 7: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• Time complexity of a problem is the time complexity of its best solution

• The algorithm might be quick with special input even if it is long. We describe difficulty using the worst-case input.

How Hard Is a Problem?

Page 8: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• Some problems are so hard the program might never finish.

• Computable problems can be solved by a computer

• Analyzing programs is often uncomputable–Halting Theorem: "Will this program

ever finish?" is sometimes uncomputable

–Security analysis: "Does any input crash this program?" is often uncomputable

Computability

Page 9: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• One-way functions are more time-consuming to undo than to do

• RSA encryption keys (used for HTTPS) are hard to crack because multiplying is faster than factoring

• Multiplying big prime numbers is a one-way function

Encryption and Time Complexity

Page 10: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• Linear time complexity: Twice as much input takes twice as much time

Time Complexity

Page 11: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• Quadratic time complexity: –Double the input 4x the time–Triple the input 9x the time

Time Complexity

Page 12: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• Factoring takes longer than quadratic time. So prime numbers can keep our secrets safe . . . maybe.

Encryption Keys Broken by Factoring

Page 13: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• Feel free to appreciate the beauty without getting into details

An Adventure to the Edge of Math

Page 14: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• One of seven six unsolved Millennium Problems ("Million Dollar Questions")

• If proved (or disproved), these problems would tell us a lot about what computers can or cannot do–We don't know "how hard" some

problems are–Are the hardest "NP problems"

(pictured below) solvable in polynomial time?

Does P=NP?

Page 15: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• Time to solve a P problem grows like

n some number

• Time to check an NP problem grows like some number n

Does P=NP? The Details

Page 16: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• If a problem can be checked in reasonable time, can it be solved in reasonable time?

• NP-Complete problems are the hard ones. They've been shown to be equivalent to each other.

• Three famous NP-Complete problems with many applications–Travelling Salesperson–Knapsack Problem–3-Color a Graph

Does P=NP? We Don't Know!

Page 17: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• What is the shortest route visiting all these cities?

NP-Complete Problems: Travelling Salesperson Problem

Page 18: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

NP-Complete Problems: Knapsack Problem• Choice of items that have weight and

value• Maximize value without exceeding

maximum weight10 lbs

$150

15 lbs$220

3 lbs$40

3 lbs$40

5 lbs$70

3 lbs$40

3 lbs$405

lbs$70

5 lbs$70

5 lbs$70

Page 19: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

• Color all nodes using 3 colors total• Adjacent nodes must not share color

NP-Complete: 3-Color a Graph

Page 20: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

Another 3-Coloring Problem

Page 21: Complexity © 2014 Project Lead The Way, Inc.Computer Science and Software Engineering.

Can You 3-Color It?


Recommended