Binary Tree Types, Storage, and Traversal Techniques
Binary trees are hierarchical data structures with nodes containing up to two children. Common types include full binary trees where every node has either zero or two children, and complete binary trees where all levels are fully filled except possibly the last level.
Storage methods include linked storage using node references and sequential s ...
Posted on Tue, 22 Sep 2026 16:49:27 +0000 by homer.favenir
Minimum Distance to Deliver All Orders in a Tree Network
In a tree-structured neighborhood where the root represents the delivery station, a courier must visit all requested delivery nodes at least once. The goal is to compute, after each new delivery request, the shortest total distance required to deliver all orders so far—without needing to return to the root.
The key insight is that traversing al ...
Posted on Thu, 03 Sep 2026 16:29:39 +0000 by Fritz.fx
Binary Search Tree Operations: Lowest Common Ancestor, Insertion, and Deletion
Lowest Common Ancestor in a BST (LeetCode 235)
Given a BST and two nodes p and q, find their lowest common ancestor (LCA). The BST property allows an efficient traversal from root down: the LCA is the first node whose value lies between p->val and q->val (inclusive). Because the tree is ordered, moving left/right narrows down the range un ...
Posted on Wed, 26 Aug 2026 16:29:53 +0000 by Bogart
Binary Search Tree Operations: Trimming, Construction from Sorted Array, and Conversion to Greater Sum Tree
Trimming a Binary Search TreeGiven a Binary Search Tree (BST) and a valid range [low, high], the task is to trim the tree so that all node values fall within this inclusive range. The structure of the resulting tree should maintain BST properties.A common mistake is to simply return null when encountering a node outside the range:class Solution ...
Posted on Sat, 08 Aug 2026 16:33:29 +0000 by bsprogs
Algorithmic Solutions for Programming Contest Problems
Given an integer, determine if it is a palindrome.
The straightforward apprroach is to treat the input as a string and check if it reads the same forwards and backwards, which can be done in O(n) time where n is the length of the string.
A more efficient approach uses polynomial hashing with O(n) time complexity. We'll implement both forward an ...
Posted on Sun, 02 Aug 2026 16:19:16 +0000 by briglia23
LeetCode Daily Problems: Binary Tree Traversals and Construction
590. N-ary Tree Postorder Traversal
Approach: Right-to-left, then root-to-left. Use a stack with a visited set to track processed nodes.
class Node:
def __init__(self, val=None, children=None):
self.val = val
self.children = children
def postorder(root):
if not root:
return []
stack = [root]
result = []
...
Posted on Thu, 09 Jul 2026 16:38:30 +0000 by balacay
Identifying the Youngest Generation in a Family Tree
Given a family tree, the task is to output the smallest generation (youngest descendants) and list all members belonging to that generation.
Input Format:
The first line contains an integer N (1 ≤ N ≤ 100,000), the total number of family members, each assigned a unique ID from 1 to N. The second line provides N integers where the i-th integer r ...
Posted on Fri, 19 Jun 2026 17:57:12 +0000 by dm3
Minimizing Camera Placement on a Binary Tree Using Greedy DFS
Given a binary tree, we need to install cameras on its nodes. Each camera can monitor its parent, itself, and its immediate children. The goal is to determine the minimum number of cameras reuqired to cover the entire tree.
Problem Constraints
Number of nodes ranges from 1 to 1000.
Node values are irrelevant (typically 0).
Core Strategy
The o ...
Posted on Fri, 05 Jun 2026 17:26:40 +0000 by buroy
Reconstructing Binary Trees Using Dual Traversal Sequences
Core Traversal DefinitionsPre-order: Process the root node, traverse the left subtree, then traverse the right subtree.In-order: Traverse the left subtree, process the root node, then traverse the right subtree.Post-order: Traverse the left subtree, traverse the right subtree, then process the root node.Building from Pre-order and In-order Sequ ...
Posted on Sat, 30 May 2026 19:04:00 +0000 by php-coder
Core Data Structure Interview Questions and Algorithmic Solutions
Stack and Queue Fundamentals
Stacks and queues share the trait that insertion and deletion occur solely at their endpoints.
Typical stack storage models are sequential arrays and linked lists.
A stack exhibits last-in-first-out behavior.
Linked lists lack random access; elemants must be traversed sequentially.
Linked representation simplifies ...
Posted on Wed, 20 May 2026 05:56:52 +0000 by Adam W