四川大学2012数据结构与算法 (A 闭 )
- 格式:pdf
- 大小:342.71 KB
- 文档页数:3
2022年四川大学计算机科学与技术专业《数据结构与算法》科目期末试卷A(有答案)一、选择题1、将两个各有N个元素的有序表归并成一个有序表,其最少的比较次数是()。
A.NB.2N-1C.2ND.N-12、从未排序序列中依次取出一个元素与已排序序列中的元素依次进行比较,然后将其放在已排序序列的合适位置,该排序方法称为()排序法。
A.插入B.选择C.希尔D.二路归并3、以下数据结构中,()是非线性数据结构。
A.树B.字符串C.队D.栈4、在下列表述中,正确的是()A.含有一个或多个空格字符的串称为空格串B.对n(n>0)个顶点的网,求出权最小的n-1条边便可构成其最小生成树C.选择排序算法是不稳定的D.平衡二叉树的左右子树的结点数之差的绝对值不超过l5、向一个栈顶指针为h的带头结点的链栈中插入指针s所指的结点时,应执行()。
A.h->next=sB.s->next=hC.s->next=h;h->next=sD.s->next=h-next;h->next=s6、排序过程中,对尚未确定最终位置的所有元素进行一遍处理称为一趟排序。
下列排序方法中,每一趟排序结束时都至少能够确定一个元素最终位置的方法是()。
Ⅰ.简单选择排序Ⅱ.希尔排序Ⅲ.快速排序Ⅳ.堆排Ⅴ.二路归并排序A.仅Ⅰ、Ⅲ、Ⅳ B.仅Ⅰ、Ⅱ、Ⅲ C.仅Ⅱ、Ⅲ、Ⅳ D.仅Ⅲ、Ⅳ、Ⅴ7、下列选项中,不能构成折半查找中关键字比较序列的是()。
A.500,200,450,180 B.500,450,200,180C.180,500,200,450 D.180,200,500,4508、每个结点的度或者为0或者为2的二叉树称为正则二叉树。
n个结点的正则二叉树中有()个叶子。
A.log2nB.(n-1)/2C.log2n+1D.(n+1)/29、有关二叉树下列说法正确的是()。
A.二叉树的度为2B.一棵二叉树的度可以小于2C.二叉树中至少有一个结点的度为2D.二叉树中任何一个结点的度都为210、对n个记录的线性表进行快速排序为减少算法的递归深度,以下叙述正确的是()。
软件学院数据结构与算法复习提纲(2012秋季学期)1、Data structures and algorithms概念:type, simple type, composite type, aggregate type, data type, ADT, data structure, problems, function, algorithms, programs2、Mathematical preliminaries概念:set, recursion3、Algorithm Analysis概念:asymptotic algorithm analysis, growth rate, best/worst/average case, upper/lower bound, space/time tradeoff, big-Oh/big-Omega/Theta notation4、list概念:list, array-based list, linked list, ordered/unordered list, singly/doubly linked list, array, stack, queue算法:基于list/stack/queue的算法5、binary trees概念:BST, Huffman tree, full/complete binary tree, height/depth of a binary tree,full binary tree的性质,priority queue应用题:BST中的插入/删除,Huffman树的构造,heap的构造,基于遍历序列还原二叉树算法:基于二叉树遍历的各种算法,BST上的操作6、general trees概念:traversal,Equivalence classes,K-ary tree应用题:树的存储表示看懂:traversal/UNION/FIND几个操作的实现思想7、internal sorting概念:各种排序算法的best/worst/average case时间复杂度,stable sorting algorithm应用题:shellsort/bubble sort/quicksort/heapsort/的排序过程8、File processing and external sorting概念:track/sector/cluster, Golden Rule of File Processing, logical/physical file, buffer, organization of buffer pool, Locality of Reference, external sorting, run9、Searching概念:hashing, properties of hash function, collision, Open hashing, Separate chaining, Closed hashing, Probe function, load factor应用题:hash表的构造(基于不同的冲突解决方式)10、indexing概念:entry-sequenced file, indexing, primary/secondary key, Linear indexing, 2-3 tree, B-tree, B+Tree应用题:2-3 tree/B-tree/B+Tree中的insert/delete操作11、graph概念:path, cycle, connected component, Adjacent list/matrix, BFS, DFS, topological sort, DAG, MST应用题:shortest path(Dijkstra/Floyd算法)的构造,MST(Prim/Kruskal算法)的构造。
四川大学“精品课程”计算机科学与技术专业(本科)《数据结构与算法分析》课程考试说明与模拟试卷第一部分考试说明数据结构与算法分析》是计算机科学与技术专业统设的一门重要的必修专业基础课,它主要研究数据的各种逻辑结构和在计算机中的存储结构,还研究对数据进行的插入、查找、删除、排序、遍历等基本运算或操作以及这些运算在各种存储结构上具体实现的算法。
由于本课程的主教材采用C++语言描述算法,期末卷面考试也采用C++语言描述,因而要求在做平时作业和上机实验操作时用C++开发工具(如:Visual C++或C++ Builder或Borland C++)。
下面按照主教材中各章次序给出每章的具体复习要求,以便同学们更好地进行期末复习。
第一章绪论重点掌握的内容:1. 数据结构的二元组表示,对应的图形表示,序偶和边之间的对应关系。
2. 集合结构、线性结构、树结构和图结构的特点。
3. 抽象数据类型的定义和表示方法。
4. 一维和二维数组中元素的按下标和按地址的访问方式以及相互转换,元素地址和数组地址的计算,元素占用存储空间大小和数组占用存储空间大小的计算。
5. 普通函数重载和操作符函数重载的含义,定义格式和调用格式。
6. 函数定义中值参数和引用参数的说明格式及作用,函数被调用执行时对传送来的实际参数的影响。
7. 算法的时间复杂度和空间复杂度的概念,计算方法,数量级表示。
8. 一个简单算法的最好、最差和平均这三种情况的时间复杂度的计算。
对于本章的其余内容均作一般掌握。
第二章线性表重点掌握的内容:1. 线性表的定义及判别和抽象数据类型的描述,线性表中每一种操作的功能,对应的函数名、返回值类型和参数表中每个参数的作用。
2. 线性表的顺序存储结构的类型定义,即List类型的定义和每个域的定义及作用。
3. 线性表的每一种运算在顺序存储结构上实现的算法,及相应的时间复杂度。
4.链接存储的概念,线性表的单链接和双链接存储的结构,向单链表中一个结点之后插入新结点或从单链表中删除一个结点的后继结点的指针链接过程。
四川⼤学计算机导论期末例题名词解释1. 机器指令计算机执⾏某种操作的命令,可由CPU 直接执⾏。
2. 程序计数器由若⼲位触发器和逻辑电路组成,⽤来存放将要执⾏的指令在存储器中的存放地址。
3. 进程⼀个程序(或程序段)在给定的⼯作空间和数据集合上的⼀次执⾏过程,它是操作系统进⾏资源分配和调度的⼀个独⽴单位。
4. 数据结构数据结构是指具有⼀定结构(关系)的数据元素的集合,主要研究数据的各种逻辑结构和物理结构,以及对数据的各种操作。
5. 总线若⼲信号线的集合,是计算机各部分之间实现信息传送的通路。
6. ⾼速缓冲存储器(Cache)位于CPU 和内存之间的存储器,其特点是速度快,⽬的是使存储器的速度和CPU 的速度相匹配。
7. 操作系统操作系统是由程序和数据结构组成的⼤型系统软件,它负责计算机的全部软硬件资源的分配、调度与管理,控制各类程序的正常执⾏,并为⽤户使⽤计算机提供良好的环境。
8. 计算机病毒破坏计算机功能或数据,影响计算机的使⽤,并能⾃我复制的⼀组计算机指令或程序。
9. 计算机⽹络计算机⽹络是利⽤通信线路连接起来的相互独⽴的计算机集合,其主要⽬的是实现数据通信和资源共享。
10. 指令系统⼀台计算机中所有机器指令的集合,它是表征⼀台计算机性能的重要因素。
问答题1. 请列举CPU 的主要技术指标(⾄少3 个指标),并进⾏简要说明。
(答案可在以下任选 3 个,且不限于此)基本字长:CPU⼀次处理的⼆进制数的位数。
(2分)主频:CPU内部⼯作的时钟频率,是CPU运⾏运算时的⼯作频率。
(2分)地址总线宽度(地址总线的位数):决定了CPU可以访问的存储器的容量,不同型号的CPU 总线宽度不同,因⽽可使⽤的内存的最⼤容量也不⼀样。
(2 分)数据总线宽度:数据总线宽度决定了CPU与内存、输⼊/输出设备之间⼀次数据传输的信息量。
⾼速缓存:是可以进⾏⾼速数据交换的存储器,它先于内存与CPU 交换数据。
2. 计算机的硬件主要有哪⼏个部分组成?各部分有什么功能?计算机硬件系统由运算器、控制器、存储器、输⼊设备、输出设备和总线组成。
川大软件数据结构选择题库Chapter 1 Data Structures and Algorithms: Instructor's CD questions1. The primary purpose of most computer programs isa) to perform a mathematical calculation.*b) to store and retrieve information.c) to sort a collection of records.d) all of the above.e) none of the above.2. An integer is a*a) simple typeb) aggregate typec) composite typed) a and be) none of the above3. A payroll records is aa) simple typeb) aggregate typec) composite type*d) a and be) none of the above4. Which of the following should NOT be viewed as an ADT?a) listb) integerc) array*d) none of the above5. A mathematical function is most like a*a) Problemb) Algorithmc) Program6. An algorithm must be or do all of the following EXCEPT:a) correctb) composed of concrete steps*c) ambiguousd) composed of a finite number of stepse) terminate7. A solution is efficient ifa. it solves a problem within the require resource constraints.b. it solves a problem within human reaction time.c. it solves a problem faster than other known solutions.d. a and b.*e. a and c.f. b and c.8. An array isa) A contiguous block of memory locations where each memory location stores a fixed-length data item.b) An ADT composed of a homogeneous collection of data items, each data item identified by a particular number.c) a set of integer values.*d) a and b.e) a and c.f) b and c.9. Order the following steps to selecting a data structure to solve a problem.(1) Determine the basic operations to be supported.(2) Quantify the resource constraints for each operation.(3) Select the data structure that best meets these requirements.(4) Analyze the problem to determine the resourceconstraints that anysolution must meet.a) (1, 2, 3, 4)b) (2, 3, 1, 4)c) (2, 1, 3, 4)*d) (1, 2, 4, 3)e) (1, 4, 3, 2)10. Searching for all those records in a database with key value between 10 and 100 is known as:a) An exact match query.*b) A range query.c) A sequential search.d) A binary search.Chapter 2 Mathematical Preliminaries: Instructor's CD questions1. A set has the following properties:a) May have duplicates, element have a position.b) May have duplicates, elements do not have a position.c) May not have duplicates, elements have a position.*d) May not have duplicates, elements do not have a position.2. A sequence has the following properties:*a) May have duplicates, element have a position.b) May have duplicates, elements do not have a position.c) May not have duplicates, elements have a position.d) May not have duplicates, elements do not have a position.3. For set P, the notation |P| indicates*a) The number of elements in P.b) The inverse of P.c) The powerset of P.d) None of the above.4. Assume that P contains n elements. The number of sets in the powerset of P isa) nb) n^2*c) 2^nd) 2^n - 1e) 2^n + 15. If a sequence has n values, then the number of permutations for that sequence will bea) nb) n^2c) n^2 - 1d) 2^n*e) n!6. If R is a binary relation over set S, then R is reflexive if*a) aRa for all a in S.b) whenever aRb, then bRa, for all a, b in S.c) whenever aRb and bRa, then a = b, for all a, b in S.d) whenever aRb and aRc, then aRc, for all a, b, c in S.7. If R is a binary relation over set S, then R is transitive ifa) aRa for all a in S.b) whenever aRb, then bRa, for all a, b in S.c) whenever aRb and bRa, then a = b, for all a, b in S.*d) whenever aRb and aRc, then aRc, for all a, b, c in S.8. R is an equivalence relation on set S if it is*a) reflexive, symmetric, transitive.b) reflexive, antisymmetric, transitive.c) symmetric, transitive.d) antisymmetric, transitive.e) irreflexive, symmetric, transitive.f) irreflexive, antisymmetric, transitive.9. For the powerset of integers, the subset operation defines*a) a partial order.b) a total order.c) a transitive order.d) none of the above.10. log nm is equal toa) n + m*b) log n + log mc) m log nd) log n - log m11. A close-form solution isa) an analysis for a program.*b) an equation that directly computes the value of a summation.c) a complete solution for a problem.12. Mathematical induction is most likea) iteration.*b) recursion.c) branching.d) divide and conquer.13. A recurrence relation is often used to model programs witha) for loops.b) branch control like "if" statements.*c) recursive calls.d) function calls.14. Which of the following is not a good proof technique.a) proof by contradiction.*b) proof by example.c) proof by mathematical induction.15. We can use mathematical induction to:a) Find a closed-form solution for a summation.*b) Verify a proposed closed-form solution for a summation.c) Both find and verify a closed-form solution for a summation.Chapter 3 Algorithm Analysis: Instructor's CD questions1. A growth rate applies to:a) the time taken by an algorithm in the average case.b) the time taken by an algorithm as the input size grows.c) the space taken by an algorithm in the average case.d) the space taken by an algorithm as the input size grows.e) any resource you wish to measure for an algorithm in the averagecase.*f) any resource you wish to measure for an algorithm as the input size grows.2. Pick the growth rate that corresponds to the most efficient algorithm as n gets large:a) 5n*b) 20 log nc) 2n^2d) 2^n3. Pick the growth rate that corresponds to the most efficient algorithm when n =4.a) 5nb) 20 log nc) 2n^2*d) 2^n4. Pick the quadratic growth rate.a) 5nb) 20 log n*c) 2n^2d) 2^n5. Asymptotic analysis refers to:a) The cost of an algorithm in its best, worst, or average case.*b) The growth in cost of an algorithm as the input size grows towards infinity.c) The size of a data structure.d) The cost of an algorithm for small input sizes6. For an air traffic control system, the most important metric is:a) The best-case upper bound.b) The average-case upper bound.*c) The worst-case upper bound.d) The best-case lower bound.e) The average-case lower bound.f) The worst-case lower bound.7. When we wish to describe the upper bound for a problem we use:*a) The upper bound of the best algorithm we know.b) The lower bound of the best algorithm we know.c) We can't talk about the upper bound of a problem because there canalways be an arbitrarily slow algorithm.8. When we describe the lower bound for a problem we use:a) The upper bound for the best algorithm we know.b) the lower bound for the best algorithm we know.c) The smallest upper bound that we can prove for the bestalgorithmthat could possibly exist.*d) The greatest lower bound that we can prove for the best algorithm that could possibly exist.9. When the upper and lower bounds for an algorithm are the same, we use:a) big-Oh notation.b) big-Omega notation.*c) Theta notation.d) asymptotic analysis.e) Average case analysis.f) Worst case analysis.10. When performing asymptotic analysis, we can ignore constants and low order terms because:*a) We are measuring the growth rate as the input size gets large.b) We are only interested in small input sizes.c) We are studying the worst case behavior.d) We only need an approximation.11. The best case for an algorithm refers to:a) The smallest possible input size.*b) The specific input instance of a given size that gives the lowest cost.c) The largest possible input size that meets the required growth rate.d) The specific input instance of a given size that gives the greatestcost.12. For any algorithm:*a) The upper and lower bounds always meet, but we mightnot know what they are.b) The upper and lower bounds might or might not meet.c) We can always determine the upper bound, but might not be able to determine the lower bound.d) We can always determine the lower bound, but might not be able to determine the upper bound.13. If an algorithm is Theta(f(n)) in the average case, then it is:a) Omega(f(n)) in the best case.*b) Omega(f(n)) in the worst case.c) O(f(n)) in the worst case.14. For the purpose of performing algorithm analysis, an important property of a basic operation is that:a) It be fast.b) It be slow enough to measure.c) Its cost does depend on the value of its operands.*d) Its cost does not depend on the value of its operands.15. For sequential search,a) The best, average, and worst cases are asymptotically the same.*b) The best case is asymptotically better than the average and worst cases.c) The best and average cases are asymptotically better than the worst case.d) The best case is asymptotically better than the average case, and the average case is asymptotically better than the worst case.Chapter 4 Lists, Stacks and Queues: Instructor's CD questions1. An ordered list is one in which:a) The element values are in sorted order.*b) Each element a position within the list.2. An ordered list is most like a:a) set.b) bag.*c) sequence.3. As compared to the linked list implementation for lists, thearray-based list implementation requires:a) More spaceb) Less space*c) More or less space depending on how many elements are in the list.4. Here is a series of C++ statements using the list ADT in the book.L1.append(10);L1.append(20);L1.append(15);If these statements are applied to an empty list, the result will look like:a) < 10 20 15 >*b) < | 10 20 15 >c) < 10 20 15 | >d) < 15 20 10 >e) < | 15 20 10 >f) < 15 20 10 | >5. When comparing the array-based and linked implementations, the array-based implementation has: *a) faster direct access to elements by position,but slower insert/delete from the current position.b) slower direct access to elements by position,but faster insert/delete from the current position.c) both faster direct access to elements by position, and faster insert/delete from the current position.d) both slower direct access to elements by position, and slower insert/delete from the current position.6. For a list of length n, the linked-list implementation's prevfunction requires worst-case time:a) O(1).b) O(log n).*c) O(n).d) O(n^2).7. Finding the element in an array-based list with a given key valuerequires worst case time:a) O(1).b) O(log n).*c) O(n).d) O(n^2).8. In the linked-list implementation presented in the book, a headernode is used:*a) To simplify special cases.b) Because the insert and delete routines won't work correctly withoutit.c) Because there would be no other way to make the current pointerindicate the first element on the list.9. When a pointer requires 4 bytes and a data element requires 4bytes, the linked list implementation requires less space thanthe array-based list implementation when the array would be:a) less than 1/4 full.b) less than 1/3 full.*c) less than half full.d) less than 2/3 full.e) less than 3/4 fullf) never.10. When a pointer requires 4 bytes and a data element requires 12bytes, the linked list implementation requires less space than the array-based list implementation when the array would be: *a) less than 1/4 full.b) less than 1/3 full.c) less than half full.d) less than 2/3 full.e) less than 3/4 fullf) never.11. When we say that a list implementation enforces homogeneity, wemean that:a) All list elements have the same size.*b) All list elements have the same type.c) All list elements appear in sort order.12. When comparing the doubly and singly linked list implementations,we find that the doubly linked list implementation*a) Saves time on some operations at the expense of additional space.b) Saves neither time nor space, but is easier to implement.c) Saves neither time nor space, and is also harder toimplement.13. We use a comparator function in the Dictionary class ADT:a) to simplify implementation.*b) to increase the opportunity for code reuse.c) to improve asymptotic efficiency of some functions.14. All operations on a stack can be implemented in constant timeexcept:a) Pushb) Popc) The implementor's choice of push or pop (they cannot both beimplemented in constant time).*d) None of the above.15. Recursion is generally implemented usinga) A sorted list.*b) A stack.c) A queue.Chapter 5 Binary Trees: Instructor's CD questions1. The height of a binary tree is:a) The height of the deepest node.b) The depth of the deepest node.*c) One more than the depth of the deepest node.2. A full binary tree is one in which:*a) Every internal node has two non-empty children.b) all of the levels, except possibly the bottom level, are filled.3. The relationship between a full and a complete binary tree is:a) Every complete binary tree is full.b) Every full binary tree is complete.*c) None of the above.4. The Full Binary Tree Theorem states that:*a) The number of leaves in a non-empty full binary tree is one more than the number of internal nodes.b) The number of leaves in a non-empty full binary tree is one less than the number of internal nodes.c) The number of leaves in a non-empty full binary tree is one half of the number of internal nodes.d) The number of internal nodes in a non-empty full binary tree is one half of the number of leaves.5. The correct traversal to use on a BST to visit the nodes in sortedorder is:a) Preorder traversal.*b) Inorder traversal.c) Postorder traversal.6. When every node of a full binary tree stores a 4-byte data field,two 4-byte child pointers, and a 4-byte parent pointer, the overhead fraction is approximately:a) one quarter.b) one third.c) one half.d) two thirds.*e) three quarters.f) none of the above.7. When every node of a full binary tree stores an 8-byte data field andtwo 4-byte child pointers, the overhead fraction is approximately:a) one quarter.b) one third.*c) one half.d) two thirds.e) three quarters.f) none of the above.8. When every node of a full binary tree stores a 4-byte data fieldand the internal nodes store two 4-byte child pointers, the overhead fraction is approximately:a) one quarter.b) one third.*c) one half.d) two thirds.e) three quarters.f) none of the above.9. If a node is at position r in the array implementation for acomplete binary tree, then its parent is at:*a) (r - 1)/2 if r > 0b) 2r + 1 if (2r + 1) < nc) 2r + 2 if (2r + 2) < nd) r - 1 if r is evene) r + 1 if r is odd.10. If a node is at position r in the array implementation for acomplete binary tree, then its right child is at:a) (r - 1)/2 if r > 0b) 2r + 1 if (2r + 1) < n*c) 2r + 2 if (2r + 2) < nd) r - 1 if r is evene) r + 1 if r is odd.11. Assume a BST is implemented so that all nodes in the left subtreeof a given node have values less than that node, and all nodes in the right subtree have values greater than or equal to that node.When implementing the delete routine, we must select as its replacement:a) The greatest value from the left subtree.*b) The least value from the right subtree.c) Either of the above.12. Which of the following is a true statement:a) In a BST, the left child of any node is less than the right child,and in a heap, the left child of any node is less than the right child.*b) In a BST, the left child of any node is less than the right child,but in a heap, the left child of any node could be less than or greater than the right child.c) In a BST, the left child of any node could be less or greater than the right child, but in a heap, the left child of any node must beless than the right child.d) In both a BST and a heap, the left child of any node could be either less than or greater than the right child.13. When implementing heaps and BSTs, which is the best answer?a) The time to build a BST of n nodes is O(n log n), and the time to build a heap of n nodes is O(n log n).b) The time to build a BST of n nodes is O(n), and the time tobuild a heap of n nodes is O(n log n).*c) The time to build a BST of n nodes is O(n log n), and the time to build a heap of n nodes is O(n).d) The time to build a BST of n nodes is O(n), and the time tobuild a heap of n nodes is O(n).14. The Huffman coding tree works best when the frequencies forletters area) Roughly the same for all letters.*b) Skewed so that there is a great difference in relative frequencies for various letters.15. Huffman coding provides the optimal coding when:a) The messages are in English.b) The messages are binary numbers.*c) The frequency of occurrence for a letter is independent of its context within the message.d) Never.Chapter 6 Binary Trees: Instructor's CD questions1. The primary ADT access functions used to traverse a general tree are:a) left child and right siblingb) left child and right child*c) leftmost child and right siblingd) leftmost child and next child2. The tree traversal that makes the least sense for a general treeis:a) preorder traversal*b) inorder traversalc) postorder traversal3. The primary access function used to navigate the general tree when performing UNION/FIND is:a) left childb) leftmost childc) right childd) right sibling*e) parent4. When using the weighted union rule for merging disjoint sets, the maximum depth for any node in a tree of size n will be:a) nearly constant*b) log nc) nd) n log ne) n^25. We use the parent pointer representation for general trees to solve which problem?a) Shortest pathsb) General tree traversal*c) Equivalence classesd) Exact-match query6. When using path compression along with the weighted union rule for merging disjoint sets, the average cost for any UNION or FIND operation in a tree of size n will be:*a) nearly constantb) log nc) nd) n log n7. The most space efficient representation for general trees will typically be:a) List of children*b) Left-child/right siblingc) A K-ary tree.8. The easiest way to represent a general tree is to:a) convert to a list.*b) convert to a binary tree.c) convert to a graph.9. As K gets bigger, the ratio of internal nodes to leaf nodes:*a) Gets smaller.b) Stays the same.c) Gets bigger.d) Cannot be determined, since it depends on the particular configuration of the tree.10. A sequential tree representation is best used for:*a) Archiving the tree to disk.b) Use in dynamic in-memory applications.c) Encryption algorithms.d) It is never better than a dynamic representation.Chapter 7 Internal Sorting: Instructor's CD questions1. A sorting algorithm is stable if it:a) Works for all inputs.*b) Does not change the relative ordering of records with identical key values.c) Always sorts in the same amount of time (within a constant factor) for a given input size.2. Which sorting algorithm does not have any practical use?a) Insertion sort.*b) Bubble sort.c) Quicksort.d) Radix Sort.e) a and b.3. When sorting n records, Insertion sort has best-case cost:a) O(log n).c) O(n log n).d) O(n^2)e) O(n!)f) None of the above.4. When sorting n records, Insertion sort has worst-case cost:a) O(log n).b) O(n).c) O(n log n).*d) O(n^2)e) O(n!)f) None of the above.5. When sorting n records, Quicksort has worst-case cost:a) O(log n).b) O(n).c) O(n log n).*d) O(n^2)e) O(n!)f) None of the above.6. When sorting n records, Quicksort has average-case cost:a) O(log n).b) O(n).*c) O(n log n).d) O(n^2)e) O(n!)f) None of the above.7. When sorting n records, Mergesort has worst-case cost:a) O(log n).*c) O(n log n).d) O(n^2)e) O(n!)f) None of the above.8. When sorting n records, Radix sort has worst-case cost:a) O(log n).b) O(n).c) O(n log n).d) O(n^2)e) O(n!)*f) None of the above.9. When sorting n records with distinct keys, Radix sort has a lower bound of:a) Omega(log n).b) Omega(n).*c) Omega(n log n).d) Omega(n^2)e) Omega(n!)f) None of the above.10. Any sort that can only swap adjacent records as an average case lower bound of:a) Omega(log n).b) Omega(n).c) Omega(n log n).*d) Omega(n^2)e) Omega(n!)f) None of the above.11. The number of permutations of size n is:a) O(log n).c) O(n log n).d) O(n^2)*e) O(n!)f) None of the above.12. When sorting n records, Selection sort will perform how many swaps in the worst case?a) O(log n).*b) O(n).c) O(n log n).d) O(n^2)e) O(n!)f) None of the above.13. Shellsort takes advantage of the best-case behavior of which sort? *a) Insertion sortb) Bubble sortc) Selection sortd) Shellsorte) Quicksortf) Radix sort14. A poor result from which step causes the worst-case behavior for Quicksort? *a) Selecting the pivotb) Partitioning the listc) The recursive call15. In the worst case, the very best that a sorting algorithm can dowhen sorting n records is:a) O(log n).b) O(n).*c) O(n log n).e) O(n!)f) None of the above.Chapter 8 File Processing and External Sorting: Instructor's CD questions1. As compared to the time required to access one unit of data frommain memory, accessing one unit of data from disk is:a) 10 times faster.b) 1000 times faster.c) 1,000,000 time faster.d) 10 times slower.e) 1000 times slower.*f) 1,000,000 times slower.2. The most effective way to reduce the time required by a disk-based program is to:a) Improve the basic operations.*b) Minimize the number of disk accesses.c) Eliminate the recursive calls.d) Reduce main memory use.3. The basic unit of I/O when accessing a disk drive is:a) A byte.*b) A sector.c) A cluster.d) A track.e) An extent.4. The basic unit for disk allocation under DOS or Windows is:a) A byte.b) A sector.*c) A cluster.d) A track.e) An extent.5. The most time-consuming part of a random access to disk is usually: *a) The seek.b) The rotational delay.c) The time for the data to move under the I/O head.6. The simplest and most commonly used buffer pool replacement strategy is:a) First in/First out.b) Least Frequently Used.*c) Least Recently Used.7. The C++ programmer's view of a disk file is most like:*a) An array.b) A list.c) A tree.d) A heap.8. In external sorting, a run is:*a) A sorted sub-section for a list of records.b) One pass through a file being sorted.c) The external sorting process itself.9. The sorting algorithm used as a model for most external sorting algorithms is:a) Insertion sort.b) Quicksort.*c) Mergesort.d) Radix Sort.10. Assume that we wish to sort ten million records each 10 bytes long (for a total file size of 100MB of space). We have working memory of size 1MB, broken into 1024 1K blocks. Usingreplacement selection and multiway merging, we can expect to sort this file using how many passes through the file?a) About 26 or 27 (that is, log n).b) About 10.c) 4.*d) 2.Chapter 9 Searching: Instructor's CD questions1. Which is generally more expensive?a) A successful search.*b) An unsuccessful search.2. When properly implemented, which search method is generally the most efficient for exact-match queries?a) Sequential search.b) Binary search.c) Dictionary search.d) Search in self-organizing lists*e) Hashing3. Self-organizing lists attempt to keep the list sorted by:a) value*b) frequency of record accessc) size of record4. The 80/20 rule indicates that:a) 80% of searches in typical databases are successful and 20% are not.*b) 80% of the searches in typical databases are to 20% of the records. c) 80% of records in typical databases are of value, 20% are not.5. Which of the following is often implemented using a self-organizing list? *a) Buffer pool.b) Linked list.c) Priority queue.6. A hash function must:*a) Return a valid position within the hash table.b) Give equal probability for selecting an slot in the hash table.c) Return an empty slot in the hash table.7. A good hash function will:a) Use the high-order bits of the key value.b) Use the middle bits of the key value.c) Use the low-order bits of the key value.*d) Make use of all bits in the key value.8. A collision resolution technique that places all records directlyinto the hash table is called:a) Open hashing.b) Separate chaining.*c) Closed hashing.d) Probe function.。
四川大学期末考试试题(闭卷)(2009~2010学年第2学期)课程号: 311036030 课程名称:数据结构与算法(B卷)任课教师:孙界平杨秋辉张卫华适用专业年级:软件工程 2009级学号:姓名:考试须知四川大学学生参加由学校组织或由学校承办的各级各类考试,必须严格执行《四川大学考试工作管理办法》和《四川大学考场规则》。
有考试违纪作弊行为的,一律按照《四川大学学生考试违纪作弊处罚条例》进行处理。
四川大学各级各类考试的监考人员,必须严格执行《四川大学考试工作管理办法》、《四川大学考场规则》和《四川大学监考人员职责》。
有违反学校有关规定的,严格按照《四川大学教学事故认定及处理办法》进行处理。
题号一(30%) 二(10%) 三(15%) 四(20%) 五(25%) 卷面成绩得分阅卷时间注意事项:1. 请务必将本人所在学院、姓名、学号、任课教师姓名等信息准确填写在试题纸和添卷纸上;2. 请将答案全部填写在本试题纸上;3. 考试结束,请将试题纸、添卷纸和草稿纸一并交给监考老师。
一、单项选择题(本大题共15小题,每小题2分,共30分)提示:在每小题列评阅教师得分出的四个备选项中只有一个是符合题目要求的,请将其代码填写在答题纸上。
错选、多选或未选均无分。
1. A mathematical function is most like a ( A )(A) Problem(B) Algorithm(C) Program(D) Code2. A recurrence relation is often used to model programs with ( C )(A) for loops.(B) branch control like "if" statements.(C) recursive calls.(D) function calls.3. For an air traffic control system, the most important metric is: ( C )(A) The best-case upper bound.(B) The average-case upper bound.(C) The worst-case upper bound.(D) The best-case lower bound.4. For a list of length n, the linked-list implementation's prev() function requires worst-case time: ( C )(A) O(1).(B) O(log n).(C) O(n).(D) O(n2).5. Assume a BST is implemented so that all nodes in the left subtree of a given node have values less than that node, and all nodes in the right subtree have values greater than or equal to that node. When implementing the delete routine, we must select as its replacement: ( B )(A) The greatest value from the left subtree.(B) The least value from the right subtree.(C) Either of the above.(D) The root.6. The primary ADT access functions used to traverse a general tree are: ( C )(A) left child and right sibling(B) left child and right child(C) leftmost child and right sibling(D) leftmost child and next child7. A sorting algorithm is stable if it: ( B )(A) Works for all inputs.(B) Does not change the relative ordering of records with identical key values.(C) Always sorts in the same amount of time (within a constant factor) for a given input size.(D) Most efficient.8. When sorting n records, Quicksort has worst-case cost: ( D )(A) O(log n).(B) O(n).(C) O(n log n).(D) O(n2)9. The basic unit of I/O when accessing a disk drive is: ( B )(A) A byte.(B) A sector.(C) A cluster.(D) A track.10. The sorting algorithm used as a model for most external sorting algorithms is: ( C )(A) Insertion sort.(B) Quicksort.(C) Mergesort.(D) Radix Sort.11. Which of the following is often implemented using a self-organizing list? ( A )(A) Buffer pool.(B) Linked list.(C) Priority queue.(D) B-Tree12. An entry-sequenced file stores records sorted by: ( C )(A) Primary key value.(B) Secondary key value.(C) Order of arrival.(D) Frequency of access.13. The primary difference between a B-tree and a B+-tree is: ( A )(A) The B+-tree store records only at the leaf nodes.(B) The B+-tree has a higher branching factor.(C) The B+-tree is hight balanced.(D) The B+-tree is smaller.14. The goal of a topological sort is to: ( B )(A) Sort all of the graph vertices by value.(B) Sort all of the graph vertices so that each vertex is listed prior to any others that depend onit.(C) Sort all of the graph vertices by distance from the source vertex.(D) None of the above.15. Which is a good example of a greedy algorithm? ( B )(A) Floyd's all-pairs shortest path algorithm.(B) Prim's minimal-cost spanning tree algorithm.(C) Depth-first search.(D) T opological sorting.二、判断题(本大题共5小题,每小题2分,共10分)提示:正确打T,错误打F,评阅教师得分将其结果填写在答题纸上。
数据结构与算法分析实验报告(川大)《数据结构与算法分析》课程设计报告课题名称:文本编辑器课题设计人(学号):刘佳玉2012141461134指导教师:朱宏评阅成绩:评阅意见:{case 'a'://当用户选择自行输入文本时······break;case 'b'://当用户选择使用电脑设置的文本时·····break;}2、当用户选择自己输入文本时,就需要写一些函数来存储这些信息,可以将这些函数封装在一个模板类中,只要定义一个之歌类的对象(bianji)就可以在需要的时候调用类的函数。
在这个时候需要调用的函数有:bianji.Sethang(h);//设置文本的行数bianji.Setlie(l);//设置文本的列数bianji.Setwenben();//输入文本bianji.Showwenben();//显示文本3、单用户选择使用程序初始化的文本时,只要显示文本即可。
这个时候需要的函数有:bianji.Showwenben();//显示文本4、该文本编辑器有插入,移除,替换,查找,显示和重置的功能,通过输出语句告知用户文本编辑器的功能,并询问用户要使用哪个功能。
相应代码:char ch='s';//初始化chwhile(ch!='q')//当ch!='q'时,就不会退出循环{cout<<"i代表插入文本 ";cout<<"R代表移除文本 ";cout<<"r代表替换文本 ";cout<<"f代表查找文本 ";cout<<"s代表显示当前文本 ";cout<<"n代表重新建立一个文本 ";cout<<"q代表退出 "<<endl;cout<<"请输入你的选择:";cin>>ch;······}5、当用户选择插入(insert)功能时,就只需要将当前行数加1,将要插入的行及其后面的行的文本往后移一行,在输入要插入的行的文本即可,相应代码:while(h0>bianji.Gethang()||h0<1)//如果要插入的行大于已有的//最大行或者小于第一行就会要求重新输入一个{cout<<"输入错误,请重输:";cin>>h0;}bianji.Sethang(bianji.Gethang()+1);//当前行数加1int i,j;for(i=bianji.Gethang()-1;i>=h0;i--)//把要插入行及后面的行的//文本往后一次移一行{for(j=0;j<bianji.Getlie();j++){bianji.Xiugaiwenben(i,j,i-1,j);}}for(i=0;i<bianji.Getlie();i++)//输入要插入的那一行的文本{cout<<"请输入第"<<h0<<"行第"<<i+1<<"个字符:";bianji.Fuzhiwenben(h0-1,i);cout<<endl;bianji.Showwenben();//显示文本6、当用户选择移除(remove)功能时,只需要将要移除的行的后面的文本依次往前移一行,就会顺便把要移除行的文本覆盖了,相当于达到了移除的效果,相应代码:while(h1>bianji.Gethang()||h1<1)//如果要移除的行大于已有的//最大行或者小于第一行就会要求重新输入一个{cout<<"输入有误,请重输:";cin>>h1;}bianji.Sethang(bianji.Gethang()-1);//将当前行数减1int i1,j1;for(i1=h1-1;i1<bianji.Gethang();i1++)//把要移除的行的后面的//行一次往前移一行就顺便把要移除的那一行给覆盖{ //了,从而达到移除的效果for(j1=0;j1<bianji.Getlie();j1++){bianji.Xiugaiwenben(i1,j1,i1+1,j1);}}bianji.Showwenben();7、当用户选择替换(replace)功能时,只需要重新输入要替换行的文本即可,其他行的文本不变,相应代码:for(i2=0;i2<bianji.Getlie();i2++) //得到要替换的那一行的列//数,然后输入新的文本{cout<<"请输入第"<<h2<<"行第"<<i2+1<<"个字符:";bianji.Fuzhiwenben(h2-1,i2);cout<<endl;bianji.Showwenben();8、当用户选择查找(find)功能时,只要用户输入相应列数的文本,然后将其与每一行的文本进行比较,如果完全相同,则会输出相应的行号,通过循环语句来进行匹配,相应代码:for(i3=0;i3<bianji.Getlie();i3++)//根据当前文本的列数来输入//要查找的文本{cout<<"请输入第"<<i3+1<<"列的字符:";bianji.Fuzhiwenben(bianji.Gethang(),i3);//将输入的文本放//到当前的最后一行,只是暂时的} //在这个功能完了后就会//消失,因为没有改变文本的行列for(i3=0;i3<bianji.Gethang();i3++)//根据输入的文本,一行一行//的搜,将每一行的文本域输入的文本进行匹配{ //如果匹配成功就会输出相应的行数j3=0;while(bianji.Findwenben(i3,j3)==bianji.Findwenben(bianji.Gethang(),j3)&&j3<bianji.Getlie()){j3++;//相同就会在查下一列的字符是否相同,直到这一完// 了}if(j3==bianji.Getlie()){cout<<"你要找的文本在第"<<i3+1<<"行"<<endl;count+=1;}}if(count==0)cout<<"你要找的文本不在现有文本中"<<endl;}cout<<endl;9、当用户选择显示(show)功能时,只需要调用模板类中的显示函数即可,相应代码:bianji.Showwenben();与初始化的部分相同,也只是要调用模板类中的相应函数即可,相应代码:cout<<"请输入新的行数:";cin>>h4;bianji.Sethang(h4);//新行cout<<"请输入新的列数:";cin>>l4;bianji.Setlie(l4);//新列bianji.Setwenben();//新文本bianji.Showwenben();//显示文本10、当用户选择重置(new)功能时,五、源程序清单:该程序代码分为3部分,分别是:1、模板类的代码,文件名“linklist.h”,相应代码:#ifndef LINKLIST_H_#define LINKLIST_H_#include<iostream>using namespace std;template<class ElemType>//队列的模板类class LinkList{private:ElemType wenben[256][256];//创立一个二维数组作为存储文本的空间int hang;//数组的行int lie;//数组的列public:LinkList()//构造函数{hang=1;//初始化行数为1lie=1;//初始化列数为1wenben[0][0]='a';//初始化文本为'a'}~LinkList(){}//析构函数void Xiugaiwenben(int h1,int l1,int h2,int l2)//修改文本,将文本中h2行l2列的{ //字符赋给h1行l1列wenben[h1][l1]=wenben[h2][l2];}void Fuzhiwenben(int h,int l)//给文本中h行l列赋一个字符{cin>>wenben[h][l];}ElemType Findwenben(int h,int l)//返回h行l列的字符{return wenben[h][l];}void Sethang(int h)//设定数组的行数{hang=h;}int Gethang()//得到数组的行数{return hang;}void Setlie(int l)//设定数组的列数{lie=l;}int Getlie()//得到数组的列数{return lie;}void Setwenben()//设立一个文本{int i,j;for(i=0;i<hang;i++){cout<<"请输入第"<<i+1<<"行的文本:"<<endl;for(j=0;j<lie;j++){cout<<"请输入第"<<i+1<<"行第"<<j+1<<"列的字符"<<endl;cin>>wenben[i][j];}}}void Showwenben()//显示当前文本{cout<<"当前文本是:"<<endl;int i,j;for(i=0;i<hang;i++){for(j=0;j<lie;j++){cout<<wenben[i][j];}cout<<endl;}}};#endif2、编辑类的代码,文件名是“editor.h”,相应代码:#include"linklist.h"class Editor{private:LinkList<char>bianji;//模板类的char型对象,用来调用模板类中的函数int count;//在使用查找功能时用来判断是否要查找的文本在当前文本中public:void Chushihua()//设置文本的函数{cout<<"a代表自己输入文本,b代表使用电脑设置的文本"<<endl;cout<<"请输入你的选择:"<<endl;char ch;cin>>ch;switch(ch)//对用户的不同选择执行不同的代码{case 'a'://当用户选择自行输入文本时cout<<"请输入文本的行数:";int h;cin>>h;cout<<endl;cout<<"请输入文本的列数:";int l;cin>>l;bianji.Sethang(h);//设置文本的行数bianji.Setlie(l);//设置文本的列数bianji.Setwenben();//输入文本bianji.Showwenben();//显示文本break;case 'b'://当用户选择使用电脑设置的文本时bianji.Showwenben();//显示初始化的文本break;}}void Edite()//编辑文本的函数{char ch='s';//初始化chwhile(ch!='q')//当ch!='q'时,就不会退出循环{cout<<"i代表插入文本";cout<<"R代表移除文本";cout<<"r代表替换文本";cout<<"f代表查找文本";cout<<"s代表显示当前文本";cout<<"n代表重新建立一个文本";cout<<"q代表退出"<<endl;cout<<"请输入你的选择:";cin>>ch;switch(ch)//根据用户的不同选择执行不同的代码{case 'i'://选择插入(insert)功能bianji.Showwenben();//显示当前文本cout<<"请问要插入到第几行?:";int h0;cin>>h0;while(h0>bianji.Gethang()||h0<1)//如果要插入的行大于已有的最大行或者小于第一行就会要求重新输入一个{cout<<"输入错误,请重输:";cin>>h0;}bianji.Sethang(bianji.Gethang()+1);//当前行数加1int i,j;for(i=bianji.Gethang()-1;i>=h0;i--)//把要插入行及后面的行的文本往后一次移一行{for(j=0;j<bianji.Getlie();j++){bianji.Xiugaiwenben(i,j,i-1,j);}}for(i=0;i<bianji.Getlie();i++)//输入要插入的那一行的文本{cout<<"请输入第"<<h0<<"行第"<<i+1<<"个字符:";bianji.Fuzhiwenben(h0-1,i);cout<<endl;}bianji.Showwenben();//显示文本break;case 'R'://选择移除(remove)功能bianji.Showwenben();cout<<"请问要移除哪一行?:";int h1;cin>>h1;while(h1>bianji.Gethang()||h1<1)//如果要移除的行大于已有的最大行或者小于第一行就会要求重新输入一个{cout<<"输入有误,请重输:";cin>>h1;}bianji.Sethang(bianji.Gethang()-1);//将当前行数减1int i1,j1;for(i1=h1-1;i1<bianji.Gethang();i1++)//把要移除的行的后面的行一次往前移一行就顺便把要移除的那一行给覆盖{ //了,从而达到移除的效果for(j1=0;j1<bianji.Getlie();j1++){bianji.Xiugaiwenben(i1,j1,i1+1,j1);}}bianji.Showwenben();break;case 'r'://选择替换(replace)功能bianji.Showwenben();cout<<"要替换哪一行?:";int h2;cin>>h2;int i2;for(i2=0;i2<bianji.Getlie();i2++)//得到要替换的那一行的列数,然后输入新的文本{cout<<"请输入第"<<h2<<"行第"<<i2+1<<"个字符:";bianji.Fuzhiwenben(h2-1,i2);cout<<endl;}bianji.Showwenben();break;case 'f'://选择查找(find)功能bianji.Showwenben();cout<<"请输入要查找的文件:"<<endl;int i3,j3;count=0;for(i3=0;i3<bianji.Getlie();i3++)//根据当前文本的列数来输入要查找的文本{cout<<"请输入第"<<i3+1<<"列的字符:";bianji.Fuzhiwenben(bianji.Gethang(),i3);//将输入的文本放到当前的最后一行,只是暂时的} //在这个功能完了后就会消失,因为没有改变文本的行列/*cout<<"第"<<h3<<"行的文本是:"<<endl;//输入行数就会将当前文本中那一行的文本输出for(i3=0;i3<bianji.Getlie();i3++){cout<<bianji.Findwenben(h3-1,i3);}*/for(i3=0;i3<bianji.Gethang();i3++)//根据输入的文本,一行一行的搜,将每一行的文本域输入的文本进行匹配{ //如果匹配成功就会输出相应的行数j3=0;while(bianji.Findwenben(i3,j3)==bianji.Findwenben(bianji.Getha ng(),j3)&&j3<bianji.Getlie()){j3++;//相同就会在查下一列的字符是否相同,直到这一行完了}if(j3==bianji.Getlie()){cout<<"你要找的文本在第"<<i3+1<<"行"<<endl;count+=1;}}if(count==0){cout<<"你要找的文本不在现有文本中"<<endl;}cout<<endl;break;case 's'://选择显示当前文本bianji.Showwenben();break;case 'n'://选择重置(new)功能int h4,l4;cout<<"请输入新的行数:";cin>>h4;bianji.Sethang(h4);//新行cout<<"请输入新的列数:";cin>>l4;bianji.Setlie(l4);//新列bianji.Setwenben();//新文本bianji.Showwenben();//显示文本break;case 'q':break;}}}};3、主函数的代码,文件名是“main.cpp”,相应代码:#include"linklist.h"#include"editor.h"int main(){Editor e;//编辑类的对象,用来调用类中的函数e.Chushihua();//调用设置文本的函数e.Edite();//调用编辑文本的函数return 0;}六、运行结果:1、选择自己输入文本(a),输入文本为(3行2列):qwerty进行插入操作(i),插入文本as到第2行:进行移除操作(R),移除第3行文本:进行替换操作(t),将第一行文本qw替换为df:进行查找操作(f),查找文本as和qw:进行显示操作(s):进行重置操作(n):重置操作和自己输入文本是一样的,在这里就不演示了,有兴趣可以自己尝试。