二叉树和红黑树

平衡二叉树和红黑树 目录 一、平衡二叉树 1. 二叉树 2. 平衡二叉树 二、红黑树 1.2-3-4树 (1)简介 (2)三种节点的示意图 (3)构建2-3-4树 2. 红黑树 (1)红黑树的特征 (2)从2-3-4树到红黑树 (3)通过2-3-4树构建红黑树 一、平衡二叉树 1. 二叉树 讲述平衡二叉树之前,先说一说二叉树。在计算机科学中,二叉树是每个结点最多有两个子树的有序树。通常子树的根被称作“左子树”(left subtree)和“右子树”(right s... 阅读详情
                          二叉树和红黑树
  An Introduction to Binary Search and Red-Black Trees

Author
By  cpphamza
TopCoder Member

As a programmer, you'll frequently come across tasks that deal with a number of objects -- numbers, strings, people, and so forth -- and that require you to store and process those objects. If you need to maintain a list of objects that are sorted and unique, and if you need to be able to quickly insert and retrieve objects to and from this list, the ideal data structure will be a tree set (or a tree map, if you consider each object a key and associate another object called a value to it).

Many programming languages provide built-in support for tree-based sets and maps -- for instance, Java's TreeSet/TreeMap classes and the C++ Standard Template Library's set and map classes -- but because of their common use, it's easy to misunderstand what actually happens behind the scenes, and how the underlying data structures actually work. That’s what this article is all about.

We'll start off by looking at some of the general terms and concepts used in dealing with trees We'll then focus on binary search trees (BST), a special type of tree that keeps elements sorted (but doesn’t guarantee efficient insertion and retrieval). Finally we'll look at red-black trees, a variation of binary search trees that overcome BST's limitations through a logarithmic bound on insertion and retrieval.

Trees terminology

A tree is a data structure that represents data in a hierarchical manner. It associates every object to a node in the tree and maintains the parent/child relationships between those nodes. Each tree must have exactly one node, called the root, from which all nodes of the tree extend (and which has no parent of its own). The other end of the tree – the last level down -- contains the leaf nodes of the tree.


The number of lines you pass through when you travel from the root until you reach a particular node is the depth of that node in the tree (node G in the figure above has a depth of 2). The height of the tree is the maximum depth of any node in the tree (the tree in Figure 1 has a height of 3). The number of children emanating from a given node is referred to as its degree -- for example, node A above has a degree of 3 and node H has a degree of 1.

Binary Search Tree (BST)

A binary search tree is a tree with one additional constraint -- it keeps the elements in the tree in a particular order. Formally each node in the BST has two children (if any are missing we consider it a nil node), a left child and a right child. Nodes are rooted in place based on their values, with the smallest on the left and largest on the right.


Traversing BST

A common requirement when using sets and maps is to go through the elements in order. With binary search trees, traversing from left to right is known as inordertree traversal. In a tree where each node has a value and two pointers to the left and right children, inorder tree traversal can be thought of as:

    Procedure Inorder_traversal(Node n) 
if(n == nil)
return;
Inorder_traversal(n.left_subtree);
Print(n.value);
Inorder_traversal(n.right_subtree);
…
Inorder_traversal(root);

Operations on BST (insertion, deletion and retrieval)

BST insertion:
When adding a new node to a binary search tree, note that the new node will always be a leaf in the tree. To insert a new node, all we will do is navigate the BST starting from the root. If the new node value is smaller than the current node value, we go left – if it is larger, we go right. When we reach a leaf node, the last step is to attach the new node as a child to this leaf node in a way that preserves the BST constraint.

For example, consider we want to add a new node with value 4 to the BST in Figure 1. Here are the steps we will go through:

  • Let the current node = root = 5.
  • As the new node is smaller than the current node (4 < 5), we will go left and set current node to 2.
  • As the new node is greater than current node (4 > 2), we will go right and set the current node to 3.
  • We've reached a leaf, so the last step is to attach the new node to the right of the current node. Here is how the new BST looks:

BST Deletion:
Deleting a node from BST is a little more subtle. Formally there are three cases for deleting node n from a BST:

  • If n has no children, we only have to remove n from the tree.
  • If n has a single child, we remove n and connect its parent to its child.
  • If n has two children, we need to :
    • Find the smallest node that is larger than n, call it m.
    • Remove m from the tree (if you have reached this case then m will always have no left child, though I'll leave the proof to the reader), so we apply one or the other of the above cases to do this.
    • Replace the value of n with m.

Figure 4 shows these three cases in action.


BST Retrieval:
Retrieving an element from binary search trees requires simple navigation, starting from the root and going left, if the current node is larger than the node we are looking for, or going right otherwise.

Any of these primitive operations on BST run in O(h) time, where h is the tree height, so the smaller the tree height the better running time operations will achieve. The problem with BST is that, depending on the order of inserting elements in the tree, the tree shape can vary. In the worst cases (such as inserting elements in order) the tree will look like a linked list in which each node has only a right child. This yields O(n) for primitive operations on the BST, with n the number of nodes in the tree.

To solve this problem many variations of binary search trees exist. Of these variations, red-black trees provide a well-balanced BST that guarantees a logarithmic bound on primitive operations.

Red-black Trees

Red-black trees are an evolution of binary search trees that aim to keep the tree balanced without affecting the complexity of the primitive operations. This is done by coloring each node in the tree with either red or black and preserving a set of properties that guarantee that the deepest path in the tree is not longer than twice the shortest one.

A red-black tree is a binary search tree with the following properties:

  1. Every node is colored with either red or black.
  2. All leaf (nil) nodes are colored with black; if a node’s child is missing then we will assume that it has a nil child in that place and this nil child is always colored black.
  3. Both children of a red node must be black nodes.
  4. Every path from a node n to a descendent leaf has the same number of black nodes (not counting node n). We call this number the black height of n, which is denoted by bh(n).

Figure 5 shows an example of a red-black tree.


Using these properties, we can show in two steps that a red-black tree which contains n nodes has a height of O(log n), thus all primitive operations on the tree will be of O(log n) since their order is a function of tree height.

  1. First, notice that for a red-black tree with height h, bh(root) is at least h/2 by property 3 above (as each red node strictly requires black children).
  2. The next step is to use the following lemma:
    • Lemma: A subtree rooted at node v has at least 2^bh(v) – 1 internal nodes
    • Proof by induction: The basis is when h(v) = 0, which means that v is a leaf node and therefore bh(v) = 0 and the subtree rooted at node v has 2^bh(v)-1 = 2^0-1 = 1-1 = 0 nodes.
    • Inductive hypothesis: if node v1 with height x has 2^bh(v1)-1 internal nodes then node v2 with height x+1 has 2^bh(v2)-1

For any non-leaf node v (height > 0) we can see that the black height of any of its two children is at least equal to bh(v)-1 -- if the child is black, that is, otherwise it is equal to bh(v) . By applying the hypothesis above we conclude that each child has at least 2^[bh(v)-1]-1 internal nodes, accordingly node v has at least
2^[bh(v)-1]-1 + 2^[bh(v)-1]-1 + 1 = 2^bh(v)-1
internal nodes, which ends the proof.

By applying the lemma to the root node (with bh of at least h/2, as shown above) we get
n >= 2^(h/2) – 1
where n is the number of internal nodes of a red-black tree (the subtree rooted at the root). Playing with the equation a little bit we get h <= 2 log (n+1), which guarantees the logarithmic bound of red-black trees.

Rotations

How does inserting or deleting nodes affect a red-black tree? To ensure that its color scheme and properties don't get thrown off, red-black trees employ a key operation known as rotation. Rotation is a binary operation, between a parent node and one of its children, that swaps nodes and modifys their pointers while preserving the inorder traversal of the tree (so that elements are still sorted).

There are two types of rotations: left rotation and right rotation. Left rotation swaps the parent node with its right child, while right rotation swaps the parent node with its left child. Here are the steps involved in for left rotation (for right rotations just change "left" to "right" below):

  • Assume node x is the parent and node y is a non-leaf right child.
  • Let y be the parent and x be its left child.
  • Let y’s left child be x’s right child.

Operations on red-black tree (insertion, deletion and retrieval)

Red-black tree operations are a modified version of BST operations, with the modifications aiming to preserve the properties of red-black trees while keeping the operations complexity a function of tree height.

Red-black tree insertion:
Inserting a node in a red-black tree is a two step process:

  1. A BST insertion, which takes O(log n) as shown before.
  2. Fixing any violations to red-black tree properties that may occur after applying step 1. This step is O(log n) also, as we start by fixing the newly inserted node, continuing up along the path to the root node and fixing nodes along that path. Fixing a node is done in constant time and involves re-coloring some nodes and doing rotations.

Accordingly the total running time of the insertion process is O(log n). Figure 7 shows the red-black tree in figure 5 before and after insertion of a node with value 4. You can see how the swap operations modified the tree structure to keep it balanced.


Red-black tree deletion:
The same concept behind red-black tree insertions applies here. Removing a node from a red-black tree makes use of the BST deletion procedure and then restores the red-black tree properties in O(log n). The total running time for the deletion process takes O(log n) time, then, which meets the complexity requirements for the primitive operations.

Red-black tree retrieval:
Retrieving a node from a red-black tree doesn’t require more than the use of the BST procedure, which takes O(log n) time.

Conclusion

Although you may never need to implement your own set or map classes, thanks to their common built-in support, understanding how these data structures work should help you better assess the performance of your applications and give you more insight into what structure is right for a given task. For more practice with these concepts, check out these problems from the TopCoder archive that involve trees:

References

  • "Data Structures via C++: Objects by Evolution," by A. Michael Berman
  • "Fundamentals in Data Structures in C++, Second Edition," by Ellis Horowitz, Sartaj Sahni and Dinesh P. Mehta 
  • "Introduction to Algorithms, Second Edition," by Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest and Clifford Stein.  
  • 另外维基上讲得也很详细http://en.wikipedia.org/wiki/Red-black_tree

Comparison to other structures

Both AVL trees and red-black trees are self-balancing binary search trees, so they are very similar mathematically. The operations to balance the trees are different, but both occur in constant time. The real difference between the two is the limiting height. For a tree of size n:

  • an AVL tree's height is limited to 1.44 /cdot /lg n
  • a red-black tree's height is limited to 2 /cdot /lg n

The AVL tree is more rigidly balanced than Red-Black trees, leading to slower insertion and removal but faster retrieval.


红黑树和二叉树有什么区别 红黑树和二叉树有什么区别? 什么是二叉树?什么是红黑树? 二叉树(Binary Tree)是指每个节点最多只有两个分支的树结构,即不存在分支大于 2 的节点,二叉树的数据结构如下图所示 这是一棵拥有 6 个节点深度为 2(深度从 0 开始),并且根节点为 3 的二叉树 二叉树有两个分支通常被称作 “左子树” 和 “右子树”,而且这些分支具有左右次序不能随意地颠倒 一棵空树或者满足以下性质的二叉树被称之为二叉查找树 若任意节点的左子树不为空,则左子树上所有节点的值均小于它的根节点的值; 若任意节点的 阅读详情

相关推荐

保姆级教程:在Ubuntu 22.04上搞定PX4 V1.14 + ROS2 Humble的HITL仿真(避坑实录)

本文提供在Ubuntu 22.04上配置PX4 V1.14与ROS2 Humble的HITL仿真环境的详细教程,涵盖环境准备、固件编译、QGroundControl配置、ROS2通信设置及联调测试。特别针对版本兼容性、Gazebo插件构建和MicroDDS配置等常见问题提供避坑指南,帮助开发者高效搭建无人机仿真系统。

weixin_30836759的博客 1004

二叉树与红黑树

二叉树的形成 二叉树是n(n>=0)个结点的有限集合,该集合或者为空集(称为空二叉树),或者由一个根结点和两棵互不相交的、分别称为根结点的左子树和右子树组成 二叉树特点 由二叉树定义以及图示分析得出二叉树有以下特点: 1)每个结点最多有两颗子树,所以二叉树中不存在度大于2的结点。 2)左子树和右子树是有顺序的,次序不能任意颠倒。 3)即使树中某结点只有一棵子树,也要区分它是左子树还是右子树 3.3 二叉树性质 1)在二叉树的第i层上最多有2i-1 个节点 。(i>=1) 2)二叉树中如果深度为k

小清新的博客 3159

AD9361快速锁定实战:Profile寄存器配置与频率调谐算法解析

本文深入解析了AD9361射频收发器的快速锁定(Fast Lock)功能,重点阐述了其核心机制——Profile寄存器配置。通过剖析16字节Profile结构,详细讲解了频率调谐算法,包括LO_DIV、LO_INT、LO_FRAC等关键参数的计算,以及如何通过查表获取优化的环路滤波器参数。文章提供了完整的Python算法示例和FPGA实现要点,旨在帮助工程师实现毫秒级甚至微秒级的频率切换,满足跳频通信等高性能应用需求。

weixin_29196315的博客 229

最全面 | 二叉树与红黑树

本文整理了二叉树以及由二叉树演变的满二叉树、完全二叉树、平衡二叉树、二叉排序/搜索/查找树、AVL树、B树、2-3 B树、红黑树、线索二叉树等各种树形结构,帮助新手快速全面对树形数据结构的入门理解。

Flashing-C的博客 1926

Orange:一个基于 Python 的数据挖掘和机器学习平台

Orange是一个开源的数据挖掘和机器学习平台,采用可视化编程方式,用户可通过拖拽组件构建数据分析工作流。它支持交互式数据探索、多种机器学习算法,并允许Python脚本扩展。Orange特别适合教育和研究,提供直观的界面和丰富的可视化工具。最新版本为3.39.0,支持Windows、macOS和Linux系统。作为GPL许可的免费工具,它既能满足初学者需求,又能通过Python集成实现高级功能。

likuoelie的博客 1437

UE5新手必看:如何用蓝图系统快速打造赛车游戏(含Chaos Physics配置)

本文为UE5新手提供使用蓝图系统快速打造赛车游戏的完整指南,涵盖Chaos Physics配置、载具蓝图架构设计、控制逻辑实现等关键步骤。通过详细的实战案例和优化技巧,帮助开发者高效构建具备专业物理反馈的赛车游戏原型。

weixin_29001327的博客 387

二叉树与红黑树见解

红黑树是一种自平衡的二叉查找树,是一种高效的查找树。红黑树具有良好的效率,它可在 O(logN) 时间内完成查找、增加、删除等操作1。大家应该都学过平衡二叉树(AVLTree),了解到AVL树的性质,其实平衡二叉树最大的作用就是查找,AVL树的查找、插入和删除在平均和最坏情况下都是O(logn)。AVL树的效率就是高在这个地方。如果在AVL树中插入或删除节点后,使得高度之差大于1。此时,AVL树的平衡状态就被破坏,它就不再是一棵二叉树;

Ge_yangwen的博客 2147

STM32F103移植NuttX实战:从零搭建最小系统到串口Shell(附完整配置文件)

本文详细介绍了在STM32F103C8T6开发板上移植NuttX实时操作系统的完整过程,包括环境搭建、BSP配置、系统时钟初始化、驱动裁剪、编译烧录及串口Shell交互。通过实战指南帮助开发者快速掌握NuttX移植技巧,解决典型问题,适用于嵌入式系统开发。

tree8的博客 293

二叉树、红黑树介绍

红黑树介绍 一.红黑树的性质: 1).每个节点是红的或黑的 2).根节点一定黑的 3).每个叶节点是黑的 4).如果一个节点是红的,则它的两个儿子都是黑的 5)对每个节点,从该节点到其子孙节点的所有路径上的包含相同数目的黑节点。 ...

weixin_42252757的博客 1094

C#上位机项目实战(32)——如何防止winform程序因为误操作被关闭

我们在开发的上位机软件运行起来以后,一般在右上角都有一个关闭按钮,正常情况下点击关闭按钮就能关闭软件,但是不排除我们不想关闭软件,但是因为不小心把鼠标点到了关闭按钮,如果这是一个正在生产的机器,突然关闭软件可能会导致产品损坏,那么我们如何去解决这个误操作的问题呢,本文就来讲解解决方案!

qq_34059233的博客 683

基于YOLOv8改进的目标检测算法研究及毕设实现全流程指南

在PyTorch中定义改进后的YOLOv8模型。首先,导入相关的库和模块,然后定义骨干网络、颈部和头部的结构。# 这里定义骨干网络的结构,例如使用改进的CSP结构# 卷积层、批归一化层、激活函数等# 更多的卷积层、批归一化层、激活函数等# 其他层...# 其他层的输出...然后,定义颈部和头部的结构,类似地,将注意力机制和特征增强方法集成到模型中。本毕设以YOLOv8为基础,通过集成注意力机制、应用特征增强技术等方法,改进了目标检测算法。

m0_64661770的博客 325

二叉树、红黑树 详解

树的特点:二叉树就是度不超过2的树(每个节点最多有两个子节点)一个二叉树,如果每一个层的节点树都达到最大值,则这个二叉树就是满二叉树。每一层节点个数为:2的k次方-1;k为层数;叶节点只能出现在最下层和次下层,并且最下面一层的节点都集中在该层最左边的若干位置的二叉树;之前我们学习过二叉查找树,发现它的查询效率比单纯的链表和数组的查询效率要高很多,大部分情况下,确实是这样的,但不幸的是,在最坏情况下,二叉查找树的性能还是很糟糕。 我们会发现,如果我们要查找1这个元素,查找的效率依旧会很低。...

王林的博客 983

3、利用预训练卷积神经网络进行特征提取

本文介绍了如何使用预训练的卷积神经网络(如VGG16)进行图像特征提取,并将提取的特征存储在HDF5数据集中,以便后续用于机器学习模型的训练。文章详细阐述了特征提取的原理、HDF5数据格式的优势、HDF5DatasetWriter类的实现、特征提取流程的代码实现以及实际应用案例。通过该方法,可以在多种图像数据集上高效构建高精度的分类模型。

z2a3b4c5d的博客 116

红黑树和二叉树有什么区别?

红黑树和二叉树有什么区别? 什么是二叉树?什么是红黑树? 二叉树(Binary Tree)是指每个节点最多只有两个分支的树结构,即不存在分支大于 2 的节点,二叉树的数据结构如下图所示 这是一棵拥有 6 个节点深度为 2(深度从 0 开始),并且根节点为 3 的二叉树 二叉树有两个分支通常被称作“左子树”和“右子树”,而且这些分支具有左右次序不能随意地颠倒 一棵空树或者满足以下性质的二叉树被称之为二叉查找树 若任意节点的左子树不为空,则左子树上所有节点的值均小于它的根节点的值; 若任

vincent_wen0766的博客 1万+

IDEA的使用指南

IDEA基于java的使用手册,可以最快速的上手,在使用中不断的丰富自己的使用技巧.

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

Java二叉树和红黑树

目录 1 二叉树 2 二叉查找树 3 平衡二叉树 4 红黑树 笔者会据需补充二叉树的相关一系列知识,先更新最基本的二叉树的知识. 1 二叉树 二叉树的特点 二叉树中,任意一个节点的度要小于等于2 节点: 在树结构中,每一个元素称之为节点 度: 每一个节点的子节点数量称之为度 左子节点 右子节点 值 父节点 定义时一个节点四个变量 二叉树结构图 2 二叉查找树 二叉查找树的特点.

赵广陆 1198

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

二叉树和红黑树的原理及实现

二叉树和红黑树的原理及实现 二叉树的原理及作用 二叉树是一种特殊的树状结构,每一个结点最多只有两个孩子,左孩子比父结点小,右孩子比父结点大,所有结点都满足当前性质,等于父结点的情况可以放在右边也可以放在左边,放在右边可以保持稳定性。 可以用作非线性存储结构的快速查找,在非线性结构中,二叉树对数据进行排序,查找的效率从理论上说的O(log(n)),具有和二分查找同样的性质。但是二叉树会有极端情况,就是输入的数据相对有序,这样就趋近于线性表,查找速度趋近O(n)。有AVL(二叉平衡树)、红黑树等数据结构,基于二

qq_38430038的博客 681

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

完全理解红黑树和二叉树

完全理解和,需要从基础概念、特性、操作到应用场景逐步深入。:如果插入的数据是有序的(如),BST 会退化为链表,时间复杂度从O(log n)退化为O(n)。:使用(如红黑树、AVL 树)。O(log n)

2301_81675556的博客 690

回顾Java基础——二叉树和红黑树

二叉树 二叉树是树的特殊一种,具有如下特点: 1、每个结点最多有两颗子树,结点的度最大为2。 2、左子树和右子树是有顺序的,次序不能颠倒。3、即使某结点只有一个子树,也要区分左右子树。 一、特殊的二叉树及特点 1、斜树 所有的结点都只有左子树(左斜树),或者只有右子树(右斜树)。这就是斜树,应用较少 2、满二叉树 所有的分支结点都存在左子树和右子树,并且所有的叶子结点都在同一层上,这样就是满二叉树。就是完美圆满的意思,关键在于树的平衡。 根据满二叉树的定义,得到其特点为: 叶子只能出现在最下一层。 非

zhangCheng的博客 559

平衡二叉树和红黑树的区别

插入和删除操作的复杂度:在平衡二叉树中,插入和删除操作的平均时间复杂度是O(log n),其中n是树中的节点数。总的来说,平衡二叉树和红黑树都是用于在动态情况下维护有序数据集的自平衡二叉搜索树,它们在平衡性要求、插入和删除操作的复杂度以及空间复杂度等方面存在差异。对于特定的操作:平衡二叉树在某些特定操作上可能比红黑树更高效,因为平衡二叉树不需要进行颜色调整和旋转操作,这些操作在红黑树中可能需要。而红黑树由于需要额外的颜色属性,因此在每个节点上需要存储额外的信息,使得红黑树的空间占用更高。

斯坦福-MIT-Harvard-CMU 4412

C++面试:二叉树和红黑树

基本概念:二叉树是一种树形结构,其中每个节点最多有两个子节点,分别称为“左子节点”和“右子节点”。特殊类型完全二叉树:除了最后一层外,每一层都被完全填满,且所有节点都尽可能地向左对齐。满二叉树:所有非叶子节点都有两个子节点,所有叶子节点都在同一层级。平衡二叉树(AVL树):任何节点的两个子树的高度差不超过1。首先,定义红黑树的节点结构和基本的红黑树类:int data;bool color;

Bobowen的博客 1535

红黑树与平衡二叉树的原理和区别

[json](https://www.jsonbest.com/zh)一.平衡二叉树 平衡二叉树或者是空树,或者是具有如下特征的二叉排序树: (1 )左子树和右子树的深度之差的绝对值不超过1; (2)左子树和右子树也是平衡二叉树。 若将二叉树上结点的平衡因子(Balance F a ctor, BF)定义为该结点左子树和右子树的深度之 差,则平衡二叉树上所有结点的平衡因子只可能觅-1、0和1。只要二叉树上有一个结点的平衡 因子的绝对值大于1 , 则该二叉树就是不平衡...

Light 7196

mysql红黑树_mysql二叉树和红黑树的区别是什么?

小伙伴们知道mysql中二叉树和红黑树的区别吗?虽然它们都沾着一个树字,但区别可不小,本篇文章就跟着小编来瞧瞧它们的区别吧。二叉树二叉树,指在计算机科学中的一种树结构,这种树结构每个结点最多有两个子树,一般被称为左子树(left subtree)与右子树(rightsubtree)。在二叉树层中,一棵深度为k,且具有2^k-1个结点的二叉树,被称为满二叉树。这种树的特点是每一层的结点数都是最大结点...

weixin_35396246的博客 1096

排序二叉树 和 红黑树

1.链表和数组的区别: 数组: ​ 利用索引(下标)随机访问。 ​ 数组要求分配一块连续的地址空间,每一个元素是顺序相临的。 ​ 插入与删除需要对整个数组进行调整(也就是说,需要移动各个元素)。 ​ 链表: ​ 只能够顺序查找。   ​ 链表不要求一块连续的地址空间,也就是说,元素是分开存放的。 ​ 链表的插入与删除效率非常高(只需要改变指针的指向)。 2.排序二叉树(查找二叉树) ​ (1)树(了解) ​ ​ (2)什么是排序二叉树? ​ (3)二叉树的遍历 ​ 1)先序

qq_43541242的博客 498

红黑树和平衡二叉树有什么区别?

数据结构属于理解一些源码和技术所必备的知识,比如要读懂 Java 语言中 TreeMap 和 TreeSet 的源码就要懂红黑树的数据结构,不然是无法理解源码中关于红黑树数据的操作代码的,比如左旋、右旋、添加和删除操作等。因此我们就来学习一下数据结构的基础知识,方便看懂源码或者是防止面试中被问到。 红黑树和二叉树有什么区别? 典型回答 要回答这个问题之前,我们先要弄清什么是二叉树?什么是红黑树? 二叉树(Binary Tree)是指每个节点最多只有两个分支的树结构,即不存在分支大于 2 的节点,二叉树的数据

Andrew.J 2108
上一篇: pku2406 Power Strings(kmp字符匹配,next数组)
下一篇: 基于频繁增长树(FP-树)的频繁项集挖掘算法实现
J_Factory
博客等级 码龄19年 24粉丝 49原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值