Pseudocodes

A little of a theory.
There are definitions of used data structures
(Binary Tree, Binary Heap,
Priority Queue, Binary Search Tree)
and simplified actually usedcodes of algorithms.
Binary Tree Visualiser is written in JavaScript, so these codes are also written in JavaScript syntax.
Codes are simplified to show the main functionality. Extreme cases (given empty tree, null node, etc.) are usually not solved.
Make sure you know the basics about JavaScript.
It is a scripting language. It is object oriented, dynamic typed, prototype based and has first-class functions.
In JavaScript object are passed by references, but primitive types by values.
There are no classes. Functions are used as objects constructors, and prototyping is used for inheritance.developer.mozilla.org

Binary Tree

A binary tree is an data structure with one root node (the ancestor of all nodes).
Each node has a value and at most two child nodes, usually called left child and right child.
Each node (except for root) has one parent. Root node has no parent.
Node with no children is called leaf.
The formal recursive definition is: a binary tree is either empty (represented by a null),
or is made of a single node, where the left and right references (recursive definition ahead)
each point to a binary tree.Nick Parlante

A priority queue is an abstract data type to efficiently support finding the item with the highest priority (highest value) across a series of operations (nodes).
The basic operations are: insert, get maximum and extract maximum.Paul E. Black
In Binary Tree Visualiser there is priority queue implemented as binary heap with these functions.

Heapify-down

Rearrange a heap to maintain the heap property downwards.
If the node is not greater than or equal to its children, swap it with the greater child, then recursively heapify-down that child's subtree.
Michael L. Littman

Heapify-up

Rearrange a heap to maintain the heap property upwards.
If the node is greater than its parent, swap these nodes, then recursively heapify-up the parent that changed (originally the given node).
Michael L. Littman

Insert

The new node is initially appended to the end of the heap.
The heap property is repaired by comparing the added node with its parent and swapping them if added node is grater than its parent.
The comparison is repeated until the parent is larger than or equal to the percolating element.Victor Adamchik

Delete

Remove the node and replace it with the last element of the heap and then restore the heap property.
It is necessary to check for both up- and downshifts. For example when the "last" node takes up the vacant spot, it can be over- or underevaluated. It can't be both, for obvious reasons.
Victor S.AdamchikGaminic

Binary Search Tree

A binary search tree is a type of binary tree where the nodes are arranged in order:
for each node, all nodes in its left subtree are less than the node,
and all the nodes in its right subtree are greater than or equal to the node.
Recursively, each of the subtrees must also obey the binary search tree constraint.Nick Parlante

Random Binary Search Tree

Generate a new random binary search tree.
This is my own algorithm written for this application. This is not a general generator of random binary trees.

Insert

Insert algorithm traverses the tree, choosing appropriate way to go
by comparing value of each visited node with the new value, following the binary search tree property.
Following this simple rule, the algorithm reaches a node, which has not a subtree to go.
Appended new node here.algolist.net

Find

Search algorithm traverses the tree, choosing appropriate way to go
by comparing value of each visited node with the searched value, following the binary search tree property.
Algorithm stops if a node with necessary value is found or the algorithm has no way to go.algolist.net

Delete

Node to be removed has no children: Algorithm sets corresponding link of the parent to NULL.

Node to be removed has one child: In this case, node is cut from the tree
and algorithm links single child (with it's subtree) directly to the parent of the removed node.

Node to be removed has two children: In this case node to be removed is swapped with its successor
(in that case it is minimum from right subtree). Then it is deleted as node with no or one child
because minimum of subtree cannot have tho children.algolist.net

Get Successor

There are two options:

1. The node has a right subtree.
The next larger node must be in the right subtree.
Since all nodes in a right subtree are larger than or equal to the given node,
the successor must be the smallest of all those nodes (minimum of right subtree).

2. The node does not have a right subtree.
In this case we will have to look up the tree since that's the only place we might find the next larger node.
There is no point looking at the left subtree as all nodes in the left subtree are guaranteed to be smaller than the given node.
When we look up from the given node, there can be two cases.
First, the current node is the left child of its parent. In this case the parent is the successor node.
This is because the parent always comes next in in-order traversal if you are done with left subtree (rooted at the current node).
Second, the current node is the right child of the parent.
This is an interesting case. In this case, as you keep going up the ancestor chain
you encounter smaller values if you are going up but larger values if you are going right.
The successor node will be the first node up the ancestor chain that you encounter on the right chain.Golam Kawsar

To Pre-order Array

To traverse a tree data structure is to process every node exactly once. However you may "pass through" a node many times.
For pre-order walk process node itself, recursively traverse its left subtree, recursively traverse its right subtree.Robert Holte