Data structure Practice project--tree and two-fork tree (1)

Source: Internet
Author: User

This article is for [Data Structure Basic series (6): Tree and two fork tree] 第1-10 hours

1 tree structure guided studies
2 Basic concepts of trees
3 basic terms of the tree
4 Nature of the tree
5 storage structure of the tree
62 Fork Tree Concept and properties
72 cross-tree and tree, forest conversion
82 the storage structure of the fork tree
Basic operation and implementation of 92-fork Tree
102 traversal of a fork tree

"Project 1-two fork Tree algorithm library"

Define the chain storage structure of the binary tree, implement its basic operation, and complete the test.
Requirements:
1. The header file btree.h defines the data structure and declares the function used to complete the basic operation. Functions that correspond to basic operations include:

void createbtnode (BTNode *&b,        Char *str) ; //two fork chain created by str string      Btnode *findnode (btnode *b,elemtype x) ; //returns the node pointer for the data field x       Btnode *lchildnode (Btnode *p) ; //returns the left child node pointer of the *P node       Btnode *rchildnode (Btnode *p) ;     //returns the right child node pointer of the *P node  int btnodedepth (Btnode *b) ;     //to find the depth of the binary tree b  void dispbtnode (Btnode *b) ; //output binary tree  void destroybtnode (Btnode *&b) in square notation     ; //destroy binary tree   

2. Implement these functions in Btree.cpp
3. Complete the test in the main function, including the following:
(1) using "A (B (D,e (j,k))), C (F,g (, I))", the two-tree created for testing.

(2) Output binary tree
(3) Find the node with a value of ' h ', if found, the value of the left and right child of the node with the output value ' h '
(4) Height two fork tree height
(5) Destroying the binary tree
[Reference Solution]

"Recursive algorithm for Project 2-two cross-tree traversal"

A recursive algorithm for the first order, middle order, and post-sequence traversal of a two-fork tree is implemented, and a two-fork tree created using "A (B (D,e ())) and C (F,g (, I))" is tested.
Please use the binary Tree algorithm library.
[Reference Solution]

"Item 3-solving problems by using binary tree traversal ideas"

Suppose that the binary tree uses the binary chain storage structure to store, the following algorithm is implemented, and the test is completed in the program:
(1) Calculating the number of binary tree nodes;
(2) output all leaf nodes;
(3) The number of leaf nodes of binary tree B is obtained;
(4) An algorithm level (B,X,H) is designed to return the number of layers of the node with the data value x in the binary chain B.
(5) To determine whether the binary tree is similar (about binary tree T1 and T2 similar judgment: ①t1 and T2 are empty two fork tree, similar; ②t1 and T2 One is empty, the other is not empty, it is not similar; ③t1 Zuozi and T2 are similar, and Zuozi's right subtree is similar to T1 's right sub-tree, Then T1 and T2 are similar. )
Please use the binary Tree algorithm library.
[Reference Solution]
  

On paper: "Knowledge principle" test questions

1. A tree, denoted by parentheses: A (B (E), C (F,g (i,j), H (K)), D)
(1) Please use the tree notation to draw this tree
(2) The data structure of the parent representation is defined as

typedefstruct {    ElemType data;    int parent;} PTree[MaxSize];

Please describe this tree using parental notation when storing
(3) When the child chain is stored, each node defines the following type

typedefstruct node{   ElemType data;      struct node *sons[MaxSons];} TSonNode;

Please describe this tree using child chain notation when storing
(4) Child Brother the node in the chain storage structure is defined as

typedefstruct tnode {  ElemType data;    //节点的值  struct tnode *hp;     //指向兄弟  struct tnode *vp;     //指向孩子节点} TSBNode;

Please describe this tree using the child brother chain notation when the storage
(5) tree structure can also be used in a child chain notation

//定义孩子节点,将形成一个单链表typedefstruct node{   Int no;   //孩子节点编号      struct node *next;  //指向下一个孩子} NodeType;//定义树节点类型,各节点组成顺序存储的线性表,若节点要作为孩子节点,“孩子节点编号(no)”即为在顺序表中的序号typedefstruct {    ElemType data;   //元素值    NodeType *firstChild;  //指向第一个孩子} CTree[MaxSize];

Please describe this tree using the child's brother chain notation when storing.

2. The sequential storage structure of a binary tree is as follows:

(1) Please use the tree notation to draw the structure of the two-fork tree
(2) in parentheses, give a representation of the binary tree
(3) Please write the first order, the middle order, the sequence of sequential traversal of the binary tree.

3, binary tree can also adopt a "pseudo" chain storage structure, as shown below

Among them, Lchild and rchild are the pointer fields of the child (where the node number is used as the pointer field value, 0 indicates that the pointer field is empty), and data is the node's domain. Please draw a tree representation of this binary tree.

4. The first order, the middle sequence and the sequence order of a binary tree are shown below, and some of them are not shown:
First Order: _b_f_iceh_g
Middle order: d_kfia_ejc_
Post-post: _k_fbhj_g_a
Request the contents of the space and draw a two-fork tree.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Data structure Practice project--tree and 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.