InterviewStack.io LogoInterviewStack.io

Linked Lists and Trees Questions

Dynamic and pointer based data structures including linked lists and tree structures commonly tested in interviews. For linked lists cover node based representation, traversal, insertion at head and tail, deletion, searching, reversing a list, detecting cycles, and tradeoffs versus array based lists. For trees cover basic concepts such as binary trees and binary search trees, tree node representation, insertion and deletion in search trees, recursion patterns, and traversal algorithms including depth first search with in order pre order and post order variants and breadth first search. Also include problem solving patterns such as recursion and iterative stack or queue based approaches, analysis of time and space complexity in plain terms, and common interview tasks such as lowest common ancestor, tree balancing awareness, and converting between representations. Practice includes implementing algorithms, writing traversal routines, and reasoning about correctness and performance.

HardTechnical
0 practiced
Implement Morris inorder traversal in Python to traverse a binary tree with O(1) extra space by temporarily modifying tree links and restoring them after traversal. Provide a code sketch, show when and how you create temporary threads to predecessors, and discuss correctness and limitations when modifying input structure is not allowed.
EasyTechnical
0 practiced
Implement level_order(root) in Python to perform breadth first traversal of a binary tree and return a list of lists containing node values for each depth level. Use an explicit queue and show sample tree input and output. Explain space complexity in terms of maximum width and tradeoffs when working with very wide trees in ML preprocessing.
MediumTechnical
0 practiced
Implement serialize(root) and deserialize(data) for a binary tree in Python suitable for network transfer in an AI pipeline. Choose an efficient representation such as pre-order with null markers or level order and discuss tradeoffs in compactness, streaming and GPU friendliness. Include handling of node payloads like floats or small tensors.
EasyTechnical
0 practiced
Write two functions in Python to traverse a singly linked list and yield node values: one iterative generator function list_iter(head) and one recursive function list_recursive(head) that returns a list of values. Use Node class definition class Node: def __init__(self, val, next=None): self.val = val; self.next = next. Include handling of empty list and demonstrate with sample list 1->2->3. Discuss time and space complexity of both versions.
HardTechnical
0 practiced
You must serialize computation graphs representing AI model layers into a compact on-device format with quantization. Describe an algorithm that prunes constant subtrees, folds constants, encodes opcodes and operand indices compactly and reconstructs runtime graph with minimal memory and acceptable numeric stability. Discuss versioning and operator portability.

Unlock Full Question Bank

Get access to hundreds of Linked Lists and Trees interview questions and detailed answers.

Sign in to Continue

Join thousands of developers preparing for their dream job.