Abstract Data Types Flashcards

1
Q

What is an abstract data type?

A

A definition of an organization of data and the operations we can perform on it

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

What is a Stack?

A

Stack:
- the only item you can see is the one at the top of the stack
- items are added to the top (push)
- you can only remove the top item (pop)
- optionally, you can define a peek method to look at the top
item without popping it
- there should also be an isEmpty method

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

What is a Queue?

A

Queue:
- add items to the end, remove items from the front
- add: Enqueue
- remove: Dequeue
- also has an optional peek method to see the top
- there should be an isEmpty method

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

What is Abstraction?

A

A strategy of ignoring the details: focus on what’s important in a context and ignore the details. It allows us to build systems out of complex components without getting lost.

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

What is a data abstraction?

A

A description of data storage according to the organization of the data, and the operations we can perform on it

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

How can you make a collection that can hold any type of data?

A

specify its type as Object. This means you can have any type stored in the collection, but you cannot use class-specific methods or operations on them, unless you cast them first

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

How can you safely cast an Object?

A

Use the instanceof operator, which gives a boolean result.

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

What are some applications of stacks?

A
  • to reverse items
  • to return path finding
  • the run-time stack
  • replacing recursion: by defining our own stack, we can
    simulate the use of the run-time stack in a recursive
    function
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What are some applications of queues?

A
  • when a program has to keep track of the work it needs
    to do, it can add the tasks to a queue and execute them
    in order
  • as a buffer: to store a sequence of data values that need
    to be processed
How well did you know this?
1
Not at all
2
3
4
5
Perfectly