Presentation is loading. Please wait.

Presentation is loading. Please wait.

1. Computational Thinking

Similar presentations


Presentation on theme: "1. Computational Thinking"— Presentation transcript:

1 1. Computational Thinking
A Level Computer Science

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

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

4 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

5 abstraction

6 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

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

8 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

9 Data Flow diagram

10 DFD (data flow diagrams) extension
Jump>>

11 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

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

13 Creating Data Flow Diagrams Lemonade Stand Example

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

15 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

16 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

17 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

18 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

19 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

20 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

21 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

22 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

23 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

24 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

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

26 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

27 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

28 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

29 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

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

31 task Questions 1-3 page 17

32 ALGORITHMS AND FLOWCHARTS
Sub topic

33 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

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

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

36 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”

37 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

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

39 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

40 Flowchart Symbols

41 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”

42 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)

43 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

44 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

45 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

46 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

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

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

49 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

50 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

51 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

52 “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

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

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

55 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

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

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

58 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

59 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

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

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

62 tasks Practice questions P20 q1-3


Download ppt "1. Computational Thinking"

Similar presentations


Ads by Google