Java Coding 6 extra Computational complexity David Davenport

  • Slides: 9
Download presentation
Java Coding 6 -extra Computational complexity David Davenport Computer Eng. Dept. , Bilkent University

Java Coding 6 -extra Computational complexity David Davenport Computer Eng. Dept. , Bilkent University Ankara - Turkey. email: david@bilkent. edu. tr

IMPORTANT… n Students… This presentation is designed to be used in class as part

IMPORTANT… n Students… This presentation is designed to be used in class as part of a guided discovery sequence. It is not selfexplanatory! Please use it only for revision purposes after having taken the class. Simply flicking through the slides will teach you nothing. You must be actively thinking, doing and questioning to learn! n Instructors… You are free to use this presentation in your classes and to make any modifications to it that you wish. All I ask is an email saying where and when it is/was used. I would also appreciate any suggestions you may have for improving it. thank you, David.

The Story so far… n Searching O(N) – on unordered list n O(log 2

The Story so far… n Searching O(N) – on unordered list n O(log 2 N) – on ordered list! n n Sorting O(N 2) n O(N. log 2 N) n For arrays (storing data in first N elements) Insertion & deletion O(1) - unordered O(N) - ordered

Powers of 2… log 2 N N 2 N times N 2 times 10

Powers of 2… log 2 N N 2 N times N 2 times 10 1, 024 103 106 1/1000 sec 1 second 20 1, 048, 576 1012 1 second ~12 days 30 1, 073, 741, 824 109 1018 16 minutes ~30, 000 years 40 1, 099, 511, 627, 776 1012 1024 ~12 days 50 1, 125, 899, 906, 842, 624 1015 1030 60 1, 152, 921, 504, 606, 846, 976 1018 1036 70 1, 180, 591, 620, 717, 411, 303, 424 1021 1042 80 1, 208, 925, 819, 614, 629, 174, 706, 176 1024 1048

A “simple” Decision Problem n Does a 5 by 5 arrangement exist? Yes/No? Worst

A “simple” Decision Problem n Does a 5 by 5 arrangement exist? Yes/No? Worst case: Need to check all possible arrangements How many arrangements? 25 x 24 x 23 x … x 3 x 2 x 1 = 25! How long @ 1 million/second? ~490 billion years

Exponential Polynomial Values for various functions log. N 10 >4 50 6 100 7

Exponential Polynomial Values for various functions log. N 10 >4 50 6 100 7 300 9 1000 10 N 10 50 100 300 1000 N. log. N 33 282 665 2469 9966 N 2 100 2500 10000 90000 1 million (7 digits) 2 N 1024 16 -digit number 31 -digit number 91 -digit number 302 -digit number N! 3. 6 million (7 digits) 65 -digit number 161 -digit number 623 -digit number Unimaginably large NN 10 billion (11 digits) 85 -digit number 201 -digit number 744 -digit number Unimaginably large

Times (at one million instructions per second) Exponential Polynomial 10 50 100 300 1000

Times (at one million instructions per second) Exponential Polynomial 10 50 100 300 1000 1/10000 second log. N 1/10000 second N 1/1000 second 1/100 second N. log. N N 2 1/10000 second 1/100 second 2 N 1/1000 second 35. 7 years N! 3. 6 seconds 49 -digit NN 2. 8 hours 1 second 400 trillion centuries 75 -digit # centuries 185 -digit 728 -digit # centuries 70 -digit # centuries

Worse still… Tractable (polynomial) n Intractable (exponential) n n Uncomputable n e. g. Halting

Worse still… Tractable (polynomial) n Intractable (exponential) n n Uncomputable n e. g. Halting problem! Should we be concerned?