Algorithms for the Main Data Structures Flashcards
(42 cards)
Examples of data structures.
-Stacks -Queues
-Linked Lists -Trees
What are the traversal types of trees?
Depth First (post-order)
Breadth first
What data structure is a stack an example of?
First in, Last out (FILO)
What is the single pointer that keeps track of the top of the stack called?
Top pointer
What are top pointers initialized at?
-1
What is the 1st position in the stack
0
PsuedoCode to check size of stack
size()
PsuedoCode to check if the stack is empty?
isEmpty()
PsuedoCode to return the top element in the stack (but not remove it)
peek()
PsuedoCode to add to stack
push(element)
PsuedoCode to remove the top element from the stack and return the removed element
pop()
Example of PsuedoCode size() in a stack
size()
return top +1
Example of PsuedoCode isEmpty() in a stack
isEmpty()
If top < 0:
return True
else:
return False
endif
Example of PsuedoCode peek() in a stack
peek()
if isEmpty():
return error
else:
return A[top]
endif
Example of PsuedoCode push(element) in a stack
push(element)
top += 1
A[top] = element
Example of PsuedoCode pop() in a stack
pop()
if isEmpty():
return error
else:
toRemove = A[top]
A[top] = “”
top -= 1
return toReturn
endif
What type of data structure are queues
First in, First out (FIFO)
What are stacks and queues represented as?
Arrays
What are the pointers called in a queue?
Front and back pointer
What does the front pointer hold?
The position of the first element
What does the back pointer store?
The next available space
PsuedoCode to check size of a queue
size()
PsuedoCode to check if a queue is empty
isEmpty()
PsuedoCode to check the front element of a queue (but not remove)
peek()