Part 2 Flashcards

(35 cards)

1
Q

What is an abstract data type?

A

A type that can be specified without using any programming language

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

What are the elements of an abstract data type?

A

The name of the type

The name of the primitive operations, their arguments and result types

The semantic of the operations; a description of how they behave

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

Why are ADTs beneficial?

A

They allow an application program to use the type without knowing how it is implemented.

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

To guarantee that an ADT will work correctly, the objects of the ADT must only be accessed using the _____________

A

Primitive operations

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

What are the primitive operations of a stack?

A

push

pop

top

isempty

createstack

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

How are data items in a stack accessed?

A

From the top only

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

What does the push operation do to a stack?

A

Adds an item to the top of the stack

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

What does the pop operation do to a stack?

A

Removes the top item

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

What does the top operation do to a stack?

A

Returns the top item of the stack (aka peek)

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

What does the isempty operation do to a stack?

A

Deduces whether the stack contains any items or not

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

What does the createstack operation do to a stack?

A

Creates a new stack object with no items

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

What are the 4 stack axioms?

A

isempty(createstack()) = true

isempty(push(n, s)) = false

top(push(n, s)) = n

pop(push(n, s)) = s

Where s is the stack before the operation is applied, and n is the item being applied to the stack

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

The stack axiom

isempty(createstack())

has the value

A

true

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

The stack axiom

isempty(push(n, s))

has the value

A

false

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

The stack axiom

top(push(n, s))

has the value

A

n

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

The stack axiom

pop(push(n, s))

has the value

17
Q

How does one prevent having to frequently shift elements in an array-based stack?

A

Use a large array with a cursor that indicates the start position of the stack

18
Q

What is the advantage of using an ArrayList implementation of a stack?

A

Don’t have to manually keep track of cursors etc.

Arraylist handles it all for us

19
Q

What is the disadvantage of using an arraylist implementation of stack, compared with an array implementation?

A

Possibly less efficient than keeping track of the cursor ourselves.

20
Q

What is the advantage of using a linked-list stack?

A

Don’t have to worry about array sizes

21
Q

What is the disadvantage of using a linked list to store a stack?

A

Greater memory consumption than array

22
Q

What is a queue?

A

Structure where items are added at the back and removed from the front

23
Q

What are the primitive operations of the queue?

A

add

removefront

front

isempty

24
Q

What does the add operation do in a queue?

A

adds an item to the back of the queue

25
What does the removefront operation do in a queue?
remove the front item
26
what does the front operation do in a queue?
returns the front item without removing it
27
What are the axioms for the Queue adt?
isempty(createqueue()) = true isempty(add(n, q)) = false front(add(n, q)) = n, if q is empty front(add(n, q)) = front(q), if q is not empty removefront(add(n, q)) = q, if q is empty removefront(add(n, q)) = add(n, removefront(q)), if q is not empty
28
The queue axiom isempty(createqueue()) has the value
true
29
The queue axiom isempty(add(n, q)) has the value
false
30
The queue axiom front(add(n, q)) has the value
n, if q is empty
31
The queue axiom front(add(n, q)) has the value
front(q), if q is not empty
32
The queue axiom removefront(add(n, q)) has the value
q, if q is empty
33
The queue axiom removefront(add(n, q)) has value
add(n, removefront(q)), if q is not empty
34
Using an array implementation of queues will require ___ cursors
Two
35
With a linkedlist implementation of a queue, a reference to _________ will need to be stored in addition to the reference to the \_\_\_\_\_\_\_\_\_\_\_\_
back item front item