Set up a complete binary tree has 500 nodes, the depth of the binary tree is how much? When using a linked list binary storage structure of the complete binary tree, the common

Figure

Complete binary (presence of a single branch) corresponding to the binary list

Seeking null child pointer field that is required to re-node point number × 2 + 1 (where 1 is the single branch nodes null pointer domain)

8 is a front depth complete binary tree is a full binary tree layer 9, a total of 2⁸-1 = 255 nodes

Ninth layer nodes 500-255 = 245 (found 245 odd parent node must have a single branch), the number of parent node 244/123 = 1 + 2 (which has a single branch node)

8th layer 2⁷ = 128 nodes, wherein the number of leaf nodes 128-123 = 5 (see figure do not understand)

Therefore, the number of null pointer field = 245 × 2 + 5 × 2 + 1 = 501 th

 

Pure hand is not easy to play, want to help

Guess you like

Origin www.cnblogs.com/chenxiansen/p/12076707.html