0% found this document useful (0 votes)
20 views

Principles of It ITBP 103: Unit 1 Computation

The document discusses the principles of computational thinking which includes illustrating how computers can systematically process problems by mechanizing and amplifying intellectual activities, defining computational thinking as a problem-solving strategy used to solve problems even when computers are absent, and explaining concepts like algorithms, logic, abstraction, modeling, and simulation.

Uploaded by

Mryam Al Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Principles of It ITBP 103: Unit 1 Computation

The document discusses the principles of computational thinking which includes illustrating how computers can systematically process problems by mechanizing and amplifying intellectual activities, defining computational thinking as a problem-solving strategy used to solve problems even when computers are absent, and explaining concepts like algorithms, logic, abstraction, modeling, and simulation.

Uploaded by

Mryam Al Ali
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 68

PRINCIPLES OF IT

ITBP 103

UNIT 1
COMPUTATION
This unit illustrates the ability of computers
to mechanize and amplify intellectual
activities to process problems systematically.

Spring 2021 CIT, UAE University


2 Unit Objectives

 In this chapter you will:


 Experience how to think and reason like computers
 Understand unambiguous statements (declared to be either true
or false)
 Distinguish between opinions and logical statements
 Use variables to represent and hold values
 Introduce “algorithm” as a sequence of logical statements to
instill computational thinking
 Define levels of abstraction to manage complexity in
computational thinking
 Explain a model as a language used to describe an abstract
representation of a structure or a behavior

CIT, UAEU.
3 Unit Contents

1. Computational Thinking
 Problem Solving
 Problem Specification
 Data Organization and Analysis
 Abstraction, Modeling and Simulation
 Automation
2. Algorithms
 Variables
 Assignment
 Instructions
 Sequence
3. Logic
 Proposition
 Boolean Variables
 Logical Operators and Truth Tables
4. Flowcharts
 Symbols
 Applications

CIT, UAEU.
4
COMPUTATIONAL
THINKING

CIT, UAEU.
5 Computational Thinking

General  Computational thinking is a problem-


Definition
solving strategy used to solve problems
when working with computers and
applied also to many other problems
even when computers are absent.

CIT, UAEU.
6 Computational Thinking
Decomposition

Make a Party

Definition 1:
Invite People Prepare Food

Solving a complex
problem by breaking it Write down names
Get Cookbook
Wait a day
down into smaller more Check list
Look for suggestions
Decide on food
Add names
manageable parts.
Get phone numbers Shop for ingredients
Call guests Cook food
Mark called guests

CIT, UAEU.
7 Computational Thinking
Decomposition

 Problem Example Make a Party

 We want to invite guests


through invitation cards Invite People Prepare Food

instead. Provide a strategy to


create a list that includes Write down names
Get Cookbook
Wait a day
each invited person’s name. Check list
Add names
Look for suggestions
Decide on food

This list should then be


sorted in alphabetical order, Get phone numbers Shop for ingredients
and printed on invitation Call guests
Mark called guests
Cook food

cards
8 Computational Thinking
Decomposition

 Problem Example Make a Party

 We want to invite guests


through invitation cards Invite People Prepare Food

instead. Provide a strategy to


create a list that includes Write down names
Get Cookbook
Wait a day
each invited person’s name. Check list
Add names
Look for suggestions
Decide on food

This list should then be


sorted in alphabetical order, Shop for ingredients
Sort list alphabetically
and printed on invitation Print list
Cook food

cards
9 Computational Thinking
Problem Formulation

Definition 2:
Problems formulation to enable computers to help solve
them
A problem is formulated precisely by Initial State
Precondition
what to accomplish, without any (or Input)

indication of how to do the work.

Problem Specification: Ho w Solution What


Precondition: indicates what must be true
before solving the problem.
Postcondition: indicates what will be true Postcondition Target State
(or Output)
when the problem is solved.
10 Computational Thinking
Problem Formulation

 Specification Examples:
Precondition Postcondition

Square root
n >0 value of n

n =5 s um (1, 2, ..., n) ?

Write a specification for the following problem:


A restaurant owner wants to use its best-selling dish in an advertising
brochure. What precondition and postcondition he should specify to determine
its best-selling item?
11 Computational Thinking
Use of Data

Definition 3:
Logical organization and analysis of data

Problem: at what rate are my


company stocks growing
recently?
Define and analyze data • $6.2
requirements needed to support • $6.5
the resolution of a problem • $6.4
• $6.6
• $6.6
• $6.7
• $6.8
12 Computational Thinking
Use of Data

Data Examples:

Problem: Data:
How does UAE Government allocates Number of students at UAE
budget to UAE university ? University

How does a doctor makes a diagnosis? Clinical tests

How could schools be ranked ? ?


13 Computational Thinking
Use of Data

Exercise
Think of other problems that could be
computationally solved through data
organization and analysis

CIT, UAEU.
14 Computational Thinking
Abstraction, Model and Simulation

Definition 4:
Representing real-world domains through
abstractions to derive models and simulations
Expected evolution of a storm

Abstraction = Description of a problem which


hides irrelevant details.

Model = a language used to represent


abstractions of a problem

Simulation = Result of running a model

http://en.wikipedia.org/wiki/Computer_simulation
15 Computational Thinking
Abstraction, Model and Simulation

Examples:

Abstraction = House sketch Model = Architectural drawing

Simulation = Virtual home


16 Computational Thinking
Abstraction, Model and Simulation

SIMULATIONS
You used them without
knowing!
17 Computational Thinking
Abstraction, Model and Simulation

Exercise
Discuss some simulator examples and
highlight the abstraction levels (i.e. what
has been hidden).

CIT, UAEU.
18 Computational Thinking
Algorithm

Definition 5:
Automating solutions through algorithmic steps

Algorithm = A set of steps that you take


to reach a specific goal. The same steps
can be repeated to reach some goal.
These steps form a “recipe” to automate
the process of problem-solving.
19 Computational Thinking
Algorithm

Example: An algorithm to post your status in social networks

Are you in
restaurant?

Adapted from http://www.marismith.com/wp-content/uploads/2011/11/Social-Network-Flow-Chart.jpg


20 Computational Thinking
Algorithm

 Examples:
 A cooking recipe
 Assembly instructions for a model
 The rules of how to play a game
 VCR user guide
 Description of a martial arts technique
 Directions for driving from A to B
 A knitting pattern
 A car repair manual

CIT, UAEU.
21 Computational Thinking
Algorithm

Exercise 1: Write an algorithm to calculate and print the


summation of two numbers.

Algorithm
Step 1: Start
Step 2: Get the first number
Step 3: Get the second number
Step 4: Calculate the summation by adding the first number
to the second number
Step 5: Print the summation
Step 6: Stop
22 Computational Thinking
Algorithm

Exercise 2: Write an algorithm to determine a student’s final


grade for a course and indicate whether it is passing or failing.
The final grade is calculated as the average of four marks. Express
your solution as a sequence of steps.

Algorithm
Step 1: Start
Step 2: Get the four marks
Step 3: Calculate the final grade by adding the fours marks then divide by 4
Step 4: if the final grade is less than 60 then
Print “FAIL”
else
Print “PASS”
Step 5: Stop
23 ALGORITHMS

CIT, UAEU.
24 Algorithms

History
Muhammad ibn Musa Al-Khwarizmi is the founder of Algorithm as
well as Algebra, Calculus, and other basic concepts in mathematics
25 Algorithms

Definition
A sequence of instructions describing how to do a task.

 Directions for driving from A to B  Assembly instructions for a model


26 From Algorithms to Programs

Proble
m
Algorithm: A sequence of instructions
describing how to do a task (or a process)

Java Program
27 Components of an Algorithm

Variables and values

Instructions

Procedures

Selections

CIT, UAEU.
28 Components of an Algorithm

Variables and values

Instructions

Procedures

Selections

CIT, UAEU.
29 Values

 Represent quantities, amounts or measurements

 May be numerical or alphabetical (or other things)

 Often have a unit related to their purpose

 Example:
 Recipe ingredients
30 Variables

 Are containers for values – places to store values


 Each variable has a name
 Example:
Variable Values

10 cookies
50 grams of sugar
This jar 3 slices of cake
can
contain etc.
31 Variable Assignment

Y2
X  5Y + 16
 On the left side of  , we put the name of a variable and on
the right side we put a value or an expression.
 Each variable refers to a unique location in computer memory
that contains a value. Name Value

 An assignment is executed in two steps :


 Evaluate of the expression found on the right side.
 Assign the returned value to the variable represented by its name on the
left side

Y 2 X 26
32 Restriction on Variables

 Variables may be restricted to contain a


specific type of value
X  5 16 A
33 Components of an Algorithm

Variables and values

Instructions

Procedures

Selections

CIT, UAEU.
34 Instructions

 Steps to perform specific actions on values


and variables. An algorithm is a sequence of
steps or instructions as follows:
STEP 1: Do something. Algorithm is a step-by-step method or a
STEP 2: Do something. sequence of unambiguous instructions,
STEP 3: Do something. that is guaranteed to solve a specific
. . problem
. .
. .
STEP N: Stop. You are finished.
35 Instructions
Algorithm

Exercise 1: Write an algorithm to calculate and print the


summation of two numbers.

Algorithm
Step 1: Start
Step 2: Get the first number
Step 3: Get the second number
Step 4: Calculate the summation by adding the first number
to the second number
Step 5: Print the summation
Step 6: Stop
36 Pseudocode - Definition

 A textual description of an algorithm


 Pseudocode is an informal high-level description of
the operating principle of a computer program or
other algorithm
 Simple version of programming code that does not
require any strict programming language syntax
37 Pseudocode

 To design algorithms using pseudocode:


 Commands like Start, Stop, Read/Input,
Write/Display/Print, Compute/Calculate, Set etc

 Use of proper variable names

 Logical flow

 Conditional statements and control structure


38 Pseudocode

Design the following algorithm using pseudocode:


 Write an algorithm to calculate and print the

summation of the two numbers 10 and 20.

 Step 1: Start
 Step 2: Calculate Sum  10 + 20
 Step 3: Print Sum
 Step 4: Stop
39 Pseudocode

Design the following algorithm using pseudocode:


 Write an algorithm to calculate and print the summation of

the two numbers 10 and 20.

 Step 1: Start
 Step 2: Set Num1  10 INPUT

 Step 3: Set Num2  20 PROCESS


 Step 4: Calculate Sum OUTPUT
Num1 + Num2
 Step 5: Print Sum
 Step 6: Stop
40 Pseudocode

Design the following algorithm using pseudocode:


 Write an algorithm to calculate and print the summation of

any two numbers.

 Step 1: Start
 Step 2: Input Num1
 Step 3: Input Num2
 Step 4: Calculate Sum  Num1 + Num2
 Step 5: Print Sum
 Step 6: Stop
41 Pseudocode

 Example: Write an algorithm that reads the two


sides of a rectangle then calculate and print its area
Algorithm:
Start
Input the length (L) and width (W)
Calculate the area (A) by multiplying length (L) by width(W)
Print the area (A)
Stop

Pseudocode:
Step 1: Start
Step 2: Input L, W
Step 3: Calculate A  L x W
Step 4: Print A
Step 5: Stop
42 Pseudocode

 Example: Write an algorithm to convert the length in feet to


centimeter then print the result. Note that 1 ft is equivalent to
~30cm
Algorithm:
Start
Input the length in feet (LFT)
Calculate the length in cm (LCM) by multiplying LFT with 30
Print length in cm (LCM)
Stop

Pseudocode:
Step 1: Start
Step 2: Input LFT
Step 3: Calculate LCM  LFT x 30
Step 4: Print LCM
Step 5: Stop
43 Components of an Algorithm

Variables and values

Instructions

Procedures

Selections

CIT, UAEU.
44 Procedure

 A named sequence of instructions

 So that you can


 Refer to it collectively (by name) instead of
individually (by each instruction in the sequence)

 Example:
 Drive_To_Uni
45 Procedure Example

procedure Drive_To_Uni
{
1. find car keys
2. disable car alarm ...etc...etc...etc...
3. open car door 52. find parking space
4. get in car 53. pull into parking
5. shut car door space
6. put keys in ignition 54. turn off engine
7. start car 55. remove keys from
ignition
8. back car out of
driveway 56. open car door
9. drive to end of street 57. get out
10. turn right 58. shut car door
11. drive to end of street 59. lock car door
12. turn left 60. enable alarm
...etc...etc...etc }
46 Procedure Example (Cont)

procedure Do_Wednesday procedure Do_Week


{ {
Wake_up
Do_Monday
Have_Shower
Do_Tuesday
Eat_Breakfast
Drive_To_Uni Do_Wednesday
Sit_ITBP101_Lecture Do_Thursday
...etc...etc...etc... ...etc...etc...etc...
Drive_From_Uni }
...etc...etc...etc...
}
47 Components of an Algorithm

Variables and values

Instructions

Procedures

Selections

CIT, UAEU.
48 Selection

 An instruction that decides which of two possible


sequences is executed

 The decision is based on a single true/false


condition

 Examples:
 Car repair
49 Selection

if (motor turns)
then
{
CheckFuel
CheckSparkPlugs
CheckCarburettor
}
else
{
CheckDistributor
CheckIgnitionCoil
}
50 Selection

if (motor turns)
then
{ Should be a
CheckFuel true or false
CheckSparkPlugs
CheckCarburettor
condition.
}
else
{
CheckDistributor
CheckIgnitionCoil
}
51 Selection

if (motor turns)
then
{
CheckFuel
CheckSparkPlugs
CheckCarburettor
Sequence if
}
else the condition
{ is true.
CheckDistributor
CheckIgnitionCoil
}
52 Selection

if (motor turns)
then
{
CheckFuel
CheckSparkPlugs
CheckCarburettor
} Sequence if the
else
{ condition is false.
CheckDistributor
CheckIgnitionCoil
}
53 LOGIC

CIT, UAEU.
54 Logic

What if several conditions need to be satisfied in a selection?


if ( today is Wednesday and the time is 10.00am )
then
{
Go to ITBP103 Lecture
}
else
{
Go to Library
}
55 Logic

What if at least one of several conditions need to be satisfied ?


if ( I feel hungry or the time is 1.00pm or my mate has his eye on my lunch )
then
{
Eat my lunch now
}
56 Proposition

 A proposition is a declarative sentence that is either


true (T) or false (F), but not both.
 A declarative sentence is a sentence that makes a
statement, provides a fact, offers an explanation, or
conveys information.

Examples 1: Propositions Examples 2: Not Propositions


 Beijing is the capital of China  Who are you? (question)
 Ahmed is smart  Interrogative sentence: asks a direct question
 2+3=5  Finish the homework by yourself.
 2+3=4 (command)
 Imperative sentence: used to deliver an
instruction, command, or request
 What a beautiful oasis! (exclamation)
 Exclamatory sentence: make statements that
express strong feeling or strong emotion
57 Proposition

Exercise: Proposition or not?


 The Earth is further from the sun than Venus.
2+3

 x is greater than 2

 The sun is shining.

 A prime number is any number that can be divided only by


itself and by 1.
 Come to class!

 What time is it?


58 Propositional Variable

 A propositional variable represents an arbitrary


proposition (also called Boolean variables)

 We use letters P, Q, R, . . . to denote propositional


variables

 We can form new propositions (called compound


propositions) from existing propositions using
logical operators: AND, OR and NOT
59 Logical Operators

 Logical operators are used to determine the logic


between variables or values
 NOT logical operator
 AND logical operator
 OR logical operator
Operator Name Description Example
NOT Logical not Reverse the result, returns NOT P
false if the result is true
AND Logical and Returns true if both P AND Q
statements are true
OR Logical or Returns true if one of the P OR Q
statements is true
60 Truth Table - NOT Logical Operator

 Reverse the result, returns false if the result is true


and vice versa

P NOT P
P: “Today is Friday”
F T

T F NOT P: “Today is not Friday”


61 Truth Table - AND Logical Operator

 Returns true if both statements are true

P Q P AND Q P: “Today is Friday”

F F F Q: “It is raining today”

F T F P AND Q: “Today is Friday


and it is raining today”
T F F

T T T

P AND Q Is true on rainy Fridays


P AND Q Is false on any day that is not a Friday
on Fridays when it does not rain
62 Truth Table - OR Logical Operator

 Returns true if one of the statements is true


P Q P OR Q
P: “Today is Friday”
F F F
Q: “It is raining today”
F T T
P OR Q: “Today is Friday or
T F T it is raining today”

T T T

P OR Q Is true on any day that is either a Friday


or a rainy day (including rainy Fridays)
P OR Q Is false on any days that are not a Fridays when it is not raining
63 Logic

 Example:
 b: “you are an IT major”
 c: “you are a freshman”
 Translate the following English sentences into logical
expression:
 You are an IT major or you are a freshman
 You are an IT major or you are not a freshman

 Translating sentences in natural language into logical


expressions is an essential part of writing algorithms
64 Flowcharts
65 Flowcharts

Example: Draw a flowchart to convert the length in feet to centimeter.

Flowchart

Pseudocode START

Step 1: Start Input


Input
LFT
Step 2: Input LFT
Step 3: Calculate LCM  LFT x LCM  LFT x 30
30
Step 4: Print LCM
Print
Step 5: Stop LCM

STOP
STOP
66 Flowcharts

Algorithm
-Start
Flowchart
-Start
-Get
-Get the
the four
four marks
marks
-Calculate
-Calculate thethe final
final grade
grade by
by adding
adding the
the fours
fours marks
marks then
then divide
divide by
by 4
4 START
START
-if the final grade is less than 60 then
-if the final grade is less than 60 then
Print
Print “FAIL”
“FAIL” Input
else
else M1, M2, M3, M4
Print
Print “PASS”
“PASS”
-Stop
-Stop
Calculate
GRADE(M1+M2+M3+M4)/4
Pseudocode
Step 1: Start N Y
IS
IS
Step 2: Input M1, M2, M3, M4 GRADE<6
GRADE<6
Step 3: Calculate GRADE  (M1+M2+M3+M4)/4 0
0
Step 4: if (GRADE <60) then
Print “FAIL” Print Print
Print
“PASS” “FAIL”
else
Print “PASS”
endif
Step 5: Stop STOP
STOP
67 Flowcharts

Exercise
Draw a flowchart that reads the two sides
of a rectangle then calculate and print its
area.
68 Concept Check

Across

1) The representation of an algorithm on the computer


3) Involves the use of computers to solve a problem
6) Could indicate the ratio of male and female
population in UAE
8) Used to describe an abstract representation of a
problem
10) Involves propositions that can be either true or
false
11) A state that occurs before a problem resolution
12) A graphical representation of an algorithm

Down

1) a textual representation of an algorithm


2) A computerized prototype run of a model
4) Description of a problem which hides irrelevant
details
5) Indicates what must be true before and after a
problem resolution
7) A "recipe" made by a sequence of steps to solve a
problem
9) Container of values in an algorithm

You might also like