"Data Structure" review notes--Two fork Tree 1

Source: Internet
Author: User

Two-fork Tree:

In computer science, a two-fork tree is a tree structure with a maximum of two subtrees per node. The subtree is often referred to as the leftsubtreeand the right subtree (subtree). Binary trees are often used to implement a two-fork search tree and a two-fork heap.

Each node of a binary tree has a maximum of two subtrees trees (no nodes with a degree greater than 2), and the subtree of the binary tree has left and right points, and the order cannot be reversed. There are at most 2^ (i-1) nodes in the first layer of the binary tree, and two forks with a depth of K have a maximum of 2^k-1 nodes; for any binary tree T, if its terminal node number is N1 and the node with a degree of 2 is N2, then n1=n2+1

A depth of k, and there are 2^k-1 nodes called full two-tree , the depth of k, there are N nodes of two-tree, and only if each of its nodes with a depth of k in the full two-tree, the sequence number of 1 to n corresponds to a node, called a complete binary tree .

Unlike the tree, the number of nodes of the tree is at least 1, while the number of nodes of the binary tree can be 0, the maximum degree of the nodes in the tree is not limited, and the maximum degree of the binary tree nodes is 2; the nodes of the tree have no left and right points, while the nodes of the binary tree have left and right points.


Abstract data type definition for binary tree

Type name: two fork Tree data Object set: A collection of nodes with poor points. If not empty, it consists of the root node and its left and right two fork trees. Operation set: BT? Bintree, Item? ElementType, important operations are: 1, Boolean IsEmpty (Bintree BT): To determine whether BT is empty, 2, void Traversal (Bintree BT): Traversal, in a certain order to access each node; 3, Bintree Creatbintree (): Creates a binary tree.
Common traversal methods are: void Preordertraversal (Bintree BT): First order----root, Zuozi, right subtree; void Inordertraversal (Bintree bt): Middle Sequence---Zuozi, root, right subtree;? void Postordertraversal (Bintree bt): Post----Zuozi, right subtree, root void Levelordertraversal (Bintree BT): Hierarchical traversal, top to bottom, left to right

Traversal of a binary tree
(1) First Order traversal:

The root node-the first sequence traversal of the left subtree-is the first step to traverse the right sub-tree.

void Preordertraversal (Bintree BT)/* First Order Traversal */{if (BT) {printf ("%d", bt->data); Preordertraversal (bt->left);   Preordertraversal (Bt->right); }}

(2) Middle sequence traversal:

Traversing the left sub-tree in the middle sequence--"root node"--traversing right subtree in sequence

void Inordertraversal (Bintree bt) {    if (BT)    {        inordertraversal (bt->left);        printf ("%d", bt->data);        Inordertraversal (bt->right);    }}

(3) Post-traversal

Subsequent traversal of left sub-tree-"root node"-"follow-up traversal right subtree"

void Postordertraversal (Bintree bt) {    if (BT)    {        postordertraversal (bt->left);        Postordertraversal (bt->right);        printf ("%d", Bt->data);}    }



"Data Structure" review notes--Two fork Tree 1

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.