一、数据库索引的实现原理
推荐阅读:MySQL索引背后的数据结构及算法原理
摘录:
- 数据库索引,是数据库管理系统中一个排序的数据结构,以协助快速查询、更新数据库表中数据。索引的实现通常使用B树及其变种B+树。
- 设置索引要付出代价:一是增加了数据库的存储空间,二是在插入和修改数据时要花费较多的时间(因为索引也要随之变动)。
记录、分享、成长
推荐阅读:MySQL索引背后的数据结构及算法原理
摘录:
题目来源:LeetCode: 110. Balanced Binary Tree
Given a binary tree, determine if it is height-balanced.
For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node never differ by more than 1.
概述:Python中这三种形式的定义相近,易于混淆,应注意区分.1
2
3
4Python中字典Dictionary、列表List、元组Tuple定义形式:
aDict={'a':1, 'b':2, 'c':3, 'd':4, 'e':5}
aList=[1,2,3,4,5]
aTuple=(1,2,3,4,5)
题目来源:LeetCode: 257. Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.
For example, given the following binary tree:
1
/ \
2 3
\
5
All root-to-leaf paths are:
[“1->2->5”, “1->3”]
时间复杂度:O(n), 空间复杂度O(logn)
Given a non-negative integer num, repeatedly add all its digits until the result has only one digit.
For example:
Given num = 38, the process is like: 3 + 8 = 11, 1 + 1 = 2. Since 2 has only one digit, return it.
Follow up:
Could you do it without any loop/recursion in O(1) runtime?
最初看到这个题目,觉得迭代加法取余的方式肯定是最low的,分析规律。
时间复杂度:O(1), 空间复杂度O(1)