Algorithms, Programs, and Computers

# Algorithms, Programs, and Computers

Télécharger la présentation

## Algorithms, Programs, and Computers

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
##### Presentation Transcript

1. Algorithms, Programs, and Computers CS 110 Fall 2005

2. Problem Solving • You want to make money and you have some simpletons who are willing to help • Devise aplan that will make money (write a business plan for starting a restaurant) • Tell the simpletons to execute the business plan

3. Problem Solving • The simpletons can make mistakes • Refine the communication of instructions to them • Use time cards, tables, flow charts, pictures • Develop a bullet proof “process”

4. Problem Solving • You want to make money and you have a computer to help you • Devise an algorithm (plan) • Make the algorithm very detailed so a simpleton can do it (program) • Execute the program (computer)

5. Hardware / Software • A program is a sequence of instructions that tell the computer what to do • What language do computers speak? • What language do people speak?

6. Computer Language • Assembly Language • ADD R1, R2 • MOV [R5], R1 • IF (R4 < R2) JMP A: • Very sequential • Like a flow chart • Not the language of human users

7. It Gets Worse • Computer logic is even more primitive • AND • OR • NOT • All programs (nearly every electronic device you use) operates with only these three logical operations

8. It Gets Much Better • Computer software exists to create an abstraction between AND/OR/NOT and human language/logic • Programming Languages • C++, Java, C#, Perl

9. C++ void main (int argc, char **argv) { printf (“Hello, world\n”); }

10. Java class program { public static void main(String args[]) { System.out.println("Hello World!"); } }

11. Why So Many Languages? • Each has strengths and weaknesses • Error protection • Syntax in English vs. syntax in German • Expressiveness • Eskimo words for snow

12. Multipurpose Computers • How can computers interpret so many different languages? • Translate them all into a common language (machine language) • Compilers!

13. Recap: Problem Solving • Computers execute machine language • Programs are a sequence of instructions in some language • Compilers transform programs from one language to another, usually a simpler one

14. Algorithms • The way one solves a problem • Divide and conquer • Top-down or bottom-up • Simplify • Deduction • Trial and error

15. Dealing Out Cards • Poker: deal five cards to everyone at the table How? (step by step)

16. Draw a Square

17. Draw a Triangle

18. Recap: Algorithms • An approach to solving a problem • A sequence of steps • Break a complex problem into simpler pieces The first step in making computers work for you!

19. Complexity • There’s a danger here • Time is scarce • Simple algorithms may entail inordinate time and resources • Computers are simpletons • We must think about an algorithm’s complexity before using it

20. Complexity of Cards • Consider dealing five cards • One second per deal • How long to finish dealing five cards to: 2 players

21. Complexity of Cards • Consider dealing five cards • One second per deal • How long to finish dealing five cards to: 3 players

22. Complexity of Cards • Consider dealing five cards • One second per deal • How long to finish dealing five cards to: 4 players

23. Complexity of Cards • Consider dealing five cards • One second per deal • How long to finish dealing five cards to: 100 players

24. Complexity of Cards • It takes 5 * num_players time A Linear Time Algorithm time Number of players

25. Complexity of Other Problems • Many problems are polynomial (n2) • Execution time grows as the square of the problem size (sorting names) time Problem size

26. Complexity of Other Problems • Many problems are exponential (2n) • Execution time grows as to the nth with increase in problem size (Traveling Salesperson Problem) time Problem size

27. Complexity of Other Problems • Some problems are intractable • There are 1079 atoms in Universe • It would be impossible to solve an algorithm this complex

28. Complexity of Other Problems • Some problems are not computable • Literally no end to computation to be donw

29. Recap: Algorithms • Algorithms have different complexities • Complexity is important to understand • What is knowable? • How difficult is it to acquire?