Giter VIP home page Giter VIP logo

binary-heap-visualizer's Introduction

A visualizer for Min Heap Binary Trees

A min heap binary constructor and visualizer.

From Wikipedia:

A binary heap is a heap data structure created using a binary tree. It can be seen as a binary tree with two additional constraints:

  • Shape property A binary heap is a complete binary tree; that is, all levels of the tree, except possibly the last one (deepest) are fully filled, and, if the last level of the tree is not complete, the nodes of that level are filled from left to right.

  • Heap property All nodes are less than or equal to each of their children.

Use

There are two ways to use this repo - using the visual heap builder, or cloning the repo and using the binaryheaptree constructor.

Visualizer

The Min Heap Binary Tree Visualizer can be found at this repository's Pages URL.

Enter a value in the input field in the top right and click the Push button to push the value to the min heap binary tree.

Click the Pop button to pop the lowest value.

Constructor

You can also use the binaryheaptree object constructor. To create a new Min Heap Tree:

var myMinHeapTree = new binaryheaptree();

Methods

Once you've created a new binaryheaptree() there are several methods available:

.push()

Pushed a value onto the end of the heap and floats the value to its appropriate position in the heap.

.pop()

Returns the lowest value, the moves the last value in the tree to the root and sinks the value to its appropriate position in the heap.

.clear()

Clears the tree.

.lchild(index)

Returns the index of the left child from the parent index argument.

.rchild(index)

Returns the index of the right child from the parent index argument.

.parent(index)

Returns the index of the parent from the child index argument.

.float(index)

Recursively floats the node at index to its appropriate position.

.sink(index)

Recursively sinks the node at index to its appropriate position.

.children(index)

Returns an array of length 2 containing the indexes of the children from the parent index.

.swap(index1, index2)

Swaps the nodes at index1 and index2.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.