1 / 18

Lecture 2

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.

Download Presentation

Lecture 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 2 Introduction to Computer Science (continued) CS 100 - Lecture 2

  2. Ways Algorithms can be Constructed • Sequential construction • Conditional construction • Iterative construction CS 100 - Lecture 2

  3. first do this then do this Sequential Construction CS 100 - Lecture 2

  4. testsomething either do this or do this continue Conditional Construction CS 100 - Lecture 2

  5. do something if not, repeat test if done if done, continue Iterative Construction CS 100 - Lecture 2

  6. 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

  7. 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

  8. 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

  9. Algorithm for AddingTwo m-Digit Numbers CS 100 - Lecture 2

  10. 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

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

  12. 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

  13. 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

  14. 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

  15. 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

  16. 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

  17. Organization of Text fig. from Schneider & Gersting CS 100 - Lecture 2

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

More Related