





















































































Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Prepara i tuoi esami
Studia grazie alle numerose risorse presenti su Docsity
Prepara i tuoi esami con i documenti condivisi da studenti come te su Docsity
Trova i documenti specifici per gli esami della tua università
Preparati con lezioni e prove svolte basate sui programmi universitari!
Rispondi a reali domande d’esame e scopri la tua preparazione
Riassumi i tuoi documenti, fagli domande, convertili in quiz e mappe concettuali
Studia con prove svolte, tesine e consigli utili
Togliti ogni dubbio leggendo le risposte alle domande fatte da altri studenti come te
Esplora i documenti più scaricati per gli argomenti di studio più popolari
Ottieni i punti per scaricare
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Riassunti/schemi del libro "Computational thinking: a beginner's guide to problem-solving and programming", ottimo per il corso di Computational Thinking con il prof. Giachelle (unipd, 2025/2026)
Tipologia: Sintesi del corso
1 / 93
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!






















































































Glossary
Abstraction : way of expressing an idea in a specific context while at the same time
suppressing details irrelevant in that context
Algorithm : a sequence of clearly defined steps that describe a process to follow a
finite set of unambiguous instructions with clear start and end points
Assignment : the process of setting the value of a variable
Biconditional : relationship between logical statements that tells us the second
logically follows from the first and the first logically follows from the second
Cardinality : property describing the number of elements in something
Conditional : programming construct that alters the flow of execution in a program
depending on the truth value of a condition
Conjunction (aka logical and): operation that connects two logical statements and
identifies whether both are true
Deductive reasoning : applying a chain of reasoning whose conclusion necessarily
follows from its premises (so long as it has been constructed properly and the
premises are incontrovertibly true)
Disjunction (aka logical or): operation that connects two logical statements and
identi fies whether one or both are true
Function signature : a function identifier made up of the function’s name and an
ordered list of the parameters it accepts
Heuristic : problem-solving technique that yields a sub-optimal solution judged to be
sufficient
Implication : relationship between logical statements that tells us the second logically
follows from the first
Inductive reasoning : applying a chain of reasoning whose conclusion follows as a
measure of probability from its premises
Information hiding: concealing the structure of some (potentially unstable) parts of a
program behind a stable interface
Library : collection of data and routines hidden behind an interface, intended for use
by other programs
Loop : sequence of statements that are executed potentially numerous times in
succession
Mutable : object whose value can be modified after creation, as opposed to an
immutable object, whose value is fixed at creation
Negation : operation applied to a proposition that inverts its value
Parameter: value passed to a function
Pixel: smallest addressable unit on a computer screen
Premise: proposition used in an argument
Proposition: statement that has a true or false value
Script: executable program, usually small (up to a few thousand lines of code) and
interpreted (as opposed to compiled)
Subroutine: callable sequence of program instructions packaged as a distinct unit
Tree (structure): hierarchical data structure where each node may have any number
of child nodes, but only one parent node (with the exception of the root node, which
has no parent)
Truth value: property of a logical statement that denotes whether it is true or false
Introduction: Why study computational thinking?
Computers are everywhere -> help run almost every aspect of our lives
MANY parts of modern society depend on computation
Computers are our tools. They should be subservient to us and not the other way around. They should enable us, inspire us and be a beneficial force in our lives. To help ensure this, it’s important we understand how they work and what they’re capable of doing
Computational thinking (CT) : distills important lessons and principles from computer science (CS) , the subject area that teaches us how to bend those machines to our will
importance of computational thinking in many diverse careers, such as: natural sciences; computational biology…
!! CT is even promoted as a life skill !!
Jeanette Wing emphasises the importance of CT to everyday life and suggests that everyone can get something out of studying it
What is computational thinking
Programming: educate students in how best to write programs, focuses on the production of high-quality software
CT: "thinking like a computer scientist” (Wing) -> criticised because it leaves a strong association with computer science It is an approach to problem-solving ; CT assumes a computer will execute the eventual solution Eidence is not conclusive about whether or not they succeed in their aim of teaching transferable skills
CT teaches an approach to problem-solving where the ultimate aim is to provide a solution whose form means it is ready to be programmed into a computer CT takes a relatively small subset of concepts – which just happen to be important to CS – and uses them to construct a widely applicable, problem-solving approach
The ultimate goal should not be to teach everyone to think like a computer scientist, but rather to teach them to apply these common elements to solve problems and discover new questions that can be explored within and across all disciplines
Current shortcomings (lacuna)
1. Maturity CT as a formal concept is relatively immature Definition: “a focused approach to problem-solving, incorporating thought processes that utilize abstraction, decomposition, algorithms, evaluation, and generalizations” 2. Efficacy Consequence of CT’s youth is the relative paucity (scarsità) of how effective teaching CT actually is 3. Perceived imperialism CT risk being imperialistic and off-putting (scoraggiante) Hemmendinger : proponents should be careful that CT doesn’t get into the habit of saying, ‘If it’s a good way of thinking, then it’s ours. It should be noted that many practices in CT are not original to the subject. In fact, they’re not all original to computer science; many of them have been used in other fields as well as everyday life for a long time
Summary
Computational thinking is an approach to problem-solving that involves using a set of practices and principles from computer science to formulate a solution that’s executable by a computer. It’s not just for programmers. In fact, it’s applicable in a diverse array of fields.
Approach
Logic and algorithms are essential to CT
GOOD news: humans already have an innate, intuitive understanding of both logic and algorithms BAD news: they are both mathematical concepts in nature; each has its own set of rules, procedures and definitions
Logical thinking
In brief: Logic
Logic: system used for distinguishing between correct and incorrect arguments Argument : the philosophical idea of an argument; namely a chain of reasoning that ends up in a conclusion
Logic includes a set of principles that, when applied to arguments, allow us to demonstrate what is true Ex: Socrates is a man; all men are mortal; therefore, Socates is mortal
We don’t always carry it out correctly, which can lead us to form wrong conclusions. And since we use computers essentially to automate our reasoning, we must learn to perform logic correctly before writing a computer solution -> applying logic is a way of developing and testing hypothesis
Premise: each individual thing you already know (or assume); is like any ordinary statement you might make, except that it can be evaluated to obtain an answer of ‘true’ or ‘false’. A premise, therefore, has a truth value
!! Other forms of expression, like questions or commands, can’t be premises to an argument !!
a. state the premises b. analyse them c. react accordingly with a conclusion
Inductive vs deductive arguments
Categorise arguments based on their certainty
Deductive argument (computer) : strongest form of reasoning because its conclusion neces sarily follows from its premises (ex. Socrates mortality)
**_2. propositions must have clear and unambiguous meaning
AND (conjunction)
It chains proposi tions together in a way that all of them must be true for the conclusion to be true. If any of them are false, the conclusion is rendered false also -> presence of “and” between propositions can be implicit
OR (disjunction)
Chains propositions together in a way that at least one of them must be true for the conclusion to be true also. The only way that the conclusion is falsified is if all propositions are false -> OR can also be used in cases when both conditions can be true at the same time
NOT (negation)
Doesn’t chain propositions together itself, rather it modifies a single proposition. Specifically, it flips the truth value. Sometimes, negating a proposition can make it easier to express the chain of reasoning
IMPLIES (implication)
Using this operator is to state that there is a correlation between the two statements. If the first statement is true, then the second must be true also. Keep in mind, this is a correlation not a causation. Therefore, you can’t work backwards from the conclusion of an implication
IF AND ONLY IF (biconditional)
means that the second proposition is influenced solely by the first. If the first is true, the second is true. If the first is false, the second is false. No exceptions. In this case, you can work backwards
Symbolic logic
Logic requires precision and an absence of ambiguity, but it can be difficult to meet these requirements when using natural language (it is often confusing or ambiguous)
Using mathematics symbols instead of natural language
If P and Q, then S
P V Q ↔ S
Symbolic logic gives each logical operator formal rules
Truth list : this list all the possible combinations of values of the propositions. The trith table states whether each combination is logically valid or not
it is valid to consider a disjunction true so long as one or more of its propositions are true
NOT : p ictorially represents the difference between a proposition with and without the NOT operator. In other words, whatever is true becomes false, and whatever is false becomes true —-- — The first two lines of seem sensible. If P being true implies Q is true and both are indeed true, then the
implication is valid.
Likewise, if P is true, but its consequent is not true, then the implication is invalid. The last
two lines, however, seem odd. The implication is valid regardless of the value of P.
!! Why is it valid for P to imply Q when P is false? In ‘P implies Q’, P is known as the antecedent and Q as the consequent. The explanation is that no conclusion can be drawn about an implication when the antecedent is false.
every step must be precisely defined. Each step in an algorithm can have one and only one meaning, otherwise it is ambiguous
3. Sequential Steps must be carried out in the order specified; you must respect the sequence when running through an algorithm for it to have any meaningful result 4. Detour (deviazione) : State in algorithms State: the current values of all the things the algorithm is keeping track of. The state of things can change. Sequencing the steps of an algorithm ensures that the state always changes in the same way whenever the algorithm is executed.
State : the current configuration of all information kept track of by a program at any one instant in time.
There’s an important implication to this: there is no ‘global view’ when it comes to algorithms. This means that, at each instant in time, the environment in which the algorithm is being run exists in some particular state. But by the time the next step is executed, something might have changed. The environment really exists as a series of snapshots, one for each step of the algorithm.
For algorithms, this means that individual steps are executed one by one and only a single step can be under consideration at any one time. Once a step has been executed, the computer forgets all about it and moves on to the next.
This means that some way of ‘remembering’ things that happened in previous steps needs to be provided. If you, the algorithm’s author, want the computer to remember the result of a step for later use, you have to explicitly tell the computer to do so. Algorithms provide for this by means of variables.
!! variables in programming do not correspond exactly to variables from mathematics. Mathematical variables are used in a function to represent quantities that vary. A variable in an algorithm is more like a scratchpad that’s used as a placeholder for important information the computer should keep note of. It can also have its values updated throughout an algorithm’s execution (this is called assignment ) !!
Controlling algorithm execution Interation
Variables can be used to control the execution of an algorithm in two ways:
1. Interaction (looping) Allows to repeat a series of steps over and over, without the need to write out each individual step manually
2. Selection (conditional) In a loop, one way to control how many times the steps are repeated is simply to specify it; it is a way to test a variable’s current value and make a decision based on it. It’s telling the computer to do something so long as the condition specified is currently true.
Conditions can be used at any stage in an algorithm, not only to control loops. Wherever they are, they all serve the same purpose: creating a point at which the computer has to decide between performing a set of steps or not, and encapsulating the information needed to make that decision
Pseudocode : informal means of writing an algorithm
Let’s examine this algorithm:
“Gotchas” (trucchi) The need for clarity and meticulousness
Clarity, precision and meticulousness when working with logic and algorithms. Computer programs demand precision in their rules and instructions
!!! Ex: “if score is not less than 51 per cent or greater than 80 per cent, then mark student’s grade as an ordinary pass”
- > That might seem precise at first glance, but it could be interpreted in at least two differ ent ways.
Symbolic logic provides very specific rules about how to interpret the various parts of logical statements. These rules are called the order of precedence. They dictate in what order each part of a logical expression should be evaluated.
Ex: “ if(¬(score < 51) V (score > 80))”
Let’s arbitrarily choose 55 as score if¬(false) V (score > 80) if true V false -> 55 is not minor than 51, so that’s true -> 55 is not greater than 80, so it’s false
Consulting the truth table for OR, we find that when either or both conditions are true, then the whole expression is true. In this case, the student correctly gets an ordinary pass.
Ex: “ if(¬(score < 51) V (score > 80))”
Let’s arbitrarily choose 85 as score if¬(false) V (score > 80) if true V true -> 85 is not minor than 51, so that’s true -> 85 is not greater than 80, so it’s true
We’ve demonstrated that, according to the algorithm in its present state, the student gets an ordinary pass even though they scored over 80
The problem is that our natural language way of expressing our intentions doesn’t quite agree with the rules of logic. To correct our original algorithm, we would have to put our own explicit brackets into the expression to ‘override’ the usual orders of precedence, like so:
if¬(score < 51 V score > 80) if¬(true V score > 80) if¬(true V true) if¬(true) if false
Summary
Logic and systematic reasoning are key underpinnings of CT because computer
programs are essentially an automation of our reasoning processes. Therefore,
writing solutions requires a good understanding of logic and the ability to use proper
notation over natural language.
This chapter has covered the basics of inductive and deductive reasoning, as well as
the importance of Boolean and symbolic forms of logic to computing.
Logic is an essential part of algorithms, which are the among the bedrock of
computing. They are the core of any program and thus play a part in every
computer-based solution. This chapter introduced the basic building blocks of every
algorithm and the notion of state.
It’s important in the case of both logic and algorithms to respect the need for a
systematic approach. Although both can make intuitive sense on some level, it’s also
easy to make mistakes when considering them that way. The use of correct logical
notation will help you to avoid making common mistakes
Where to start
If you have a problem: start analysing it and coming up with a solution; one that is
specifically formed so that a computer could carry it out
Where to start? -> Follow some kind of guide or process (instructions). A step-by-step procedure for problem-solving is partly a creative process
A systematic approach
George Polya : “How To Solve It” book -> first systematic approach to general problem solving -> inspired by the best traditions of mathematical and natural sciences
Whereas the scientific method follows the steps:
Pólya (1973) advocates:
Quality For any problem, there are usually multiple solutions: focus on finding the best solution you can -> For the overall problem, there is likely no perfect solution. Trade-offs between competing parts are almost inevitable
Collaboration Making problem-solving a collaborative effort: something as explaining your current work out loud often helps you to spot mistakes or potential improvements. Seek out the views of others -> While you have the attention of other people, try brainstorming with them -> wild ideas are to be encouraged
Interation Your first attempt at a solution will rarely be the best one Iterative approach: go back and repeat some of the previous steps in an attempt to improve your current solution
Decomposition Polya catalogues different problem-solving techniques called heuristics Heuristic : is a specific strategy in problem-solving that usually yields a good enough answer, though not necessarily an optimal one Decomposition: one of the heuristics (core), is an approach that seeks to break a complex problem down into simpler parts that are easier to deal with -> important in CT Programmers and computer scientists usually deal with large, complex problems that feature multiple interrelated parts -> decomposition almost invariably helps in man aging a complex problem where a computerised solution is the goal
Decomposition is a divide-and-conquer strategy, used by:
You use divide and conquer when the problem facing you is too large or complex to deal with all at once -> end up with a number of sub-problems that can be understood and solved individually -> visually, this gives the problem definition a tree structure
Recursion : a technique used to simplify a problem. It defines the solution to a large, complex problem in terms of smaller, simpler problems of the same form as the original problem. This is a very powerful idea and one that is heavily used in CS
!! Avoid getting bogged down in the details of how to solve the sub-problems. At this stage, we’re still focusing on what to do, not how to do it !!
!! Decomposition aids collaboration. If you decompose a problem well (so that the sub problems can be solved independently), then different people can work on different tasks, possibly in parallel !!
Other effective strategies Other effective strategies can complement decomposition by being applied to one or more of the resulting sub-problems
Think critically Critical thinking is to question ideas and see that they stand up to scrutiny. You should examine the available information and the decisions you’ve taken sceptically
ex. design the layout of a bookshop Question: Have I chosen a structure that makes it easy to locate a specific book?
In addition, expose assumptions in the process; assumptions made implicitly could well turn out to be false For any system you put in place, always ask the question: What if it goes wrong?
You could either work to improve your solution and eliminate the possibility of the problem occurring, or you could accept the possibility of it going wrong and put a contingency plan in place to be executed when the failure occurs.
Solve a concrete instance Terms you’re dealing with can sometimes feel quite abstract and devoid of detail Dromey: it’s easier to deal with problems in concrete terms because the details are more readily manipulated and understood
ex. we could draw a smiley face by breaking it down into several simpler shapes, which are each easy to draw
Find a related problem Dromey : examine the solution to a closely related problem. This helps for reasons that are similar to the previous strategy. A solution to another similar problem can point the way to a solution for your own problem
Caution : it is used to give you insight into a problem, not to solve it completely. Any solution you find will need some changes
Work backwards
-> the execution of loops is often controlled by a variable, which encapsulates the thing that varies from iteration to iteration.
Subroutines Concerns patterns among separate blocks of instructions It is a sequence of instructions that perform a distinct, often-invoked task and which can therefore be ‘packaged’ as a unit ex. - ‘Draw eye’ is a subroutine (r1, r2, x,y)
Rules Rules are normally indicated by words like ‘when’ and ‘unless’, as well as patterns like ‘if–then’
Summary
Decomposition and generalisation are related. Whereas decomposition involves breaking the problem down into smaller parts, generalisation involves combining those smaller parts. These actions are not the inverse of one another; when you generalise the individual parts, you’re not putting the problem together again in the same way as before. The point of generalisation is to look at the decomposed parts and find ways to make the solution easier to handle and more widely applicable to similar problems. In the example above, instead of having numerous parts which can each draw only one type of eye, there is one generic part that can draw many different types of eye.
CAP 4 - ABSTRACTION AND MODELLING
Abstraction
Decomposition: complex problem is divided into smaller -> motivation behind solving a series of simple problems is easier then trying to tackle a big complex one Generalisation: identifies patterns among those individual sub-problems and simplifies them -> is about hiding details result in ABSTRACTION
Abstraction : a way of expressing an idea in a specific context while at the same time suppressing details irrelevant in that context
The essence is preserving information that is relevant in a given context, and forgetting information that is irrelevant in that context
Reason of the abstraction: semplify the real world (because of too much information), so we can explain that to computers -> create models of the real world -> example: underground map is an abstraction (like a lot of other things in the real world) or mails
Context and layers
Context is the key of abstraction: an abstraction of something operates at a certain level of detail and puts a layer over the top to obscure some of the information. You can take any abstraction, peel back the layer and go further ‘down’ to reveal more information (thus considering it in a more detailed context), or go further ‘up’, adding more layers to suppress further details about it (a less detailed context)
takes numerous concrete ideas and unifies them into more abstract concepts. However, building abstractions can sometimes go the other way: that is, start with a fairly abstract concept and add more detail as you go along
Exercising caution
Warning label: “Caution! Abstraction may distract from reality!”
Abstraction: is a way of avoiding details, either by suppressing or deferring them -> do it carefully: it can be useful and productive -> do it recklessly: can be easy to get lost in abstraction
Question: “how does it work?”
Putting abstraction to use
It requires it to be made concrete somehow -> instantiated = requires attention to details
Leaking details
!! You have unwillingly ignored a detail that affects the way abstraction behaves -> hidden details have become important to how something works -> details have leaked out of the abstraction
When your abstractions are shown to leak, amend your model to take the problem into account. Details that turn out to be important need to be brought explicitly into the model
Modelling
Model : a type of abstraction