search
HomeCommon ProblemBinary tree formulas you must understand
Binary tree formulas you must understandJun 22, 2019 am 09:45 AM
Binary treeofficial

Binary tree formulas you must understand

1. Properties of general binary trees

Properties 1. On the i level of a non-empty binary tree, there are at most 2^i nodes .

Property 2. In a binary tree with height K, there are at most 2^(k 1)-1 nodes.

Property 3. For any non-empty binary tree, if the number of leaf nodes is n0 and the number of nodes with degree 2 is n2, then n0=n2 1.

2, Complete Binary Tree

Definition: If in a binary tree, only the degrees of the nodes at the bottom two levels are less than 2, the degrees of the nodes at all other levels are equal to 2, and the nodes of the bottom layer are concentrated in the leftmost positions of the layer, then this binary tree is called a complete binary tree.

Property 1. The height k of a complete binary tree with n nodes is [log^2n].

Property 2. For a complete binary tree with n nodes, if all the nodes in the binary tree are sequenced from top (root node) to bottom (leaf node) and from left to right, Numbering starts from 0 to n-1, then for any node whose subscript is i, there are:

(1) If i=0, it is the root node and it has no parent node; If i>0, then the subscript of its parent node is (i-1)/2.

(2) If 2i 1

(3) If 2i 2

3, Full Binary Tree

Definition: If any node of a binary tree is either a leaf, or has two non-empty subtrees, then this binary tree is called Full binary tree.

Property, in a full binary tree, the number of leaf nodes is 1 more than the number of branch nodes.

4, Expanded Binary Tree

Definition: An expanded binary tree is an expansion of an existing binary tree. After the expansion, the nodes of the original binary tree become branches with degree 2. Node. That is to say, if the degree of the original node is 2, it will remain unchanged; if the degree is 1, then one branch will be added; if the degree is 0, then two branches will be added.

Property 1. In the extended binary tree, the number of external nodes is 1 more than the number of internal nodes.

Property 2. For any extended binary tree, the following relationship is satisfied between the external path length E and the internal path length I: E=I 2n, where n is the number of internal nodes.

For more technical articles related to frequently asked questions, please visit the FAQ column to learn more!

The above is the detailed content of Binary tree formulas you must understand. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
PPT插入公式效果的流程图的详细方法PPT插入公式效果的流程图的详细方法Mar 26, 2024 pm 04:36 PM

1、打开PPT,单击【插入】选项卡,在【插图】组中单击【smartArt】按钮。2、在打开的【选择smartArt图形】对话框中单击【流程】。3、在打开的【流程】窗格中选择【公式】流程图。4、单击【确定】,【公式】流程图便插入到幻灯片窗格。5、在【在此处键入文字】栏【文本】处单击,或单击图形上【文本】,可以输入内容。6、在图形中选择形状,单击【smartArt工具】的【设计】选项卡,在【创建图形】组单击【添加形状】按钮,可以添加形状。7、图形中的形状也可以选择后删除,当然也可以根据需要在smar

Excel表格公式怎么操作Excel表格公式怎么操作Mar 20, 2024 pm 12:07 PM

工作中用到excel软件时,常常要用到函数公式,要想熟练运用excel,就要熟练操作函数公式。对于掌握公式,其实也不是很难的,我们可以从最简单的开始学习,今天小编就来跟大家分享Excel表格公式怎么操作,以乘法公式为例,跟大家一起来学习!1.首先,打开excel,由于我是在这里做演示,所以随便输入了两组数据,现在我们要计算这两组数据的乘积。我们想要算A列和B列的乘积,把单元格放在D4处,如下图红色圈出部分所示:2.然后,在单元格中输入等号,选择第一个参数B4单元格,输入乘号,选择第二个参数C4单

在C语言中打印二叉树的左视图在C语言中打印二叉树的左视图Sep 03, 2023 pm 01:25 PM

任务是打印给定二叉树的左节点。首先,用户将插入数据,从而生成二叉树,然后打印所形成的树的左视图。每个节点最多可以有2个子节点,因此这里程序必须仅遍历与节点关联的左指针如果左指针不为空,则意味着它将有一些与之关联的数据或指针,否则它将是要打印并显示为输出的左子级。示例Input:10324Output:102这里,橙色节点代表二叉树的左视图。在给定的图中,数据为1的节点是根节点,因此它将被打印,而不是转到左子节点,它将打印0,然后它将转到3并打印其左子节点,即2。我们可以使用递归方法来存储节点的级

Java中的二叉树结构详解Java中的二叉树结构详解Jun 16, 2023 am 08:58 AM

二叉树是计算机科学中常见的数据结构,也是Java编程中常用的一种数据结构。本文将详细介绍Java中的二叉树结构。一、什么是二叉树?在计算机科学中,二叉树是一种树形结构,每个节点最多有两个子节点。其中,左侧子节点比父节点小,右侧子节点则比父节点大。在Java编程中,常用二叉树表示排序,搜索以及提高对数据的查询效率。二、Java中的二叉树实现在Java中,二叉树

在C语言中,将二叉树的右视图打印出来在C语言中,将二叉树的右视图打印出来Sep 16, 2023 pm 11:13 PM

任务是打印给定二叉树的右节点。首先用户将插入数据以创建二叉树,然后打印所形成的树的右视图。上图展示了使用节点10、42、93、14、35、96、57和88创建的二叉树,其中选择并显示在树的右侧的节点。例如,10、93、57和88是二叉树的最右节点。示例Input:1042931435965788Output:10935788每个节点都有两个指针,即左指针和右指针。根据这个问题,程序只需遍历右节点。因此,不需要考虑节点的左子节点。右视图存储了所有那些是其所在层级的最后一个节点的节点。因此,我们可以

公式vlookup怎么用公式vlookup怎么用Feb 19, 2024 pm 10:37 PM

公式VLOOKUP是微软Excel中非常常用的一个函数,它用于在一个表格或数据集中查找特定的值,并返回与之相关联的其他值。在本篇文章中,我们将学习如何正确使用VLOOKUP公式。VLOOKUP函数的基本语法如下:VLOOKUP(lookup_value,table_array,col_index_num,[range_lookup])其中:lookup

二叉树中等腰三角形的数量二叉树中等腰三角形的数量Sep 05, 2023 am 09:41 AM

二叉树是一种数据结构,其中每个节点最多可以有两个子节点。这些孩子分别称为左孩子和右孩子。假设我们得到了一个父数组表示,您必须使用它来创建一棵二叉树。二叉树可能有几个等腰三角形。我们必须找到该二叉树中可能的等腰三角形的总数。在本文中,我们将探讨几种在C++中解决这个问题的技术。理解问题给你一个父数组。您必须以二叉树的形式表示它,以便数组索引形成树节点的值,而数组中的值给出该特定索引的父节点。请注意,-1始终是根父节点。下面给出的是一个数组及其二叉树表示。Parentarray=[0,-1,3,1,

如何使用Python实现二叉树的遍历如何使用Python实现二叉树的遍历Jun 09, 2023 pm 09:12 PM

作为一种常用的数据结构,二叉树经常被用来存储数据、搜索和排序。遍历二叉树是非常常见的操作之一。Python作为一种简单易用的编程语言,有许多方法可以实现二叉树的遍历。本文将介绍如何使用Python实现二叉树的前序、中序和后序遍历。二叉树的基础在学习二叉树的遍历之前,我们需要了解二叉树的基本概念。二叉树由节点组成,每个节点都有一个值和两个子节点(左子节点和右子

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft