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...
Common Search Structures Structure Type Data Format Time Complexity Sequential Search Any O(N) Binary Search Sorted O(log N) Binary Search Tree (BST) Any O(N) to O(log N) Balanced BST (AVL, Red-Black) Any O(log N) Hash Table Any O(1) average These structures are suitable for in-memory (internal) sea...
Givan a colection of words, the objective is to detremine the shortest unique prefix for each word. A prefix is a substring starting from the first character. For instance, the word "carbon" has prefixes: "c", "ca", "car", "carb", "carbo",...
Removing Nodes with a Specific Value from a Linked List Given the head node of a singly linked list and an integer value, the task is to delete all nodes whose value matches the given integer and return the new head of the list. Example: Input: head = [1,2,6,3,4,5,6], val = 6 Output: [1,2,3,4,5] App...
A Binary Search Tree (BST) is a specialized binary tree structure where each node's left subtree contains only values less than the node's key, and its right subtree contains only values greater than the key. This property must hold recursive for all subtrees. An in-order traversal of a BST yields t...