Java Coding 6-extra David Davenport Computer Eng. Dept.,

Slides:



Advertisements
Similar presentations
Java Coding 8 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Object-Oriented Design Example - The.
Advertisements

Java Coding OOP David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Towards Event-driven programming &
Everyday Algorithms David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction to.
Lecture # 38 Algorithms & Problem Solving: How Hard Can it Get?
Introduction to UML David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. …Unified Modeling Language.
1 The Limits of Computation Intractable and Non-computable functions.
Eleg667/2001-f/Topic-1a 1 A Brief Review of Algorithm Design and Analysis.
Java Coding 6 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Collections.
Java Coding 2 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Decisions, decisions…!
Object (Data and Algorithm) Analysis Cmput Lecture 5 Department of Computing Science University of Alberta ©Duane Szafron 1999 Some code in this.
Java Coding 3 David Davenport Computer Eng. Dept.,
Java Coding 8 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Object-Oriented Design Examples.
Review: OOP & Arrays David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. …from CS101.
Robo David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction to the engineering.
1 Section 2.3 Complexity of Algorithms. 2 Computational Complexity Measure of algorithm efficiency in terms of: –Time: how long it takes computer to solve.
Java Coding David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey.
Java Coding 4 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Method madness.
Java Coding 5 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. To object or not…
Java Coding 3 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Over & over again!
1 Complexity Lecture Ref. Handout p
Java Coding 5 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. To object or not…
Chapter 7 Inefficiency and Intractability CS 345 Spring Quarter, 2014.
Problems you shouldn’t tackle. Problem Complexity.
Complexity A decidable problem is computationally solvable. But what resources are needed to solve the problem? –How much time will it require? –How much.
Computational Algorithms David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction.
G5BAIM Artificial Intelligence Methods Graham Kendall History.
Java Coding 6 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Collections.
3.3 Complexity of Algorithms
Java Coding OOP_3 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Some important Java interfaces +
1 Algorithms  Algorithms are simply a list of steps required to solve some particular problem  They are designed as abstractions of processes carried.
From Algorithms to Architecture David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. lightning introduction.
Graham Kendall +44 (0) G5AIAI Introduction to AI Graham Kendall Combinatorial Explosion.
SNU OOPSLA Lab. 1 Great Ideas of CS with Java Part 1 WWW & Computer programming in the language Java Ch 1: The World Wide Web Ch 2: Watch out: Here comes.
Java Coding 8 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. Object-Oriented Design Examples.
Java Coding 5 – Part 2 David Davenport Computer Eng. Dept., Bilkent University Ankara - Turkey. To object or not…
1 Computability Tractable, Intractable and Non-computable functions.
Algorithm Analysis 1.
Chapter 23 Sorting CS1: Java Programming Colorado State University
CMPT 438 Algorithms.
Java Coding – part 2 David Davenport Computer Eng. Dept.,
Analysis of Algorithms
Java Coding Extra David Davenport Computer Eng. Dept.,
Introduction to Analysis of Algorithms
Thought for the Day “Years wrinkle the skin, but to give up enthusiasm wrinkles the soul.” – Douglas MacArthur.
Analysis of Algorithms
Introduction Algorithms Order Analysis of Algorithm
Introduction to Analysis of Algorithms
Java Coding 3 – part2 David Davenport Computer Eng. Dept.,
1.5 Intractable problems.
Java Coding 3 David Davenport Computer Eng. Dept.,
Java Coding 8 David Davenport Computer Eng. Dept.,
Standard Algorithms Higher Computing.
Sorting Data are arranged according to their values.
What is CS 253 about? Contrary to the wide spread belief that the #1 job of computers is to perform calculations (which is why the are called “computers”),
Lecture 6 Efficiency of Algorithms (2) (S&G, ch.3)
Sorting Data are arranged according to their values.
Chapter 11 Limitations of Algorithm Power
Algorithmic Complexity
Java Coding 6 – part2 David Davenport Computer Eng. Dept.,
Introduction to Data Structures
Java Coding 8 David Davenport Computer Eng. Dept.,
8. Comparison of Algorithms
Java Coding 4 (part2) David Davenport Computer Eng. Dept.,
Java Coding 6_part3 David Davenport Computer Eng. Dept.,
G5BAIM Artificial Intelligence Methods
Java Coding 6 David Davenport Computer Eng. Dept.,
Java Coding 6 David Davenport Computer Eng. Dept.,
Algorithms and data structures: basic definitions
CS 2210 Discrete Structures Algorithms and Complexity
Java Coding 5 – Part 2 David Davenport Computer Eng. Dept.,
Presentation transcript:

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

IMPORTANT… Students… Instructors… This presentation is designed to be used in class as part of a guided discovery sequence. It is not self-explanatory! 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! 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… Searching Sorting O(N) – on unordered list O(log2N) – on ordered list! Sorting O(N2) O(N.log2N) For arrays (storing data in first N elements) Insertion & deletion O(1) - unordered O(N) - ordered Different implementations offer different complexity measures. Slide shows values for the common simple method of storing valid data in first N elements of array Note that, in practice, may also need to be concerned with initialisation. What is its complexity? Consider alternative implementations, eg. using –1 values to mark invalid array elements. Next semester we will look at other more complex data structures that offer different performance characteristics.

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

A “simple” Decision Problem Does a 5 by 5 arrangement exist? Yes/No? Worst case: Need to check all possible arrangements No rotation. 25 possible pieces for first square, 24 left for next, then 23 for next, and so on. Gives 25 factorial. Big bang was ~15 billion years ago! Oops! How many arrangements? 25x24x23x … x3x2x1 = 25! How long @ 1 million/second? ~490 billion years

Values for various functions 10 50 100 300 1000 logN >4 6 7 9 N N.logN 33 282 665 2469 9966 N2 2500 10000 90000 1 million (7 digits) 2N 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 Polynomial For comparison: number of protons in known universe has 79 digits number of microseconds since big bang has 24 digits Polynomial time algorithms are said to be reasonable or tractable Exponential time algorithms are said to be unreasonable or intractable! Source: Algorithmics, David Harel. Exponential

Times (at one million instructions per second) 10 50 100 300 1000 logN 1/10000 second N 1/1000 second N.logN 1/100 second N2 1 second 2N 35.7 years 400 trillion centuries 75-digit # centuries N! 3.6 seconds 49-digit # centuries NN 2.8 hours 70-digit # centuries 185-digit # centuries 728-digit # centuries Polynomial For comparison: big bang was about 15 billion years ago. Tower of Hanoi problem 2 to the power N 64 rings @ 1 million per second = 0.5 million years! Tiling puzzles see next slide… Adapted from: Algorithmics, David Harel. Exponential

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