Uploaded by Tran Viet Hoang QP3380

PracticeTest2 CSD201 3

advertisement
CSD201 PROGRESS TEST 2
Time (60 minutes) The Question will be submitted along with your source code
to edu-next.
PART 1: Answer the Question. (40 pts)
1. Given an empty AVL tree, how would you construct the AVL tree when a set of numbers
are given without performing any rotations?
a.
b.
c.
d.
just build the tree with the given input
find the median of the set of elements given, make it as root, and construct the tree
use trial and error
use dynamic programming to build the tree
2. What do the below definitions convey?
i. A binary tree is balanced if for every node it is going to hold that the number of inner nodes in the
left subtree and the number of inner nodes in the right subtree differ by at most 1.
ii. A binary tree is balanced if, for any two leaves, the difference of the depth is at most 1.
a.
b.
c.
d.
weight-balanced and height-balanced tree definitions
height-balanced and weight-balanced tree definitions
definitions of weight-balanced tree
definitions of height-balanced tree
3. Searching and sorting algorithms are best implemented with which data structure?
a.
b.
c.
d.
An array-based list
A linked list
Both of the above
None of the above
4. A binary search algorithm can be best described as what?
a.
b.
c.
d.
An instant lookup method
A divide and conquer technique
Start at the head, move through the list until found
None of the above
5. The following best describes which algorithm? The elements are compared and swapped if the
previous values are found to be greater than the element.
a. Selection-sort algorithm
b. Quick-sort algorithm
c. Bubble-sort algorithm
d. None of the above
6. For the given graph(G), which of the following statements is true?
a.
b.
c.
d.
G is a complete graph
G is not a connected graph
The vertex connectivity of the graph is 2
The edge connectivity of the graph is 1
7. Binary search tree T is said to be balanced when for every node n in T?
a.
b.
c.
d.
n’s left and right subtrees have equal height.
n’s left and right subtrees have equal size.
n’s left and right subtrees have heights that differ by at most one.
n’s left and right subtrees have sizes that differ by at most one
8. The set of all addition edges generated by the BFS tree starting at node B is.
a. A D F G C E
b. A D
c. A C D G F E
d. Cannot be generated
9. The set of all addition edges generated by the DFS tree starting at node C is.
a.
b.
c.
d.
e.
BADGFE
GBADEF
BG EDAF
DGBAFE
FADEBG
10. The common data structure required for Depth First Traversal on a graph is.
a.
b.
c.
d.
Stack
Queue
Tree
All of the above
11 Which is the correct order for Kruskal’s minimum spanning tree algorithm to add edges to
the minimum spanning tree for the figure shown Below?
a. (AD)(BD)(DE)(EG)(GF)(AC)
b. (AD)(EG)(BD)(BE)(GF)(AC)
c. None of the above
d. Both of the above
12. For minimum spanning tree (MST) construction, Prim’s algorithm selects?
a. With minimum weight so that cost of MST is always minimum
b. with the maximum number of vertices connected to it so that MST has the least
diameter
c. that does not introduce a cycle
d. that adds a new vertex to a partially constructed tree with minimal increment in the
cost of MST
13. What happens when you delete Node 10 of this AVL tree? Draw the new tree.
14. The max heap constructed from the list of numbers 19 2 63 52 47 6 3 18 33 is
a.
b.
c.
d.
63 47 52 33 19 18 6 3 2
63 52 47 33 19 18 6 3 2
63 47 52 19 33 6 18 2 3
63 47 52 33 19 18 6 2 3
15. Suppose we remove the root node from the following BST tree, which could be
the new root?
a.
b.
c.
d.
2
1
5
4
16. Suppose we are sorting an array of eight integers using quick sort, and we have just
finished the first partitioning with the array looking like this: 2 5 1 7 9 12 11 10 Which
statement is correct?
a.
b.
c.
d.
the pivot could be 7 or 9
the pivot could be 7
the pivot could be 9
none of the above
17. In the quick sort method, a desirable choice for the portioning element in real-life data
will be?
a.
b.
c.
d.
The first element of the list.
The median element of the list.
The last element of the list.
The average value.
18, The number of swapping needed to sort the numbers 8,22,7,9,31,19,5,13 in descending
order?
a.
b.
c.
d.
14
12
16
10
19) What happen to this BST tree when convert to AVL. Draw the AVL tree.
20) The Quick-sort algorithm belongs to
a.
b.
c.
d.
Greedy
Dynamic Programming
Divide and conquer
None of the above
PART 2: (60 pts)
2. Construct the adjacency list to manage Students for the following
graph. Each student has information about studentID, the student
name, and the student's average mark, each student will connect with
another student with the acquaintance points.
a. Write the BFS method to traverse the connection of the students
from any student
b. Write the DFS method to traverse the student by student avg
descending order
c. From A, write a method to answer is F have any connection to
A ? , show the fastest way to know F from A.
d. Construct minimum spanning tree from this graph
e. Write method to find Euler-path or circle for this graph
Download