【面试】介绍二叉搜索树(中英)

中文

二叉搜索树(Binary Search Tree,BST) 是一种特殊的二叉树,它满足以下性质:

  1. 对于任意一个节点,其左子树上所有节点的值都小于该节点的值。
  2. 对于任意一个节点,其右子树上所有节点的值都大于该节点的值。
  3. 左右子树本身也是二叉搜索树。
时间复杂度
  • 查找:在理想情况下(树是平衡的),查找的时间复杂度为 O ( log ⁡ n ) O(\log n) O(logn),其中 n n n 是树中节点的数量。最坏情况下(树退化为链表),查找的时间复杂度为 O ( n ) O(n) O(n)
  • 插入:插入操作的时间复杂度与查找操作相同,为 O ( log ⁡ n ) O(\log n) O(logn) O ( n ) O(n) O(n)
  • 删除:删除操作的时间复杂度也与查找操作相同,为 O ( log ⁡ n ) O(\log n) O(logn) O ( n ) O(n) O(n)

English Version

A Binary Search Tree (BST) is a special kind of binary tree that satisfies the following properties:

  1. For any given node, all nodes in its left subtree have values less than the node’s value.
  2. For any given node, all nodes in its right subtree have values greater than the node’s value.
  3. Both the left and right subtrees are also binary search trees.
Time Complexity:
  • Search: In the best case (when the tree is balanced), the time complexity for searching is O ( log ⁡ n ) O(\log n) O(logn), where n n n is the number of nodes in the tree. In the worst case (when the tree degenerates into a linked list), the time complexity is O ( n ) O(n) O(n).
  • Insertion: The time complexity for insertion is the same as for searching, O ( log ⁡ n ) O(\log n) O(logn) or O ( n ) O(n) O(n).
  • Deletion: The time complexity for deletion is also the same as for searching, O ( log ⁡ n ) O(\log n) O(logn) or O ( n ) O(n) O(n).
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值