Thursday, May 10, 2018

Upwork Data Structures Test

1. Which graph traversal algorithm uses a queue to keep track of the vertices which need to be processed?
Answers:
• Breadth-first search
• Depth-first search
2. A simple graph with n vertices and k components can have at the most _______.
Answers:
• n edges
• n-k edges
• (n-k)(n-k-1)/2 edges
• (n-k)(n-k+1)/2 edges
3. What is the minimum number of edges which must be removed from a complete bipartite graph of six nodes K(6) so that the remaining graph is a planar?
Answers:
• 2
• 3
• 4
• 6
4. Which feature of heaps allows them to be efficiently implemented using a partially filled array?
Answers:
• Heaps are binary search trees
• Heaps are complete binary trees
• Heaps are full binary trees
• Heaps contain only integer data
5. What happens if you make a recursive call without making the problem smaller?
Answers:
• The operating system detects the infinite recursion because of the "repeated state"
• The program keeps running until you press Ctrl-C
• The results are non-deterministic
• The run-time stack overflows, halting the program
6. Tree algorithms typically run in time O(d) . What is d?
Answers:
• The depth of the tree
• The number of divisions at each level
• The number of nodes in the tree
• The total number of entries in all the nodes of the tree
7. Here is a code for an integer variable n
    
      while (n > 0)
      {
        n = n/10; // Use integer division
      }
What is the worst case scenario analysis for the above loop?
Answers:
• O(1)
• O(log n)
• O(n)
• O(n2)
8. Suppose we have a circular array implementation of a queue, with ten items in the queue stored at data[2] through data[11]. The CAPACITY is 42. Where does the push member function place the new entry in the array?
Answers:
• data[1]
• data[2]
• data[11]
• data[12]
9. Which of the following sorting algorithms yield approximately the same worst-case and average-case running time behavior in O(n*log(n))?
Answers:
• Bubble sort and selection sort
• Heap sort and merge sort
• Quick sort and radix sort
• Tree sort and Median-of-3 quicksort
10. The operation for adding an entry to a stack is traditionally called ________.
Answers:
• add
• append
• insert
• push
11. For a complete binary tree with depth d, the total number of nodes is:
Answers:
• 2d+1
• 2d
• 2d-1
• 2d2
12. Which of the following is false?
Answers:
• A binary search begins with the middle element in the array
• A binary search continues halving the array either until a match is found or until there are no more elements to search
• If the search argument is greater than the value located in the middle of the binary, the binary search continues in the lower half of the array
13. Which of the following applications may use a stack?
Answers:
• A parentheses balancing program
• Keeping track of local variables at run time
• Syntax analyzer for a compiler
• All of the above
14. What is the value of the post-fix expression 6 3 2 4 + - *?
Answers:
• Something between -15 and -100
• Something between -5 and -15
• Something between 5 and 15
• Something between 15 and 100
15. The minimum number of interchanges needed to convert the array 89,19,14,40,17,12,10,2,5,7,11,6,9,70 into a heap with the maximum element at the root is:
Answers:
• 0
• 1
• 2
• 3
16. Suppose T is a complete binary tree with 14 nodes. What would be the minimum possible depth of T?
Answers:
• 0
• 3
• 4
• 5
17. In which data structure do the insertion and deletion take place at the same end?
Answers:
• Linked list
• Tree
• Stack
• Linked list of stack
18. What is the formulae to find maximum number of nodes n in a perfect binary tree?
Answers:
• 2h + 1 - 1
• 2h + 1
• 2h
• 2h + 1 + 1
19. A chained hash table has an array size of 512. What is the maximum number of entries that can be placed in the table?
Answers:
• 511
• 512
• 1024
• There is no maximum limit
20. In which dynamically created linked list can the first node be recovered after moving to the second node?
Answers:
• Simple linked list
• Circular linked list
• Doubly linked list
• Both b and c
21. What is the best definition of a collision in a hash table?
Answers:
• Two entries are identical except for their keys
• Two entries with different data have exactly the same key
• Two entries with different keys have exactly the same hash value
• Two entries with exactly the same key have different hash values
22. What is the pre-order traversal equivalent of the following algebraic expression?

[a+(b-c)]*[(d-e)/(f+g-h)]
Answers:
• abc-+de-fg+h-/*
• *+a-bc/-de-+fgh
• a+*b-/c-d-e+fgh
• *+a-bc-/d+e-fgh
23. A sparse matrix can be a lower-triangular matrix when____.
Answers:
• all the non-zero elements lie only on the leading diagonal
• all the non-zero elements lie above the leading diagonal
• all the non-zero elements lie below the leading diagonal
• None of the above
24. A graph in which all nodes are of an equal degree is known as:
Answers:
• Multigraph
• Non - regular graph
• Regular graph
• Complete graph
25. What is the maximum number of statements that may be recursive calls in a single function declaration?
Answers:
• 1
• 2
• n (n is the argument)
• There is no fixed maximum
26. Which additional requirement is placed on an array so that binary search may be used to locate an entry?
Answers:
• The array elements must form a heap
• The array must have at least 2 entries
• The array must be sorted
• The array's size must be a power of two
27. What is the worst-case scenario for heapsort to sort an array of n elements?
Answers:
• O(log n)
• O(n)
• O(n log n)
• O(n2)
28. The recurrence relation T(n)=mT(n/2)+an2 is satisfied by___
Answers:
• T(n)=O(nm)
• T(n)=O(m*log(m))
• T(n)=O(n*log(m))
• T(n)=O(m*log(n))
29. If 'data' is a circular array of CAPACITY elements and 'last' is an index in that array, what is the formula for the index after 'last'?
Answers:
• (last % 1) + CAPACITY
• last % (1 + CAPACITY)
• (last + 1) % CAPACITY
• last + (1 % CAPACITY)
30. Consider the node of a complete binary tree whose value is stored in data[i] for an array implementation. If this node has a right child, where will the right child's value be stored (the array's first index is 0)?
Answers:
• data[i+1]
• data[i+2]
• data[2*i + 1]
• data[2*i + 2]
31. In a complete binary tree, the parent of any node k can be determined by ________.
Answers:
• 2k
• 2k+1
• K/2
• 2K-1
32. Consider a linked list of n elements which is pointed by an external pointer. What is the time taken to delete the element which is a successor of the pointed element by a given pointer?
Answers:
• O(1)
• O(log2n)
• O(n)
• O(n*log2n)
33. Suppose X is a B-tree leaf containing 41 entries and has at least one sibling. Which of the statements would be true in this case?
Answers:
• Any sibling of X is also a leaf
• Any sibling of X contains at least 41 entries
• The parent of X has exactly 42 entries
• X has at least 41 siblings
34. In a complete binary tree of n nodes, how far are the most distant two nodes? Assume each in the path counts 1. Assume log(n) is log base 2.
Answers:
• about log(n)
• about 2*log(n)
• about 3*log(n)
• about 4*log(n)
35. In a graph G, F is a spanning forest of G if

(i)F is a subgraph of G containing all the nodes of G
(ii)F is an order forest containing trees T1,T2,...Tn
(iii)Ti contains all the nodes that are reachable in G from the root Ti and are contained in Tj for some j<i..

Which of the above conditions is/are true?
Answers:
• (i),(ii)
• (ii),(iii)
• (i),(iii)
• (i),(ii) and (iii)
36. Which information is not saved in the activation record when a function call is executed?
Answers:
• Current depth of recursion
• Formal parameters
• Location where the function should return when done
• Local variables
37. The linked list implementation of sparse matrices is superior to the generalized dope vector method because it is __________.
Answers:
• conceptually easier and completely dynamic
• efficient if the sparse matrix is a band matrix
• efficient in accessing an entry
• all of these
38. Which situation occurs frequently if the selected hash function is poor?
Answers:
• Overflow
• Underflow
• Collision
• None of the above
39. The post-order traversal of a binary tree starts with:
Answers:
• Post-order traversal of the left sub tree
• Post-order traversal of the right sub tree
• Post-order traversal of the root
• Post-order traversal of the lowest node
40. One difference between a queue and a stack is:
Answers:
• Queues require dynamic memory but stacks do not
• Stacks require dynamic memory but queues do not
• Queues use two ends of the structure but stacks use only one
• Stacks use two ends of the structure but queues use only one
41. What is the minimum number of nodes in a full binary tree with depth 3?
Answers:
• 4
• 8
• 11
• 15
42. Using which traversal in a sorted binary insertion tree can a sorted array of numbers be obtained?
Answers:
• Pre-order traversal
• Post-order traversal
• In order traversal
• Top-down traversal
43. Where does the push member function place the new entry on the linked list in the linked list implementation of a queue?
Answers:
• At the head
• At the tail
• After all other entries that are greater than the new entry
• After all other entries that are smaller than the new entry
44. Which term is used to describe an O(n) algorithm?
Answers:
• Constant
• Linear
• Logarithmic
• Quadratic
45. What is the minimum number of nodes in a complete binary tree with depth 3?
Answers:
• 4
• 8
• 11
• 15
46. What is true of the complete bipartite graphs K(3,3) and K(2,4)?
Answers:
• Both are planar
• Neither is a planar
• Both are isomorphic
• None of these
47. If X is the adjacency matrix of a graph G with no self loops, the entries along the principle diagonal of X are ______.
Answers:
• all zeros
• all ones
• both zeros and ones
• different
48. Consider a linked list implementation of a queue with two pointers: front and rear. The time needed to insert element in a queue of length n is:
Answers:
• O(1)
• O(log2n)
• O(n)
• O(n*log2n)
49. What is the worst-case scenario for mergesort to sort an array of n elements?
Answers:
• O(log n)
• O(n)
• O(n log n)
• O(n2)
50. Consider a hashing function that resolves collision by quadratic probing. Assume that the address space is indexed from 1 to 8. If a collision occurs at position 4, the location which will never be probed is:
Answers:
• 4
• 5
• 8
• 2

No comments:

Post a Comment