Computational Thinking and Compilers
- 79Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is computational thinking?
79 questions
- 1
What is computational thinking?
Model answer
Computational thinking is the process of formulating problems using abstractions so that their solutions can be represented as computational steps and algorithms.
Explanation
The definition emphasizes abstraction, computational procedures, and algorithms as the central elements of computational thinking.
- 2
How have abstractions and algorithms changed compiler design?
Model answer
They transformed compiler design from an informal art into a systematic scientific discipline.
Explanation
Well-defined abstractions and algorithms made compiler construction more reusable, analyzable, and reliable.
- 3
Why is there no single standard definition of abstraction across all fields?
Model answer
Different fields use abstractions to represent different kinds of objects, relationships, and activities.
Explanation
The abstractions used in chemistry, for example, differ fundamentally from those used in music or computer science.
- 4
What two components make up an abstraction in the computer-science definition?
Model answer
An abstraction consists of a data model and a set of operations for manipulating that model.
Explanation
The operations distinguish this definition from abstractions that describe data without specifying how it can be manipulated.
- 5
Why can the operations of an abstraction be viewed as a programming language?
Model answer
The operations define the permitted actions on the abstraction's data, although they do not necessarily form a Turing-complete language.
Explanation
An abstraction specifies both what data exists and which computational actions can be performed on it.
- 6
What is an algorithm?
Model answer
Informally, an algorithm is a recipe for doing something; formally, it is a Turing machine that halts on every input.
Explanation
Halting on all inputs distinguishes an algorithm from a computation that may run forever.
- 7
What is the difference between an algorithm and a partially defined computation?
Model answer
An algorithm must halt on every input, whereas a partially defined computation may fail to halt for some inputs.
Explanation
The distinction is based on total termination behavior.
- 8
What are the four categories in the taxonomy of computer-science abstractions?
Model answer
The categories are fundamental abstractions, abstract implementations, declarative abstractions, and computational abstractions.
Explanation
The taxonomy classifies abstractions according to their purpose and level of computational expressiveness.
- 9
What are fundamental abstractions, and what are examples of them?
Model answer
Fundamental abstractions are basic structures commonly introduced in computer science, such as dictionaries, stacks, queues, graphs, trees, classes, and methods.
Explanation
These abstractions describe common data structures and programming constructs without specifying implementations for their methods.
- 10
What are abstract implementations?
Model answer
Abstract implementations are data structures used to implement fundamental abstractions, such as hash tables and search trees.
Explanation
They provide implementation mechanisms for higher-level structures such as dictionaries.
- 11
What are declarative abstractions?
Model answer
Declarative abstractions specify what should be computed without specifying how to compute it, and they need not be Turing-complete.
Explanation
Context-free grammars and flow graphs are examples used in compiler design.
- 12
What are computational abstractions?
Model answer
Computational abstractions closely model programming languages and are Turing-complete; examples include Turing machines, Boolean circuits, and quantum circuits.
Explanation
Their computational power allows them to represent general-purpose computation.
- 13
How can abstractions be layered?
Model answer
One abstraction can be implemented using algorithms or in terms of another abstraction.
Explanation
For example, a dictionary abstraction can be implemented using a linked-list abstraction.
- 14
Why is layering useful for analyzing an abstraction?
Model answer
Layering allows the running time of a higher-level abstraction to be derived from the algorithms and lower-level abstractions used to implement it.
Explanation
The cost of operations can be analyzed by composing the costs of the implementation layers.
- 15
What is the data model of a dictionary abstraction?
Model answer
It consists of a universal set U of elements and a subset S⊆U, initially empty.
Explanation
The subset S represents the elements currently stored in the dictionary.
- 16
What operations does the dictionary abstraction provide?
Model answer
It provides operations to insert an element into S, delete an element from S, and test whether a given element belongs to S.
Explanation
These operations capture the basic behavior required of a dictionary or symbol table.
- 17
Why is a dictionary abstraction useful in a compiler?
Model answer
A dictionary models the symbol table, which stores and looks up information about program symbols.
Explanation
Compiler symbol tables require insertion, deletion, and membership or lookup operations.
- 18
What is the overall role of a compiler?
Model answer
A compiler translates a source program into a semantically equivalent target program.
Explanation
Semantic equivalence means that the target program preserves the intended behavior of the source program.
- 19
How is a modern compiler organized as a sequence of phases?
Model answer
The compiler translates the source program through a sequence of semantically equivalent, progressively lower-level representations before generating the target program.
Explanation
Each phase performs a distinct transformation while preserving program meaning.
- 20
What are the front end and back end of a compiler?
Model answer
The front end analyzes the source language and produces an intermediate representation, while the back end transforms that representation into target-machine code.
Explanation
The front end is generally source-language dependent, whereas the back end is generally target-machine dependent.
- 21
How does LLVM support multiple source and target languages?
Model answer
Different front ends translate source languages into LLVM intermediate representation, which can then be optimized and processed by different target-code generators.
Explanation
A shared intermediate representation allows front ends and back ends to be reused independently.
- 22
What is the role of an optimizer in the LLVM-style compiler framework?
Model answer
The optimizer transforms the intermediate representation into a form from which a better target program can be generated.
Explanation
Optimization improves the generated code while preserving the program's semantics.
- 23
Why does an existing compiler framework simplify development of a new compiler?
Model answer
A new source language generally requires only a new front end, while an existing target architecture generally requires only a new intermediate-representation-to-machine-code generator.
Explanation
Reusable optimization and code-generation components reduce the amount of compiler-specific work.
- 24
What is the data model of the regular-expression abstraction?
Model answer
Its data model is a set of strings over an alphabet.
Explanation
Regular expressions describe collections of strings that can be recognized by lexical-analysis tools.
- 25
What are the fundamental operations of regular expressions?
Model answer
The operations are union, concatenation, and Kleene closure.
Explanation
These operations combine sets of strings to form more complex regular languages.
- 26
How did the running times of the regular-expression matching methods described differ?
Model answer
Thompson's method ran in time linear in the product of the pattern and input lengths, while a dynamically constructed DFA method had observed time linear in their sum.
Explanation
The algorithms used different implementation strategies, producing substantially different performance behavior.
- 27
What does Lex do?
Model answer
Lex converts a token specification based on regular expressions into a lexical analyzer.
Explanation
It allows users to construct scanners without implementing the pattern-matching algorithm themselves.
- 28
How does a Lex specification for integers work?
Model answer
It recognizes one or more digits, stores the digit sequence in a table, and returns a
NUMtoken together with a pointer to the stored digits.Explanation
The generated lexer converts a character sequence into a token and associated semantic information.
- 29
Why are Lex and tools such as Flex useful to compiler developers?
Model answer
They automate construction of efficient lexical analyzers and allow developers to specify token syntax without learning the matching algorithm.
Explanation
This makes scanner construction faster and more accessible.
- 30
What is the role of a context-free grammar in a compiler?
Model answer
A context-free grammar specifies the grammatical structure or syntax of a programming language.
Explanation
The parser uses the grammar to determine how a token stream forms valid language constructs.
- 31
What does a syntax-directed translation scheme add to a context-free grammar?
Model answer
It attaches rules to grammar productions that guide translation of a token stream into an output structure, usually a syntax tree.
Explanation
The rules connect syntactic recognition with construction of an intermediate representation.
- 32
What is YACC?
Model answer
YACC is a tool for constructing syntax analyzers from grammar specifications; its name means “Yet Another Compiler Compiler.”
Explanation
YACC generates parsers so compiler developers do not need to implement the parsing algorithm manually.
- 33
Why are YACC and its descendants useful?
Model answer
They let developers write grammatical specifications while automating construction of the parser, and they identify difficult or conflicting grammar constructs.
Explanation
This improves development productivity and helps reveal ambiguity in a grammar.
- 34
How can Lex and YACC be used together?
Model answer
Lex generates a lexical analyzer that produces tokens, and YACC uses those tokens with a grammar to construct a parser, such as one for a desk calculator.
Explanation
The tools divide compiler front-end construction into lexical and syntactic analysis.
- 35
What is the difference between LL and LR parsing in the context described?
Model answer
LL parsing is a top-down, recursive-descent style, whereas LR parsing is a bottom-up method that can handle a broader class of grammars deterministically.
Explanation
LR methods were developed to parse grammars that may not fit the restrictions of simple LL parsing.
- 36
Why did grammar writers often modify grammars for LL or restricted LR parsers?
Model answer
They had to reshape grammars to fit the structural restrictions of the selected parsing technique, even when the original grammar naturally described the language.
Explanation
This could be difficult for compiler writers who were not specialists in parsing theory.
- 37
How does YACC resolve a shift-reduce conflict in the convention described?
Model answer
YACC favors shifting when a shift-reduce conflict occurs.
Explanation
This rule can disambiguate certain constructs, such as the association of an
ifstatement with anelseclause. - 38
Why can an ambiguous grammar be useful for expressing operator precedence?
Model answer
Instead of creating a separate syntactic category for every precedence level, a compact ambiguous grammar can be combined with explicit precedence and associativity rules.
Explanation
For a language such as C, this avoids writing many separate grammar levels for operators.
- 39
What is a limitation of parser generators for some industrial languages?
Model answer
Some languages, such as C++, have syntax so complex that they may require specially designed or carefully maintained parsers rather than a straightforward parser-generator specification.
Explanation
Highly complex language syntax may not fit conveniently into standard grammar formalisms.
- 40
What is a flow graph used to model?
Model answer
A flow graph models the possible flow of control through a computer program.
Explanation
Its nodes represent basic blocks and its edges represent possible transfers of control.
- 41
What is a basic block in a compiler flow graph?
Model answer
A basic block is a node representing a sequence of intermediate-representation statements with control entering at the beginning and leaving at the end.
Explanation
The flow graph connects blocks according to which blocks can execute after one another.
- 42
What is a reaching definition?
Model answer
A definition of a variable at statement S reaches statement T if there is an execution path from S to T along which the variable is not redefined.
Explanation
A redefinition along the path kills the earlier definition.
- 43
What is the reaching-definitions problem?
Model answer
It is the problem of determining which variable definitions may reach each program point.
Explanation
The information describes which assignments can provide the current value of a variable.
- 44
Which compiler optimizations can use reaching definitions?
Model answer
Reaching definitions can support optimizations such as constant propagation and loop-invariant code motion.
Explanation
These optimizations need information about where values originate and whether assignments remain valid.
- 45
What is the data model of the flow-graph abstraction for reaching definitions?
Model answer
It consists of a semilattice of subsets of variable definitions, together with a directed graph of basic blocks and their control-flow relationships.
Explanation
The subsets are the data-flow values propagated through the graph.
- 46
What data-flow values are associated with each node in a flow graph?
Model answer
Each node has a value for definitions reaching the beginning of the basic block and a value for definitions reaching its end.
Explanation
These input and output values describe how definitions flow through the block.
- 47
What does the transfer function do in a flow-graph abstraction?
Model answer
The transfer function computes the output data-flow value at the end of a node from the input value at its beginning.
Explanation
It represents the effects of the statements in the basic block.
- 48
What does the confluence operator do?
Model answer
It computes the data-flow value at the beginning of a node from the values at the ends of all its predecessor nodes.
Explanation
It combines information arriving along different control-flow paths.
- 49
Why must the confluence operator be commutative and associative?
Model answer
Because the data-flow values form a semilattice, combining predecessor information must be independent of the order and grouping of the combination.
Explanation
These properties make the merge operation well-defined across multiple incoming paths.
- 50
How did compiler abstractions and tools affect the development of programming languages?
Model answer
They made it possible to create innovative programming languages and their compilers much more quickly than earlier compiler projects.
Explanation
Reusable lexical, parsing, optimization, and code-generation abstractions reduced the effort required for compiler construction.
- 51
What role did compiler tools play in compiler education?
Model answer
They enabled students to design programming languages and build working compilers as semester projects.
Explanation
The tools allowed students to focus on language design and software engineering rather than implementing every compiler algorithm from scratch.
- 52
What does the example of the Upbeat language demonstrate?
Model answer
It demonstrates how a student-designed language and compiler can connect program-detected input patterns with multimedia behavior, such as selecting music based on stock-market data.
Explanation
The example illustrates the practical creativity enabled by compiler abstractions and tools.
- 53
Why did compiler construction become more like software engineering with frameworks such as GCC and LLVM?
Model answer
Existing frameworks provide reusable intermediate representations, optimizers, and code generators, so developers can concentrate mainly on the new front end or target back end.
Explanation
Component reuse reduces the need to construct an entire compiler pipeline independently.
- 54
What is a qubit?
Model answer
A qubit is a unit vector in a complex vector space and can exist in a superposition of the basis states ∣0⟩ and ∣1⟩.
Explanation
Unlike a classical bit, a qubit is not restricted to one definite basis value before measurement.
- 55
How is the state of a qubit represented mathematically?
Model answer
A qubit can be written as α∣0⟩+β∣1⟩, where α and β are complex amplitudes satisfying ∣α∣2+∣β∣2=1.
Explanation
The normalization condition ensures that the total measurement probability is one.
- 56
What is a unitary operator in quantum computing?
Model answer
A unitary operator is a reversible linear transformation that preserves the norm of quantum states and can be viewed as a rotation in Hilbert space.
Explanation
Unitary evolution describes the behavior of a closed quantum system.
- 57
What does the Hadamard operator do to the computational basis states?
Model answer
It maps ∣0⟩ to 2∣0⟩+∣1⟩ and ∣1⟩ to 2∣0⟩−∣1⟩.
Explanation
The Hadamard gate creates equal superpositions with different relative signs.
- 58
What happens when the Hadamard operator is applied twice?
Model answer
Applying it twice produces the identity transformation: H2=I.
Explanation
The Hadamard operator is its own inverse.
- 59
How does a CNOT gate operate?
Model answer
It leaves the control qubit unchanged and flips the target qubit if and only if the control qubit is ∣1⟩.
Explanation
For input control ∣1⟩ and target ∣0⟩, the output is control ∣1⟩ and target ∣1⟩.
- 60
What happens to a qubit during measurement?
Model answer
Measurement produces a classical bit and collapses the qubit to the corresponding basis state.
Explanation
Measurement is not unitary and therefore differs from reversible quantum evolution.
- 61
What are the measurement probabilities for the state α∣0⟩+β∣1⟩?
Model answer
The probability of measuring 0 is ∣α∣2, and the probability of measuring 1 is ∣β∣2.
Explanation
The squared magnitudes of the amplitudes determine measurement probabilities.
- 62
How does the state space change when qubits are combined?
Model answer
The composite state space is the tensor-product space of the component spaces; combining n qubits gives a space of dimension 2n.
Explanation
Adding one qubit doubles the dimension of the state space.
- 63
Why are large quantum systems difficult to simulate classically?
Model answer
Their state spaces grow exponentially with the number of qubits, so even a few hundred qubits require an impractically large number of dimensions to represent.
Explanation
The exponential state-space growth is a major obstacle for classical simulation.
- 64
What is a quantum circuit?
Model answer
A quantum circuit is a graph of wires connecting unitary gates and measurement gates.
Explanation
It is also called the gate model of quantum computation.
- 65
Why do quantum circuits not permit fan-out or copying of arbitrary states?
Model answer
The no-cloning theorem prohibits copying an unknown quantum state, so quantum circuits cannot freely duplicate a qubit.
Explanation
This is a fundamental difference between quantum circuits and ordinary Boolean circuits.
- 66
How can a Hadamard gate followed by a CNOT gate generate an entangled state?
Model answer
Starting with ∣00⟩, the Hadamard gate creates a superposition on the first qubit, and the CNOT gate produces 2∣00⟩+∣11⟩.
Explanation
The resulting Bell state cannot be written as a tensor product of two independent single-qubit states.
- 67
What is an entangled state?
Model answer
An entangled state is a composite quantum state that cannot be expressed as the tensor product of separate states for its component systems.
Explanation
Entanglement creates correlations that have no equivalent description as independent component states.
- 68
How does Shor's algorithm affect public-key encryption?
Model answer
Shor's algorithm can factor integers in polynomial time on a sufficiently large fault-tolerant quantum computer, threatening schemes such as RSA.
Explanation
RSA relies on the practical difficulty of factoring large integers on classical computers.
- 69
Why is RSA not currently defeated by Shor's algorithm in practice?
Model answer
Existing quantum computers do not have the scale and error correction needed to factor the large integers used by RSA.
Explanation
Current systems have roughly hundreds of qubits, while practical factoring would require vastly more, on the order of a million or more qubits.
- 70
What is the role of classical computation in Shor's algorithm?
Model answer
A classical computer performs preprocessing and postprocessing, while the quantum computer performs the period-finding portion of the computation.
Explanation
This illustrates that practical quantum systems are hybrid classical-quantum systems.
- 71
How are current quantum computers typically operated?
Model answer
A classical computer prepares inputs, controls the quantum processor, receives classical measurement results, and performs further computation.
Explanation
The quantum processor functions as a specialized component attached to a classical computer.
- 72
What restriction does the no-cloning theorem impose on quantum programming languages?
Model answer
A quantum programming language cannot provide an unrestricted operation that copies the value of an unknown quantum variable.
Explanation
Quantum compiler and language designs must respect the physical impossibility of cloning unknown states.
- 73
How can classical compiler techniques be applied to quantum programming languages?
Model answer
The same general compiler framework can be used, although quantum languages require operations and analyses that respect quantum constraints such as reversibility, measurement, and no-cloning.
Explanation
Quantum compilers can still use phases such as front ends, intermediate representations, optimization, and code generation.
- 74
Why are quantum computers expected to remain hybrid with classical computers for the foreseeable future?
Model answer
Classical computers are needed for control, preprocessing, measurement handling, and postprocessing, while quantum processors perform specialized quantum operations.
Explanation
Current quantum hardware is not a stand-alone replacement for classical computation.
- 75
Why is natural language an ambiguous basis for programming?
Model answer
Natural language is inherently ambiguous, so programmers and compilers could disagree about the intended meaning of a statement.
Explanation
Precise programming languages avoid this problem by defining unambiguous syntax and semantics.
- 76
How might machine learning and natural-language processing change compiler construction?
Model answer
They may allow spoken or written descriptions to be translated into program code or even complete compilers, although handling highly complex languages remains an open challenge.
Explanation
The approach is promising for simpler tasks but its ability to manage languages such as C++ is uncertain.
- 77
Why can repeating instruction in different formats help students learn computational thinking?
Model answer
Students have different learning preferences, so presenting an idea through text, visuals, games, or other methods may make it understandable to more learners.
Explanation
Learning is described as idiosyncratic, making varied explanations more effective than repeating the same presentation.
- 78
Why can computer games be useful for teaching computational thinking?
Model answer
Games can motivate students to learn by solving puzzles and experimenting with computational ideas in an engaging context.
Explanation
Some students respond more positively to interactive problem solving than to reading alone.
- 79
What programming strategy was recommended before writing software?
Model answer
Programmers should think through the problem before beginning to code.
Explanation
Planning first is presented as more effective than coding immediately and only later investigating why the program fails.

Ask anything
We've read this whole study set, so questions about it get the best answers.