11 2019 档案
摘要:7-4 Dijkstra Sequence (30 分) Dijkstra's algorithm is one of the very famous greedy algorithms. It is used for solving the single source shortest path
阅读全文
摘要:7-3 Postfix Expression (25 分) Given a syntax tree (binary), you are supposed to output the corresponding postfix expression, with parentheses reflecti
阅读全文
摘要:7-2 Merging Linked Lists (25 分) Given two singly linked lists L 1 =a 1 →a 2 →...→a n−1 →a n L1=a1→a2→...→an−1→an and L 2 =b 1 →b 2 →...→b m−1 →b m L2=
阅读全文
摘要:7-1 Forever (20 分) "Forever number" is a positive integer A with K digits, satisfying the following constrains: the sum of all the digits of A is m; t
阅读全文
摘要:影响排序性能的要素: 时间性能; 辅助空间 算法的复杂度 简单排序【n^2】 算法思想: 第一趟: 从第一个记录开始,通过n-1次关键字比较,从n个记录中选出最小的并和第一个记录交换; 第二趟: 从第二个记录开始,通过n-2次关键字比较,从n -1个记录中选出最小的并和第二个记录交换; 复杂度稳稳的
阅读全文
摘要:Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, a binary tree can be u
阅读全文
摘要:Telefraud(电信诈骗) remains a common and persistent problem in our society. In some cases, unsuspecting victims lose their entire life savings. To stop th
阅读全文
摘要:Zhejiang University is about to celebrate her 122th anniversary in 2019. To prepare for the celebration, the alumni association (校友会) has gathered the
阅读全文
摘要:Sexy primes are pairs of primes of the form (p, p+6), so-named since “sex” is the Latin word for “six”. (Quoted from http://mathworld.wolfram.com/Sexy
阅读全文
摘要:暴力匹配: 假设现在我们面临这样一个问题:有一个文本串S,和一个模式串P,现在要查找P在S中的位置,怎么查找呢? 如果用暴力匹配的思路,并假设现在文本串S匹配到 i 位置,模式串P匹配到 j 位置,则有: 如果当前字符匹配成功(即S[i] == P[j]),则i++,j++,继续匹配下一个字符; 如
阅读全文
摘要:In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the
阅读全文
摘要:A proper vertex coloring is a labeling of the graph's vertices with colors such that no two vertices sharing the same edge have the same color. A colo
阅读全文
摘要:A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, namely, T for the top level, A for advance and B for
阅读全文
摘要:In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the picture below) for recruitment. The content is supe
阅读全文
摘要:题目: 给出一个mxn 的矩阵,矩阵中的元素为0或1。称位置(x,y)与其上下左右四个位置(x,y+1)、(x,y-1)、(x+1,y)、(x-1,y)是相邻的。如果矩阵中有若干个1是相邻的(不必两两相邻),那么称这些1构成了一个“块”。求给定的矩阵中“块”的个数。 0 1 1 1 0 0 1 0
阅读全文
摘要:背包问题是一个np问题: 一般题意为: 存在n件物品,每件物品的重量为w[i],价值为v[i],现在有一个包,承重限制为weight,现在让你从n件物品中,选择一些物品装入背包中,在不超重的前提下,使得背包中所装物品的总价值最大。 由于每件物品【应该是每种物品】存在着两种情况,一种是,每种物品唯有一
阅读全文
摘要:最长回文子串的问题描述: 给出一个字符串S,求S的最长回文子串的长度。 样例: 字符串"PATZJUJZTACCBCC"的最长回文子串为“ATZJUJZTA”,长度为9。 先看暴力解法:枚举子串的两个端点i和j,判断在i,区间内的子串是否回文。 从复杂度上来看,枚举端点需要O(n2),判断回文需要O
阅读全文
摘要:The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants. Given any two nodes in a bin
阅读全文
摘要:The "travelling salesman problem" asks the following question: "Given a list of cities and the distances between each pair of cities, what is the shor
阅读全文
摘要:When shipping goods with containers, we have to be careful not to pack some incompatible goods into the same container, or we might get ourselves in s
阅读全文
摘要:Werewolf(狼人杀) is a game in which the players are partitioned into two parties: the werewolves and the human beings. Suppose that in a game, player #1
阅读全文
摘要:设G=(V,E)是无向连通带权图,V={1,2,…,n}; 设最小生成树T=(V,TE),该树的初始状态为只有n个顶点而无边的非连通图T=(V,{}),Kruskal算法将这n个顶点看成是n个孤立的连通分支。 它首先将所有的边按权值从小到大排序,然后只要T中选中的边数不到n-1,就做如下的贪心选择:
阅读全文
摘要:适用范围:要求无向图 prim算法(读者可以将其读作“普里姆算法”)用来解决最小生成树问题, 其基本思想是: ·对图G(VE)设置集合S,存放已被访问的顶点, ·然后每次从集合V-S中选择与集合S的最短距离最小的一个顶点(记为u),访问并加入集合S。 ·令顶点u为中介点,优化所有从u能到达的顶点v与
阅读全文
摘要:最小生成树: 最小生成树(Minimum Spanning Tree,MST)是在一个给定的无向图G(V,E)中求一棵树T,使得这棵树拥有图G中的所有顶点,且所有边都是来自图G中的边,并且满足整棵树的边权之和最小。 图10-43给出了一个图G及其最小生成树T,其中较粗的线即为最小生成树的边。可以看到
阅读全文
摘要:AOV网: 顶点活动(Activity On Vertex,AOV)网是指用顶点表示活动,而用边集表示活动间优先关系的有向图。例如图10-57的先导课程示意图就是AOV网,其中图的顶点表示各项课程,也就是“活动”;有向边表示课程的先导关系,也就是“活动间的优先关系”。显然,图中不应当存在有向环,否则
阅读全文
摘要:哈希表结构讲解: 哈希表(Hash table,也叫散列表),是根据关键码值(Key value)而直接进行访问的数据结构。也就是说,它通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度。这个映射函数叫做散列函数,存放记录的数组叫做散列表。 记录的存储位置 = function(关键字)
阅读全文
摘要:This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given directed grap
阅读全文
摘要:In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the
阅读全文
摘要:The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try to find another sequence of inte
阅读全文
摘要:Given N integers, you are supposed to find the smallest positive integer that is NOT in the given list. Input Specification: Each input file contains
阅读全文
摘要:The lowest common ancestor (LCA) of two nodes U and V in a tree is the deepest node that has both U and V as descendants. A binary search tree (BST) i
阅读全文
摘要:A clique is a subset of vertices of an undirected graph such that every two distinct vertices in the clique are adjacent. A maximal clique is a clique
阅读全文
摘要:After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the rank
阅读全文
摘要:Look-and-say sequence is a sequence of integers as the following: D, D1, D111, D113, D11231, D112213111, ... where D is in [0, 9] except 1. The (n+1)s
阅读全文
摘要:youtube-dl: Youtube-dl是谷歌github上的一个开源项目,它是一款轻量级的命令行 下载实用工具,阿刚曾在乐软博客里文章《不仅仅是youtube,youtube-dl在线视频下载神器》一文章,详细介绍过Youtube-dl。 作为一款命令行视频下载神器,Youtube-dl功能强
阅读全文
摘要:Given a reference of a node in a connected undirected graph, return a deep copy (clone) of the graph. Each node in the graph contains a val (int) and
阅读全文
摘要:在一条环路上有 N 个加油站,其中第 i 个加油站有汽油 gas[i] 升。 你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i+1 个加油站需要消耗汽油 cost[i] 升。你从其中的一个加油站出发,开始时油箱为空。 如果你可以绕环路行驶一周,则返回出发时加油站的编号,否则返回 -1。 说
阅读全文
摘要:老师想给孩子们分发糖果,有 N 个孩子站成了一条直线,老师会根据每个孩子的表现,预先给他们评分。 你需要按照以下要求,帮助老师给这些孩子分发糖果: 每个孩子至少分配到 1 个糖果。相邻的孩子中,评分高的孩子必须获得更多的糖果。那么这样下来,老师至少需要准备多少颗糖果呢? 示例 1: 输入: [1,0
阅读全文
摘要:Given a non-empty array of integers, every element appears twice except for one. Find that single one. Note: Your algorithm should have a linear runti
阅读全文
摘要:Given a non-empty array of integers, every element appears three times except for one, which appears exactly once. Find that single one. Note: Your al
阅读全文
摘要:A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null. Return a deep copy
阅读全文
摘要:Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequ
阅读全文
摘要:Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, add spaces in s to construct a sentence where each word is
阅读全文
摘要:Given a linked list, determine if it has a cycle in it. To represent a cycle in the given linked list, we use an integer pos which represents the posi
阅读全文
摘要:Given a linked list, return the node where the cycle begins. If there is no cycle, return null. To represent a cycle in the given linked list, we use
阅读全文