The next lower level uses the next bit significance, and so on. Less significant bits are sometimes ignored to reduce the tree size. The algorithm is highly memory efficient because the tree's size can be limited. The bottom level of the octree consists of leaf nodes that accrue color data not represented in the tree; these nodes initially contain single bits. If much more than the desired number of palette colors are entered into the octree, its size can be continually reduced by seeking out a bottom-level node and averaging its bit data up into a leaf node, pruning part of the tree. Once sampling is complete, exploring all routes in the tree down to the leaf nodes, taking note of the bits along the way, will yield approximately the required number of colors. The example recursive algorithm outline below (MATLAB syntax) decomposes an array of 3-dimensional points into octree style bins. The implementation begins with a single bin surrounding all given points, which then recursively subdivides into its 8 octree regions. Recursion is stopped when a given exit condition is met. Examples of such exit conditions (shown in code below) are:  function [binDepths,binParents,binCorners,pointBins] = OcTree(points) binDepths = [0] % Initialize an array of bin depths with this single base-level bin binParents = [0] % This base level bin is not a child of other bins binCorners = [min(points) max(points)] % It surrounds all points in XYZ space pointBins(:) = 1 % Initially, all points are assigned to this first bin divide(1) % Begin dividing this first bin function divide(binNo) % If this bin meets any exit conditions, do not divide it any further. binPointCount = nnz(pointBins==binNo) binEdgeLengths = binCorners(binNo,1:3) - binCorners(binNo,4:6) binDepth = binDepths(binNo) exitConditionsMet = binPointCountvalue if exitConditionsMet end % Otherwise, split this bin into 8 new sub-bins with a new division point newDiv = (binCorners(binNo,1:3) + binCorners(binNo,4:6)) / 2 for i = 1:8 end Taking the full list of colors of a 24-bit RGB image as point input to the Octree point decomposition implementation outlined above, the following example show the results of octree color quantization.