Presentation is loading. Please wait.

Presentation is loading. Please wait.

Lecture 2 Introduction to Computer Science (continued)

Similar presentations


Presentation on theme: "Lecture 2 Introduction to Computer Science (continued)"— Presentation transcript:

1 Lecture 2 Introduction to Computer Science (continued)
11/15/2018 Lecture 2 Introduction to Computer Science (continued) 11/15/2018 CS Lecture 2 CS 100

2 Ways Algorithms can be Constructed
Lecture 2 11/15/2018 Ways Algorithms can be Constructed Sequential construction Conditional construction Iterative construction 11/15/2018 CS Lecture 2 CS 100

3 Sequential Construction
Lecture 2 11/15/2018 Sequential Construction first do this then do this After showing this observe: If we have two or more operations, we can either do: ALL of them (AND), or ONE of them (OR) If we do ALL of them, we can either: do them one at a time (as above) do them all at once (parallel execution, which we won’t discuss) If we are only going to do ONE of them, we must decide which… 11/15/2018 CS Lecture 2 CS 100

4 Conditional Construction
Lecture 2 11/15/2018 Conditional Construction test something either do this or do this It is also possible to have choices between more than two alternatives Also, if one alternate is “do nothing” then in effect we have the choice of whether to do something or not (We could pick which to do by tossing a coin, but that sort of non-decision can be reduced to this form) continue 11/15/2018 CS Lecture 2 CS 100

5 Iterative Construction
Lecture 2 11/15/2018 Iterative Construction do something if not, repeat test if done This is a sort of combination of the previous two: we do something AND then we decide to do it again OR not Note that this is not the only kind of iterative operation This form does the operation at least once if done, continue 11/15/2018 CS Lecture 2 CS 100

6 Developing an Algorithm
Lecture 2 11/15/2018 Developing an Algorithm Often good to begin by investigating how a person would do it Control structures: Shows how to order the steps Reveals what different conditions may occur Data structures: Shows how to organize information Reveals what additional information is required 11/15/2018 CS Lecture 2 CS 100

7 Developing Decimal Addition Algorithm: Example
Lecture 2 11/15/2018 Developing Decimal Addition Algorithm: Example 1 carry 15 5 1 04 4 4 1 1 We could have two cases, carry or no-carry, but it’s simpler to always add in the carry and make it either 1 or 0. 14 12 2 11/15/2018 CS Lecture 2 CS 100

8 Developing Decimal Addition Algorithm: More General Case
Lecture 2 11/15/2018 Developing Decimal Addition Algorithm: More General Case carry cc3 c3 c cc2 c2 c c1 c c0 c c4 a3 a2 a1 a0 b3 b2 b1 b0 Note that we make the first column like the others by setting the initial carry to 0 cc1 cc0 11/15/2018 CS Lecture 2 CS 100

9 Algorithm for Adding Two m-Digit Numbers
Lecture 2 11/15/2018 Algorithm for Adding Two m-Digit Numbers Note, we always must be clear about what inputs our algorithm should work on. Numbers of at least one digit? AT least 2? Is there a maximum? 11/15/2018 CS Lecture 2 CS 100

10 Algorithm Set value of c (carry) to 0.
Lecture 2 11/15/2018 Algorithm Set value of c (carry) to 0. Set value of i (column number) to 0. Repeat steps (a) – (d) until i > m–1. Set ci to c + ai + bi. If ci < 10, then set c to 0, otherwise set c to 1 and reset ci to ci – 10. Add 1 to i. Set cm to value of c. Print answer cmcm–1…c1c0. Note that this is very slightly different from the book (p. 7) for greater clarity. 11/15/2018 CS Lecture 2 CS 100

11 Importance of Algorithms
Lecture 2 11/15/2018 Importance of Algorithms If you can specify an algorithm to solve a problem, then you can automate its solution 11/15/2018 CS Lecture 2 CS 100

12 Requirements for Automated Computation
Lecture 2 11/15/2018 Requirements for Automated Computation Ability to make device to do basic operations Ability to make control device for sequencing and conditional tests Technology not available until early 20th century 11/15/2018 CS Lecture 2 CS 100

13 Algorithmic Problem Solving
Lecture 2 11/15/2018 Algorithmic Problem Solving Are there algorithmic solutions for all problems? No! Gödel discovered algorithmically unsolvable problems in 1930s Can algorithmically solvable problems be solved efficiently? No! They are inherently hard problems Even for problems that are efficiently algorithmically solvable, efficient algorithms may be difficult to find These are some of the issues addressed by computer scientists 11/15/2018 CS Lecture 2 CS 100

14 Non-Algorithmic Information Processing
Lecture 2 11/15/2018 Non-Algorithmic Information Processing “Cognitive inversion”: many things that are easy for people are hard for computers, and vice versa e.g., face recognition vs.calculating Suggests that computers & brains work in very different ways Much research in non-algorithmic information processing in neural networks Note it took several days to get the Mars Rover past the blocked ramp. 11/15/2018 CS Lecture 2 CS 100

15 Definition of “Algorithm”
Lecture 2 11/15/2018 Definition of “Algorithm” An algorithm is a well-ordered collection of unambiguous and effectively computable operations that produces a result and halts in a finite amount of time …a well-ordered collection… …of unambiguous and effectively computable operations… …that produces a result… …and halts in a finite amount of time well-ordered collection: we know the order in which the operations should be performed of unambiguous and effectively computable operations: unambiguous: we have to know what we are supposed to do depends on computing agent (context) the most basic operations are called primitive operations effectively computable: an operation performable by a computing agent that produces a result: generally algorithms are used to get answers in some cases, algorithms control devices, etc., so “result” must be taken broadly and halts in a finite amount of time: we can’t wait forever some algorithms are designed to run forever (or indefinitely), but they must do their work along the way in finite time 11/15/2018 CS Lecture 2 CS 100

16 Definition of CS Reconsidered
Lecture 2 11/15/2018 Definition of CS Reconsidered Computer Science is the study of algorithms, including: Their formal and mathematical properties Their hardware realizations Their linguistic realizations Their applications 11/15/2018 CS Lecture 2 CS 100

17 Organization of Text fig. from Schneider & Gersting 11/15/2018
Lecture 2 11/15/2018 Organization of Text fig. from Schneider & Gersting 11/15/2018 CS Lecture 2 CS 100

18 Reading Read one chapter of S&G per week unless I say otherwise
Lecture 2 11/15/2018 Reading Read one chapter of S&G per week unless I say otherwise Read ch. 2 for the next class 11/15/2018 CS Lecture 2 CS 100


Download ppt "Lecture 2 Introduction to Computer Science (continued)"

Similar presentations


Ads by Google