1. Computational Thinking

Slides:



Advertisements
Similar presentations
ALGORITHMS AND FLOWCHARTS
Advertisements

ALGORITHMS AND FLOWCHARTS
DFD Examples Yong Choi BPA CSUB.
Summer ’12 AP Computer Science APCS Summer Assignments Read thoroughly this ppt and solve examples 6 and 7.
ALGORITHMS AND FLOWCHARTS
PROBLEM SOLVING TECHNIQUES
ALGORITHMS AND FLOWCHARTS
Fundamentals of Algorithms MCS - 2 Lecture # 4
Chapter 9 Describing Process Specifications and Structured Decisions
DT211 Stage 2 Software Engineering
Chapter 1 Program Design
Developing logic (Examples on algorithm and flowchart)
Fundamentals of C programming
ALGORITHMS AND FLOWCHARTS
Chapter 6: The Traditional Approach to Requirements
DFD examples.
DFD Examples Yong Choi BPA CSUB. Creating Data Flow Diagrams Steps: 1.Create a list of activities 2.Construct Context Level DFD (identifies external entities.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Chapter 9 Describing Process Specifications and Structured Decisions
Prepared by Afra`a Sayah. Introduction. Weekly Tasks. Plane Phase. Analysis Phase. Design Phase. Report Rules. Conclusion. 2.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
1 DATA FLOW DIAGRAM. 2 Outline Process decomposition diagrams Data flow diagram (DFD)
Flowcharting & Algorithms. Quick. Close your Eyes and Listen You are still sitting in the classroom. However, you have been called to the counselor’s.
1 Program Planning and Design Important stages before actual program is written.
Creating Data Flow Diagrams Presenter: Ms. Somia Razzaq.
Concepts of Algorithms CSC-244 Unit Zero Pseudo code, Flowchart and Algorithm Master Prince Computer College Qassim University K.S.A.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
ALGORITHMS AND FLOWCHARTS. A typical programming task can be divided into two phases: Problem solving phase  produce an ordered sequence of steps that.
Introduction to Flowcharts
Software Specification Models
Lecture 2: Introduction to Programming EEE2108: 공학프로그래밍 서강대학교 전자공학과 2011 학년도 2 학기 - Algorithms and Flowcharts -
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
Systems Analysis and Design in a Changing World, Fourth Edition
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
DFD Examples Yong Choi BPA CSUB.
Software Specification Models
Program design Program Design Process has 2 phases:
Problem Solving & Computer Programming
ALGORITHMS AND FLOWCHARTS
GC101 Introduction to computers and programs
Business Process Modeling
Problem Solving Concepts
DATA FLOW DIAGRAMS Budi Arifitama.
Identifying Data Flows
Unit 3: ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
FLOWCHARTS.
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
System Process Modeling
CS111 Computer Programming
Algorithms and Flowcharts
DFD Examples Yong Choi BPA CSUB.
REQUIREMENTS ANALYSIS
Chapter 1: Data Flow Diagram Structuring System Process Requirements
Process & Logic Modeling
Programming Fundamentals
ALGORITHMS AND FLOWCHARTS
DFD Example : Bus Garage Repairs
Unit# 9: Computer Program Development
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
Introduction to Algorithms and Programming
Chapter 7: Data Flow Diagram Structuring System Process Requirements
Chapter 11 Describing Process Specifications and Structured Decisions
Introduction to Programming
REQUIREMENTS ANALYSIS
DFD Examples Yong Choi BPA CSUB.
DFD Examples Yong Choi BPA CSUB.
DFD Examples Yong Choi BPA CSUB.
DFD Process & Examples.
Presentation transcript:

1. Computational Thinking A Level Computer Science

Chapter 1: Computational thinking Computer science has produced many useful methodologies to make developing systems more reliable and less effort, e.g: software engineering modelling the real world systems analysis programming techniques and paradigms Layering (e.g. TCP/IP) pipelining. These can be applied to more than just making computer systems. A programming paradigm is a fundamental style of computer programming, serving as a way of building the structure and elements of computer programs. Imperative, Logical, Functional, Object-Oriented Layering is the organization of programming into separate functional components that interact in some sequential and hierarchical way, with each layer usually having an interface only to the layer above it and the layer below it. With Pipelining, the computer architecture allows the next instructions to be fetched while the processor is performing arithmetic operations, holding them in a buffer close to the processor until each instruction operation can be performed. The staging of instruction fetching is continuous. The result is an increase in the number of instructions that can be performed during a given time period.y, with each layer usually having an interface only to the layer above it and the layer below it.

Computational Thinking A problem-solving approach makes use of such things as: abstraction decomposition algorithms. Pattern recognition

Abstraction Abstraction is the process of filtering out – ignoring - the characteristics of patterns that we don't need in order to concentrate on those that we do. It is also the filtering out of specific details. From this we create a representation (idea) of what we are trying to solve. Video

abstraction

Abstraction Layers of abstraction allow efficient problem solving – focusing on one part of problem at a time.  Examples of abstraction: a variable a data structure a network address layers in a network a symbol on a map

Decomposition - Breaking Down problems The breaking down of a problem into smaller parts that are easier to solve. The smaller parts can sometimes be solved recursively; that is, they can be run again and again until that part of the problem is solved.

Task Think of one example that can be solved using a tree hierarchy, and one example of a problem that can be solved using alternative pathways Tree Hierarchy Alternative Pathways Pythagoras Theorem Holiday bookings

Data Flow diagram

DFD (data flow diagrams) extension Jump>>

Creating Data Flow Diagrams Steps: Create a list of activities Construct Context Level DFD (identifies external entities and processes) Construct Level 0 DFD (identifies manageable sub process ) Construct Level 1- n DFD (identifies actual data flows and data stores ) Check against rules of DFD

DFD Naming Guidelines External Entity  Noun Data Flow  Names of data Process  verb phrase a system name a subsystem name Data Store  Noun

Creating Data Flow Diagrams Lemonade Stand Example

Creating Data Flow Diagrams Example Steps: The operations of a simple lemonade stand will be used to demonstrate the creation of dataflow diagrams. Create a list of activities Old way: no Use-Case Diagram New way: use Use-Case Diagram Construct Context Level DFD (identifies sources and sink) Construct Level 0 DFD (identifies manageable sub processes ) Construct Level 1- n DFD (identifies actual data flows and data stores )

Creating Data Flow Diagrams Example Create a list of activities Think through the activities that take place at a lemonade stand. Customer Order Serve Product Collect Payment Produce Product Store Product

Creating Data Flow Diagrams Example Create a list of activities Also think of the additional activities needed to support the basic activities. Customer Order Serve Product Collect Payment Produce Product Store Product Order Raw Materials Pay for Raw Materials Pay for Labor

Creating Data Flow Diagrams Example Create a list of activities Group these activities in some logical fashion, possibly functional areas. Customer Order Serve Product Collect Payment Produce Product Store Product Order Raw Materials Pay for Raw Materials Pay for Labour

Creating Data Flow Diagrams Example Construct Context Level DFD (identifies sources and sink) Create a context level diagram identifying the sources and sinks (users). Context Level DFD Sales Forecast CUSTOMER 0.0 Lemonade System EMPLOYEE Order Production Schedule Customer Order Serve Product Collect Payment Produce Product Store Product Order Raw Materials Pay for Raw Materials Pay for Labor Product Served Pay Payment Time Worked Received Goods Payment Purchase Order VENDOR

Creating Data Flow Diagrams Example Construct Level 0 DFD (identifies manageable sub processes ) Create a level 0 diagram identifying the logical subsystems that may exist. Level 0 DFD 1.0 Sale Sales Forecast Customer Order Serve Product Collect Payment Produce Product Store Product Order Raw Materials Pay for Raw Materials Pay for Labor Customer Order Product Ordered CUSTOMER Payment 2.0 Production EMPLOYEE Production Schedule Product Served Inventory Received Goods VENDOR 3.0 Procure-ment Purchase Order Order Decisions Payment Pay Time Worked 4.0 Payroll

Creating Data Flow Diagrams Example Construct Level 1- n DFD (identifies actual data flows and data stores ) Create a level 1 decomposing the processes in level 0 and identifying data stores. Level 1 DFD CUSTOMER Customer Order Request for Forecast Customer Order Serve Product Collect Payment Produce Product Store Product Order Raw Materials Pay for Raw Materials Pay for Labor ORDER 1.1 Record Order 1.3 Produce Sales Forecast Severed Order Payment Sales Forecast 1.2 Receive Payment PAYMENT

Creating Data Flow Diagrams Example Construct Level 1 (continued) Create a level 1 decomposing the processes in level 0 and identifying data stores. Level 1 DFD Product Order ORDER 2.1 Serve Product Customer Order Serve Product Collect Payment Produce Product Store Product Order Raw Materials Pay for Raw Materials Pay for Labor Quantity Severed RAW MATERIALS Production Schedule 2.2 Produce Product Quantity Used INVENTORTY Production Data 2.3 Store Product Quantity Produced & Location Stored

Creating Data Flow Diagrams Example Construct Level 1 (continued) Create a level 1 decomposing the processes in level 0 and identifying data stores. Level 1 DFD Order Decision PURCHASE ORDER 3.1 Produce Purchase Order Customer Order Serve Product Collect Payment Produce Product Store Product Order Raw Materials Pay for Raw Materials Pay for Labor Quantity On-Hand RAW MATERIALS Quantity Received Received Goods 3.2 Receive Items RECEIVED ITEMS Payment Approval 3.3 Pay Vendor VENDOR Payment

Creating Data Flow Diagrams Example Construct Level 1 (continued) Create a level 1 decomposing the processes in level 0 and identifying data stores. Level 1 DFD Time Worked TIME CARDS 4.1 Record Time Worked Customer Order Serve Product Collect Payment Produce Product Store Product Order Raw Materials Pay for Raw Materials Pay for Labor Employee ID EMPLOYEE Payroll Request 4.2 Calculate Payroll Unpaid time cards PAYROLL Payment Approval 4.3 Pay Employee PAYMENTS Payment

Process Decomposition 1.0 Sale 1.1 Record Order 1.2 Receive Payment 2.0 Production 2.1 Serve Product 2.2 Produce Product 2.3 Store Product 0.0 Lemonade System 3.0 Procure-ment 3.1 Produce Purchase Order 3.2 Receive Items 3.3 Pay Vendor 4.0 Payroll 4.1 Record Time Worked 4.2 Calculate Payroll 4.3 Pay Employee Context Level Level 0 Level 1

DFD Example: Bus Garage Repairs Buses come to a garage for repairs. A mechanic and helper perform the repair, record the reason for the repair and record the total cost of all parts used on a Shop Repair Order. Information on labour, parts and repair outcome is used for billing by the Accounting Department, parts monitoring by the inventory management computer system and a performance review by the supervisor.

DFD Example: Bus Garage Repairs (cont’d) External Entities: Bus, Mechanic, Helper, Supervisor, Inventory Management System, Accounting Department, etc. Key process (“the system”): performing repairs and storing information related to repairs Processes: Record Bus ID and reason for repair Determine parts needed Perform repair Calculate parts extended and total cost Record labor hours, cost

DFD Example: Bus Garage Repairs (cont’d) Data stores: Personnel file Repairs file Bus master list Parts list Data flows: Repair order Bus record Parts record Employee timecard Invoices

Bus Garage Context Diagram Mechanical problem to be repaired Fixed mechanical problems Supervisor Helper Bus Repair Process System Repair summary Labor List of parts used Inventory Management System Labor Labor, parts cost details Mechanic Accounting

CSUB Burger’s Order Processing System Draw the CSUB Burger’s context diagram System Order processing system External entities Kitchen Restaurant Customer Processes Customer order Receipt Food order Management report

Decomposition and oo A common way of breaking down a problem and functionality.

task Questions 1-3 page 17

ALGORITHMS AND FLOWCHARTS Sub topic

ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution of problem this sequence of steps is called an algorithm Implementation phase implement the program in some programming language

Steps in Problem Solving First produce a general algorithm (one can use pseudocode) Refine the algorithm successively to get step by step detailed algorithm that is very close to a computer language. Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode is very similar to everyday English.

Algorithm Example 1: Write an algorithm to determine a student’s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks.

Algorithm Input a set of 4 marks Calculate their average by summing and dividing by 4 if average is below 50 Print “FAIL” else Print “PASS”

Algorithm Detailed Algorithm Step 1: Input M1,M2,M3,M4 Step 2: GRADE  (M1+M2+M3+M4)/4 Step 3: if (GRADE < 50) then Print “FAIL” else Print “PASS” endif

The Flowchart (Dictionary) A schematic representation of a sequence of operations, as in a manufacturing process or computer program. (Technical) A graphical representation of the sequence of operations in an information system or program. Information system flowcharts show how data flows from source documents through the computer to final distribution to users. Program flowcharts show the sequence of instructions in a single program or subroutine. Different symbols are used to draw each type of flowchart.

The Flowchart shows logic of an algorithm A Flowchart shows logic of an algorithm emphasizes individual steps and their interconnections e.g. control flow from one action to the next

Flowchart Symbols

Example Step 1: Input Q1,Q2,Q3,Q4 Step 2: GRADE  (Q1+Q2+Q3+Q4)/4 START Input Q1,Q2,Q3,Q4 GRADE(Q1+Q2+Q3+Q4)/4 IS GRADE<50 PRINT “FAIL” STOP Y N Step 1: Input Q1,Q2,Q3,Q4 Step 2: GRADE  (Q1+Q2+Q3+Q4)/4 Step 3: if (GRADE <50) then Print “FAIL” else Print “PASS” end if PRINT “PASS”

Example 2 Write an algorithm and draw a flowchart to convert the length in feet to centimeter. Input the length in feet (Lft) Calculate the length in cm (Lcm) by multiplying LFT with 30 Print length in cm (LCM)

Example 2 Flowchart Algorithm Step 1: Input Lft Step 2: Lcm  Lft x 30 Step 3: Print Lcm START Input Lft Lcm  Lft x 30 Print Lcm STOP

Example 3 Write an algorithm and draw a flowchart that will read the two sides of a rectangle and calculate its area. Input the width (W) and Length (L) of a rectangle Calculate the area (A) by multiplying L with W Print A

Example 3 Algorithm Step 1: Input W,L Step 2: A  L x W Step 3: Print A START Input W, L A  L x W Print A STOP

DECISION STRUCTURES The expression A>B is a logical expression it describes a condition we want to test if A>B is true (if A is greater than B) we take the action on left print the value of A if A>B is false (if A is not greater than B) we take the action on right print the value of B

DECISION STRUCTURES is A>B Print B Print A Y N

IF–THEN–ELSE STRUCTURE The structure is as follows If condition then true alternative else false alternative endif

IF–THEN–ELSE STRUCTURE The algorithm for the flowchart is as follows: If A>B then print A else print B endif is A>B Print B Print A Y N

Relational Operators Operator Description Relational Operators > Greater than < Less than == Equal to  Greater than or equal to  Less than or equal to != Not equal to

Example 4 Write an algorithm that reads two values, determines the largest value and prints the largest value with an identifying message. Step 1: Input VALUE1, VALUE2 Step 2: if (VALUE1 > VALUE2) then MAX  VALUE1 else MAX  VALUE2 endif Step 3: Print “The largest value is”, MAX

“The largest value is”, MAX Example 4 MAX  VALUE1 Print “The largest value is”, MAX STOP Y N START Input VALUE1,VALUE2 MAX  VALUE2 is VALUE1>VALUE2

NESTED IFS One of the alternatives within an IF–THEN–ELSE statement may involve further IF–THEN–ELSE statement

Example 6 Write an algorithm that reads three numbers and prints the value of the largest number.

Example 6 Step 1: Input N1, N2, N3 Step 2: if (N1>N2) then if (N1>N3) then MAX  N1 [N1>N2, N1>N3] else MAX  N3 [N3>N1>N2] endif if (N2>N3) then MAX  N2 [N2>N1, N2>N3] MAX  N3 [N3>N2>N1] Step 3: Print “The largest number is”, MAX

Example 6 Flowchart: Draw the flowchart of the above Algorithm.

Example 7 Write and algorithm and draw a flowchart to read an employee name (NAME), overtime hours worked (OVERTIME), hours absent (ABSENT) and determine the bonus payment (PAYMENT).

Example 7 Bonus Schedule OVERTIME – (2/3)*ABSENT Bonus Paid >40 hours >30 but  40 hours >20 but  30 hours >10 but  20 hours  10 hours £50 £40 £30 £20 £10

Step 1: Input NAME,OVERTIME,ABSENT Step 2: if (OVERTIME–(2/3)*ABSENT > 40) then PAYMENT  50 else if (OVERTIME–(2/3)*ABSENT > 30) then PAYMENT  40 else if (OVERTIME–(2/3)*ABSENT > 20) then PAYMENT  30 else if (OVERTIME–(2/3)*ABSENT > 10) then PAYMENT 20 else PAYMENT  10 endif Step 3: Print “Bonus for”, NAME “is £”, PAYMENT

Your Flow Charts Calculates greatest common factor (GCF) of two numbers. A man has to get a fox, a chicken, and a sack of corn across a river. He has a rowboat, and it can only carry him and one other thing. If the fox and the chicken are left together, the fox will eat the chicken. If the chicken and the corn is left together, the chicken will eat the corn. How does the man do it? Solve the problem and make a flow chart with solution. Change an engine oil algorithm.

Your Flow Charts You want badly to take a friend out for a movie and dinner. And guess what? Your friend gladly accepted but you are broke. Now you have 36 hours (3 days) to get $100 and avoid embarrassment. Your sources are a last minute neighbor’s mow yard, parents, relatives, or else. Watch The Big Bang Theory – The Friendship Algorithm online. Have fun and enjoy summer.

tasks Practice questions P20 q1-3