Finding the data structure of the data with high scores Binary tree problems relines, etc. .

Updated on technology 2024-05-10
2 answers
  1. Anonymous users2024-02-10

    A tree can have no nodes called an empty tree, and can have only one node root

    A tree can be divided into multiple sub-tree combinations, and binary trees have left sub-trees and right sub-trees.

    Degree of node:The number of subtrees of this node. In the image above, node 1 has a degree of 5 and node 2 has a degree of 2.

    Degree of the tree:The maximum of all the nodal degrees, the degree of the tree in the image above is 5

    Leaf node:A node with a degree of 0.

    Number of layers:The root node is at the first layer, and the children of the root node are at the second layer. And so on.

    Depth of the node:The maximum of all node depths, the depth of the tree in the graph is 4

    Height of the tree:The maximum of all node heights, the height of the tree in the graph is 4

    Features: The following are all binary trees.

    Features of binary trees:

    All nodes are either 0 or 2

    The last layer node has a degree of 0, and the other nodes have a degree of 2

    Suppose the height of the full binary tree is h(h >=1), then.

    Nodes are numbered from top to bottom and left to right, and all of them can correspond to numbers in a full binary tree of the same height

    The diagram below is not a full binary tree.

    The nature of a complete binary tree.

    Suppose the height of a complete binary tree is h(h >=1), then.

    A complete binary tree (n > 0) with n nodes, numbered from top to bottom, left to right, starting from 1, to any ith node

    A complete binary tree (n > 0) with n nodes, numbered from top to bottom, left to right, starting from 0, for any ith node

    Interview question: If a complete binary tree has 768 nodes, find the number of leaf nodes?

    Solution: 384

    Suppose the number of leaf nodes is n0, the number of nodes with degree 1 is n1, and the number of nodes with degree 2 is n2

    The number of summary points n = n0 + n1 + n2, and n0 = n2 + 1

    So: n = 2n0 + n1 1

    The n1 of a complete binary tree is either 0 or 1

    When n1 is 1, n = 2n0, n must be even.

    The number of leaf nodes n0 = n 2, and the number of non-leaf nodes n1 + n2 = n 2

    When n1 is 0, n = 2n0 1, n must be odd.

    The number of leaf nodes n0 = n + 1) 2, and the number of non-leaf nodes n1 + n2 = n 1) 2

    Number of leaf nodes n0 = floor( ( ( n + 1) 2 ) = ceiling( n 2 )

    Number of non-leaf nodes n1 + n2 = floor( n 2 ) ceiling( ( n 1) 2 ).

  2. Anonymous users2024-02-09

    Basic terms

    Path and path length The branches from one node to another in the tree form the path between the two nodes The number of branches on the path is called the path length The length of the tree's path The sum of the path lengths from the root of the tree to each node The weighted path length of the tree The sum of the weighted path lengths of all leaf nodes in the tree is denoted as.

    The Huffman tree, also known as the optimal binary tree, is the binary tree with the smallest WPL length of the weighted path among all the binary trees composed of n tree leaf nodes.

    Construct a huffman tree

    Huffman's algorithm ( Construct a set of n binary trees according to the given n weights f= where there is only one root node with wi in each binary tree ti Its left and right subtrees are unprecedentedly quiet ( In f, the weights of the two root nodes are selected as the trees with the least reserve as the left and right subtrees to form a new binary tree, and the weights of the root nodes of the new binary tree are the sum of the weights of the root nodes on the left and right subtrees ( Delete the two trees in f and add the new binary tree to f ( Repeat ( ) and ( ) Until f contains only one tree, that tree is the storage structure of the huffman tree.

    Implement the Huffman algorithm.

    lishixinzhi/article/program/sjjg/201311/22685

Related questions
4 answers2024-05-10

Binary tree. The drawing method can be divided into:

1. Determine the root node. >>>More

9 answers2024-05-10

Satisfactory Answer: Telescope Level 8 2010-03-22 Complete Binary Tree. >>>More

9 answers2024-05-10

It is strongly recommended that the landlord make the topic clear, including how to input and what the output format is.

9 answers2024-05-10

A node without a daughter tree is a leaf node.

The degree of a node refers to the number of subtrees of the node, and there is no node with a degree greater than 2 in the binary tree. That is, each node can have a maximum of two subtrees. >>>More

7 answers2024-05-10

The Huffman tree is:

The weighted path length of a tree is the sum of the weighted path lengths of all leaf nodes in the tree, and the weighted path length of a node is the product of the path length from the node to the root node and the weights on the node. >>>More