
(2007-2008学年第1学期)
课程号: 课程名称: 数据结构与算法分析(A卷) 任课教师:
适用专业年级: 06级软件工程 学号: 姓名:
考试须知
四川大学学生参加由学校组织或由学校承办的各级,必须严格执行《四川大学考试工作管理办法》和《四川大学考场规则》。有考试违纪作弊行为的,一律按照《四川大学学生考试违纪作弊处罚条例》进行处理。
| 四川大学各级的监考人员,必须严格执行《四川大学考试工作管理办法》、《四川大学考场规则》和《四川大学监考人员职责》。有违反学校有关规定的,严格按照《四川大学教学事故认定及处理办法》进行处理。 | ||||||||
| 题 号 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 卷面成绩 |
| 得 分 | 20 | 10 | 10 | 15 | 15 | 15 | 15 | |
| 阅卷教师 | ||||||||
| 阅卷时间 | ||||||||
(1)An algorithm must be or do all of the following EXCEPT:
a) correct
b) composed of concrete steps
c) ambiguous
d) composed of a finite number of steps
(2)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.
(3)Pick the quadratic growth rate.
a) 5n b) 20 log n
c) 2n^2 d) 2^n
(4)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.
(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 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 | >
(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 with
a) 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 class
template 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 partition virtual int leftLength() const = 0; // Return length of right partition virtual 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 getValue(Elem&) const = 0; // Print the contents of the list virtual 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 8 4.(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 4 5.(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 class template public: // Return the node's element virtual Elem& val() = 0; // Set the node's element virtual void setVal(const Elem&) = 0; // Return the node's left child virtual BinNode* left() const = 0; // Set the node's left child virtual void setLeft(BinNode*) = 0; // Return the node's right child virtual BinNode* right() const = 0; // Set the node's right child virtual void setRight(BinNode*) = 0; // Return true iff the node is a leaf virtual 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 Vertex 3. Show the final MST.
