Abstract Data Types Flashcards
What is an abstract data type?
A definition of an organization of data and the operations we can perform on it
What is a Stack?
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
What is a Queue?
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
What is Abstraction?
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.
What is a data abstraction?
A description of data storage according to the organization of the data, and the operations we can perform on it
How can you make a collection that can hold any type of data?
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 can you safely cast an Object?
Use the instanceof operator, which gives a boolean result.
What are some applications of stacks?
- 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
What are some applications of queues?
- 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