四川大学数据结构复习
2022年四川大学计算机科学与技术专业《数据结构与算法》科目期末试卷A(有答案)
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算法)的构造。
四川大学数据结构期末复习毛华老师
The growth rate of ������ ������ is less than or equal to that of������ ������
Upper Bound on ������ ������ Usage: the algorithm is in ������(������ 2 ) in [best, average, worst] case
empty stack
push A top
push B
B A
Pop B
top
top
A
top
A
Problems that Use Stacks
Create a new node with value x The new node links to the node in position k The node in position k-1 links to the new node
C A Head B K Tail NULL
C
Recursive Method: A recursive method is a method that calls itself. i.e., the compute() method makes a call to itself
compute()
Running Time
For most algorithms, running time depends on the “size” of the input. Given the size of the input, ������:
p A
Create a new node q with element X
[四川大学]《数据结构2264》在线作业2
22.带有头结点的单循环链表的头指针为head,则该链表为空的判定条件是()。 A.head= =NUL B.head-next= =NULL C.head!=NULL D.head-next= =head 答案:D
15.若某线性表中最常用的操作是在最后一个元素之后插入一个元素和删除第一个元素,则最节省运 算时间的存储方式是()。 A.单链表 B.仅有头指针的单循环链表 C.双链表 D.仅有尾指针的单循环链表 答案:D
16.一散列表长度m为100,采用除留余数法构造散列函数,即H()=K%P (),,为使散列函数具有较好 的性能,P的选择应是()。 A.99 B.100 C.97 D.93 答案:C
7.采用开放定址法处理散列表的冲突时,其平均查找长度()。 A.低于链接法处理冲突 B.高于链接法处理冲突 C.与链接法处理冲突相同 D.高于二分查找 答案:B
8.对关键字序列()进行增量为3的一趟希尔排序的结果为()。 A.(19, 23, 56, 34, 78, 67, 88, 92) B.(23, 56, 78, 66, 88, 92, 19, 34) C.(19, 23, 34, 56, 67, 78, 88, 92) D.(19, 23, 67, 56, 34, 78, 92, 88) 答案:D
9.设有个结点的无向图,该图至少应有()条边才能确保是一个连通图。 A.5 B.6 C.7 D.8 答案:A
10.树最适合用来表示()。 A.有序数据元素 B.无序数据元素 C.元素之间具有分支层次关系的数据 D.元素之间无联系的数据 答案:C
11.下列关于数据结构的叙述中,正确的是()。 A.数组是不同类型值的集合 B.递归算法的程序结构比迭代算法的程序结构更为精炼 C.树是一种线性结构 D.用一维数组存储一棵完全二叉树是有效的存储方法 答案:D
四川大学2021计算数据结构考试题2(含答案100分)
一.单选题(共44题,52.8分)1采用开放定址法处理散列表的冲突时,其平均查找长度( )。
•A、低于链接法处理冲突•B、高于链接法处理冲突•C、与链接法处理冲突相同•D、高于二分查找正确答案:B 我的答案:B得分:1.2分答案解析:2在二叉树结点的先序序列、中序序列和后序序列中,所有叶子结点的先后顺序( )。
•A、都不相同•B、完全相同•C、先序和中序相同,而与后序不同•D、中序和后序相同,而与先序不同正确答案:B 我的答案:B得分:1.2分答案解析:3对一个算法的评价,不包括如下( )方面的内容。
•A、健壮性和可读性•B、并行性•C、正确性•D、时空复杂度正确答案:B 我的答案:B得分:1.2分答案解析:4对于关键字序列(7,34,77,25,64,49,20,14)进行散列存储时,若选用H(K)=K%7作为散列函数,则散列地址为0的元素有( )个。
•A、1•B、2•C、3•D、4正确答案:D 我的答案:得分:0.0分答案解析:5该二叉树有( )个叶子。
•A、3•B、2•C、5•D、4正确答案:A 我的答案:A得分:1.2分答案解析:6从二叉搜索树中查找一个元素时,其时间复杂度大致为( )。
•A、O(n)•B、O(1)•C、O(log2n)•D、O(n2)正确答案:C 我的答案:C得分:1.2分答案解析:7数据的基本单位是( )。
•A、数据项•B、数据类型•C、数据元素•D、数据变量正确答案:A 我的答案:A得分:1.2分答案解析:8设有6个结点的无向图,该图至少应有( )条边才能确保是一个连通图。
•A、5•B、6•C、7•D、8正确答案:A 我的答案:A得分:1.2分答案解析:9对n个记录进行堆排序,所需要的辅助存储空间为( )。
•A、O(1og2n)•B、O(n)•C、O(1)•D、O(n2)正确答案:C 我的答案:C得分:1.2分答案解析:10设有一个二维数组A[m][n],假设A[0][0]存放位置在644,A[2][2]存放位置在676,每个元素占一个空间,则A[3][3]存放位置在( )。
四川大学软件学院数据结构与算法分析期末试题(2006 级B)
四川大学期末考试试题(2007-2008学年第1学期)课程号:课程名称:数据结构与算法分析(A卷)任课教师:适用专业年级:06级软件工程学号:姓名:(1)An algorithm must be or do all of the following EXCEPT:a) correctb) composed of concrete stepsc) ambiguousd) composed of a finite number of steps(2)For set P, the notation |P| indicatesa) The number of elements in P. b) The inverse of P.c) The powerset of P. d) None of the above.(3)Pick the quadratic growth rate.a) 5n b) 20 log nc) 2n^2 d) 2^n(4)For set P, the notation |P| indicatesa) The number of elements in P.b) The inverse of P.c) The powerset of P.d) None of the above.(5)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.(6)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. (7)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 looklike:a) < 10 20 15 >b) < | 10 20 15 >c) < 10 20 15 | >d) < 15 20 10 >e) < | 15 20 10 >f) < 15 20 10 | >(8)An entry-sequenced file stores records sorted by:a) Primary key value. b) Secondary key value.c) Order of arrival. d) Frequency of access.(9)Breadth-first search is best implemented using:a) A stack or recursion. b) A queue.c) A tree.(10)A recurrence relation is often used to model programs witha) for loops. b) branch control like "if" statements.c) recursive calls. d) None of the above.2.(10 scores)Assume a list has the following configuration:<| 6, 28, 16, 8, 9>Write a series of C++ statements using the List ADT as follows to delete the element with value 16.// List abstract classtemplate <class Elem> class List {public:// Reinitialize the list. The client is responsible for// reclaiming the storage used by the list elements. virtual void clear() = 0;// Insert an element at the front of the right partition.// Return true if successful, false if the list is full. virtual bool insert(const Elem&) = 0;// Append an element at the end of the right partition.// Return true if successful, false if the list is full. virtual bool append(const Elem&) = 0;// Remove the first element of right partition. Return// true if successful, false if right partition is empty.// The element removed is returned in the parameter. virtual bool remove(Elem&) = 0;// Place fence at list start, making left partition empty virtual void setStart() = 0;// Place fence at list end, making right partition empty virtual void setEnd() = 0;// Move fence one step left; no change if already at start virtual void prev() = 0;// Move fence one step right; no change if already at end virtual void next() = 0;// Return length of left partitionvirtual int leftLength() const = 0;// Return length of right partitionvirtual int rightLength() const = 0;// If pos or more elements are in the list, set the size// of left partition to pos and return true. Otherwise,// do nothing and return false.virtual bool setPos(int pos) = 0;// Return in first parameter the first element of the// right partition. Return true if successful, false// if the right partition is empty.virtual bool getV alue(Elem&) const = 0;// Print the contents of the listvirtual void print() const = 0;};3.(10 scores)Build the Huffman coding tree and determine the codes for the following set of letters and weights:a e i o u.1 3 5 7 84.(15 scores)Show the max-heap that results from running buildHeap on the following values stored in an array:10 5 12 3 2 1 8 7 9 45.(15 scores)When implementation Insertion Sort, a binary search could be used to locate the position within the first i – 1 elememts of the array into which element i should be inserted. How would this affect the number of comparisons required? How would using such a binary search affect the asymptotic running time for Insertion Sort?6.(15 scores)// Binary tree node abstract classtemplate <class Elem> class BinNode {public:// Return the node's elementvirtual Elem& val() = 0;// Set the node's elementvirtual void setV al(const Elem&) = 0;// Return the node's left childvirtual BinNode* left() const = 0;// Set the node's left childvirtual void setLeft(BinNode*) = 0;// Return the node's right childvirtual BinNode* right() const = 0;// Set the node's right childvirtual void setRight(BinNode*) = 0;// Return true iff the node is a leafvirtual bool isLeaf() = 0;};Write a recursive function that returns the height of a binary true..7.(15 scores)List the order in which the edges of the following graph are visited when running Prim’s MST algorithm starting3at V ertex 3. Show the final MST.。
川大软件数据结构选择题库
_______________________________ 少年易学老难成,一寸光阴不可轻-百度文库一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 aa)) 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 b e) 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.1_______________________________ 少年易学老难成,一寸光阴不可轻-百度文库_______ 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 storesa 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 resource constraints 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 F, the notation |P| indicatesa)) The number of elements in Pb)The inverse of Pc)The powerset of F.d)None of the above.4.Assume that P contains n elements. The number of sets in the powerset of P isa)nb)n A2*c) 2A nd)2A n - 1e) 2A n + 15.If a sequence has n values, then the number of permutations for that sequence will bea)nb)n A2c)n A2 - 1d)2A 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 isa)) 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 average case.*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)2nA2d)2A n3.Pick the growth rate that corresponds to the most efficient algorithm when n =4.a)5nb)20 log nc)2nA2*d)2A n4.Pick the quadratic growth rate.a)5nb)20 log n*c) 2nA2d) 2An5.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 can alwaysbe 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 best algorithm that 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 greatest cost.12.For any algorithm:a)) The upper and lower bounds always meet, but we might not 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 ofa 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, the array-based listimplementation 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 prev function requiresworst-case time:a)O(1).b)O(log n).*c) O(n).d) O(n A2).7.Finding the element in an array-based list with a given key value requiresworst case time:a)O(1).b)O(log n).*c) O(n).d) O(n A2).8.In the linked-list implementation presented in the book, a header node isused:*a) To simplify special cases._______________________________ 少年易学老难成,一寸光阴不可轻-百度文库一b)Because the insert and delete routines won't work correctly without it.c)Because there would be no other way to make the current pointer indicatethe first element on the list.9.When a pointer requires 4 bytes and a data element requires 4 bytes, thelinked 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 第full.e)less than 34 fullf)never.10.When a pointer requires 4 bytes and a data element requires 12 bytes, thelinked 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 34 fullf)never.11.When we say that a list implementation enforces homogeneity, we meanthat: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 findthat 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 to implement.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 time except:少年易学老难成,一寸光阴不可轻-百度文库a) Pushb)Popc)The implementor's choice of push or pop (they cannot both be implementedin 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 sorted order 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,10少年易学老难成,一寸光阴不可轻-百度文库two 4-byte child pointers, and a 4-byte parent pointer, theoverhead 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 and 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.8.When every node of a full binary tree stores a 4-byte data field and theinternal 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 a complete binarytree, 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 a complete binarytree, 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_______________________________ 少年易学老难成,一寸光阴不可轻-百度文库—11.Assume a BST is implemented so that all nodes in the left subtree of agiven node have values less than that node, and all nodes in the rightsubtree have values greater than or equal to that node. Whenimplementing 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 be less 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 to build 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 to build a heap of n nodes is O(n).14.The Huffman coding tree works best when the frequencies for letters 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.12_______________________________ 少年易学老难成,一寸光阴不可轻-百度文库一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 A25.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 n13_______________________________ 少年易学老难成,一寸光阴不可轻-百度文库一7.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).14_______________________________ 少年易学老难成,一寸光阴不可轻-百度文库*b) O(n).c)O(n log n).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 A2)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 A2)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 A2)e)O(n!)f)None of the above.7.When sorting n records, Mergesort has worst-case cost:a)O(log n).b)O(n).*c) O(n log n).d)O(n A2)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 A2)e)O(n!)15少年易学老难成,一寸光阴不可轻-百度文库*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 A2)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 A2)e)Omega(n!)f)None of the above.11.The number of permutations of size n is:a)O(log n).b)O(n).c)O(n log n).d)O(n A2)*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 A2)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 sort16_______________________________ 少年易学老难成,一寸光阴不可轻-百度文库_______________14.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 do when sorting n records is:a)O(log n).b)O(n).*c) O(n log n).d)O(n A2)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.17少年易学老难成,一寸光阴不可轻-百度文库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. Using replacement 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 questions18少年易学老难成,一寸光阴不可轻-百度文库1.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.19少年易学老难成,一寸光阴不可轻-百度文库9.Hashing is most appropriate for:a)In-memory applications.b)Disk-based applications.*c) Either in-memory or disk-based applications.10.Hashing is most appropriate for:a)) Range queries.b)Exact-match queries.c)Minimum/maximium value queries.11.In hashing, the operation that will likely require more record accesses is: *a) insertb) deleteChapter 10 Indexing: Instructor's CD questions1.An entry-sequenced file stores records sorted by:a)Primary key value.b)Secondary key value.*c) Order of arrival.d) Frequency of access.2.Indexing is:a) Random access to an array.*b) The process of associating a key with the location of a corresponding data record.c) Using a hash table.3.The primary key is:a)) A unique identifier for a record.b)The main search key used by users of the database.c)The first key in the index.4.Linear indexing is good for all EXCEPT:a)Range queries.b)Exact match queries.*c) Insertion/Deletion.d)In-memory applications.e)Disk-based applications.5.An inverted list provides access to a data record from its:a) Primary key.20______________________________ 少年易学老难成,一寸光阴不可轻-百度文库*b) Secondary key.c) Search key.6.ISAM degrades over time because:a) Delete operations empty out some cylinders.*b) Insert operations cause some cylinders to overflow.c) Searches disrupt the data structure.7.Tree indexing methods are meant to overcome what deficiency in hashing? *a) Inability to handle range queries.。
川大软件数据结构选择题库
川大软件数据结构选择题库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《数据结构与算法》试卷及答案
四川大学期末考试试题(闭卷)(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,评阅教师得分将其结果填写在答题纸上。
四川大学锦城学院数据结构与算法期末复习总结
1、从逻辑上可以把数据结构分为(C)两大类。
A.动态结构、静态结构B.顺序结构、链式结构C.线性结构、非线性结构D.初等结构、构造型结构2、以下数据结构中,哪一个是线性结构( D)?A.广义表 B. 二叉树 C. 稀疏矩阵 D. 串3、在下面的程序段中,对x的赋值语句的频度为(C)for (i=1;i<=n;i++)for (j=1;j<=n;i++)x=x+1;n) A. O(2n) B.O(n) C.O(n2) D.O(log24、下面关于线性表的叙述中,错误的是哪一个?( B )A.线性表采用顺序存储,必须占用一片连续的存储单元。
B.线性表采用顺序存储,便于进行插入和删除操作。
C.线性表采用链接存储,不必占用一片连续的存储单元。
D.线性表采用链接存储,便于插入和删除操作。
5、某线性表中最常用的操作是在最后一个元素之后插入一个元素和删除第一个元素,则采用( D )存储方式最节省运算时间。
A.单链表 B.仅有头指针的单循环链表 C.双链表 D.仅有尾指针的单循环链表6、静态链表中指针表示的是( B).A.内存地址 B.数组下标 C.下一元素地址 D.左、右孩子地址7、下面的叙述不正确的是( BC)A.线性表在链式存储时,查找第i个元素的时间同i的值成正比B. 线性表在链式存储时,查找第i个元素的时间同i的值无关C. 线性表在顺序存储时,查找第i个元素的时间同i 的值成正比D. 线性表在顺序存储时,查找第i个元素的时间同i的值无关8、若长度为n的线性表采用顺序存储结构,在其第i个位置插入一个新元素的算法的时间复杂度为( C )(1<=i<=n+1)。
A. O(0)B. O(1)C. O(n)D. O(n2)9、在单链表指针为p的结点之后插入指针为s的结点,正确的操作是:( B )。
A.p->next=s;s->next=p->next; B. s->next=p->next;p->next=s;C.p->next=s;p->next=s->next; D. p->next=s->next;p->next=s;10、对于一个头指针为head的带头结点的单链表,判定该表为空表的条件是( B )A.head==NULL B.head→next==NULL C.head→next==head D.head!=NULL11、一个栈的输入序列为123…n,若输出序列的第一个元素是n,输出第i (1<=i<=n)个元素是( B)。
四川大学《数据结构》期末考试必备通关指导
《数据结构》复习资料一、填空题1.设二维数组B[10][10]是对称矩阵,存储其下三角中的元素,按行优先存储,每个元素占4个单元,B[0,0]的地址是1000,则B[4,7]的地址是1128 。
2.一个具有6个顶点的连通无向图至多有 15 条边。
3.装载因子是散列表的一个重要参数,它反映了散列表的装满程度。
4.已知图G=(V,E),其中V={v1, v2, v3, v4, v5},E={, , , , , },对图G进行拓扑排序所得到的结点序列为 v1、v2、v3、v4、v5 ,顶点v4的入度为 2 。
5.去除广义表LS=(a1,a2,a3,……,an)中第1个元素,由其余元素构成的广义表称为LS的表尾。
6.已知一棵二叉树的中序序列为ACBD,后序序列为CDBA,则它的前序序列为ABCD 。
7.散列存储中,冲突指的是不同的关键字经过同一个哈希函数的映射后,得到相同的哈希地址。
8.一棵二叉树中有36个叶子结点,仅有一个孩子的结点有21个,则这棵二叉树共有 92 个结点。
9.索引文件由文件数据区和索引表组成。
10.用边表示活动的网络(AOE网)的关键路径是指从源点到终点的路径长度最长的路径。
11.一棵含999个结点的完全二叉树的深度为 10 。
12.用字符数组存储长度为n的字符串,数组长度至少为 n+1 。
13.有n个记录的文件,如关键字位数为d,基数为r,则基数排序共要进行 B遍分配与收集。
(A) n (B) d (C) r (D) n - d14.对广义表L=((a,b),(c,d),(e,f))执行操作tail(tail(L))的结果是 B 。
A. (e,f)B. (f)C. ((e,f))D. ( )15、图的邻接矩阵表示法适用于表示 C 。
A. 无向图B. 有向图C. 稠密图D.稀疏图16.下列排序算法中,其时间复杂度和记录的初始排列无关的是 B 。
A. 冒泡排序B. 堆排序C. 插入排序D. 快速排序17.中缀表达式2+X*(Y+3)的后缀形式是 D 。
四川大学《数据结构》课程综合练习题——高起专计算机应用技术专业5
四、算法设计题 1、二维数组 a[m][n]和 b[m][n] void matrixadd(int a[m][n], int b[m][n], c[m][n]) { int j, k; for (j = 0; j < m; j++) { for (k = 0; k < n; k++) { c[j][k] = a[j][k] + b[j][k]; } } } 2、上面所列的几种排序方法的速度都很块,但快速排序、归并排序、基数排序和希尔排序都是在
(n-1)+(n-2)+(n-3)+…+2+1=n(n-1)/2 所以其结论成立。 3、不合适。因为一个城市的设计和规划涉及非常多的项目,很复杂,经常需要修改、 扩充和删除 各种信息,才能适应不断发展的需要。有鉴于此,顺序线性表不能很好适应其需要,故是不合适的。
4、具有 3 个结点的树
具有 3 个结点的二叉树
CBED 和 HGIJF 依此可推出前序遍历的左、右子树的结点序列为
BCDE 和 FGHIJ B 和 F 又分别为左、右子树的根结点,进而又可推出以 B 为根结点的左、右子树,以及 以 F 为根 结点的左、右子树。依此类推,可推出二叉树见下图。ABFC
DG
EH
I
J
三、简答题 1、共有 5 种不同形态的二叉树,具体如下:
2、证明 方法一:用归纳法证明 当 n=1 时,边数为 0,结论成立。 当 n=2 时,边数为 1,结论成立。 当 n=1,2…,k 时均成立,即当 n=k 时,边数为 k(k-1)/2。现证明当 n=k+1 时若仍然 成立,
则结论正确。 由前面证得,对于有 k 个顶点时,其边数总和为 k(k-1)/2。 当再增加一个新顶点时,由于是无向完全图,故该顶点到原来各个顶点均有一条边, 这样就共有
(完整word版)四川大学计算机学院数据结构与算法分析期末试题(2013级A)
注:试题字迹务必清晰,书写工整。
本题2页,本页为第1页教务处试题编号:四川大学期末考试试题(2014-2015学年第1学期)课程号: 课程名称: 数据结构与算法分析(A 卷) 任课教师:适用专业年级: 学号:姓名:1.在一棵高度为5的2叉树中,所含结点个数最多为( )。
A )30B )31C )32D )292.当求链表的直接后继与求直接前驱的时间复杂度都相同时,此链表应为( )。
A )单链表B )双向链表C )单向循环链表D )前面都不正确 3.队列的工作方式是( )。
A )可在队尾删除B )可在队头插入C )先进先出D )先进后出 4.若串S="software",其子串数目是( )。
A )8B )37C )36D )95.设一棵二叉树中没有度为1的结点,已知叶子结点数为n ,此树的结点数为( )。
A )2n+2B )2n+1C )2nD )2n-1 6.对于具有n 个顶点的强连有向图,其有向边条数的最小值为( )。
A )n+1B )nC )n-1D )n-27.已知某二叉树先序遍历为A ,B ,D ,C ,E ,则它可能的中序遍历序列为( )。
A )B ,C ,A ,D ,E B )C ,B ,A ,D ,E C )B ,E ,A ,C ,D D )B ,D ,A ,E ,C 8.在折半查找中,第i 次查找成功的记录个数最多为( )。
A )2iB )2i+1C )2i -1D )2i-1 9.快速排序执行一遍之后,已经到位的元素个数是( )。
A )1B )3C )4nD )2n10.如果只想得到1000个元素组成的序列中第5个最小元素之前的部分排序的序列,用( )方法平均时间最少。
A )起泡排序B )简单选择排序C )Shell 排序D )堆排序 二、(本题10分)一棵非空的有向树中恰有一个顶点入度为0,其他顶点入度为1。
但一个恰有一个顶点入度为0、其他顶点入度为1的有向图却不一定是一棵有向树。
四川大学数据结构复习大纲
第一章绪论重点掌握的内容:1. 数据结构的二元组表示,对应的图形表示,序偶和边之间的对应关系。
2. 集合结构、线性结构、树结构和图结构的特点。
3. 抽象数据类型的定义和表示方法。
4. 一维和二维数组中元素的按下标和按地址的访问方式以及相互转换,元素地址和数组地址的计算,元素占用存储空间大小和数组占用存储空间大小的计算。
5. 普通函数重载和操作符函数重载的含义,定义格式和调用格式。
6. 函数定义中值参数和引用参数的说明格式及作用,函数被调用执行时对传送来的实际参数的影响。
7. 算法的时间复杂度和空间复杂度的概念,计算方法,数量级表示。
8. 一个简单算法的最好、最差和平均这三种情况的时间复杂度的计算。
对于本章的其余内容均作一般掌握。
第二章线性表重点掌握的内容:1. 线性表的定义及判别和抽象数据类型的描述,线性表中每一种操作的功能,对应的函数名、返回值类型和参数表中每个参数的作用。
2. 线性表的顺序存储结构的类型定义,即List类型的定义和每个域的定义及作用。
3. 线性表的每一种运算在顺序存储结构上实现的算法,及相应的时间复杂度。
4.链接存储的概念,线性表的单链接和双链接存储的结构,向单链表中一个结点之后插入新结点或从单链表中删除一个结点的后继结点的指针链接过程。
5. 单链表中结点的结构,每个域的定义及作用,即LNode类型的定义及结构。
6. 带表头附加结点的链表、循环链表、双向链表的结构特点。
7. 线性表的每一种运算在单链表上实现的算法及相应的时间复杂度。
8. 在顺序存储或链接存储的线性表上实现指定功能的算法的分析和设计。
9.Josephus问题的求解过程。
10.顺序表和线性链表的性能比较及各自使用背景。
对于本章的其余内容均作一般掌握。
第三章数组和广义表重点掌握的内容:1.多维数组的逻辑结构特征。
2. 多维数组的顺序存储结构及地址计算公式。
3.数组是一种随机存取结构的原因。
4.特殊矩阵和稀疏矩阵的概念。
(完整word版)四川大学计算机学院数据结构与算法分析期末试题(级B)
四川大学期末考试试题(2014-2015学年第1学期)课程号:课程名称:数据结构与算法分析(B卷)任课教师:适用专业年级:学号:姓名:一、单项选择题(每小题2 分,共20分)1.在数据类型中,值不可分解的类型为()。
A)原子类型B)结构类型C)固定聚合类型D)可变聚合类型()。
2.如某链表中最常用的操作是在最后一个结点后插入一个结点和删除最后一个结点,则()存储方式最节省运行时间。
A)单链表B)带头结点的单链表C)单循环链表D)带头结点的双循环链表3.在解决计算机主机与打印机之间速度不匹配问题时通常设置一个打印数据缓冲区,这样主机将要输出的数据依次写入该缓冲区,而打印机则从该缓冲区中取出数据打印。
该缓冲区应该是一个()结构。
A)栈B)队列C)数组D)线性表4.串的长度是()。
A)串中不同字母的个数B)串中不同字符的个数C)串中所含数字的个数D)串中所有字符的个数5.一棵深度为5的满二叉树的结点数为()。
A)16 B)15 C)32 D)316.采用邻接表存储的图按深度优先搜索方法进行遍历的算法类似于二叉树的()。
A)先序遍历B)中序遍历C)后序遍历D)层次遍历7.某二叉树的先序遍历序列与后序遍历序列相反,则此二叉树一定为()。
A)高度等于其结点数B)空或只有一个结点C)任一点无左孩子D)任一结点无右孩子8.堆排序的时间复杂度是()。
A)O(1) B)O(n) C)O(n2) D)O(nlogn)9.每一趟都能选出一个元素放在其最终位置上,并且不稳定的排序算法是()。
A)冒泡排序B)简单选择排序C)希尔排序D)直接插入排序10.若需在O(nlogn)的时间内完成对数组的排序,且要求排序是稳定的,则可选择的排序方法是()。
A)快速排序B)堆排序C)归并排序D)直接插入排序二、(本题10分)有二叉树中序序列为:ABCEFGHD;后序序列为:ABFHGEDC;请画出此二叉树。
三、(本题10分)已知序列7,31,13,11,20,35,25,8,4,11,24,40,27,请画出此序列列的排序二叉树,分别给出下列操作后的二叉树:(1)插入数据9;(2)删除结点17;(3)再删除结点13。
数据结构与算法分析 复习试卷B1
四川大学期末考试试题(闭卷)(2009~2010学年第1学期)课程号:311036030课程名称:数据结构与算法分析(B卷)任课教师:孙界平,张卫华适用专业年级:软件工程 2008级学号:姓名:注意事项:1. 请务必将本人所在学院、姓名、学号、任课教师姓名等信息准确填写在试题纸和添卷纸上;2. 请将答案全部填写在本试题纸上;3. 考试结束,请将试题纸、添卷纸和草稿纸一并交给监考老师。
一、单项选择题(本大题共20小题,每小题2分,共40分)提示:在每小题列评阅教师得分出的备选项中只有一个是符合题目要求的,请将其代码写到答题纸上。
错选、多选或未选均无分。
1. 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 Which of the following is not a good proof technique.a) proof by contradiction.*b) proof by example.c) proof by mathematical induction.3. 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 can always be an arbitrarily slow algorithm.4. 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 greatest cost.5. In the linked-list implementation presented in the book, a header node is used:*a) T o simplify special cases.b) Because the insert and delete routines won't work correctly without it.c) Because there would be no other way to make the current pointer indicate the first element on the list.6. Recursion is generally implemented usinga) A sorted list.*b) A stack.c) A queue.7. 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.8. When every node of a full binary tree stores a 4-byte data field and 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. 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 be less 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.10. 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.11. 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.12. 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.13. A poor result from which step causes the worst-case behavior for Quicksort?*a) Selecting the pivotb) Partitioning the listc) The recursive call14. 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.15. 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.16. Self-organizing lists attempt to keep the list sorted by:a) value*b) frequency of record accessc) size of record17. 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.18. An entry-sequenced file stores records sorted by:a) Primary key value.b) Secondary key value.*c) Order of arrival.d) Frequency of access.19. An inverted list provides access to a data record from its:a) Primary key.*b) Secondary key.c) Search key.20. The goal of a topological sort is to: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 on it.c) Sort all of the graph vertices by distance from the source vertex.二、判断题(本大题共8小题,每小题1分,共8分)提示:正确答T,错误答F,评阅教师得分将其结果写到答题纸上。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Review of Data Structures and AlgorithmsChapter 1 Data structures and algorithmsConceptType: A type is a collection of values.Simple type: Its values contain no subparts.Composite type/Aggregate type: Its values contain subparts called data item or member. Data type: A data type is a type together with a collection of operations to manipulate the type.ADT: An abstract data type (ADT) is the realization of a data type as a software component. The interface of the ADT is defined in terms of a type and a set of operations on that type. The behavior of each operation is determined by its inputs and outputs.Data structure: A data structure is the physical implementation for an ADT.Problems: A problem is a task to be performed.Function: A function is a matching between inputs (the domain) and outputs (the range). Algorithm: An algorithm is a recipe for solving a problem whose steps are concrete and unambiguous. Algorithms must be correct, of finite length, and must terminate for all inputs.Programs: A program is an instantiation of an algorithm in a programming language. Chapter 2 Mathematical preliminariesConceptSet: A set is a collection of distinguishable members or elements.Recursion: An algorithm is recursive if it calls itself to do part of its work.Chapter 3 Algorithm AnalysisConceptAsymptotic algorithm analysis(对资源消耗进行评估,对同一程序算法进行分析): Asymptotic analysis attempts to estimate the resource consumption of an algorithm.It allows us to compare the relative costs of two or more algorithms for solving the same problem. Asymptotic analysis also gives algorithm designers a tool for estimating whether a proposed solution is likely to meet the resource constraints for a problem before they implement an actual program.Growth rate(算法随着输入增长导致整体花费增长的比重): the rate at which the cost of the algorithm grows as the size of its input grows.Best/worst/average case: They express what the resource usage is at least, at most and on average, respectively.Upper/Lower bound: It indicates the upper/lower or highest/least growth rate that the algorithm can have.Big-Oh/Big-Omega notation(最大最小增长率,最多最少资源消耗): It describes an upper/lower bound to its growth rate of f(n). It states a claim about the greatest/least amount of some resource that is required by an algorithm for some class of inputs of size n. Theta notation: When the upper and lower bounds are the same within a constant factor, we indicate this by using it.Space/time tradeoff(时间和空间的平衡): One can often achieve a reduction in time if one is willing to sacrifice space or vice versa.Chapter 4 Lists, Stacks and QueuesConceptList: list is a finite, ordered sequence of data items known as elements.Array-based/Linked list: Implement lists make use of arrays/pointers.Ordered/Unordered list:A list that the elements in it are stored in ascending order.Singly/Doubly linked list:Each list node has a single pointer to the next node on the list.A doubly linked list allows convenient access from a list node to the next node and also to the preceding node on the list.Stack: The stack is a list-like structure in which elements may be inserted or removed from only one end.Array-based/Linked stack: Implement stacks make use of arrays/pointersQueue:The queue is a list-like structure that provides restricted access to its elements. Queue elements may only be inserted at the back and removed from the front.Array: A contiguous block of memory locations, where each memory location stores one fixed-length data item.Array-based/Linked queue: Implement queues make use of arrays/pointers.Circular queue: The first position of the storage space are connected to the last position, so this form a loop in the queue.AlgorithmInsert and deleteChapter 5 Binary TreesBST:Binary Search Tree.A binary tree that conforms to the following condition, known as the Binary Search Tree Property: All nodes stored in the left subtree of a node whose key value is K have key values than K. All nodes stored in the right subtree of a node whose key value is K have key values greater than or equal to K.Huffman treeFull binary tree: Each node is either a leaf or internal node with exactly two non-emptychildren.(叶节点数为内节点数加1,删除一个内部节点的两个叶节点则内部节点数减1,空指针数= 非空指针数+1)Complete binary tree: If the height of the tree is d, then all leaves except possibly level d-1are completely full. The bottom level has all nodes to the left side.Height/depth of a binary treeThe depth of a node M in the tree is the length of the path from the root of the tree to M.(指单独一个点)The height of a tree is one more than the depth of the deepest node in the tree.Preorder traversal(前): Visit each node before visiting its children.template <typename E> // Good implementationvoid preorder(BinNode<E>* root) {if (root == NULL) return; // Emptyvisit(root); // Perform some actionpreorder(root->left());preorder(root->right());}Postorder traversal(后): Visit each node after visiting its children. LRVRLVtemplate <typename E>void postorder(BinNode<E>* root) {if (root == NULL) return; // Emptypostorder(root->left());postorder(root->right());visit(root); // Perform some action}Inorder traversal(中): Visit the left subtree, then the node, then the right subtree. template <typename E>void inorder(BinNode<E>* root) {if (root == NULL) return;inorder(root->left());visit(root);inorder(root->right());}BST插入:template <typename Key, typename E>BSTNode<Key,E>* BST<Key,E>::inserthelp(BSTNode<Key,E>* root,const Key& k, const E& it) {if (root == NULL) // Empty: create nodereturn new BSTNode<Key, E>(k,it,NULL,NULL);if (k < root->key())root->setLeft(inserthelp(root->left(), k, it));else root->setRight(inserthelp(root->right(), k, it));// Return tree with node insertedreturn root;}BST删除:template <typename Key, typename E>BSTNode<Key,E>* BST<Key, E>::deletemin(BSTNode<Key,E>* rt) {if (rt->left() == NULL)return rt->right();else { // Continue leftrt->setLeft(deletemin(rt->left()));return rt;}}Heap(堆):Complete binary tree with the heap property(partially ordered)Priority queue:When a collection of objects is organized by importance or priority Heap: 构造堆时按编号一个一个插入(不比较大小),比较时从最后一个非叶子树开始与自己的子节点进行对比。