Exam Flashcards

1
Q

Definition of Stack?

A

Stack is a linear list in which insertions and deletions are allowed only at one end, called top

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

Stack follows a LIFO, true or false

A

True

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

Stack operations name and describe all stack operations:

A

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

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

Definition of Queues:

A

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.

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

Queue follows a First-in-first-out (FIFO), true or false?

A

True

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

Name and describe queue operations:

A

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

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

What are two types of applications of Queues?

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How is a graph defined?

What is a graph?

A

A graph is defined as: G=(V,E)

A graph is a set of vertices connected by edges.

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

Define terms related to graphs:

A

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

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

Identify and describe the four types of graphs in data structures:

A

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.

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

Describe a spanning tree and a minimum spanning tree:

A

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.

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

What is a heap? And identify and describe the two types of heaps.

A

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.

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

Define an AVL tree.

A

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.

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

An AVL tree is said to be balanced if balance factor of each node is between -1 to 1, true or false?

A

True

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

What is the calculation for balance factor?

A

Balance factor (k) = height (left(k)) - height (right(k))

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

Identify 5 applications of trees:

A
  • Manipulate hierarchical data
  • Make information easy to search
  • Manipulate sorted lists of data
  • Router algorithms
  • Form of a multi-stage decision-making
17
Q

Identify and describe the four types of tree traversals.

A

Inorder (Left,Root,Right) - Inorder traversal will cause all nodes to be visited in ascending order.

Preorder (Root, Left Right) - Preorder traversal will visit the node sub tree first before going on to the left sub tree and the right sub-tree respectively.

Postorder (Left, Right, Root) - Postorder traversal firstly visits the left sub tree, then the right sub tree and lastly the root.

Breadth First or Level Order - A tree has different levels.

18
Q

Define a hash function and a hash table.

A

A hash function is a function that converts a given big phone number to a small practical integer value.

A hash table is an array that stores pointers to records corresponding to a given phone number.

19
Q

Identify and describe two ways to handle collisions.

A

Separate chaining - The idea is to make each cell of the hash table point to a linked lit of records that have the same has function value.

Open addressing - In open addressing all the elements are stored in the hash table itself, each table entry contains either a record or NIL.

20
Q

Identify 3 advantages and disadvantages of Separate chaining.

A

Advantages:

  • Simple to implement
  • Hash table never fills up
  • Less sensitive to the hash function or load factors

Disadvantages:

  • Cache performance of chaining is not good
  • Wastage of space
  • Uses extra space of links
21
Q

Identify 3 ways in which open addressing can be performed and compare them.

A

Linear probing - has the best cache performance but suffers from clustering. Yet it is easy to compute.

Quadratic probing - lies between the two terms of cache performance and clustering.

Double hashing - has poor cache performance but no clustering. Also requires more computation time.

22
Q

What is a Disjoint set.

A

A disjoint set is a collection of distinct dynamic sets {S1, S2…SK}. Each set is identified by a member of the set, called a representative.

23
Q

Identify and describe the 3 disjoint set operations.

A

MakeSet (x) - creates a new set where x is its only element and is therefore a representative of that set.

Union (x, y) - combines the two sets containing x and y into one new set.

Find (x) - returns the representative of the set containing x

24
Q

What is a disjoint set forest?

A

A disjoint set forest is a collection of trees. Each element points to its parent and the root of each tree is the representative of the set.

25
Q

What is union by rank?

A

Union by rank is when each node is associated with a rank. The rank is the approximate depth of the tree.

26
Q

What is path compression?

A

Path compression means that when we find x, we make all nodes encountered point directly to the representative element for x. Initially all elements have Rank 0.