Trees & Graphs Basics Questions
Understand binary trees, binary search trees, and basic graph concepts. Know tree traversal methods: in-order, pre-order, post-order, and level-order (BFS). Practice DFS and BFS implementations. Know the difference between directed and undirected graphs. Solve medium-difficulty tree and graph problems.
MediumTechnical
20 practiced
Implement iterative inorder traversal of a binary tree in Python using an explicit stack (no recursion). Explain time and space complexity and compare to recursive approach. Optionally describe Morris inorder traversal for O(1) space and mention when pointer mutation is acceptable.
EasyTechnical
22 practiced
Given a graph represented as an adjacency list (a dict mapping node -> list of neighbors), implement a recursive depth-first search in Python that returns the set or list of nodes reachable from a given source. Carefully handle the visited set to avoid infinite recursion and mention complexity.
EasyTechnical
21 practiced
Define precisely: leaf node, tree height, and node depth. Provide small examples (balanced binary tree and a skewed tree), compute number of nodes as a function of height in each case, and explain the implications for recursion depth and stack usage in tree algorithms.
EasyTechnical
33 practiced
Implement a function search_bst(root, target) in Python that searches for target in a binary search tree and returns the node (or None). Assume TreeNode(val, left, right). Aim for O(h) average-case time and O(1) extra space. Explain how behavior changes for skewed trees and for balanced trees.
HardTechnical
26 practiced
Write a Python function is_isomorphic(t1, t2) that checks whether two binary trees are isomorphic in structure (ignoring node values). Then implement is_mirror_isomorphic(t1, t2) that checks whether t2 is the mirror image of t1. Analyze time and space complexity and discuss edge cases.
Unlock Full Question Bank
Get access to hundreds of Trees & Graphs Basics interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.