Exam Flashcards
Definition of Stack?
Stack is a linear list in which insertions and deletions are allowed only at one end, called top
Stack follows a LIFO, true or false
True
Stack operations name and describe all stack operations:
stack() - creates a new empty stack
push(item) - adds a new item to top of stack
pop() - removes an item from top of stack
peek() - returns the top item from the stack but does not remove it
isEmpty() - checks to see if stack is empty or not
size() - returns number of items in stack
Definition of Queues:
Queue is a linear list in which elements can be inserted only at one end called rear and deleted only at the other end called front.
Queue follows a First-in-first-out (FIFO), true or false?
True
Name and describe queue operations:
queue() - creates a new empty queue
enqueue() - adds a new item to the rear of the queue
dequeue() - removes the front item from the queue
isEmpty() - checks whether queue is empty
size() - returns number of items in queue
What are two types of applications of Queues?
- Queues are widely used as waiting lists for a single shared resource like a printer
- Queues are used as a buffer in MP3 media players
How is a graph defined?
What is a graph?
A graph is defined as: G=(V,E)
A graph is a set of vertices connected by edges.
Define terms related to graphs:
Vertices - collections of data items (nodes)
Edges - Lines that connect one vertex to another
Adjacent - When two vertices are connected by an edge
Path - The structure of vertices
Connected graph - When there is a path between a pair of vertices
Identify and describe the four types of graphs in data structures:
Directed graphs - A directed graph is when edges have direction from one vertex to another.
Undirected graphs - An directed graph is when edges have no direction from one vertex to another.
Weighted graphs - A weighted graph shows the length of the edges.
Unweighted graphs - An unweighted graph does not show the length of the edges.
Describe a spanning tree and a minimum spanning tree:
Spanning tree - A spanning tree is an undirected graph where all edges are connected to vertices.
Minimum spanning tree - A minimum spanning tree is an undirected weighted graph that has a weight related to each edge to find a spanning tree that has a minimum total weight.
What is a heap? And identify and describe the two types of heaps.
A heap is a special tree-based data structure in which the tree is a complete binary tree.
Max heap - In a max-heap the key present at the root node must be greatest amongst all of its children.
Min heap - In a min-heap the key present at the root node must be smaller than all of its children.
Define an AVL tree.
An AVL tree can be defined as a height balanced binary search tree in which each node is associated with a balance factor which is calculated by subtracting the height of the left sub-tree by the height of the right sub-tree.
An AVL tree is said to be balanced if balance factor of each node is between -1 to 1, true or false?
True
What is the calculation for balance factor?
Balance factor (k) = height (left(k)) - height (right(k))