Search Algorithms in Problem Solving
Definition
Search algorithms systematically explore state spaces to find optimal solutions or count valid configurations through exhaustive enumeration. This approach leverages understanding of state transitions to navigate possible states.
Search Algorithm Applications
When explicit enumeration becomes infeasible (e.g., permutations for n=100 ...
Posted on Thu, 02 Jul 2026 17:04:03 +0000 by littlejones
Graph Traversal: Searching References
Problem Description
Little K enjoys browsing Luogu blog articles for knowledge. Each article may have several (or none) reference links pointing to other blog articels. Little K is very curious: if he reads an article, he will certainly read its references (unless he has already read that reference).
Assume there are n (n ≤ 10^5) articles on Lu ...
Posted on Wed, 01 Jul 2026 16:36:22 +0000 by coder4Ever
Implementing Inorder Traversal for Binary Trees
To retrieve node values from a binary tree in ascending order (for a BST) or the standard left-root-right sequence, a recursive approach works cleanly. The traversal explores the left subtreee first, records the current node, then visits the right subtree. Below are Python implementations that illustrate this technique.
class TreeNode:
def ...
Posted on Mon, 29 Jun 2026 17:39:32 +0000 by patrikG
Understanding Simulation, DFS/BFS, Dynamic Programming, and Block Decomposition for Competitive Programming
Simulation problems, often labeled as "warm-up" or "signature" tasks in contests, require translating problem statements directly into code without relying on predefined algorithms. While they appear simple, their difficulty lies in accurately interpreting edge cases and constraints. A single oversight in boundary checks or ...
Posted on Sun, 14 Jun 2026 16:51:10 +0000 by ldougherty
Binary Tree Algorithms: Bottom-Left Value, Path Sum Variants, and Tree Construction from Traversals
Finding the Bottom-Left Node Value
Given the root of a binary tree, return the value of the leftmost node at the deepest level.
Breadth-First Search (Iterative)
A level-order traversal naturally visits nodes layer by layer. The first node encountered in the final level is the answer.
#include <queue>
int findBottomLeftValue(TreeNode* roo ...
Posted on Sat, 13 Jun 2026 17:35:17 +0000 by eideticmnemonic
Solving Problems ABC 269 (A-G)
A: Basic Arithmetic and Output
Given integers a, b, c, d, compute (a + b) * (c - d) and output the result followed by the string "Takahashi".
int a = input(), b = input(), c = input(), d = input();
cout << (a + b) * (c - d) << endl;
cout << "Takahashi" << endl;
Time complexity: O(1)
B: Finding Corne ...
Posted on Wed, 10 Jun 2026 16:36:46 +0000 by Elephant
Computing Minimum Knight Moves on a Chessboard Using BFS and DFS
Given an n × m chessboard (with 1 < n, m ≤ 400) and the starting position of a knight, determine the minimum number of moves required for the knight to reach every other square. If a square is unreachable, output -1.
Input Format
A single line containing four integers: n, m, start_x, and start_y.
Output Format
Print an n × m matrix. Each val ...
Posted on Tue, 09 Jun 2026 17:50:23 +0000 by fourteen00
Solving AtCoder Beginner Contest 367 Problems with C++
A - Shout Everyday
This problem involves checking if a specific hour falls within a given time range spanning across midnight. We handle the wrap-around by adjusting the end time.
#include <cstdio>
int main() {
int target, start, end;
scanf("%d %d %d", &target, &start, &end);
if (end <= start) en ...
Posted on Tue, 09 Jun 2026 16:32:03 +0000 by $var
Solution: COCI 2015-2016 #6 Problem SAN
Problem Analysis: Digit DP
Before explaining the correct solution, let's first discuss the partial score approach.
For 50% of the data, where (1 \le L, R \le 10^6), a brute force simulation might be feasible. However, since we don't know the exact positions where each number appears, directly simulating with a 2D array is likely to cause memory ...
Posted on Thu, 28 May 2026 19:36:55 +0000 by Fawkman
Minimum Button Presses for a Strange Elevator
A building has an unusual elevator system. Each floor i (where 1 ≤ i ≤ N) has a fixed value K[i], which determines how many floors the elevator moves when the "up" or "down" button is pressed. The elveator can only move up by K[i] floors or down by K[i] floors from floor i. If the target floor would be below 1 or above N, th ...
Posted on Mon, 18 May 2026 01:53:57 +0000 by bobdabuilder