Advanced Data Structures Hub

Advanced Data Structures Hub | 高級資料結構中心

Advanced Data Structures

Master Stacks, Queues, and Trees with Interactive 3D Visualizations

Data Structure Fundamentals

📚

Stack (LIFO)

Last-In-First-Out structure, like a stack of plates. Perfect for undo operations, function calls, and expression evaluation.

🚶‍♂️

Queue (FIFO)

First-In-First-Out structure, like a line of people. Ideal for task scheduling, breadth-first search, and buffering.

🌳

Tree (Hierarchical)

Hierarchical structure with parent-child relationships. Essential for file systems, DOM structure, and decision trees.

Complexity Analysis

Time Complexity Comparison

3D Interactive Visualization

Loading 3D Scene...

Operation Log

Code Laboratory

Python
# Stack Implementation in Python class Stack: def __init__(self): self.items = [] def push(self, item): self.items.append(item) return self def pop(self): if not self.is_empty(): return self.items.pop() raise IndexError("Stack is empty") def peek(self): if not self.is_empty(): return self.items[-1] return None def is_empty(self): return len(self.items) == 0 def size(self): return len(self.items) # Example usage stack = Stack() stack.push(1).push(2).push(3) print(f"Stack size: {stack.size()}") print(f"Top element: {stack.peek()}")
JavaScript
// Stack Implementation in JavaScript class Stack { constructor() { this.items = []; } push(item) { this.items.push(item); return this; } pop() { if (this.isEmpty()) { throw new Error('Stack is empty'); } return this.items.pop(); } peek() { if (this.isEmpty()) { return null; } return this.items[this.items.length - 1]; } isEmpty() { return this.items.length === 0; } size() { return this.items.length; } } // Example usage const stack = new Stack(); stack.push(1).push(2).push(3); console.log(`Stack size: ${stack.size()}`); console.log(`Top element: ${stack.peek()}`);

Output

Interactive Learning

Performance Comparison

100

Algorithm Steps Visualization

Real-World Applications

Browser History (Stack)

Web browsers use stacks to manage navigation history. Each page visit pushes onto the stack, and the back button pops the most recent page.

History Stack:

Task Scheduler (Queue)

Operating systems use queues for task scheduling. Tasks are processed in the order they arrive, ensuring fairness.

Task Queue:

File System (Tree)

File systems organize data in tree structures with directories as nodes and files as leaves.

Directory Tree:

Programming Challenges

Challenge 1: Balanced Parentheses

Write a function to check if parentheses in a string are balanced using a stack.

Challenge 2: Hot Potato

Simulate the hot potato game using a queue to determine the last person standing.

Challenge 3: Binary Tree Traversal

Implement different tree traversal methods and compare their outputs.

留言