























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
computational thinking appunti
Tipologia: Appunti
1 / 31
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!
























SUBJECT OF THE EMAILS: [CT2020] topic Exams dates:
CT is the thought process involved in f ormulating a problem and expressing its solution (s) in such a way that a computer -human or machine- can effectively carry out. The same instruction that I give to a human, I can give it to a computer. CT is the mental activity for abstracting problems anche formulating solutions that can be automated. The process of recognizing aspects of computation in the world that surrounds us, and applying tools and techniques from Computer Science to understand and reason about both natural and artificial system and processes. ALGORITHMIC THINKING Algorithms are sequences of basic steps a non-intelligent being can blindly follow to solve a problem. They are to be basic because they have to be follow by a non-intelligent being. The actions you use to actually solve the problem once you now the solution, the algorithm is the operational step. We can use algorithmic thinking to save lives. Locked-in Syndrome, for any reason somebody can think but has a completely locked body. “MR Qwerty is paralyzed except for the blink of an eye, yet he wants to describe his condition and help others”. How can we help him? How can we communicate with him? One solution: turns blinks into letters: one blink: A, two blinks: B… now we have a solution, you just need to count blinks. We came up with a sequence of steps that a helper can follow to guarantee the letters Mr. Qwerty is thinking of are communicated. Our algorithm has two component: Mr. Qwerty and the helper. They both need to know that a certain number of blinks corresponded to a precise letter. ALGORITHMS NEED TO FOLLOW A PROTOCOL. BUT our algorithm is slow, need extra chars, is error prone. What we need to do is a evaluation of the efficiency of our solution.our mission in not complete, we must be sure that our algorithm is solid enough. PROBLEM-SOLUTION-ALGORITHM-EVALUATION Often problems are essentially the same as something you have seen in a different situation. Have I ever seen a solution fore this problem? PATTERN MATCHING : we can apply predictive texting that’s used in your phone. A-n-t-e-l —-> antelope. Recognizing that our problem is similar to an other problem we have the solution for. GENERALIZATION : we might have a solution that works for a variety of similar problems. Similar, we might adapt Morse Codes to Mr. Qwerty’s situation.
If we use pattern matching and generalization we came up with another solution. Some letters are more common than others, so we might order the letters on frequency basis. One blink, most used letter, 26 blinks, less used letter. How fast is this algorithm? Let’s run the algorithm several times by employing different people and measure time. We need to have different people, more clever, who blink faster or slower… Time + Effort: estimate the time each letter takes, multiply by the number of letter said. —> ABSTRACTION : we used “the number of letters said” in place of the actual time taken to say them. How do we estimate how mane letters have to be said, we consider the WORST CASE ABSTRACTED , if you are unlucky what’s the worts sequence of letters we can encounter? When you estimate the execution time of your algorithm in the worst case, you know you can always do better and guarantee you can not do worst. You have to think in a pessimistic way. AVERAGE-CASE : when you have a good solution for the worst case, you know you’ll have a good solution also for the average-case. But the average-case requires a real experience, we need to know what’s going on on the reale life to come up with the average-case. For each A there is a Z, for each B there is a Y, this leads to 13 blinks per letter. We sum up the worst case and the better case, to obtain the average-case. If we multiply by the number Mr. Qwerty wants to say, we have an estimate of the running time. Even though we consider the frequency analysis improvement, the algorithm is still pretty slow. We may go to 10 blinks per letter on average, but worts case is stil 26 blinks. Our worst case doesn’t chance. We need to think a better algorithm! 20 question for letters! Answering yes/no is like is like blink/no blink. We can always find the right letter with at most 5 five questions, GUARANTEED! With question we need to use? We might ask: is it vowel? If it’s a vowel, narrowed down the problem to 5 letters, else wr’re still in trouble. we could use this system: DIVIDE AND CONQUER
hospital bed with the locked-in syndrome. Unfortunately, he did not know to think computationally. Nevertheless, he managed to write a book. PILLARS OF CT:
Humans have an innate understanding of both logic and algorithms. But they are both mathematical concepts in nature. Hence, they have their own set of rules, procedures and definitions. Logic is a system to distinguish between correct and incorrect arguments. Logic includes a set of principles that, when applied to arguments, allow us to demonstrate what is true, the difference between opinions and facts.
A precise, systematic method for producing a specified result. In real life we do the all the time:
Algorithm is a procedure and sequence of actions to accomplish some task. The concept of an algorithm is often illustrated by the example of a recipe, although many algorithms are much more complex; algorithm often have steps that repeat (iterate) or require decisions (such as logic or comparison). In most higher level programs, algorithms act in complex patterns, each using smaller and smaller sub-methods with are built up to the program as whole. An algorithm solves a problem, can be repeated over and over and over, with the same results
1. Input specified : data to be transformed during the computation to produce the output. Must specify type, amount, and form of data. 2. Output specified : data resulting from computation-intended result. It’s possible to have no output. 3. Definiteness : specify the sequence of events. Details of each step, including how to handle errors. 4. Effectiveness : the operations are do-able, you can do the operation. 5. Finiteness : must eventually stop, with an error or a solution. When you have this, you have an algorithm. Program VS Algorithm A program is an algorithm that has be customize to solve a specific task, under a specific set of circumstances, using a specific language.
Tic tac toe:
1. The game is started = variable “game” initialized 2. Begin a loop : starting point of a loop ( iteration ) the indentation shows what’s inside the loop. it’s a sequence of steps that are executed in a loop, until something happens, I stop, I exit the loop. If I have an infinite loop, I have something wrong. Inside the loop all the instruction are spaced, this is called indentation , that means investing something inside something else. This is fundamentally in python. The instruction tells how to manage the game. 3. Exit loop if game is won or game is drawn = checking ending condition 4. After al the instructions, display message “game over”. The algorithm is execute in sequence , i.e. one instruction at a time. LOGICAL THINKING, PUZZLES, LOGIC AND PATTERNS Cut Hives: a cut Hive puzzle consists of a block of hexagons, with different areas market out using thicker lines. There are two rules that must hold of a completed block.
Why Python?
The number of children function c c(Martin Luther king Jr) = 4 f(x) = x+ x = 2 f(x) = 2+1 = 3 Function is an algorithm turning a number to another number, in this case. Recursion: Factorial of a number You take the number n (input) and multiply n with n-1 till you reach 1. fact(0) = 1, it’s rule, a definition. fact(1)=fact(0) * 1 = 1 * 1 = 1 fact(2) = fact(1)∗2 = 1∗2 = 2 fact(3) = fact(2)∗3 = 2∗3 = 6 Recursive function: fact(n) = fact(n-1)n*
Unimportant characteristics can be filtered out and ignored. PATTERN RECOGNITION/MATCHING
Color is repeated x times = general rule. ALGORITHM An example of algorithm is how to make tea and we can represent it with a flow chart. What if we let the user decide between herbal tea, green tea or black tea? The temperature of boiling and the time of steeping will be different, so… We will have to think to an algorithm that can solve all the problems with other teas. Let’s narrow it down to herbal or black tea:
Finding the largest Value: How do you solve this problem manually? 52, 34, 78, 12, 24, 90, 87, 99, 45 You might skim through the numbers by selecting the largest digit on the left. Then compare only the numbers with the largest digit and pick up the largest number overall. A computer can’t solve a problem like that. We need to provide a solution using binary operations, such as comparisons (23>12? True/false). How do we solve this problem computationally?
D is the correct answer. LINEAR SEARCH We need to check if the number 90 is present in a given sequence: 52, 34, 78, 12, 24, 90, 87, 99, 45 We need to provide a solution using binary operations such as comparison (23==12? True/false) As we have done for finding the largest value.
element?
This algorithm works, but what if the list is very long? Is this algorithm efficient? How we define efficiency? Can we do better?
Exercise A health worker has created an assessment tool that allows respondents to rate their symptoms as not occurring, mild , moderate , or severe. He wants to ke ep track of the number of times the respondent selects severe. The flowchart on the right describes an algorithm that counts the number of occurrences of a target value, but there are some problems with it. Can you spot them?
Linear search: 10 comparisons Binary search: 4 comparison What is the worst case? The sought element is not in the list Linear search: 17 comparisons Linear running time -> n Binary search: 4 comparisons Logarithmic running time -> log2(n)