• 数据结构与算法(周测1-算法分析)


    判断题

    1.In a singly linked list of N nodes, the time complexities for query and insertion are O(1) and O(N), respectively.

         T      F

    查找是O(N),因为需要沿着next指针找下去。而插入是O(1),只需要改变指针就行了。

    2.If N numbers are stored in a singly linked list in increasing order, then the average time complexity for binary search is O(logN).

         T      F

    因为链表不支持随机存取,而O(logN)的算法严重依赖于随机存取,所以不可能完成。

    3.If keys are pushed onto a stack in the order abcde, then it's impossible to obtain the output sequence cedab.

         T      F

    a在b的前面意味着a如果不在一开始取出就不能在b之前被取出,所以是不可能的。

    4.An algorithm to check for balancing symbols in an expression uses a queue to store the partial expression.

         T      F

    balancing symbols指的是一组匹配的符号,类似于圆括号,花括号,方括号。可见这道题的意思是求解逆波兰表达式,使用stack而非queue。

    5.To sort N distinct records by bubble sort, the number of record swaps must reach its maximum when the original sequence is almost in sorted order.

         T      F

    冒泡排序的record swaps取决于逆序对的数量,对于一个已经排序过的序列,逆序对的数量可以是0或者最大,逆序对的数量可能最大也可能最小。

    6.To sort N records by simple selection sort, the numbers of comparisons and record movements are O(N2) and O(N), respectively.

         T      F

    比较次数的计算:(n-1)+(n-2)+...+2+1。共用n2/2次。移动只在一轮比较完成后,所以就算每次都需要移动,一共也才(n-1)次,所以比较可以看作O(N2),移动可以看作O(N)。

    7.(neuDS)算法必须有输出,但可以没有输入。

         T      F

    算法有0个或多个输入,以刻画运算对象的初始情况;算法有一个或多个输出,以反映对输入数据加工后的结果。

    8."Circular Queue" is defined to be a queue implemented by a circularly linked list or a circular array.

         T      F

    循环队列是一个抽象的概念,不局限于实现方式。

    9.对于一个随机算法,其最坏情况下的运行时间等于运行时间期望值的常数倍。

         T      F

    虽然我们希望如此,因为这会使算法比较稳定,但大多数算法的运行时间期望值是最优和最差的情况的折中。

    10.For a sequentially stored linear list of length N, the time complexities for query and insertion are O(1) and O(N), respectively.

         T      F

    顺序存储的线性表支持随机存取,所以查询的时间是常数时间,但插入需要把后面每一个元素的位置都进行调整,所以是线性时间。

    11.The Fibonacci number sequence {FN} is defined as: F0=0, F1=1, FN=FN-1+FN-2, N=2, 3, .... The space complexity of the function which calculates FN recursively is O(logN).

         T      F

    为了求FN,需要从F0到FN的值,需要O(N)。

    12.斐波那契数列FN的定义为:F0=0, F1=1, FN=FN-1+FN-2, N=2, 3, …。用递归函数计算FN的空间复杂度是O(logN)。

         T      F

    13.(neuDS)数据的物理结构是指数据在计算机中的实际存储形式。

         T      F

    物理结构和计算机的硬件直接相关。

    14.If keys are pushed onto a stack in the order {1, 2, 3, 4, 5}, then it is impossible to obtain the output sequence {3, 4, 1, 2, 5}.

         T      F

    FIFO结构。

    15.If the most commonly used operations are to visit a random position and to insert and delete the last element in a linear list, then sequential storage works the fastest.

         T      F

    频繁地对最后一个元素查删,顺序表完全可以胜任。

    16.For the following piece of code

    if ( A > B ){     
      for ( i=0; i<N*2; i++ )         
        for ( j=N*N; j>i; j-- )             
          C += A; 
    }
    else {     
      for ( i=0; i<N*N/2; i++ )         
        for ( j=N; j>i; j-- ) 
          for ( k=0; k<N*100; k++)
            C += B; 
    } 
    

    the lowest upper bound of the time complexity is O(N5)

         T      F

    最多是O(N4)。

    17.If keys are pushed onto a stack in the order abcde, then it's impossible to obtain the output sequence cdabe.

         T      F

    18.If N numbers are stored in a doubly linked list in increasing order, then the average time complexity for binary search is O(logN).

         T      F
    即使双链表还是无法通过下标查询,速度依然不可能到达O(logN)。

    19.Given the input sequence onto a stack as {1, 2, 3, ..., N}. If the first output is i, then the j-th output must be j-i-1.

         T      F
    除非能保证序列在完全入栈前都不出栈。

    20.用动态规划而非递归的方法去解决问题时,关键是将子问题的计算结果保存起来,使得每个不同的子问题只需要被计算一次。子问题 的解可以被保存在数组或哈希散列表中。

         T      F

    21.Let S be the set of activities in Activity Selection Problem. The greedy rule of "collecting the activity that starts the latest" is correct for finding a maximum-size subset of mutually compatible activities of S.

         T      F
    贪婪算法适用于通过求解局部最优解获得全局最优解的情况。和题目描述相符合。

    22.(neuDS_C++)空串与空格串是相同的。

         T      F

    23.(neuDS)线性表的逻辑顺序和存储顺序总是一致的。

         T      F

    24.(nueDS_C++)如果一个串中的所有字符均在另一串中出现,则说前者是后者的子串。

         T      F
    注意串的序列性。

    25.(neuDS)单链表不是一种随机存取的存储结构。

         T      F

    26.设只包含根结点的二叉树高度为0,则高度为k的二叉树最小结点数为k+1。

         T      F
    树退化成线性表。

    27.二叉树通常有顺序存储结构和链式存储结构。

         T      F

    28.存在一棵总共有2016个结点的二叉树,其中有16个结点只有一个孩子。

         T      F
    假设二叉树的结点拥有0个,1个,2个孩子的结点分别为N0,N1,N2。首先,需要了解,二叉树中度为2的结点数量比叶节点少一,那么$N_{0}+N_{1}+N_{2}=2016 Rightarrow N_{1}+2N_{2}+1=2016 Rightarrow N_{1}+2N_{2}=2015$,看来N1必须是奇数。

    29.具有10个叶结点的二叉树中,有9个度为2的结点。

         T      F
    参考上一题的分析。

    30.An algorithm to check for balancing symbols in an expression uses a stack to store the symbols.

         T      F
    参考第四题。

    选择题

    1.If a linear list is represented by a linked list, the addresses of the elements in the memory:

        A.must be consecutive
        B.may or may not be consecutive
        C.must be consecutive for part of the elements
        D.must be nonconsecutive

    2.If the most commonly used operations are to insert a new element after the last element, and to delete the first element in a linear list, then which of the following data structures is the most efficient?

        A.singly linked list
        B.singly linked circular list with a tail pointer
        C.singly linked circular list with a head pointer
        D.doubly linked list
    循环链表的尾指针可以很快地找到头指针,头指针却不能很快地找到尾指针

    3.When is the linked list structure suitable for representing a linear list L?

        A.frequently insert into and delete from L
        B.frequently change the key values of the nodes in L
        C.L contains large amount of nodes
        D.the structure of the nodes in L is complicated
    链表适合插入和删除

    4.The best "worst-case time complexity" for any algorithm that sorts by comparisons only is:

        A.O(logN)
        B.O(N)
        C.O(NlogN)
        D.O(N2)
    对于比较排序算法,堆排序和归并排序的最坏时间复杂度都是O(NlogN)。

    5.To sort N distinct elements in descending order by bubble sort, under which condition of the elements that the method will make the most number of swaps?

        A.pre-sorted in ascending order
        B.pre-sorted in descending order
        C.unsorted
        D.almost sorted
    当数据是升序排序时,执行降序排序的逆序对数量最多,交换次数也最多。

    6.To sort N elements by simple selection sort, the numbers of comparisons and movements are:

        A.O(N2), O(N)
        B.O(N), O(logN)
        C.O(logN), O(N2)
        D.O(NlogN), O(NlogN)
    参考判断题第六题对选择排序的分析。

    7.Use simple insertion sort to sort 10 numbers from non-decreasing to non-increasing, the possible numbers of comparisons and movements are:

        A.100, 100
        B.100, 54
        C.54, 63
        D.45, 44
    插入排序的比较次数为$(n-1)+(n-2)+...+1=frac{n(n-1)}{2}$,交换次数一定比比较次数低,所以选择D。

    8.Since the speed of a printer cannot match the speed of a computer, a buffer is designed to temperarily store the data from a computer so that later the printer can retrieve data in order. Then the proper structure of the buffer shall be a:

        A.stack
        B.queue
        C.tree
        D.graph

    9.Represent a queue by a singly linked list. Given the current status of the linked list as 1->2->3 where x->y means y is linked after x. Now if 4 is enqueued and then a dequeue is done, the resulting status must be:

        A.1->2->3
        B.2->3->4
        C.4->1->2
        D.the solution is not unique

    10.Use binary search to find a number from 100 sorted numbers, the worst-case number of comparisons is:

        A.7
        B.10
        C.50
        D.99

    11.Given the rucurrent equations for the time complexity of a program as: T(1)=1, and T(N)=2T(N/2)+N. Then the time complexity must be:

        A.O(logN)
        B.O(N)
        C.O(NlogN)
        D.O(N2)

    为了获得T(N),需要计算递归等式logN次,2T(N/2)计算logN次后就等于N,N计算logN次后等于NlogN,两边取大的一方,最终的结果就是NlogN。

    12.The recurrent equations for the time complexities of programs P1 and P2 are:

    • P1: T(1)=1, T(N)=T(N/2)+1;
    • P2: T(1)=1, T(N)=2T(N/2)+1;

    Then the correct conclusion about their time complexities is:

        A.they are both O(logN)
        B.O(logN) for P1, and O(N) for P2
        C.they are both O(N)
        D.O(logN) for P1, and O(NlogN) for P2

    P1的加号左边经过logN次递归等式计算恒等于1,而右边每次递归等式都加1,经过logN次计算最后为logN,两边取大是logN;

    P2加号的左边经过logN次递归等式计算是N,右边每次递归等式都加1,经过logN次计算最后为logN,两边取大总体为N。

    13.For a sequentially stored linear list of length N, the time complexities for query and insertion are:

        A.O(1), O(1)
        B.O(1), O(N)
        C.O(N), O(1)
        D.O(N), O(N)

    14.For a sequentially stored linear list of length N, which of the following operations has the time complexity O(1)?

        A.visit the i-th (1≤i≤N) node and find the immediate predecessor of the i-th (2≤i≤N) node
        B.insert a new node after the i-th (1≤i≤N) node
        C.delete the i-th (1≤i≤N) node
        D.sort the N nodes in increasing order

    15.切原木问题:给定一根长度为N米的原木;另有一个分段价格表,给出长度L=1,2,...,M对应的价格PL。要求你找出适当切割原木分段出售所能获得的最大收益RN。例如,根据下面给出的价格表,若要出售一段8米长的原木,最优解是将其切割为2米 和6米的两段,这样可以获得最大收益R8=P2+P6=5+17=22。而若要出售一段3米长的原木,最优解是 根本不要切割,直接售出。

    Length L 1 2 3 4 5 6 7 8 9 10
    Price PL 1 5 8 9 10 17 17 20 23 28

    下列哪句陈述是错的?

        A.此问题可以用动态规划求解
        B.若N≤M,则有RN=max{PN,max1<=i<N{Ri+RN-i}}
        C.若N>M,则有RN=max1<=i<N{Ri+RN-M}
        D.算法的时间复杂度是O(N2)
    N>M时,应该为RN=max1<=i{Ri+RM-i}

    16."二叉树为空"意味着二叉树() 。

        A.由一些没有赋值的空结点构成
        B.根结点没有子树
        C.不存在
        D.没有结点

    17.栈和队列的共同点( )。

        A.都是先进先出
        B.都是后进先出
        C.只允许在端点处插入和删除元素
        D.没有共同点

    18.广义表是一种()数据结构。

        A.非递归的
        B.递归的
        C.树型
        D.图状
    广义表容许表中的元素拥有自己的数据结构,使用递归的方式定义,所以是递归的数据结构。

    19.若串S="software",其子串的数目是

        A.8
        B.37
        C.36
        D.9
    子串包含空串。

    20.What is the major difference among lists, stacks, and queues?

        A.Lists use pointers, and stacks and queues use arrays
        B.Stacks and queues are lists with insertion/deletion constraints
        C.Lists and queues can be implemented using circularly linked lists, but stacks cannot
        D.Lists are linear structures while stacks and queues are not

    21.线性表是一个()。

        A.有限序列,可以为空
        B.有限序列,不能为空
        C.无限序列,可以为空
        D.无限序列,不能为空

    22.Given a 12×12 symmetric matrix M. If the upper triangular entries mi,j (1≤i≤j≤12) of M are stored row by row in a 1-dimentional array N (in C programming language). What is the index of m6,6 in N?

        A.50
        B.51
        C.55
        D.66
    上三角每一行的第一个元素为mi,i,所以m6,6为第12+11+10+9+8+1=51个元素,因为数组下标从0开始,所以最后得到的下标为50。

    23.阅读下列程序,其功能是()。

    typedef struct {
    ElemType *list;
    int size;
    intMaxSize;
    }SeqList;
    void fun1(SeqList&L) {
    inti, j;
    ElemType temp;
       for (i=0, j= L.sise-1; i<j; i++, j--) {
           temp=L.list[i];
           L.list[i]=L.list[j];
           L.list[j]=temp;
       }
    }
    
        A.将顺序表原地逆置
        B.将链表原地逆置
        C.将顺序表首尾元素对换
        D.将链表首尾元素对换

    24.If the pushing sequence of a stack is {1, 2, 3, ..., N} and the first number being popped out is i, then the j-th number being popped must be:

        A.i?j?1
        B.i?j
        C.j?i?1
        D.cannot be determined

    25.In-order traversal of a binary tree can be done iteratively. Given the stack operation sequence as the following:

    push(1), push(2), push(3), pop(), push(4), pop(), pop(), push(5), pop(), pop(), push(6), pop()
    

    Which one of the following statements is TRUE?

        A.3 and 5 are siblings
        B.1 is the parent of 5
        C.6 is the root
        D.None of the above
    这道题本质上讲的是中序遍历的非递归实现,根据给出的stack序列,能够构建出一个二叉树。 ![](https://img2018.cnblogs.com/blog/1694164/201910/1694164-20191029212412099-1674792758.png)

    26.Given an empty stack S and an empty queue Q. Push elements {1, 2, 3, 4, 5, 6, 7} one by one onto S. If each element that is popped from S is enqueued onto Q immediately, and if the dequeue sequence is {3, 2, 6, 5, 7, 4, 1}, then the minimum size of S must be:

        A.2
        B.3
        C.4
        D.5
    栈元素数量最大的时候是1,4,5,6。

    27.What is NOT a feature of a linked list?

        A.do insertion and deletion without having to move the elements
        B.easy for random query
        C.no pre-estimation of the size is necessary
        D.the space taken is proportional to the size of the list

    28.Suppose that an array of size m is used to store a circular queue. If the front position is front and the current size is size, then the rear element must be at:

        A.`front+size`
        B.`front+size-1`
        C.`(front+size)%m`
        D.`(front+size-1)%m`
    考虑满的情况,size==m,front应该比rear少1,所以明显选D。

    29.Suppose that enqueue is allowed to happen at both ends of a queue, but dequeue can only be done at one end. If elements are enqueued in the order {a, b, c, d, e}, the impossible dequeue sequence is:

        A.b a c d e
        B.d b a c e
        C.e c b a d
        D.d b c a e
    这道题考虑序列的时候只要反着思考,从a出发,如果这个序列可以被有序地拿掉,那么就是合法地,D中a的左右两边都和a不连续,明显错了。

    30.依次在初始为空的队列中插入元素a,b,c,d以后,紧接着做了两次删除操作,此时的队头元素是( )。

        A.a
        B.b
        C.c
        D.d
  • 相关阅读:
    Beginning SDL 2.0(5) 基于MFC和SDL的YuvPlayer
    Beginning SDL 2.0(6) 音频渲染及wav播放
    Beginning SDL 2.0(4) YUV加载及渲染
    Beginning SDL 2.0(3) SDL介绍及BMP渲染
    获取windows可执行文件的version信息(版本号)
    visual studio 2005提示脚本错误 /VC/VCWizards/2052/Common.js
    Beginning SDL 2.0(2) TwinklebearDev SDL 2.0 Tutorial
    Beginning SDL 2.0(1) SDL功能简介
    ffmpeg与H264编码指南
    2015-07学习总结——网络编程(TCP/IP)
  • 原文地址:https://www.cnblogs.com/nonlinearthink/p/11735810.html
Copyright © 2020-2023  润新知