Linked List
Linear data structure with dynamic memory allocation using nodes.
Visualization
Interactive visualization for Linked List
Interactive visualization with step-by-step execution
Implementation
1class ListNode {
2 val: number;
3 next: ListNode | null;
4
5 constructor(val: number) {
6 this.val = val;
7 this.next = null;
8 }
9}
10
11class LinkedList {
12 head: ListNode | null = null;
13
14 append(val: number): void {
15 const newNode = new ListNode(val);
16 if (!this.head) {
17 this.head = newNode;
18 return;
19 }
20
21 let current = this.head;
22 while (current.next) {
23 current = current.next;
24 }
25 current.next = newNode;
26 }
27
28 prepend(val: number): void {
29 const newNode = new ListNode(val);
30 newNode.next = this.head;
31 this.head = newNode;
32 }
33
34 delete(val: number): void {
35 if (!this.head) return;
36
37 if (this.head.val === val) {
38 this.head = this.head.next;
39 return;
40 }
41
42 let current = this.head;
43 while (current.next && current.next.val !== val) {
44 current = current.next;
45 }
46
47 if (current.next) {
48 current.next = current.next.next;
49 }
50 }
51}Complexity
Time
O(1) insertion
O(n) search
O(n)
Space
O(n)
Applications
Use Cases
Related Algorithms
Binary Search Tree (BST)
A hierarchical data structure where each node has at most two children, maintaining the property that all values in the left subtree are less than the node's value, and all values in the right subtree are greater. This ordering property enables efficient O(log n) operations on average for search, insert, and delete. BSTs form the foundation for many advanced tree structures and are fundamental in computer science.
Stack
LIFO (Last-In-First-Out) data structure with O(1) push/pop operations. Stack is a fundamental linear data structure where elements are added and removed from the same end (top). It's essential for function calls, expression evaluation, backtracking algorithms, and undo operations in applications.
Queue
FIFO (First-In-First-Out) data structure with O(1) enqueue/dequeue operations. Queue is a fundamental linear data structure where elements are added at one end (rear) and removed from the other end (front). Essential for breadth-first search, task scheduling, and buffering systems.
Hash Table (Hash Map)
A data structure that implements an associative array abstract data type, mapping keys to values using a hash function. Hash tables provide O(1) average-case time complexity for insertions, deletions, and lookups, making them one of the most efficient data structures for key-value storage. The hash function computes an index into an array of buckets from which the desired value can be found.