Insertion Sort Insertion sort constructs a sorted array incrementally. It takes one element from the input data and finds its correct position within the sorted list, repeating until no elements remain. Simple Insertion Sort For each element at index i (from 1 to n-1), the algorithm compares it with...
Arithmetic Operations on Numbers Basic operations include addition (+), subtraction (-), multiplication (*), and division (/). Use floor division (//) for integer results (rounds down). Modulo (%) returns the remainder. Functions: abs(x) for absolute value, max(x, y)/min(x, y) for extrema, pow(x, y)...
Introduction to Singly Linked Lists A singly linked list is a linear data strcuture where each element, called a node, contains data and a pointer to the next node in the sequence. Unlike arrays, nodes are not stored contiguous in memory, allowing dynamic memory allocation and efficietn insertions a...
Union-Find is a tree-based data structure designed to handle disjoint sets, supporting operations like merging two sets and querying connectivity. It efficiently addresses problems involving connectivity and merging of non-overlapping collections. In Union-Find, each set is represented as a tree whe...
Reference Book: [1] Clifford A. Shaffer. Data Structures and Algorithm Analysis[M]. Beijing: Electronic Industry Press, 2020. Data Structures and Algorithms Problems, Algorithms, and Programs Q: What can be called an algorithmm? It must be correct. It is composed of a series of concrete steps. It is...
Dynamic Segment Tree Merging Combining two dynamically allocated segment trees enables efficient aggregation of information across disjoint sets or hierarchical structures. The operation recursively merges corresponding nodes from both trees. When one subtree is empty, the non-empty counterpart is r...
Problem Context In developing a Gomoku game program, features like undo/redo moves are essential. Typically, a 2D array represents the board state, but this approach stores many default values (e.g., 0 for empty cells), leading to inefficient memory usage. Sparse arrays can address this issue. Spars...
A binary tree is a hierarchical data structure composed of nodes, each containing a data element and pointers to left and right child nodes. Its widely used in computer science for tasks like searching, sorting, and hierarchical representation. Key Components of a Binary Tree Node: The fundamental u...
A singly linked list consists of nodes, each containing a data element and a reference too the next node. import java.util.Scanner; public class LinkedList<E> { private int count = 0; private class ListNode { E value; ListNode successor; ListNode(E value, ListNode successor) { this.value = val...
Linear structures represent a fundamental and widely used category of data structures. Their defining characteristic is a linear relationship between elements. Common implementations like dynamic arrays, linked lists, stacks, and queues all fall under this category. While they share the property of...