Unit summary

  • A graph is a set of vertices joined by edges, and may be directed, undirected or weighted.
  • Graphs are stored as adjacency matrices or adjacency lists, and traversed by BFS (queue) or DFS (stack).
  • A tree is a connected acyclic graph with a root; a binary tree has at most two children per node.
  • Binary trees are traversed in preorder, inorder and postorder.
  • A binary search tree keeps smaller keys on the left and larger on the right, with O(h) operations.
  • AVL trees keep balance factors in −1 to +1 by rotations, giving O(log n) operations.

Glossary

Term Meaning
Adjacency list A list of neighbours for each vertex.
Adjacency matrix An n × n matrix of edges.
AVL tree A height-balanced BST.
Balance factor Height of left minus height of right subtree.
BFS Breadth-first search using a queue.
Binary search tree An ordered binary tree.
Binary tree A tree with at most two children per node.
Cycle A path that returns to its start.
Degree The number of edges at a vertex.
DFS Depth-first search using a stack.
Edge A link between two vertices.
Graph Vertices joined by edges.
Height The largest level of a node in a tree.
Inorder Left, root, right traversal.
Inorder successor The smallest key in the right subtree.
Leaf A node with no children.
Path A sequence of vertices joined by edges.
Rotation A pointer change that rebalances a tree.
Tree A connected acyclic graph with a root.
Vertex A node of a graph.

Question bank

Short Answer Questions (2 marks each)

  1. Define a graph.
  2. What is the degree of a vertex?
  3. What is an adjacency list?
  4. Distinguish BFS and DFS.
  5. Define a binary tree.
  6. What is a leaf node?
  7. Write the inorder traversal rule.
  8. Define a binary search tree.
  9. What is an AVL tree?
  10. What is a balance factor?

Medium Answer Questions (5 marks each)

  1. Explain the representation of graphs.
  2. Explain BFS with an example.
  3. Explain DFS with an example.
  4. Explain the traversals of a binary tree with an example.
  5. Explain deletion in a binary search tree.
  6. Explain the rotations of an AVL tree.

Long Answer Questions (15 marks each)

  1. Explain graphs, their terminology and representation, and their traversal by BFS and DFS.
  2. Explain trees and binary trees, with their terminology and representation.
  3. Explain the traversals of binary trees and the operations of a binary search tree.
  4. Explain AVL trees, with insertion and deletion and the four rotations.

Sources

  • Official BCA syllabus Data Structures, course code 25BCA402DS02, Unit IV