feat(viz): heap pattern with kth largest

This commit is contained in:
2025-09-03 21:30:46 +01:00
parent 03db344fb2
commit 31c74f177b
7 changed files with 1153 additions and 1 deletions

View File

@@ -89,6 +89,10 @@ export interface DataState {
// Grid support (for DP visualizations)
grids?: GridState[];
gridPointers?: GridPointerState[];
// Decision tree support (for Backtracking)
decisionTrees?: DecisionTreeState[];
// Heap support
heaps?: HeapState[];
}
/** Single step in the visualization */
@@ -250,6 +254,30 @@ export interface QueueState {
label?: string;
}
// ============================================
// Decision Tree Types (for Backtracking)
// ============================================
/** State of a decision tree node for backtracking */
export interface DecisionNodeState {
id: string;
value: string; // Current subset as string: "[]", "[1]", "[1,2]"
state: 'normal' | 'exploring' | 'complete' | 'backtracking' | 'current';
left: string | null; // Include branch
right: string | null; // Exclude branch
decision?: string; // "Include 2?" label
depth: number; // Recursion depth (0-indexed)
}
/** Complete decision tree state */
export interface DecisionTreeState {
id: string;
nodes: DecisionNodeState[];
rootId: string;
label?: string;
currentPath?: string[]; // IDs of nodes in current exploration path
}
// ============================================
// Grid Types (for DP visualizations)
// ============================================
@@ -280,3 +308,24 @@ export interface GridPointerState {
col: number;
color: 'current' | 'dependency' | 'result' | 'default';
}
// ============================================
// Heap Types
// ============================================
/** State of a heap node */
export interface HeapNodeState {
id: string;
value: number;
index: number; // Position in heap array (0-indexed)
state: 'normal' | 'comparing' | 'swapping' | 'settled' | 'highlighted' | 'removing';
}
/** Complete heap state */
export interface HeapState {
id: string;
elements: HeapNodeState[];
label?: string;
heapType: 'min' | 'max';
maxSize?: number; // For bounded heaps (like top-k)
}