Week 4 - From Problems to Programs Flashcards

1
Q

Basing your answer on Unit 1, what is the definition of abstraction as used in the context of computational thinking.

A

In computer science, an abstraction is basically a simplification, a model of some problem or object from which all but the relevant details have been eliminated.

  1. modelling
  2. encapsulation.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

ADTs

A

Abstract Data Types

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the three basic things that computers can do ?

A

Sequence - computer operate by executing instructions.
Iteration - repeating a sequence of instructions over and over.
Selection - computers are able to make a choice.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How would you define an ADT in a few words?

A

At the heart of data abstraction is the abstract data type (or ADT). 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. Programmers need to work these out themselves.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

How does the concept of an ADT relate to the idea of abstraction as encapsulation?

A

Also central to the idea of the ADT is the concept of encapsulation: the data handled by the data type is hidden inside it and can only be accessed through the operations it offers – its interface.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the relationship between an ADT and a data structure?

A

When an ADT is implemented, the result is a data structure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Recall the description of an ADT, thinking of it as a ‘Black Box’

A

Essentially, an ADT can be thought of as a black box with a set of operations defined on it. All we know about the box is its interface: what we can ask it to do for us and what it will give us in return. What goes on inside the box is not specified.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is meant by a linear data structure?

A

Stacks, queues, deques and lists are examples of data collections whose items are ordered depending on how they are added or removed. Once an item is added, it stays in that position relative to the other elements that came before and after it.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does LIFO stand for and what does it mean?

A

LIFO stands for ‘Last-in First-out’. 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the operations of the stack ADT, and what do they do?

A

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
size() - Returns the number of items in the stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do i iterate over a stack in python?

A

for x in range(aStack.size()):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a boundary value error?

A

is a name given to a bug that causes a program to branch into the wrong track or get stuck in an infinite loop. They are called this because the problems occur at the dividing lines between various conditions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

In a truth table when is P –> Q False?

A

the truth table for P –> Q is as follows
P Q P–>Q
F F T
F T T
T F F
T T T

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is P –> Q equivalent to?

A

(P ^ Q) v ¬P

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the inertial convention?

A

Aspects of an ADT’s state not referred to in the postcondition are unaffected by the operation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is an invariant?

A

An invariant o fan ADT A is a condition that must apply to every data structure that implements A, throughout its lifetime.

17
Q

Think of some property that will be true of BoundedStack at all times. (an invariant)

A

recall that the stack is limited in size, so we can state informally that the size of the stack will never be greater than its specified maximum size.

18
Q

What do Miller and Ranum mean by a basic unit of computation? What is their example of such a unit?

A

the example given is an assignment statement (=).

19
Q

What is Big-O notation?

A

The Big-O notation O(f(n)) expresses an approximation of the number of steps an algorithm will take when it executes to conclusion on an input of size n.
It tracks the growth of the dominant term in a function (cubic over quadratic for example)

20
Q

What are the best and worst case inputs for sequential and binary search of an ordered list?

A

best for sequential 1 worst n

best for ordered 1 worst logn