Data structure notes 6 trees and binary trees

Data structure notes 6 trees and binary trees

Preface

Data structure notes 5 array

Write a note about trees and binary trees.

Mental framework

Tree definition and basic terminology

Tree definition and basic terminology

Binary tree

Binary tree

Traverse binary trees and trail binary trees

Traverse binary trees and trail binary trees

Trees and forests and huffman trees

Six, trees and binary trees

exercise

Multiple choice

\12. In a binary tree with n nodes, the number of null pointer fields is ________.

A) 2n+1 B) n-1 C) n+1 D) Not sure

13. If the binary tree T is converted from the polytree F, then the leaves of the tree F should be nodes that meet the condition of _________ in the binary tree T.

A) The left subtree is empty and the right subtree is not empty B) The left and right subtrees are both empty

C) The left subtree is empty. D) The right subtree is empty.

14. It is known that the post-order sequence of the binary tree is: FDEBHGCA, and the middle-order sequence is: BFEDAGHC, then the pre-order sequence is: _________.

A)ABEDFGCH B)ABCEGFDH

C)ABCEFDGH D)ABEFDCGH

15. In a binary tree with a total of 23 nodes, except for the nodes with degree 2 in the tree, all are leaf nodes, then the number of leaf nodes in the tree is _________.

A)9 B)10 C)11 D) 12

\16. If the binary tree T is converted from the polytree F, then the post-root sequence of the tree F should be the _________ of the binary tree T.

A) Hierarchical traversal sequence B) Preorder sequence

C) Middle sequence D) Post sequence

\17. The depth of a complete binary tree with 64 nodes is _______.

​ A) 5 B) 6 C) 7 D) 8

​ ( n=2K-1)

\18. A binary tree with 3 nodes has ______ kinds of forms.

A) 3 B) 4 C) 5 D) 6

\19. If a binary tree has 10 nodes with degree 2 and 5 nodes with degree 1, the number of nodes with degree 0 is ()

​ A) 9 B) 11 C) 15 D) Not sure

20. In a 4-ary tree with 13 nodes, all nodes except leaf nodes have a degree of 4, so the number of leaf nodes in the tree is _____.

​ A)8 B)9 C)10 D) 11

\21. A binary tree with a depth of h, the maximum number of nodes is _______.

A)2h+1 B)2h-1 C)2h+1 D)2h-1

12.C 13.C 14.D 15.D 16.C 17.C 18.C 19.B 20.C

21.D

True or False

() A polytree is converted into a binary tree, and the root node of the binary tree must not have a right subtree.

() Binary trees can only be stored in a chain structure, and cannot be stored in a sequential storage structure.

() There can be at most one node with degree 1 in a complete binary tree.

() There must be no node with degree 1 in the complete binary tree.

() The depth of a binary tree with n nodes must be less than n.

9.√ 10.X

\11. √ 12. X 13. X

Short answer

Tree leaf node

Write a recursive algorithm to find the value of the node at the kth position in the preorder traversal in the binary tree.

Write a recursive algorithm to count the number of leaf nodes in the binary tree

Write a recursive algorithm to exchange the left and right subtrees of all nodes in the binary tree.

Write the first and last root sequences of the tree

to sum up

The main test points of tree and binary tree are the nature of binary tree, binary tree traversal, conversion of binary tree and forest, and Huffman tree.

I have learned the first five parts so far. If you take a closer look, they are actually related to each other. Data structure note 1 Introduction to popular science on the concept of data structure and time complexity; data structure note 2 linear table explains the simplest sequence structure and chain structure; data structure note 3 stack and queue explain the linear structure commonly used in life (Recursion, Queue); Data Structure Note 4 explains the data structure of strings, which is also a data structure commonly used in life-text; Data Structure Note 5 Array explains the data structure of arrays, which is the basis of graphics processing- Two-dimensional array;

This part is a tree and a binary tree, which are actually commonly used in traversal. In Vue, the virtual DOM tree is used to select the best rendering method through internal calculations.

The virtual DOM greatly improves the performance of modifying HTML elements, making web pages more responsive.

The DOM is stored in memory and provides a series of APIs for manipulating and modifying HTML elements. DOM operation is the core of front-end development. The earliest popular front-end frameworks are known for their excellent DOM operations, such as jQuery. Compared with JavaScript logic, the performance consumption of DOM operations is very high. In the era of webpages dominated by static content, the performance loss of a small number of DOM operations can basically be ignored. However, for webapps with rich dynamic content, a large amount of frequent DOM Operations gradually became a performance bottleneck.

The core of virtual DOM technology is to create a lightweight clone of the DOM object. The virtual DOM has all the attributes of the original DOM except the API for manipulating HTML elements. For JavaScript, the virtual DOM is just an object with rich attributes, and all operations on the DOM are mapped to the modification of the JavaScript object, and the performance is much better than the operation on the DOM directly. After receiving dynamic data or user operations, Vue or react will update the virtual DOM tree in memory, compare and check the affected objects, and then modify the real DOM corresponding to these objects. Thanks to the diff algorithm of Vue or react, the full update strategy can be adopted and the comparison performance can be guaranteed.

This part is temporarily written here.

Update address: GitHub

For more content, please pay attention: CSDN , GitHub , Nuggets

Guess you like

Origin blog.csdn.net/weixin_42875245/article/details/109179045