Computational Thinking, Problem-Solving and Programming

Preview:

DESCRIPTION

Topic 4. Computational Thinking, Problem-Solving and Programming. Assessment Objectives. Assessment objective 1 : classify, define, draw, label, list, state Assessment objective 2 : annotate, apply, calculate, describe, design, distinguish, estimate, identify, outline , present, trace - PowerPoint PPT Presentation

Citation preview

Computational Thinking, Problem-Solving and Programming

Topic 4

Assessment Objectives

Assessment objective 1: classify, define, draw, label, list, state

Assessment objective 2: annotate, apply, calculate, describe, design, distinguish, estimate, identify, outline, present, trace

Assessment objective 3: analyse, comment, compare, compare and contrast, construct, contrast, deduce, demonstrate, derive, determine, discuss, evaluate, examine, explain, formulate, interpret, investigate, justify, predict, sketch, suggest, to what extent

Computational Thinking

Five different types of computational thinking

Find out what they are Examples of each

Example

You have decided to invite your friends over to watch the big basketball game. You are going to make food for everyone.

How will you use computational thinking to make sure your day goes well?

Give examples of where you can apply each of the five types of computational thinking to this situation.

Thinking Ahead

Think back to the basketball game task

In what ways did you need to think ahead?

What examples of thinking ahead do you know of from the world of computing?

Pre-conditions and post-conditions A method of specifying what a

procedure accomplishes without going into the details of how it works

Go and write me a function. I don't care how you do it, just make sure these

requirements are met.

Example

void print_sqrt(double d) {// pre-condition: d>=0// post-condtion: sqrt(d) written // to standard output

}You should add these comments to every non-trivial method that you write in your Java IA

Working in teamsYour job is to write

the function. When I call it, I will ensure

that the pre-conditions are met.

Well as long as you meet the pre-conditions, I

guarantee it will work.

But just to be on the safe

side my function will check if a

pre-condition has been

violated, and report an

error if it has.

Conditions to Decisions

IB documentation wants you to realise that pre- and post-conditions affect the decisions that will be made in the implementation of the function

Think back to the sqrt() function Give an example of an if… then…

block that will follow from the preconditions

Your turn

Consider a function that tells you how many times a particular letter occurs within a word

What pre- and post-conditions will there be?

Write the function in Java, and link the decisions in the function to the conditions outside it

Gantt chartsDecomposition in subtasks. Thinking procedurally, thinking ahead, thinking concurrently.

Review

What are the five types of computational thinking?

Concurrent thinking in everyday life

Things to do: Put the clothes into the washing

machine and turn it on Take the clothes out of the washing

machine and hang them up Put the food into the oven Take the food out of the oven

What order is best?

Thinking concurrently

What examples of concurrent thinking can you think of from the world of computer science?

Multi-tasking OS time-slicing scheduling interrupts

RDBMS (database) transactions

Dining Philosophers

Philosophers like to think a bit, eat a bit, think a bit, etc.

Need two chopsticks to eat

Have to pick them up one at a time

Can't steal them from someone else! DEA

DLOCK

Thinking Abstractly

a publication a newspaper

The San Francisco Chronicle the May 18 edition of the The San Francisco

Chronicle my copy of the May 18 edition of the The San

Francisco Chronicle my copy of the May 18 edition of the The San

Francisco Chronicle as it was when I first picked it up (as contrasted with my copy as it was a few days later: in my fireplace, burning)

Abstraction

Considering the same object from different viewpoints

Different aspects of the object are important to different audiences

Describe a car from the viewpoint of: A driver A mechanic A physicist

What are the benefits of abstraction? How does it help us?

The best example of abstraction in the world ever

Some abstractions

TCP Segment

IP Datagram

Ethernet Frame

HTTP Packet

Different names for different types of packet

Task: The OSI Model and abstraction Write a brief outline of how the OSI Model

uses abstraction. How does it make complex tasks simple?

What does each layer know about the one below? What does each packet know about its payload?

Imagine you are Mr Brown and you want to send a letter to the head of ISKL. What layers of abstraction exist to facilitate this process? Describe them and explain why they are useful.

Flowcharts

yes

noyes

no

I = 0

I = N?

START

ARRAY[I]=TARGET?

I = I + 1

STOP

STOP

This algorithm finds the index of TARGET within an ARRAY of N elements.

Check that you understand how the algorithm works by explaining how you could tell whether or not TARGET was found.

Tasks

Flowchart for finding a given value in an array

Flowchart for BubbleSort Trace tables

Read chapter from the blog Do exercises

Task: Produce a trace table

int a = 2, b = 4, c;int x = 20, y = 20;for (int i = 0; i < 3; i ++) { System.out.print(" i = " + i); for ( int j = 0; j < 3; j ++) { c = a * b; System.out.print(" c = " + c); a ++; b ++; x += 20; } // end inner loopx = 20;y += 20;} // end outer loop

yes

no

B – N < 1?

START

B = B - N STOP

OUTPUT A, BA = A + 1

A = 0

Trace this flowchart for B = 26, N = 7

State what the algorithm does and note preconditions and postconditions

Write the algorithm in pseudocode

Write the algorithm as a method in Java. (B and N should be passed into the method as parameters. A and B should be returned by the method.)

INPUT B, N

Do this exercise quietly, on your own. Don'tshout out the answers. Let other people work.

Practice on these

An algorithm that takes an integer input N and prints the Fibonacci

sequence up to N

An algorithm that takes an integer input N and prints the sum of all numbers from one up to

N

An algorithm that takes an integer input N and prints out all the integer factors of N

An algorithm that takes an integer input N and

prints out the Nth triangular number

An algorithm that takes an integer array input A[] and prints out the largest number in A[]

An algorithm that takes an integer array input A[] and prints out true if it is palindromic and false otherwise

An algorithm that takes a 2d integer array argument A[][] and

outputs the sum of each column

An algorithm takes takes an integer N and a sorted array A[] and inserts N in the right

place in A

An algorithm that takes an integer array input A[] and output true if it is sorted (ascending or descending)

and false otherwise

An algorithm that takes an integer argument N and outputs its position in

linked list LIST, or -1 if it is not found

An algorithm that takes integer arguments N and B and prints N out in base B (assuming that N is denary

to start with)

An algorithm that takes string input A and B and outputs true if A is a substring of B and

false if not

Do this exercise quietly, on your own. Don'tshout out the answers. Let other people work.

Assembly Tutorial

http://skilldrick.github.io/easy6502/

Recommended