Fading Coder

One Final Commit for the Last Sprint

Union-Find Data Structure for Efficient Connectivity Queries in Python

The Union-Find (or Disjoint Set Union) data structure efficiently manages a collection of disjoint sets, suppporting two core operations: determining which set an element belongs to (find) and merging two sets (union). It is particularly useful for modeling connectivity in graphs, networks, and dyna...

Fundamental Data Structures: Stacks and Queues in C

A stack operates on a Last-In, First-Out (LIFO) principle. It is a linear structure where insertion and deletino occur exclusively at one end, known as the top. The opposite end is the base. Adding an element is termed pushing, while removing one is popping. Sequential Stack Implementation Using a f...

Segment Tree for Range Minimum and Frequency Queries with Point Updates

Given an array of n integers and q operations, the task is to handle two types of requests efficiently: Update: Set the value at index x to d. Query: For a range [l, r], find the minimum value and count how many times it appears in that range. Data Structure Design We define a structure AggData to s...

Understanding Python Lists: Internal Implementation and Common Operations

Dynamic Array Implementation Python lists are implemented as dynamic arrays thatt automatically resize when elements are added or removed. The underlying mechanism uses contiguous memory allocation with over-allocation strategies to optimize performence. When a list exceeds its current capacity, Pyt...

Stack and Queue Data Structures

Stack and Queue Stack - Last In, First Out (LIFO), with only one end for operations. Implemented using arrays or linked lists. Queue - First In, First Out (FIFO), with two ends for operations: one for adding and one for removing elements. Implemented using arrays or linked lists. Stack Operations Qu...

Reconstructing a Binary Tree from Preorder and Inorder Traversal Arrays

The problem requires constructing a binary tree given two integer arrays, preorder and inorder, representing the tree's preorder and inorder traversals, respectively, and returning the root node. The solution leverages the distinct properties of these traversal orders. In a preorder traversal, nodes...

Scapegoat Tree: A Self-Balancing Binary Search Tree Implementation

A Scapegoat Tree is a type of self-balancing binary search tree that guarantees O(log n) time complexity for operations. When the tree contains at most m nodes simultaneously, its space complexity can also achieve O(m) due to its special non-pointer memory recycling mechanism. The Scapegoat Tree emp...

Nordic Collegiate Programming Contest 2021 Solutions

A - Antenna Analysis The mathematical expression can be decomposed into two separate components: #include <iostream> #include <queue> #include <vector> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, c; cin >> n >> c; priority_que...

Fundamental Sorting Algorithms for Integer Arrays

1. Selection SortThe algorithm divides the input list into two parts: a sorted sublist built up from left to right, and the remaining unsorted items. During each iteration, the smallest element from the unsorted section is identified and swapped into its correct position at the end of the sorted sub...

Efficient Search Methods Using Python

Sequential Scan This method traverses the collection element by element starting from the first index. It imposes no constraints on data ordering, functioning effectively on both sorted and unsorted sequences. The process terminates immediately upon finding the target value. def sequential_scan(arr,...