Topic 3 - Stack ADT Flashcards

1
Q

Give examples of where LIFO is useful.

A

1) Backtracking in puzzles and games.
2) Browsers - to keep track of pages visited in a browser tab
3) Parenthesis - first closed parenthesis closes the previous open parenthesis
4) Undo operations - keeps track of most recent operations
5) Markup Languages - HMTL, XML, have formatting information (tags) as well as raw text - checks for matching tags
6) Stack calculators - to convert an infix expression to postfix, to make evaluation easier
7) Compilers - convert infix expressions to postfix, to make translation of high-level language such as Java or C to a lower level language easier
8) Call Stack (Runtime Stack) - stores information about the active subroutines of a computer program, used by runtime system when methods are invoked, for a method call / return processing

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

Every collection has a ___?

A

A set of operations that define how we interact with it, for example:

  • add elements
  • remove elements
  • determine if the collection is empty
  • determine the collection’s size
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Define all the Stack Operations

A

Push: add an element at the top of the stack
Pop: remove the element at the top of the stack
Peek: examine the element at the top of the stack
isEmpty: determines whether the stack is empty
size: determines the number of elements in the stack
toString: returns a string representation of the stack

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

Define: Stack Abstract Data Type (Stack ADT)

A

it is a collection of data, together with the operations on that data - we just discussed the operations in previous slides

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

Java has a programming construct called an Interface that___?

A

that we use to formally define what the operations on a collection are in Java

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

Define Java Interface:

A
  • A list of abstract methods and constant
  • must be public
  • constants must be declared as final static
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Define Abstract Method

A

A method that does not have an implementation ie. it just consists of the header of the method. ex:
return type method name (parameter list)

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

Define: Infix Notation

A

Operators are between operands: 3+4*2

Parantheses force precedence: (3+4)*2

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

Define: postfix epxression

A

The operator comes after its two operands

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

Does an application program need to know how the Stack collection is implemented?

A

No - we are using the Stack collection for its functionality (what); how it is implemented is not relevant

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

The class ArrayStack implements______?

A
the StackADT interface:
public class ArrayStack implements StackADT
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

constructors are not specified in the Java interface for the StackADT (why not?)

A

BecauseThe elements of the stack array are of generic type T

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

pop() does what?

A

Returns value of and deletes top element

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

Can we instantiate anything of a generic type? Ie. create a constructor that creates an instance of a generic type? If, yes, explain. If no, then what do we do instead.

A

No.

We need to instantiate an element of type Object and cast it into the type T

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

In a Java interface, can we have attributes? Constants? How do you declare each if yes.

A

No. Yes. Constants must be declared as final static

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