摘要:
本文共列出了11个常见的二叉树遍历算法。二叉树的遍历主要有深度优先遍历和广度优先遍历。深度优先遍历包含前序遍历、中序遍历和后序遍历。值得一提的是, 其中的 Morris 算法 可以线性时间不需要额外空间(用户栈或系统栈空间)实现二叉树的前序遍历、中序遍历和后序遍历。关于Morris算法, 可参考ht... 阅读全文
摘要:
Given an n x n grid with a person and obstacles, how would you find a path for the person to a particular destination? The p... 阅读全文
摘要:
Describe an algorithm that takes an unsorted array of axis‐aligned rectangles and returns any pair of rectangles that overlaps, if ... 阅读全文
摘要:
Given n balloons, indexed from 0 to n-1. Each balloon is painted with a number on it represented by array nums. You are asked to burst all the balloon 阅读全文
摘要:
展示一段程序,对其做一些讨论。 这段是测试在继承语义下对象构造时 this 指针的程序。首先在 main 函数中声明了一个X对象x和一个Y对象y,然后x和y分别通过指针成员ptr调用func函数。看X和Y的定义我们知道Y是继承自X的,是X的子类。X中有自定义默认构造函数,一个数据成员ptr和一个虚拟 阅读全文
摘要:
问题背景:假设数据库中存有搜索词条和对应的搜索频度, 当用户输入某一串字符(不区分大小写)时, 需要输出以输入为前缀的若干搜索频度最大的词条。下面是基于Trie的算法实现。 基于Trie的实现的好处是查询效率高, 支持动态查询(能快速更新数据库)。C++ 源代码: 1 #include 2 #... 阅读全文
摘要:
二叉树的直径,无根树的直径 阅读全文
摘要:
算法渐进复杂度记号,Stirling公式, 取整函数 阅读全文
摘要:
归并排序,原地归并排序,冒泡排序,选择排序,逆序对数(n^2, nlgn) 阅读全文
摘要:
算法的概念,为什么研究算法,循环不变式,插入排序,线性搜索 阅读全文