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.

EasyTechnical
95 practiced
Given two sorted singly linked lists, implement merge_two_sorted_lists(l1, l2) in Python that returns a merged sorted list by reusing node pointers. Implement iteratively in O(n + m) time and O(1) extra space. Show example l1 = 1->3->5 and l2 = 2->4 and resulting list.
EasyTechnical
88 practiced
Implement reverse_list_recursive(head) in Python to reverse a singly linked list using recursion. Explain base case and how recursion rewires pointers during unwinding. Discuss recursion depth limits, stack usage and space complexity compared to iterative solution and how to mitigate stack overflow for long lists.
EasyTechnical
78 practiced
Implement two methods for a singly linked list in Python: insert_head(value) and insert_tail(value). Provide a LinkedList class that maintains head and optionally tail pointer. Explain time complexity for each operation and show how maintaining a tail pointer enables O(1) tail insertion. Include handling of empty list and edge cases.
EasyTechnical
69 practiced
Implement insert_bst(root, value) iteratively in Python to insert a value into a binary search tree and return the updated root. Explain time complexity O(h) where h is height, and show behavior for empty tree, duplicates and deep unbalanced trees.
HardTechnical
73 practiced
Implement conversion functions between a general rooted tree where each node has a list of children and its left-child right-sibling binary tree representation. Provide convert_to_lcrs(root) and convert_from_lcrs(root) in Python. Discuss advantages of this representation for storage, recursion and applications in NLP parse trees or XML processing.

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.