摘要:
经典问题-Ordering Tasks dfs函数的返回值表示是否成环,若存在有向环,则不存在拓扑排序。不包含有向环的有向图称为有向无环图(DAG) 可以借助DFS完成拓扑排序,在访问完一个结点时把他加入当前拓扑序的首部。 举个栗子:比如一个(1,2),(1,3),(2,3)的有向无环图,就先搜索1 阅读全文
摘要:
In order to understand early civilizations, archaeologists often study texts written in ancient languages. One such language, used in Egypt more than 阅读全文
摘要:
Alex has invented a new game for fun. There are n integers at a board and he performs the following moves repeatedly:1. He chooses three numbers a, b 阅读全文
摘要:
先建树 递归写法简单又清晰: 先序遍历(DLR)的递归过程为:若二叉树为空,遍历结束。否则: 遍历过程如图 中序遍历(LDR)的递归过程: 若二叉树非空,则依次执行如下操作: ⑴遍历左子树; ⑵访问根结点; ⑶遍历右子树。 遍历过程如图: 代码如下: 后序遍历(LRD)的递归过程为: 若二叉树为空则 阅读全文
摘要:
树的定义以及术语 1.树的定义:树(tree)是n(n≥0)个节点的有限集合。当n=0时,称这棵树为空树;当n>0时,该集合满足以下条件: (1)有且只有一个特殊的结点称为树的根(root),根结点没有父结点,但有零个或多个直接子节点。(除了根结点之外的所有结点有且只有一个父结点,树的所有结点可以没 阅读全文