Understanding Binary Trees: Structure, Properties, and Operations

1.1 Basic Concepts A tree is a non-linear data structure consisting of a finite set of nodes (n ≥ 0) that form a hierarchical relationship. It's called a tree because it resembles an inverted tree with the root at the top and leaves at the bottom. Trees have the following characteristics: There is a special node called the root node, which has ...

Posted on Mon, 12 Oct 2026 16:43:14 +0000 by mingwww

Understanding Linked Lists and Their Implementation

Linked List Fundamentals A linked list is a fundamental data structure that represents a linear sequence of elements, where each element points to the next one rather than being stored in contiguous memory locations. This design allows for efficient insertions with O(1) complexity, outperforming arrays in dynamic scenarios. However, accessing s ...

Posted on Mon, 12 Oct 2026 16:38:12 +0000 by tony_l

Essential Algorithm Templates for Competitive Programming

Linear Sieve for Prime Numbers (O(2N)) bool composite[N]; int primes[N], prime_count; void build_sieve(int limit) { for (int num = 2; num <= limit; num++) { if (!composite[num]) { primes[prime_count++] = num; } for (int j = 0; j < prime_count && num * primes[j] <= limit; j++) { ...

Posted on Mon, 12 Oct 2026 16:14:11 +0000 by synstealth

Python Essentials: Data, Control, Files, and Libraries

Data Types and Operations Python provides a variety of built‑in data types. Numeric types include int, float, complex, and the now‑unused long (Python 2). Integers can be written in decimal, binary, octal, or hexadecimal. Floating‑point numbers represent real numbers, while complex numbers use a j suffix for the imaginary part. Strings are sequ ...

Posted on Sun, 11 Oct 2026 16:21:50 +0000 by jworisek

Implementing Hash Tables and String Rolling Hashes in C++

A hash table delivers expected O(1) time complexity for data retrieval and insertion by mapping arbitrary keys into a fixed-size array. This technique compresses a large key space (e.g., integers up to 10^9) into a manageable index range (typically 10^5 to 10^6). Unlike discretization, which preserves relative order, hashing focuses solely on e ...

Posted on Sat, 10 Oct 2026 16:07:28 +0000 by colake

Graph Data Structures and Algorithms: Adjacency List, Topological Sort, MST, and Shortest Path

1. Adjacency List Implementation 1.1 Java Implementation public class Graph { public Map<Integer, Vertex> vertices; public Set<Edge> edges; public Graph() { vertices = new HashMap<>(); edges = new HashSet<>(); } } public class Vertex { public int id; public int inDegree; publ ...

Posted on Thu, 08 Oct 2026 16:17:39 +0000 by fewtrem

Binary Search Tree Pair Sum Algorithm Implementation

Problem Overview Given two binary search trees and a target sum, find all unique pairs of values (one from each tree) that add up to the target. This requires efficient traversal and searching techniques to handle large datasets within time constraints. Inefficient Approach (O(n²) complexity) The first approach involves traversing the first tre ...

Posted on Thu, 08 Oct 2026 16:01:16 +0000 by rustyofco

Implementing Heap Sort and Quick Sort Algorithms

Heap Sort Implementation Heap sort utilizes a binary heap structure to sort elements. A heap is a complete binary tree where each node satisfies the heap property - either being a max-heap (parent >= children) or min-heap (parent <= children). The algorithm consists of two phases: heap construction and element exrtaction. Heap Constructio ...

Posted on Mon, 05 Oct 2026 16:43:36 +0000 by brokencode

Algorithm Practice Day 11: Postfix Expression Evaluation, Sliding Window Maximum, and Top K Frequent Elements

Problem Solving 1.1 Evaluate Reverse Polish Notation Original Link: Code Suizhanglu Problem Link: 150. Evaluate Reverse Polish Notation - LeetCode Description Given an array of strings tokens represanting a postfix expression, compute the result of this expression. Return an integer representing the value of the expression. Notes: Valid oper ...

Posted on Sun, 04 Oct 2026 16:03:09 +0000 by jqa

Essential Python Syntax: I/O Operations, Data Structures, Functions, Classes, and Error Handling

Input and Output Operations Reading Keyboard Input To read input from the keyboard, use the input() function which reads a line of text: user_input = input("Please enter something: ") print("You entered: ", user_input) File Operasions To work with files, you need to open them first: # Using context manager (recommended) wit ...

Posted on Fri, 02 Oct 2026 16:26:10 +0000 by Hiro