Unit 2 Flashcards
Give a brief definition of ‘abstraction’ as it is used in the context of computational thinking.
an abstraction is basically a simplification, a model of some problem or object from which all but the relevant details have been eliminated.
two kinds of abstraction:
- abstraction as modelling some part of reality, ignoring irrelevant details
- abstraction as encapsulation, where the inner mechanisms of a model are hidden from users.
Sequence
computers operate by executing instructions, such as assigning a value to a variable or evaluating an expression a sequence is a list of one or more instructions executed in order.
Iteration
repetition or looping, in other words repeating a sequence of instructions over and over. For instance, the Python while loop while a
Selection
computers are capable of is making a choice: they can perform a test of some kind and then branch into executing one sequence or another, depending on the evaluation of at least one Boolean expression.
How would you define an ADT in a few words?
an ADT is a description of a data structure purely in terms of the operations that can be carried out on it. the ADT offers no account of how these operations are programmed, how the data is stored, the programming language used, or any other specific details.
How does the concept of an ADT relate to the idea of abstraction as encapsulation?
with encapsulation the data handled by the data type is hidden inside it and can only be accessed through the operations it offers – its interface.
What is the relationship between an ADT and a data structure?
when an ADT is implemented, the result is a data structure.
Linear data structure
the stack is an example of a linear structure, in which items persist in the same position, relative to other elements.
all linear structures can be thought of as having two ends; in the case of a list, the ‘beginning’ and the ‘end’; in the case of a stack, the ‘top’ and the ‘base’.
What does LIFO stand for and what does it mean?
stacks are LIFO (last-in first-out) structures.
items added to a stack last come out first so, an item’s position in the stack is related to the order in which it was added.
What are the operations of the Stack ADT, and what do they do?
Stack() Constructor; creates an empty stack
push(item) Adds item to the top of the stack
pop() Removes and returns the item at the top of the stack
peek() Returns the item at the top of the stack
isEmpty() Returns True if the stack is empty; False otherwise
size() Returns the number of items on the stack
What is a parenthesised expression, and what does it mean for it to be balanced or unbalanced?
to be interpreted properly (‘parsed’), such expressions must balance, so that opening parentheses match closing parentheses correctly.
Simple mathematical notation to denote a sequence
S = (s1, s2, s3, …, sn) S denotes the sequence s1, s2, s3, …, sn denote the items in the sequence, such that s1 is the first item in the sequence, s2 the second, etc. sn means the last item in the sequence.
What is the naive way of searching the dictionary for a word?
the strategy is to start with the first word in the dictionary and then plough through each word, one by one, either until the target word is located or until the end of the dictionary
Four logical connectives
∧ and
∨ or
¬ not
→ if … then
What benefits might the statement of pre- and postconditions have?
clarity - if the pre- and postconditions are clearly documented, then it is clear where the obligations between client and supplier lie.
non-redundancy - with clear statements of responsibility, programmers can avoid making unnecessary checks.
simplicity - with less redundancy, code becomes simpler, and therefore easier to read and debug.