Data Structures and Algorithms Mid-Term Study Flashcards
The Queue ADT
-stores arbitrary objects- insertions and deletions follow the first-in, first-out scheme-insertions at the rear,removals at the front
enqueue()
inserts an element at the end of the queue
dequeue()
removes and returns the element at the front of the queue
object first() (Queue)
returns the element at the front without removing it
integer size() (Queue)
returns the number of elements stored
boolean isEmpty() (Queue)
indicates whether no elements are stored
Queue boundary cases
Attempting the execution of deqeueue() or first() on an empty queue returns null
Direct Applications for a Queue
- Waiting lists, bureaucracy- Access to shared resources- Multiprogramming
Indirect Applications for a Queue
- Auxiliary data structure for algoritms- Component of other data structures
Queue is limited to the __________ of the array.
size
Queue Performance runs in _________.
O(1)
enqueue() corresponds to what java.util.Queue?
add(e)offer(e)
dequeue() corresponds to what java.util.Queue?
remove()poll()
In a queue, first() corresponds to what java.util.Queue?
element()peek()
In a queue, size() corresponds to what java.util.Queue?
size()
In a queue, isEmpty() corresponds to what java.util.Queue?
isEmpty()
How do you impliment a round robin scheduler using a queue?
repeat the following steps:- e = Q.dequeue()- Service element e- Q.enqueue(e)
What method does a circular queue have that other queues don’t?
rotate()
List the methods of the Double Ended Queue.
enqueueLast(object)enqueueFirst(object)dequeueFirst()dequeueLast()
What does ADT stand for?
Abstract Data Type
What’s an example of an ADT?
A simple stock trading system.order buy(stock, shares, price)order sell(stock, shares, price)void cancel(order)
Stack
Follows Last in first out scheme.Think of the pez despenser!push(object)object pop()top()size()isEmpty()
What built in utility does java use for the stack?
java.util.Stack
Can the operations pop and top be performed even though the stack is empty?
Yes
Direct Applications of using the stack.
- Page-visited history in a web browser- undo sequence in a text editor- Chain of method calls in the Java Virtual Machine
Indirect applications of the stack.
Auxiliary data structure for algorithmsComponent of other data structures
Operator precedence
- has precedence over +/-
Recursive definition
f(n) = { 1 if n = 0n-f(n-1) else
factorial function
n! = 123……..(n-1)n
Base Cases
Values of the input variables for which we perform no recursive calls
Recursive Calls
- calls to the current method- Each recursive call should be defined so that it makes progress towards a base case.
Application on using Recursion
Drawing ticks on an English Ruler
reversing an array
reverseArray(A, i, j)if (i < j){Swap A[i] and A[j]reverseArray(A, i+1, j-1)}return
Recursive power function
p(x,n) = { 1 if n=0x*p(x,n-1) else
What is an Algorithm?
A step by step process that creates a result in a finite amount of time
The Seven Important Functions
Constant = 1Logarithmic = log nLinear = nN-Log-N = n log nQuadratic = n^2Cubic = n^3Exponential = 2^n
Big-Oh Notation
Characterizes functions according to their growth rates: different functions with the same growth rate may be represented using the same O notation.