CMSC201 Computer Science I for Majors Lecture 02 – Algorithmic Thinking Prof. Katherine Gibson Based on slides by Shawn Lupoli and Max Morawski at UMBC.

Slides:



Advertisements
Similar presentations
LECTURE 1 CMSC 201. Overview Goal: Problem solving and algorithm development. Learn to program in Python. Algorithm - a set of unambiguous and ordered.
Advertisements

ITEC113 Algorithms and Programming Techniques
Introduction to Computer Programming I CSE 113
Chapter 3 Planning Your Solution
Chapter 1: Introduction To Computer | SCP1103 Programming Technique C | Jumail, FSKSM, UTM, 2005 | Last Updated: July 2005 Slide 1 Introduction To Computers.
Chapter 1 Pseudocode & Flowcharts
Adapted from slides by Marie desJardins
Flow Charting. Goals Create Algorithms using Flow Charting procedures. Distinguish between Flow Charting and Pseudocode. Top-Down Design Bottom-up Design.
Algorithmic Problem Solving CMSC 201 Adapted from slides by Marie desJardins (Spring 2015 Prof Chang version)
Chapter 2 - Algorithms and Design
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
Lecture 5: Developing Procedural Thinking (How to think like a programmer) B Burlingame 30 Sept 2015.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Flowcharts. Problem Solving Computer programs are written to solve problems or perform tasks Programmers translate the solutions or tasks into a language.
Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source.
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
1 Program Planning and Design Important stages before actual program is written.
Programming at a high level. Developing a Computer Program Programmer  Writes program in source code (VB or other language) Compiler  Converts source.
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Lecture 2 Debugging,
The Department of Engineering Science The University of Auckland Welcome to ENGGEN 131 Engineering Computation and Software Development Lecture 2 Debugging,
CMSC201 Computer Science I for Majors Lecture 12 – Midterm Review Prof. Katherine Gibson.
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Prof. Jeremy.
All materials copyright UMBC unless otherwise noted CMSC201 Computer Science I for Majors Lecture 02 – Algorithmic Thinking.
Last Class We Covered Decision structures One-way (using if)
Component 1.6.
CMSC201 Computer Science I for Majors Lecture 07 – While Loops
CMSC201 Computer Science I for Majors Lecture 03 – Variables
CMSC201 Computer Science I for Majors Lecture 05 – Comparison Operators and Boolean (Logical) Operators Prof. Katherine Gibson Based on slides by Shawn.
ALGORITHMS AND FLOWCHARTS
Writing algorithms Introduction to Python.
CMSC201 Computer Science I for Majors Lecture 20 – Recursion (Continued) Prof. Katherine Gibson Based on slides from UPenn’s CIS 110, and from previous.
INTRODUCTION TO PROBLEM SOLVING
Component 1.6.
CMSC201 Computer Science I for Majors Lecture 04 – Expressions
1-1 Logic and Syntax A computer program is a solution to a problem.
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
CS1001 Programming Fundamentals 3(3-0) Lecture 2
The Selection Structure
Unit 2 Smarter Programming.
CMSC201 Computer Science I for Majors Lecture 13 – Midterm Review
Introduction to Flowcharting
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
UMBC CMSC 104 – Section 01, Fall 2016
CMSC201 Computer Science I for Majors Lecture 03 – Operators
Algorithm and Ambiguity
CS 240 – Lecture 11 Pseudocode.
ALGORITHMS AND FLOWCHARTS
Lesson 2 Programming constructs – Algorithms – Scratch – Variables Intro.
How to develop a program?
Algorithms & Pseudocode
Programming Right from the Start with Visual Basic .NET 1/e
2008/09/22: Lecture 5 CMSC 104, Section 0101 John Y. Park
ALGORITHMS AND FLOWCHARTS
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Programming.
Algorithm and Ambiguity
Flowcharts and Pseudo Code
ICT Gaming Lesson 2.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
CMSC201 Computer Science I for Majors Final Exam Information
Winter 2019 CISC101 4/16/2019 CISC101 Reminders
Chapter 2 - Algorithms and Design
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Introduction to Flowcharting
WJEC GCSE Computer Science
CMPT 120 Lecture 3 - Introduction to Computing Science – Programming language, Variables, Strings, Lists and Modules.
CMSC201 Computer Science I for Majors Lecture 12 – Midterm Review
WRITING AN ALGORITHM, PSEUDOCODE, AND FLOWCHART LESSON 2.
Presentation transcript:

CMSC201 Computer Science I for Majors Lecture 02 – Algorithmic Thinking Prof. Katherine Gibson Based on slides by Shawn Lupoli and Max Morawski at UMBC

Last Class We Covered Syllabus Computer System Components Grading scheme, expectations, etc. Academic Integrity Policy Computer System Components Binary numbers Converting between binary and decimal Algorithmic thinking Making sandwiches for aliens

Any Questions from Last Time?

Today’s Objectives To practice thinking algorithmically To understand and be able to implement proper program development To start learning about control structures To be able to express an algorithm using a flow chart

What is an Algorithm? Steps used to solve a problem Problem must be Well defined Fully understood by the programmer Steps must be Ordered Unambiguous Complete

Developing an Algorithm

Program Development Understand the problem Represent your solution (your algorithm) Pseudocode Flowchart Implement the algorithm in a program Test and debug your program

Step 1: Understanding the Problem Input What information or data are you given? Process What must you do with the information/data? This is your algorithm! Output What are your deliverables?

“Weekly Pay” Example Create a program to calculate the weekly pay of an hourly employee What is the input, process, and output? Input: pay rate and number of hours Process: multiply pay rate by number of hours Output: weekly pay

Step 2: Represent the Algorithm Can be done with flowchart or pseudocode Flowchart Symbols convey different types of actions Pseudocode A cross between code and plain English One may be easier for you – use that one

Step 2A: Pseudocode Start with a plain English description, then… Variables: hours, rate, pay Display “Number of hours worked: ” Get hours Display “Amount paid per hour: ” Get rate pay = hours * rate Display “The pay is $” , pay

Data Processing Symbol Flowchart Symbols Start Start Symbol Input/Output End End Symbol Decision Symbol Data Processing Symbol Flow Control Arrows

Step 2B: Flowchart Start End Get rate Get hours Display “Number of hours worked: ” pay = hours * rate Get hours Display “The pay is $ ” , pay Display “Amount paid per hour: ” End

Steps 3 and 4: Implementation and Testing/Debugging We’ll cover implementation in detail next class Testing and debugging your program involves identifying errors and fixing them We’ll talk about this later today

Algorithms and Language Notice that developing the algorithm didn’t involve any Python at all Only pseudocode or a flowchart was needed An algorithm can be coded in any language All languages have 3 important control structures we can use in our algorithms

Control Structures

Control Structures Structures that control how the program “flows” or operates, and in which order Sequence Decision Making Looping

Sequence One step after another, with no branches Already wrote one for “Weekly Pay” problem What are some real life examples? Dialing a phone number Purchasing and paying for groceries

Decision Making Selecting one choice from many based on a specific reason or condition If something is true, do A … if it’s not, do B What are some real life examples? Walking around campus (construction!) Choosing where to eat for lunch

Decision Making: Pseudocode Answer the question “Is a number positive?” Start with a plain English description Variable: num Display “Enter the number: ” Get num If num > 0 Display “It is positive” Else Display “It is negative”

Decision Making: Flowchart Start Display “Enter the number: ” Get num TRUE num > 0 FALSE Display “It is positive” Display “It is negative” End

Looping Doing something over and over again Combined with decision making Otherwise we loop forever (an “infinite loop”) What are some real life examples? Doing homework problem sets Walking up steps

Looping: Pseudocode Write an algorithm that counts from 1-20 Start with a plain English description Variable: num num = 1 While num <= 20 Display num num = num + 1 (End loop)

There’s an error in this flowchart… do you see it? Looping: Flowchart Start num = 1 There’s an error in this flowchart… do you see it? num >= 20 num >= 20 TRUE Display num num = num + 1 FALSE End

Looping: Flowchart Start num = 1 End num <= 20 num = num + 1 TRUE Display num num = num + 1 FALSE End

Debugging

A Bit of History on “Bugs” US Navy lab – September 9, 1947 Grace Hopper and colleagues were working on the Harvard Mark II Or trying to… it wasn’t working right They found a literal bug inside the machine Taped the bug (a moth) into their log book Grace Hopper didn’t invent the term, but she did bring it to popularity, especially within the realm of computing. She loved to recount this story.

Errors (“Bugs”) Two main classifications of errors Syntax errors Prevent Python from understanding what to do Logical errors Cause the program to run incorrectly, or to not do what you want

Syntax Errors “Syntax” is the set of rules followed by a computer programming language Similar to grammar and spelling in English Examples of Python’s syntax rules: Keywords must be spelled correctly True and False, not Ture or Flase or Truu Quotes and parentheses must be closed: (“Open and close”)

Syntax Error Examples Find the syntax errors in each line of code below: 1 prnit("Hello") 2 print("What"s up? ") 3 print("Aloha!) 4 print("Good Monring")

Syntax Error Examples Find the syntax errors in each line of code below: 1 prnit("Hello") 2 print("What"s up? ") 3 print("Aloha!) 4 print("Good Monring") not actually a syntax error

Logical Errors Logical errors don’t bother Python at all… they only bother you! Examples of logical errors: Using the wrong value for something currentYear = 2013 Doing steps in the wrong order “Put jelly on bread. Open jelly jar.”

Exercise Write an algorithm that asks a user for their name, then responds with “Hello NAME” You can use a flowchart or pseudocode Start End Data Processing Input/Output Decision Flow Control

Exercise #2 Write an algorithm that asks a user for their grade, and tells them their letter grade. A: 100 - 90 C: <80 - 70 F: <60 - 0 B: <90 - 80 D: <70 - 60 Start End Data Processing Input/Output Decision Flow Control

Announcements Your Lab 1 is an online lab this week! Homework 1 is out Due by this Thursday (Sept 3rd) at 8:59:59 PM Homework 1 is out Due by next Tuesday (Sept 8th) at 8:59:59 PM Both of these assignments are on Blackboard Weekly Agendas are also on Blackboard