0% found this document useful (0 votes)
3 views33 pages

ENGG1003 08 ComputationalThinking(1)

The document discusses computational thinking, defining it as the process of formulating problems and expressing solutions in a way that computers can execute. It highlights the importance of computational thinking in various disciplines and daily life, emphasizing problem-solving strategies, tools, and algorithms. Additionally, it outlines the four components of computational thinking: decomposition, pattern recognition, abstraction, and algorithm design.

Uploaded by

ychw318
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views33 pages

ENGG1003 08 ComputationalThinking(1)

The document discusses computational thinking, defining it as the process of formulating problems and expressing solutions in a way that computers can execute. It highlights the importance of computational thinking in various disciplines and daily life, emphasizing problem-solving strategies, tools, and algorithms. Additionally, it outlines the four components of computational thinking: decomposition, pattern recognition, abstraction, and algorithm design.

Uploaded by

ychw318
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

ENGG1003

Computational Thinking
First ThingS in the Morning
• Do you break-fast with an empty stomach?
• Any urgency in answering the call of nature?
• Need to boil some drinking water?
• When do you brush teeth?
• Do you wash face?
• Blink and send first message to your loved ones?

• Well, what is the order of the events? Concurrency?


Definition
Computational thinking is the thought processes
involved in formulating a problem and expressing its
solution(s) in such a way that a computer—human or
machine—can effectively carry out.

“Thinking like a computer scientist” in short.

Wing, Jeannette (2014). "Computational Thinking Benefits Society".


40th Anniversary Blog of Social Issues in Computing.
Driving New Disciplines
Computational physics Computational law

Computational biology Computational social science

Algorithmic medicine Digital archaeology

Computational economics Digital arts

Computational finance Digital humanities

Big data and cloud computing Digital journalism

Machine learning Data science


Outline

• Plan a route in CUHK for a visitor!

• How coders and programmers think?


• Abstraction, Formulation, Expression, Execution.

• Python app demo: weather_to_bring_umbrella?!

• Components of Computational Thinking


• Problem example: finding variance

• Lab activities
Problem Scenario
• A visitor wants to go to Sir Run Run Shaw Hall from
MTR University Station. Let's plan a route.

https://www.cuhk.edu.hk/english/campus/cuhk-campus-map.html CUHK, licensed by Google.


Problem Definition
Starting point

Destination
GOAL
Time limit? &
Objectives
Mode of transportation? Budget?
Accessibility? Weather conditions?
Sight-seeing? Check-points?
Problem Solving Tools
• Ask a friend/ staff/ passer-by.
• Use a mapping app (online VS offline.)
• Use CUHK Mobile app.
• Get a CUHK pamphlet or paper map.
• Call a taxi or Uber.

Many different goals and objectives, thus strategies:


• Shortest distance, earliest arrival, gentle path, accessible,
cheapest or free of charge, avoid sunlight
Using the Tools –
Algorithms
• How to find "the" shortest path from one point to
some destination on a map?
Users VS Advanced Users
• General users see basic services of a mapping app.
• Pitfall: options, tools and even solutions are restricted,
for example, the route through YIA escalators is missed.

• Advanced users may gather more information and


use more advanced tools.
• E.g., add a check-point at
1.1 km
Madam S.H. Ho Hall:
1.2 km  1.1 km
Solutions in Action
• On foot/ ride a bicycle:
• Take lifts and/or escalators as far as possible.
• Take a direct path, perhaps with stairways.
• Go along Station Road, University Ave and Central Ave.
• Random walk around the campus.

• By shuttle bus, taxi, Uber, friend's free ride.


• If the visitor drives, parking is another problem.

• Infeasible within campus: MTR, cable car, tram, ferry, etc.


https://cutv.cpr.cuhk.edu.hk/detail/286?t=introduction-of-yasumoto-international-academic-park by CPR, CUHK.
Challenges and
Adaptations
• Subject to limitations/ restrictions:
• Physical fitness and strength in going uphill on foot.
• Stairs pose a challenge to bicycles, wheelchairs & carts.
• Service hours and bus-stop locations of shuttle buses.
• Availability, waiting time and cost by taxi and Uber.

• Mixed or adaptive solutions:


1. Take YIA escalators to Madam S.H. Ho Hall.
2. Try to catch a shuttle bus at a nearby stop on time.

https://www.cuhk.edu.hk/english/images/visitors/P1090449_215_215px.jpg by CUHK
Assimilation
• Employ computational thinking in daily life.

• Help analyze and tackle problems systematically.

• Help solve problems efficiently and effectively,


while objectives are considered thoroughly.
• Even the visitor is a casual sight-seer, a clear goal can
help pick a satisfying way, even enjoying a random walk!

https://www.cuhk.edu.hk/v6/en/media/presskit/chungchiweiyuanlake.html by CUHK
Coders and Programmers
• We perceive problems using generalization.

• We apply abstraction and modelling during analysis.


• E.g., route-finding on a map  shortest path in a graph

• We get insight and algorithms in solution finding.


• E.g., Dijkstra's algorithm or flood fill algorithm

• We implement the algorithm, thus creating a computer


program (an app) for solving the problem.
https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm#/media/File:Dijkstra_Animation.gif by Ibmua under Public Domain.
Power of Abstraction –
Transformation of a
Problem
Power of Abstraction –
Representation Edit
Delete

Move

Copy

Print

Share

https://upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Yellow_folder.JPG/1200px-Yellow_folder.JPG by Unknown Author is licensed under CC BY-SA.


https://www.publicdomainpictures.net/en/view-image.php?image=42091&picture=folder-silhouette released by Piotr Siedlecki is under CC0 Public Domain.
Abstraction in Daily Life

AC 220

https://upload.wikimedia.org/wikipedia/commons/0/02/Illuminated_light_switch.jpg by Unknown Author is licensed under CC BY-SA


https://upload.wikimedia.org/wikipedia/commons/thumb/f/fb/Opened_light_switch.JPG/1200px-Opened_light_switch.JPG by Unknown Author is licensed under CC BY-SA
https://i.stack.imgur.com/Ht0Bt.gif (circuit diagram) by Unknown Author is licensed under CC BY-SA
Re-cap… Abstraction!

Computational thinking is the thought processes


involved in formulating a problem and expressing its
solution(s) in such a way that a computer—human or
machine—can effectively carry out.

“Thinking like a computer scientist”


Formulating a Problem
• Let's build an app that can advise user to bring an
umbrella based on local (Sha Tin) weather report.
• What we need?
• Input: gather weather report data/ information.
• Process: use simple rules to formulate an advice.
• Rainy OR Shinny  Bring an umbrella
• Rainfall > 2mm OR UV level > 6
• Output: issue an advice.

http://www.publicdomainfiles.com/show_file.php?id=13534621212335 weather symbols by sivvus in Open Clip Art Library is under Public Domain.
Expressing a Solution -
Coding
• Use a computer programming language, Python
• Employ readily available modules and objects:
• urllib for reading data from an URL like https://...
• json for processing data from HK Observatory
Application Programming Interface (API)
• Python built-in abstract data types list and dict
• Apply simple logic to automate advice generation
• if-else branching construct
• number comparison operator, >, greater than
Carry Out – Running/
Execution
• Write a complete Python program.
• Store the program in a code file/ executable for
repeated execution and distribution.
• Run the Python program
• on a computer standalone OR
• on a browser using Jupyter Notebook over the web.
• Sample code follows…
weather_to_bring_umbrella.py
Relax, this is just a proof-of-
concept!
#!/usr/bin/env python3

import urllib.request
import json

# INPUT
HKO_API = "https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=rhrread&lang=en"
apiURL = urllib.request.urlopen(HKO_API)
data = apiURL.read()
report = json.loads(data)

# PROCESS
for record in report["rainfall"]["data"]:
if record["place"] == "Sha Tin":
shatin_rainfall = record["max"]

uvindex = report["uvindex"]["data"][0]["value"]

It looks scary!
# OUTPUT
if shatin_rainfall > 2 or uvindex > 6:
print("Bring an umbrella!")
else:
print("Neither rainy nor shinny")
Four Components of
Computational Thinking
• Decomposition – break down a problem

• Pattern Recognition – look for similarities

• Abstraction – use high-level tools and constructs

• Algorithm Design – layout a solution


Problem Example
• Given input data set X = [ X1, X2, X3, …, Xn ]

• Calculate variance using the following formula:

Variance = Mean of Squares – Square of Mean

• Suppose given 5 weight data in kg: 67, 32, 54, 60, 45.

• Calculate variance of the population by hand or on back-of-the-envelope:


Mean of X2 = ( 672 + 322 + 542 + 602 + 452 ) / 5 = 2810.8
Mean of X = ( 67 + 32 + 54 + 60 + 45 ) / 5 = 51.6
Variance = Mean of X2 – ( Mean of X )2 = 2810.8 - 51.62 = 148.24
Need an Automated
Solution
• Do NOT always calculate by hand!
• What if n = 5000?!

Goal: solving the general problem!!


• Need a computational solution that is:
• for arbitrary problem size n;
• for different sets of input data;
• repeatable with reproducible results;
• automated;
• reusable in other problems (even partly) or by others.
Direct Solution First
• Use information literacy skill: ask for a
keyword and search for an existing solution!

• Use spreadsheet function VAR.P( )


• Simple and direct solution!

• Use Python interactively, with statistics package:


import statistics
X = [67, 32, 54, 60, 45]
statistics.pvariance(X)
Indirect Solution
• Use spreadsheet/ coding skill: tabulate given data and
formulate a solution!

• Use spreadsheet operators such as ^2 (for squaring), division,


subtraction, as well as AVERAGE(…) or SUM(…).

• Use Python interactively, creating squares in Y:


X = [67, 32, 54, 60, 45]
Y = [X_i**2 for X_i in X]
sum(Y)/len(Y) - (sum(X)/len(X))**2

Python note: **2 for squaring; len(X) and len(Y) are 5


Proof on a Spreadsheet
X X^2
67 4489
Indirect Solution by tabulation 32 1024
and formula 54 2916
60 3600
45 2025
Mean using AVERAGE(…) function 51.6 2810.8
or SUM(…) / 5
Mean_of_square - Square_of_mean = 2810.8 - 51.6^2 = 148.24

Variance of a population using Excel = VAR.P ( X2:X6 ) = 148.24


Direct Solution by function
Four Components of Automation!
Computational Thinking
• Decomposition – break down a problem
• Separate the calculation into two parts
• Pattern Recognition – look for similarities
• Find mean of X, and mean of X2 with the same formula
• Abstraction – use high-level tools and constructs
• Use functions in Excel OR packages in Python
• Algorithm Design – layout a solution
• Write formula in Excel OR program in Python
Change Our Habits – Better
Tools
Better Habit

Cloud-based notes Back-of-the-envelope


taking apps calculation
Spreadsheet Desktop calculator
Voice typing Post-it everywhere
Jupyter Notebook Jot notes on paper
Type-and-save Write-and-dump

Old School
Search-and-find Lost-and-not-found
Summary
• Computational Thinking
- Thinking like a computer scientist
• Employ computational thinking in daily life

• Solving a Problem
• Definition of Goals and Objectives
• Use of Tools, Strategies and Algorithms
• Solution Implementation and Adaptations
Take Away Outcomes for
Today
• Understand computational thinking in daily life

• Seeing how to solve example problems in a


computational thinking style: abstraction,
formulation, expression and execution

• Solve simple problems using basic variables,


expressions, conditions and repetitions in Python
Extras: Are We Aware of
These?
Digital Being Well Being
High res camera, 4K display Treasure eye sight, good viewing habits
High fidelity audio, noise reduction Healthy hearing, suitable audio level
Speech synthesis, voice typing Master language use, practice more
Computer games, e-sports Physical exercises, social/board games
Networking Interpersonal communication
Cloud computing Live and serve well in a society
System protection, anti-virus Health management, proper vaccination
Artificial intelligence Nurture intelligence, wisdom, creativity
Machine learning Live-long learning, bear curiosity

You might also like