Part 1: Exercises

Contents

Part 1: Exercises#

Exercise 1

What are all the possible sentences that one can produce using the regular grammar introduced in Section “Historic hero: Noam Chomsky”?

Exercise 2

What is the result of applying the second natural language definition of the Fibonacci function in Section “Natural languages vs programming languages” using “7” as input?

Exercise 3

Write down two objects or situations that refer to the same pattern if analysed from an abstract point of view, as introduced in Section “Abstraction is the key”. What features do they have in common?

Exercise 4

What is the result of the execution of the algorithm in Figure 9 of the chapter “Algorithms” using "Peroni", "HTML", and "Peroni, S., Osborne, F., Di Iorio, A., Nuzzolese, A. G., Poggi, F., Vitali, F., Motta, E. (2017). Research Articles in Simplified HTML: a Web-first format for HTML-based scholarly articles. PeerJ Computer Science 3: e132. e2513. DOI: https://doi.org/10.7717/peerj-cs.132" as input values?

Exercise 5

Write the flowchart of an algorithm that takes in input two objects and returns the string “yes” whether the two objects are the same; otherwise, it returns the string “no”.

Exercise 6

The Chapter “Introduction to Computational Thinking” illustrates two different algorithms expressed in natural language, for implementing the Fibonacci function. Create two distinct flowcharts to implement both of them.

Exercise 7

Write the table of instructions of a Turing machine with four states – A (initial state), B, C, and D (final state) – such that, once the final state is reached, only the cells immediately on the left and on the right of the initial position of the head of the machine will have the value 1 specified. The final state must not have any instruction set in the table.

Exercise 8

Consider an algorithm that takes as input a 0-1 sequence of exactly five symbols and returns 1 if the sequence contains at least three consecutive 1s, and returns 0 otherwise. Implement the algorithm using a Turing machine, with the cell corresponding to the head’s starting position storing the final result. Also, the five cells following the starting position of the head are initialised with the 0-1 sequence of five symbols used as input to the algorithm.

Exercise 9

Consider an algorithm that takes as input a 0-1 sequence of exactly five symbols and returns 1 if the sequence contains at least three 1s in any order, while it returns 0 otherwise. Implement the algorithm using a Turing machine, with the cell corresponding to the head’s starting position storing the final result. Also, the five cells following the starting position of the head are initialised with the 0-1 sequence of five symbols used as input to the algorithm.

References#