Essential Algorithms for Programming Competition Preparation

This collection presents fundamental algorithms and their applications to simple problems, primari sourced from the Lanqiao Cup competition. The problems are relatively straightforward, focusing more on algorithm templates and basic approaches. For better algorithm retention, the implementations are concise, frequently utilizing built-in C++ fu ...

Posted on Wed, 29 Jul 2026 16:32:20 +0000 by ThaboTheWuff

Zigzag Level Order Traversal of Binary Tree

Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between). For example: Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 7 return its zigzag level order traversal as: [ [3], [20,9], [15,7] ] Appr ...

Posted on Mon, 27 Jul 2026 16:05:55 +0000 by Hypnos

Graph Algorithms and Critical Path Analysis in C

Depth-First Search on Adjacency-Matrix Graphs void DFS(MGraph G, Vertex v, void (*visit)(Vertex)) { visit(v); Visited[v] = true; for (Vertex w = 0; w < G->Nv; ++w) if (G->G[v][w] && !Visited[w]) DFS(G, w, visit); } Breadth-First Search on Adjacency-List Graphs void BFS(LGraph G, Vertex s, void ...

Posted on Wed, 22 Jul 2026 16:36:11 +0000 by han2754

Determining Graph Connectivity using DFS and BFS

Algorithmic Approach When handling graph problems, especially those involving large datasets, an adjacency list is often preferred over an adjacency matrix to optimize memory usage, particularly when the vertex count may exceed standard limits. To determine if an undirected graph is connected, one can traverse the structure using either Depth-F ...

Posted on Sun, 19 Jul 2026 16:48:56 +0000 by Jay87

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

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

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

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