In a complete binary tree with seven nodes, A is the set of the first three nodes visited by root-started BFS and B the set of the first three visited by root-started DFS. Find |A−B|.
BFS first visits the root and its two children. DFS first visits the root, one child and one grandchild on that child’s side. Thus the root and one child are shared, leaving the other root child in A but not B. Therefore |A−B|=1, independent of whether left or right is explored first.
More Trees and Binary Search Trees questions
GATE 2026 CS (CS1) Q33– The height of a binary tree is the number of edges in the longest path from the root to a…
GATE 2026 CS (CS1) Q40– Let P be the set of all integers from 1 to 15. Consider any order of insertion of the…
GATE 2026 CS (CS1) Q62– The following sequence corresponds to the preorder traversal of a binary search tree T:…
GATE 2026 CS (CS2) Q12– The set T represents various traversals over a binary tree. The set S represents the order…
GATE 2026 CS (CS2) Q49– Consider a binary search tree (BST) with n leaf nodes, where n>0. All keys are distinct…
GATE 2025 CS (CS1) Q26– Which of the following statement(s) is/are TRUE for any binary search tree (BST) having n…