Merge Sort Implementation for Singly Linked Lists

Algorithm Overview Split: Use slow-fast pointer technique to locate the midpoint and partition the list into two halves. Recurse: Apply the same sorting procedure recursively on both halves. Merge: Combine the two sorted sublists into a single sorted list using a linear-time merge step. Implementation class ListNode { int value; ListN ...

Posted on Fri, 19 Jun 2026 17:24:15 +0000 by brainstem

Understanding the FIFO Queue Data Structure

Definition and Core Principles A Queue is a fundamental linear data structure that operates on the First-In-First-Out (FIFO) principle. Conceptually, it functions similarly to a real-world waiting line: entities enter from one end, known as the rear, and exit from the opposite end, known as the front. This strict ordering ensures that the eleme ...

Posted on Fri, 19 Jun 2026 16:41:24 +0000 by disconne

Efficient Sorting and Merging with Heap Data Structures

Heap Data Structure Implementation Heaps are specialized tree-based data structures that satisfy the heap property. They are commonly used to implement priority queues and for efficient sorting algorithms. This article explores two practical applications of heaps: heap sort and sequence merging. Heap Sort Implemantation Heap sort is an efficien ...

Posted on Thu, 18 Jun 2026 16:37:37 +0000 by Eddie Fisher

FHQ Treap: A Non-Rotating Balanced Binary Tree Implementation

Data Structure DefinitionThe FHQ Treap (Fredman, Hendler, and Zhou Treap) relies on a randomized heap priority to maintain balance without requiring complex tree rotations. Each node in the structure maintains essential metadata: pointers to left and right children, the node's value, a random priority weight, and the size of the subtree rooted ...

Posted on Wed, 17 Jun 2026 17:45:38 +0000 by Backara_Drift

Sliding Window Technique and Spiral Matrix Generation

Minimum Size Subarray Sum Given an array of positive integers nums and a positive integer target, find the minimal length of a contiguous subarray whose sum is greater than or equal to target. If no such subarray exists, return 0. Examples: Input: target = 7, nums = [2,3,1,2,4,3]Output: 2Explanation: The subarray [4,3] has the minimal lengt ...

Posted on Tue, 16 Jun 2026 17:11:50 +0000 by kusarigama

Solving the Two Sum Problem with Python

The objective is to identify two numbers within an integer array that sum up to a specific target value and return their indices. It is assumed that there is exactly one valid solution per input and that an element cannot be used twice. For example, given the array nums = [2, 7, 11, 15] and target = 9, the function should return [0, 1] becuase ...

Posted on Tue, 16 Jun 2026 17:01:38 +0000 by ciaranmg

Algorithmic Review and Competition Strategies for NOIP

Contest preparation requires a structured approach to covering fundamental algorithms and optimizing problem-solving strategies. The following outlines core technical topics and execution practices essential for competitive programming. Core Algorithms and Data Structures Simulation and Mathematics High-precision arithmetic is critical for p ...

Posted on Mon, 15 Jun 2026 17:54:23 +0000 by press711

Core Algorithmic Techniques in Java for Competitive Programming

Sorting, searching, dynamic programing, and graph algorithms form the backbone of competitive programming. This article presents a curated list of such patterns, each accompanied by a concise Java implementation. The examples draw inspiration from the ACwing problem set, covering topics from basic sorting to advanced combinatorial mathematics. ...

Posted on Mon, 15 Jun 2026 17:07:00 +0000 by zhaohongli

LeetCode 54: Spiral Matrix and 445: Add Two Numbers II

LeetCode 54: Spiral Matrix Problem Given an m x n matrix, return all elements of the matrix in spiral order. Example 1 Input: matrix = [[1,2,3],[4,5,6],[7,8,9]] Output: [1,2,3,6,9,8,7,4,5] Example 2 Input: matrix = [[1,2,3,4],[5,6,7,8],[9,10,11,12]] Output: [1,2,3,4,8,12,11,10,9,5,6,7] Approach Traverse from left to right along the top r ...

Posted on Sun, 14 Jun 2026 16:12:36 +0000 by thebusinesslad

Essential Algorithm Templates in C++

Number Theory Primality Testing via Trial Division #include <iostream> using namespace std; bool isPrime(int num) { if (num < 2) return false; for (int d = 2; d <= num / d; ++d) if (num % d == 0) return false; return true; } int main() { int queries; cin >> queries; while (queries--) { ...

Posted on Sat, 13 Jun 2026 17:12:21 +0000 by sebjlan