In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
What is the tree and binary tree in Python? aiming at this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible method.
Tree is a kind of important nonlinear data structure, which is a hierarchical structure defined by branch relationship.
Definition:
A tree (tree) is a finite set T of n (n > 0) nodes, where there is and only one specific node, called the root of the tree.
When n > 1, the rest of the nodes can be divided into m (m > 0) disjoint finite sets T1, T2, …... Tm, in which each set itself is a tree, called the subtree of the root
Features: there is at least one node in the tree-the subtrees in the root tree are disjoint sets.
Basic terminology
Node (node)-represents the elements in the tree, including data items and branches pointing to their subtrees
The degree of the node (degree)-the number of subtrees and leaves of the node (leaf)-the node with degree 0
Child (child)-the root of the node tree is called the child of the node
Parents (parents)-the upper node of the child node is called the node.
Sibling-- A child of the same parent
The degree of a tree-the largest node degree in a tree
The level of the node-from the root node, the root is the first layer, and its child is the second layer.
Depth (depth)-the maximum number of layers of nodes in the tree
Forest (forest)-- A collection of m (m 0) disjoint trees
A binary tree is a set of finite elements, which is either empty or consists of an element called root and two disjoint binary trees called left subtree and right subtree, respectively.
Each node of a binary tree has at most two subtrees (there are no nodes with a degree greater than 2). The subtrees of a binary tree can be divided into left and right, and the order can not be reversed.
The level I of the binary tree has at most 2 ^ {imur1} nodes.
A binary tree with depth k has at most 2 ^ k-1 nodes.
For any binary tree T, if the number of terminal nodes is N0 and the number of nodes with degree 2 is N2, then N0=N2+1
Traversing binary tree
Preorder traversal
If the tree is empty, the empty operation returns. Otherwise, first visit the root node, then preorder traverse the left subtree, and then preorder traverse the right subtree. Type (W) (center, left, right)
Mid-order traversal
If the tree is empty, the empty operation returns. Otherwise, start with the root node (note that you don't visit the root node first), iterate through the left subtree of the root node, then access the root node, and finally traverse the right subtree of the root node. Type (M), (left, middle and right)
Subsequent traversal
If the tree is empty, the empty operation returns. Otherwise, it traverses the left and right subtrees from left to right, leaves first and then nodes, and finally accesses the root node. (left and right center) counterclockwise (left and right center)
Sequence traversal
If the tree is empty, the empty operation returns. Otherwise, access starts from the first layer of the tree, that is, the root node, traversing layer by layer from top to bottom, and nodes are accessed one by one in the same layer in the order from left to right.
The answer to the question about the tree and binary tree in Python is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.