Part 2 Flashcards
What is an abstract data type?
A type that can be specified without using any programming language
What are the elements of an abstract data type?
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
Why are ADTs beneficial?
They allow an application program to use the type without knowing how it is implemented.
To guarantee that an ADT will work correctly, the objects of the ADT must only be accessed using the _____________
Primitive operations
What are the primitive operations of a stack?
push
pop
top
isempty
createstack
How are data items in a stack accessed?
From the top only
What does the push operation do to a stack?
Adds an item to the top of the stack
What does the pop operation do to a stack?
Removes the top item
What does the top operation do to a stack?
Returns the top item of the stack (aka peek)
What does the isempty operation do to a stack?
Deduces whether the stack contains any items or not
What does the createstack operation do to a stack?
Creates a new stack object with no items
What are the 4 stack axioms?
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
The stack axiom
isempty(createstack())
has the value
true
The stack axiom
isempty(push(n, s))
has the value
false
The stack axiom
top(push(n, s))
has the value
n