Intermediate · 25 minYou are hereRead
Binary trees
A binary tree is a set of nodes, each pointing to at most two children. Nodes scattered across the heap form a branching shape, and its height decides how much it can hold.
Trees
Members: · Free account
Intermediate · 25 minYou are hereRead
A binary tree is a set of nodes, each pointing to at most two children. Nodes scattered across the heap form a branching shape, and its height decides how much it can hold.
Intermediate · 20 minYou are hereRead
A binary tree can live in an array, with the children of cell i at 2i + 1 and 2i + 2. A complete tree fills it exactly; a lopsided one leaves gaps. Trees with any number of children use two pointers per node.
Intermediate · 30 minYou are hereRead
A recursive walk visits every node of a tree once. Printing a node before, between or after its two subtrees gives preorder, inorder or postorder, and the same pattern measures a tree.
Intermediate · 25 minYou are hereRead
A loop that keeps nodes in a stack walks a tree depth first, as the recursion did. Swap the stack for a queue and the same loop visits the tree level by level.
Related topics