NOTE FOR PTA WEEK(小题)

WEEK2

判断

1-1 For a sequentially stored linear list of length NN, the time complexities for deleting the first element and inserting the last element are O(1)O(1) and O(N)O(N), respectively. (1分)

T         F

key:false,删除的时候需要先遍历找到这个结点,所以应该是O(N)的时间复杂度,插入要遍历到最后一个结点,也是O(N)


1-2 If a linear list is represented by a linked list, the addresses of the elements in the memory must be consecutive.

T         F

key:false,链表的存储地址不连续。


ps:linear list和linked list 区别,linear list是一种数据结构,线性表中数据元素之间的关系是一对一的关系,即除了第一个和最后一个数据元素之外,其它数据元素都是首尾相接的。linear list一般有两种实现形式,一种是数组(Array),一种是链表(Linked list)。一般认为线性表中数据存储是在一块连续的存储空间之中,而链表的存储可以是分散的,下一地址储存在节点之中。


WEEK4

选择

2-2 

Given a tree of degree 4. Suppose that the numbers of nodes of degrees 1, 2, 3 and 4 are 4, 2, 1 and 1, respectively. Then the number of leaf nodes must be: (3分)

  1. 4
  2. 6
  3. 8
  4. 10
key:C.8 degree意为度,结点的度为结点子树的个数,树的度为所有节点中的最大度数。用到的公式为 树的总分叉数+1=树的节点数 ,树的总分叉数=1x4+2x2+3+4=15,所以总的节点数为16,leaf node指度为1的结点,个数=16-4-2-1-1=8

WEEK5
2-2 Among the following threaded binary trees (the threads are represented by dotted curves), which one is the postorder threaded tree?  (2分)
key: B。线索二叉树中,左线索为上一个结点,右线索为下一个结点,根据c结点可以判断出来B正确

WEEK6
选择
2-6

If a binary search tree of NN nodes is complete, which one of the following statements is FALSE? (1分)

  1. the average search time for all nodes is O(logN)O(logN)
  2. the minimum key must be at a leaf node
  3. the maximum key must be at a leaf node
  4. the median node must either be the root or in the left subtree
key:C,最大值可能在上一层的最右边的结点(此节点只有leftchildren)

WEEK8
选择
2-1

A strongly connected graph with NN vertices must have at least __ edges. (2分)

  1. N-1N1
  2. NN
  3. N+1N+1
  4. N(N-1)N(N1)
key:强联通图意为可以从任意一个结点出发回到原点,当所有节点围成一个环时所用边数最少,为n条边
2-2

If graph G is NOT connected and has 28 edges, then it must have at least __ vertices. (3分)

  1. 7
  2. 8
  3. 9
  4. 10
key:C。n个结点时,最多可以有n(n-1)/2条边,有8个节点时,最多有27条边,此时图为强联通图,9个结点时,最多有36条边,将一个结点去除8条边时,图不连通,可以实现。
2-3

In a directed graph, the sum of in- and out-degrees of all the vertices is __ times the number of edges. (2分)

  1. 1/2
  2. 1
  3. 2
  4. 4
key:C。存在一条边时,就有in-degree+1和out-degree+1,所以入度和出度的和是边的两倍。
WEEK13
选择
2-4

If quick sort is implemented recursively to sort an array of records, then which one of the following statements is TRUE? (2分)

  1. After each partition, handling the longer sublist first will reduce the number of recursions.
  2. After each partition, handling the shorter sublist first will reduce the number of recursions.
  3. The number of recursions has nothing to do with the order of handling the sublists after each partition.
  4. The number of recursions has nothing to do with the initial condition of the input.
key:C。quick sort与处理的顺序没有关系,处理的方法有关系(当序列较短时,不采用快排,用插入排序)




你可能感兴趣的:(数据结构,PTA)