Data structure - binary storage structure

Sequential storage representation

Data storage is an integer, for example.

// 二叉树的最大节点数
# define MAX_TREE_SIZE 100
//0号单元存储根节点
typedef int SqBiTree[MAX_TREE_SIZE];
SqBiTree bt;

A logical binary tree structure is as follows:

Here Insert Picture Description

It sequentially stores the following structure:

Here Insert Picture Description

As the binary tree is not necessarily a complete binary tree, so I hope to visit parent and sibling, child node numbers, then you must add the virtual node of the tree. From the above disadvantages of storage structure can be seen to do so is to have a lot of storage space is wasted.

So are generally binary tree structures for storing the chain.

Chain stores a

Binary list

Logical structure:

Here Insert Picture Description

Node structure:

Here Insert Picture Description

Trigeminal list

Logical structure:

Here Insert Picture Description

Node structure:

Here Insert Picture Description


If a binary tree containing n n nodes, then it must contain the binary list in 2 n 2n pointers domain must n + 1 n +1 empty chain domain.

prove:

The number of branches n 1 n - 1 , i.e., there is non-empty chain domain n 1 n-1 th, it is equal to the empty chain domain 2 n ( n 1 ) = n + 1 2n - (n-1) = n + 1 Ge.

Guess you like

Origin blog.csdn.net/hjc256/article/details/94281054