Test 3 Flashcards
is one of the most commonly used data structures in computer science
A stack
The stack’s storage policy is
Last-In, First Out , or LIFO
What methods can Stacks use?
boolean empty() E peek() E pop() E push( E obj )
a string that reads identically in either direction, letter by letter (ignoring case)
Palindrome
When analyzing arithmetic expressions, it is important to determine whether an expression is balanced with respect to parentheses.
The problem is further complicated if braces or brackets are used in conjunction with parentheses
The solution is to use:
stacks!
PITFALL of stacks: attempting to pop an empty stack will:
throw an Emptystackexception . You can guard against this by either testing for an empty stack or catching the exception
Stacks are so common in computing , that Java included. A Stack class in its early versions:
import java.util.Stack; Stack myStack = new Stack();
A queue differs from a stack in one important way:
a queue a is FIFO list - First-In, First-Out
Operating systems use queues to:
keep track of tasks waiting for a scarce resource
ensure that the tasks are carried out in FIFO order
Queue uses methods:
boolean offer(E item) E remove() E peek() E element()
The __________ class provides methods for inserting and removing elements at either end of a linked list, which means all _______ methods can be implemented easily
Linkedlist
Queue
can be used to generate simple solutions to problems that are difficult to solve by other means
Recursion
reduces a problem into one or more simpler versions of itself
Recursion
I’m recursive strategy there must be _______________ (the _________), for a small value of n, that can be solved directly
at least one case
base case
In recursive strategy a problem of a given size n can be reduced to smaller versions of the same problem (____________)
recursive case(s)