A simple TypeScript project that uses viz.js
to visualize min heap operations in a web browser.
- Vanilla Setup: No frameworks required—just
webpack
for bundling. - Object-Oriented Design: Min Heap implemented as a class with methods.
- Visualizer: Displays heap operations visually in the browser at
localhost:8080
.
Follow these steps to set up and run the project:
Ensure you have the following installed:
-
Clone the Repository:
git clone <repository-url>
-
Open containing folder
cd <repository-folder>
-
Install Dependencies: Run the following command to install all required packages:
npm install
-
Run the Development Server: Start the local server to view the project in your browser:
npx webpack server
-
View in Browser:
Open your web browser and navigate to:http://localhost:8080
The Min Heap class includes the following methods:
Adds a new value to the heap while maintaining the heap property.
Removes and returns the smallest value from the heap.
Returns the smallest value without removing it.
Returns the current number of elements in the heap.
Generates a DOT string representation of the heap for visualization with viz.js
.
-
Create a Min Heap: Instantiate the Min Heap class and use its methods:
const minHeap = new MinHeap(); minHeap.insert(10); minHeap.insert(5); minHeap.insert(20); console.log(minHeap.extractMin());
-
Visualize the Heap: Use the
toDot
method to generate the DOT representation and render it usingviz.js
:const dot = minHeap.toDot(); viz.renderSVGElement(dot).then((svgElement) => { document.body.appendChild(svgElement); });