Core Algorithmic Building Blocks for Competitive Programming
Mathematical Algorithms
Fast Exponentiation
Reduces the time complexity of computing powers to logarithmic time by leveraging binary decomposition of the exponent.
long long binary_pow(long long base, long long exp, long long mod) {
long long res = 1;
base %= mod;
while (exp > 0) {
if (exp & 1) res = (res * base) % mo ...
Posted on Sun, 17 May 2026 15:51:07 +0000 by TheMagician
Algorithms for Finding the Maximum Subarray Sum
Given a sequence of integers of length n, the objective is to identify a contiguous subarray that yields the maximum possible sum. This is a fundamental problem in computer science, solvable through several distinct algorithmic approaches.
Dynamic Programming
The optimal substructure for this problem can be defined by letting f(i) represent the ...
Posted on Sun, 17 May 2026 06:36:02 +0000 by Jiin
Understanding and Calculating Time and Space Complexity
Algorithm Efficiency
Algorithm efficiency is measured in two dimensions: time efficiency and space efficiency.
Big O Notation
Big O notation mathematically describes the asymptotic behavior of a function. It provides an estimation of an algorithm's growth rate. The rules for deriving Big O are:
Replace all additive constants in the runtime fun ...
Posted on Sun, 17 May 2026 01:01:04 +0000 by janderson
Implementation of Sequential List Operations
This problem requires implementing six core functions for an integer sequantial list that supports input, output, retrieval, search, insertion, and deletion operations. The sequential list structure manages integer data elements with fixed-size array storage.
Function Interface Definitions:
The sequential list structure is defined as:
typedef s ...
Posted on Sat, 16 May 2026 23:32:52 +0000 by sriusa
Identifying Edges on Shortest Paths in Directed Graphs
To determine which edges can lie on a shortest path from source S to target T in a directed graph, compute shortest distances from S to all nodes. Then, perform a reverse BFS starting from T on the transposed graph. For each dequeued node cur and its neighbor nex in the transposed graph, if Dist[nex] == Dist[cur] - weight(cur->nex) holds, th ...
Posted on Sat, 16 May 2026 15:21:00 +0000 by dustinnoe
Binary Search Algorithm Implementation and Performance Analysis in Java
Binary search operates with O(log n) time complexity on a sorted array of n elements. The algorithm repeatedly divides the search interval in half, achieving logarithmic performance.
Algorithm Fundamentals
Binary search, also known as half-interval search, is an efficient algorithm for locating a target value within a sorted sequence. It compar ...
Posted on Sat, 16 May 2026 09:08:13 +0000 by XPertMailer
Binary Tree Construction, Traversal, and Optimization Algorithms
Constructing Binary Trees from Inorder and Preorder TraversalsGiven the preorder and inorder traversal sequences of a binary tree, the tree structure can be uniquely reconstructed. The first element in the preorder sequence always represents the root of the current subtree. By locating this root value within the inorder sequence, one can partit ...
Posted on Sat, 16 May 2026 04:24:49 +0000 by Draco_03
LeetCode Problem Solutions: Sliding Window and Hash Table Techniques
Trpaping Rain Water Problem
Given an array representing elevation maps, this problem calculates how much water can be trapped between bars after raining.
vector<int> leftMax(n, 0);
vector<int> rightMax(n, 0);
if (n == 0) return 0;
leftMax[0] = height[0];
rightMax[n-1] = height[n-1];
for (int i = 1; i < n; ++i) {
leftMax[i] = ...
Posted on Fri, 15 May 2026 23:00:45 +0000 by jck
Java Solutions for Blue Bridge Cup Algorithm Challenges
Secret Code Decoding
Recover Chinese character bitmaps from byte sequences and interpret hidden messages. Each character is represented by 32 bytes arranged in 16 rows of 2 bytes. Convert byte values to binary, replacing 0s with spaces to visualize the characters.
Constraints
Max runtime: 1 second
Max memory: 128MB
<java>
public class B ...
Posted on Fri, 15 May 2026 16:06:03 +0000 by Syphon
Computing Sorted Squares of a Non-Decreasing Integer Array
Method 1: Square then Sort
This approach squares each element first and subsequently sorts the resulting array.
#include <stdio.h>
#include <stdlib.h>
int compareElements(const void* first, const void* second) {
int elemA = *((int*)first);
int elemB = *((int*)second);
if (elemA < elemB) return -1;
if (elemA > elemB) r ...
Posted on Fri, 15 May 2026 09:48:25 +0000 by prc