搭好博客勤备份
之前,在搭好博客后我就可是对博客的备份了,备份了配置文件和文章的Markdown文件,以及自己修改的主题。
由于备份的并不是十分勤奋,以至于在我重新做系统后,将备份到Github上的数据Clone到本地后,傻眼了。出现了以下两个大问题:
- 少了几篇文章,最重大的损失。
- 一些设置没有了,包括博客的自定义主题。
之前,在搭好博客后我就可是对博客的备份了,备份了配置文件和文章的Markdown文件,以及自己修改的主题。
由于备份的并不是十分勤奋,以至于在我重新做系统后,将备份到Github上的数据Clone到本地后,傻眼了。出现了以下两个大问题:
打算分为以下几个方面记录一些校园资料。虽然大部分都被我存到笔记软件中,以后就放这里吧。笔记软件里面的东西越来越多,尽管已经为每篇笔记设置了标签和分类,但依然有点冗肿了,并且搜索有点慢。
列出的解答仅为自己的思路,仅供参考,欢迎指出错误。
http://www.algorithm.cs.sunysb.edu/algowiki/index.php/Search-TADM2E
该页面答案,也是由用户编辑的,不确定是完全的正确。
题目
A derangement is a permutation p of {1,…,n} such that no item is in its proper position, i.e. pi≠i for all 1≤i≤n. derangement Write an efficient backtracking program with pruning that constructs all the derangements of n items.
列出的解答仅为自己的思路,仅供参考,欢迎指出错误。
http://www.algorithm.cs.sunysb.edu/algowiki/index.php/Weighted-graphs-TADM2E
该页面答案,也是由用户编辑的,不确定是完全的正确。
题目
Is the path between two vertices in a minimum spanning tree necessarily a shortest path between the two vertices in the full graph? Give a proof or a counterexample.
列出的解答仅为自己的思路,仅供参考,欢迎指出错误。
http://www.algorithm.cs.sunysb.edu/algowiki/index.php/Graphs-TADM2E
题目
In breadth-first and depth-first search, an undiscovered node is marked discovered when it is first encountered, and marked processed when it has been completely searched. At any given moment, several nodes might be simultaneously in the discovered state.
(a) Describe a graph on n vertices and a particular starting vertex v such that Θ(n) nodes are simultaneously in the discovered state during a breadth-first search starting from v.
(b) Describe a graph on n vertices and a particular starting vertex v such that Θ(n) nodes are simultaneously in the discovered state during a depth-first search starting from v.
(c) Describe a graph on n vertices and a particular starting vertex v such that at some point Θ(n) nodes remain undiscovered, while Θ(n) nodes have been processed during a depth-first search starting from v. (Note, there may also be discovered nodes.)
解答
(a) Wrost case: 所有的节点都与根节点v直接相连。
(b) Wrost case: 所有的节点的出度都小于等于2,即所有的点都在一条线上。
(c) 非连通图。
列出的解答仅为自己的思路,仅供参考,欢迎指出错误。
http://www.algorithm.cs.sunysb.edu/algowiki/index.php/Sorting-searching-TADM2E
题目
Given a search string of three words, find the smallest snippet of the document that contains all three of the search words—i.e., the snippet with smallest number of words in it. You are given the index positions where these words occur in the document, such as word1: (1, 4, 5), word2: (3, 9, 10), and word3: (2, 6, 15). Each of the lists are in sorted order, as above.
解答
每个单词出现的位置列表都是有序的,将它们看做是队列。设定min_len
保存当前最短的片段的长度,初始化为-1.算法步骤如下:
(a1, a2, a3)
max
,与最小值min
,则当前片段长度len = max-min+1
min_len
为-1或min_len
大于len
,min_len = len
,保存三元组.min
,若min
对应队列不空,取新元素加入到三元组,执行2,若空,退出循环。变形
假设输入数据不是3个单词的出现位置,而直接是一个字符串数组,那么如何找到满足要求的最小片段?
分析
设cur
为访问数组的当前位置,3个变量l1, l2, l3
,代表cur
前面离cur
最近的3个单词(w1, w2, w3)的位置。若cur上的单词为3个单词之一,不妨设为w3,则计算w3与w1,w2的距离即cur-l1+1
和cur-l2+1
,取小者为min
,另min
与min_len
比较,若min更小,保存min
,及当前3个单词的位置。当遍历数组结束时,最后的min_len
与保存的3元素的位置即满足要求的最小片段。