180 likes | 193 Views
Lecture 2. Introduction to Computer Science (continued). Ways Algorithms can be Constructed. Sequential construction Conditional construction Iterative construction. first do this. then do this. Sequential Construction. test something. either do this. or do this. continue.
E N D
Lecture 2 Introduction to Computer Science (continued) CS 100 - Lecture 2
Ways Algorithms can be Constructed • Sequential construction • Conditional construction • Iterative construction CS 100 - Lecture 2
first do this then do this Sequential Construction CS 100 - Lecture 2
testsomething either do this or do this continue Conditional Construction CS 100 - Lecture 2
do something if not, repeat test if done if done, continue Iterative Construction CS 100 - Lecture 2
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 CS 100 - Lecture 2
carry 1 1 1 0 12 14 04 1 15 2 4 4 5 1 Developing Decimal Addition Algorithm: Example 8 1 4 7 7 2 9 5 CS 100 - Lecture 2
c c c c cc0 cc1 cc2 c4 cc3 c0 c1 c2 c3 c4 Developing Decimal Addition Algorithm: More General Case carry 0 a3a2a1a0 b3b2b1b0 CS 100 - Lecture 2
Algorithm for AddingTwo m-Digit Numbers CS 100 - Lecture 2
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. CS 100 - Lecture 2
Importance of Algorithms If you can specify an algorithm to solve a problem, then you can automate its solution CS 100 - Lecture 2
Requirements forAutomated 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 CS 100 - Lecture 2
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 CS 100 - Lecture 2
Non-AlgorithmicInformation 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 CS 100 - Lecture 2
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 CS 100 - Lecture 2
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 CS 100 - Lecture 2
Organization of Text fig. from Schneider & Gersting CS 100 - Lecture 2
Reading • Read one chapter of S&G per week unless I say otherwise • Read ch. 2 for the next class CS 100 - Lecture 2