Algorithmic Analysis of CSP-S Mock Contest: Graphs, Number Theory, and Data Structures
Competition Overview
This mock contest featured relatively weak test data, allowing suboptimal solutions to score significantly higher than expected (often 50+ points above theoretical estimates). The official solutions sometimes relied heavily on pattern recognition and handling specific subtasks rather than pure algorithmic elegance. This hig ...
Posted on Sat, 03 Oct 2026 16:33:46 +0000 by sidney
Classic Binary Tree Algorithms and Solutions
Non-Recursive Implementation of Preorder, Inorder, and Postorder Traversals
The three traversal methods—preorder, inorder, and postorder—form the foundation for all tree-related problems.
Preorder Traversal
Algorithm:
Create an empty stack and push the root node onto it.
While the stack is not empty:
Pop a node from the stack and process it ( ...
Posted on Tue, 22 Sep 2026 16:22:07 +0000 by mbaroz
Solving Binary Tree Problems: Construction, Merging, Searching, and Validation
Constructing Maximum Binary Tree (Problem 654)
This problem requires building a binary tree from an integer array where the maximum element becomes the root, and the process repeats recursively for left and right subarrays. The solution involves identifying the peak value within a specified range and recursively constructing subtrees for the re ...
Posted on Tue, 01 Sep 2026 16:07:24 +0000 by glossary
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
Understanding the Execution Order of Logic in Binary Tree Recursion
The placement of code within a recursive function significantly impacts how the program interatcs with the state of a binary tree. This is particularly evident when using external or persistent variables to track the relationship between different nodes during traversal.
Impact of Early Assignment
When calculating the minimum absolute differenc ...
Posted on Sun, 07 Jun 2026 18:17:22 +0000 by djsl
Recovering and Validating Binary Search Trees
Recovering a Swapped Binary Search Tree
A binary search tree (BST) has two of its nodes swapped by mistake. The task is to restore the tree to its correct BST form without altering its structure. The challenge is to achieve this with constant space complexity (O(1) space), avoiding the use of a full in-order traversal list.
Approach
The key obs ...
Posted on Thu, 14 May 2026 13:38:34 +0000 by John_S