DSA Final
DSA Final
DSA Final
A. Perform the mathematical analysis to find the relationship between T(n) and n
C. Derive the mathematical formula of T(n) from the code (or pseudo-code)
a. C A B
b. B A C
c. A C B
24. To solve a big problem of Mr.T, Dummy try to call some people to help. Each person found
that their assigned task is quite similar to others' and so they usually ask other if they have the
solution for the similar problem. The final solution will be collected and combined by Dummy.
So what type of method is best describe the way Dummy used to solve the problem?
a. FIT student's method
b. Divide and conquer method
c. Dynamic programming method
d. Balancing subproblems method
25. In terms of complexity analysis, _____ is more important (more informative).
a. worst case
b. Normal case
c. best case
26. The ______ can't give us an upper bound on performance.
a. Worst case
b. Best case
27. The best case of an algorithm A is a function
BA: N → N where BAno is the _____ number steps performed by A on an input of size n.
a. Not of all the above
b. minimum
c. maximum
28. The number of steps of the recursive (devide and conquer) algorithm for the Tower of Hanoi
_________ those of the simple non-recursive algorithm described at the textbook!
a. equals
b. is less than
c. is more than
29. Dijkstra algorithm is to find the _____.
a. shortest parth based on number of edges
b. shortest parth based on cloud computing
c. shortest parth based on edge weight
30. The runtime complexity of Dijkstra's Algorithm of a connected graph depends mainly on _____
.
a. the operations of graph
b. None of the above
c. the number of Edges and number of Vertices of the graph
31. WHICH PREQUISITE IS NEEDED BY DIJKSTRA ALGORITHM?
a. Non cycles
b. No vertex with more than 4 edges
c. Non-negative edge weights
d. Both of the above
32. What is true about stack?
a. It is Last In First Out
b. Stack is a variation of List.
c. All of the above
d. It is First In Last Out
33. What is true about stack?
a. It is First In First Out List
b. Stack and List have no relation
c. All of the above
d. It is Last In First Out List
34. What is true about Queue?
a. It is a variation of List
b. All of the above
c. It is FIFO
35. In Stack, insertions and deletions can be performed at _____ of it.
a. one end
b. both head and tail
c. two termials
36. What happend if we pop() all the elements from a stack and insert() into a queue, after that, we
delete() all the elements from the queue and push() them to the Stack?
a. we have the stack with revert order of element
b. we have an empty stack
c. I don't know
d. we have done a stupid job
37. What happend if we sequentially POP all the elements from a stack and sequentially INSERT
into a queue, after that, we DELETE all the elements from the queue and PUSH them back to
the Stack?
a. we have the stack with revert order of element
b. b. we have an empty stack (x)
c. I don't know
d. we have done a stupid job
38. In ADT definition of FIFO queue, what operation cannot be ignored?
a. IsFull()
b. Size()
c. All of the above
d. Insert() /// Enqueue
39. What operation(s) can be ignored when defining the ADT of Stack?
a. IsFull()
b. Pop()
c. Push()
40. In a Singly linked list that has only one node, if a Nodes (data, pointer) is a head, the pointer
points to _____.
a. head
b. somewhere in the memory.
c. null
d. tail
41. In a Circular linked liste, if a Nodes (data, pointer) is a tail, the pointer points to _____.
a. tail
b. somewhere in the memory
c. head
d. null
42. A linear list, for which all insertions and deletions (and usually all accesses) are made at both
ends of the list, is called: _____.
a. Dequeue (Double-end queue)
b. all-day queue
c. Singly Linked Queue
d. None of the above
43. In the definition of abtract data type of a List, isEmpty() is the method which returns _____
value.
a. true
b. boolean
c. wrong
d. void
44. In the definition of abtract data type of a List, remove (int position) is the method which returns
_____ value.
a. integer
b. string
c. long
d. void
45. In the definition of abtract data type of a List, size() is the method which returns _____ value.
a. no
b. integer
c. yes
d. void
46. You write a program to find the LARGEST AND SMALLEST elements in an array of n
elements. Generally, this can be done in at least _____ comparisions.
a. n/2
b. b. 2n -1 (x)
c. n - 1
d. 2n - 3
47. What is true about array-based list and reference-based list?
a. reference-based list cannot perform insertion and deletion
b. array-based list is not as flexible in size as reference-based list
c. array-based list is more flexible in size than reference-based list
48. What is true about array-based list and reference-based list?
a. array-based list is lower cost of insertation but not deletion.
b. reference-based list can not perform insertion and deletion
c. for the same problem, reference-based list has larger size than array-based list.
49. What is true about array-based list and reference-based list?
a. reference-based list is lower cost of insertation and deletion.
b. array-based list is completely bad.
c. array-based list is lower cost of insertation but not deletion.
50. What is true about array-based list and reference-based list?
a. reference-based list is harder to perform lookup operation compared to array-
based list
b. They can be implemented by Java language only.
c. elements of array can be located dinamically and discontinuous like reference-based
list
d. reference-based list is an other name of array-based list
51. What is the result of this code below:
----------------------------------------
for (int i=1; i<5; i++)
{
for (int j = 1; j < i-5; j++)
{
System.out.print("*");
}
System.out.println();
}
}
a. nothing
b. //result:
***
**
*
c. //result:
*
**
***
52. What is the result of this code below:
----------------------------------------
for (int i=1; i<5; i++)
{
for (int j = 1; j < 5-i; j++)
{
System.out.print("*"); //Similar to print in C
}
System.out.println(); //similar to print new line in C
}
a. //result:
***
**
*
b. //result:
******
c. //result:
*
**
***
53. What is the result of this code below:
----------------------------------------
for (int i=1; i<5; i++)
{
for (int k=5-i;k<5;k++)
System.out.print("!");
for (int j = 1; j < 5-i; j++)
{
System.out.print("*");
}
System.out.println();
}
a. //result:
*
**
***
b. nothing
c. //result:
!***
!!**
!!!*
!!!!
54. What is the result of this code below:
----------------------------------------
for (int i=1; i<5; i++)
{
for (int k=i;k<5;k++)
System.out.print("!");
for (int j = 5-i; j < 5; j++)
{
System.out.print("*");
}
System.out.println();
}
a. //Result:
***
***
***
***
b. //Result:
*
**
***
****
c. //Result:
!!!!*
!!!**
!!***
!****
d. nothing
55. If we use Adjacency matrix for weighted undirected graph, we will have:
a. None of the above
b. A symmetric matrix over its diagonal
c. An asymmetric matrix
56. Which is the appropriate implementation of Graph
a. Adjacency matrix
b. Adjacency list
c. All of the above
57. What is maximum number of nodes in a binary tree of depth 5?
a. 15
b. 63
c. 30
58. What is number of nodes in a full binary tree of depth 4?
a. 32
b. 10
c. 17
d. 31
59. What is maximum number of nodes in level 4 of a binary tree could have?
a. 16
b. 7
c. I don't know
d. 4
60. How many nodes in total of a full binary that has 33 leaves?
a. 49
b. 40
c. 50
d. 65
61. How many leaves does the complete binary tree that has 19 nodes in total have?
a. a. 9 (x)
b. 11
c. 12
d. 10
62. How many internal nodes of a full binary tree that has 10001 nodes in total?
a. 333
b. 600
c. 768
d. 500
63. Given 2 result of a binary tree traversal:
a. preorder : YZCDEXBUTA
b. inorder : DCEZYUBTXA
64. What is the root node of the tree?
a. B
b. X
c. Y
d. A
65. What is the left child of node B?
a. C
b. X
c. U
d. A
66. What is the right child of node Z?
a. D
b. T
c. Y
d. null
67. Calculate the result of Prefix expression:
a. + 4 5 * / 6 2 3
a. 24
b. 18
c. -8
d. 0
68. Calculate the result of Prefix expression:
+ 10 * 5 + 2 3
a. 31
b. 75
c. 55
d. 35
69. Calculate the result of Postfix expression:
62-31-4*2+*
a. 20
b. 23
c. 17
d. 40
70. Calculate the result of Postfix expression:
62-31-4/2+*
a. 30
b. 10
c. 7
d. 5
71. Calculate the result of Postfix expression:
62+31-4*2+*
a. 120
b. 80
c. 72
d. 36
72.
72.
WHAT IS NOT THE RESULT OF TOPOLOGY SORT?
a. 5, 7, 11, 2, 3, 8, 9, 10
b. 5, 7, 8, 11, 3, 2, 9, 10
c. 5, 7, 3, 8, 11, 2, 9, 10
75.
76.
What is the result of inorder tree traversal? Fill the blanks with correct letter order:
D C E B A U Z T X Y
----------------------------------------------
94. -------------------------------------------------
2. #define TOTAL_SLOTS 100
3. typedef struct queue Queue;
4. struct queue
{ int front;
5. int rear;
6. int items[TOTAL_SLOTS];
7. };
----------------------------------------------------
What implementation type of the queue from the code?
a. J-based implemenation
b. Dont know
c. Linked Implemenation
d. array based implementation
95. What is the maximum nodes in this queue?
a. 99
b. 100
c. n
d. Don’t know
96. What is the maximum nodes in this queue?
-------------------------------------------------
1. //Initialize MAX_SIZE=1000
2. public class Queue {
3. Queue()
4. { int front = 0;
4. int rear = 0;
5. int data[MAX_SIZE];
6. };
----------------------------------------------------
a. Don't know
b. 1000
c. n
d. 999
97. void bubblesort_checkpasses(int x[ ], int N)
{
int temp, i,j;
boolean switched = TRUE;
{...}
}
WITH THE INTRODUCTION OF A BOOLEAN VARIABLE switched, WHAT IS THE
BEST CASE TIME COMPLEXITY OF THE CODE?
a. O(log n)
b. O(n^2)
c. O(n)
d. O(1)
98. //LOOK AT THE GRAPH OPERATION BELOW
//WHAT DOES IT DO?
unmark all vertices in G;
Creat a queue q;
mark s;
insert(s,q)
while (!isempty(q))
__curr = delete(q);
__visit curr; // e.g., print its data
__ for each edge
__ __ if V is unmarked
______mark V;
____ insert(V,q);
a. breadth first search
b. post order graph traversal
c. in order graph traversal
d. depth first search
99. What is the condition of this queue to be empty?
-------------------------------------------------
1. #define TOTAL_SLOTS 100
2. typedef struct queue Queue;
3. struct queue
4. { int front;
4. int rear;
5. int items[TOTAL_SLOTS];
6. };
----------------------------------------------------
a. front = 0;
b. front == rear;
c. rear = 0;
d. rear = null
100. What does this piece of code do to a List?
---------------------------------------------
1. Node current = head;
2. while(current != null)
3. {
5.}
---------------------------------------------
a. insert new node
b. delete the tail
c. Traversing the list
101. Pseudo code:
Use a pointer p to traverse the list and search the node and compare the data.
If found: return the pointer to the node.
Otherwise return NULL. Node(data, next)
----------------------------------------------------------------
1. NodePtr SearchNode(NodePtr pList, int data)
2. { NodePtr p=pList;
3. while (p!=NULL)
4. { if (p->data== _____) //(A)
5. return p;
6. p = _____; //(B)
7. }
8. return NULL;
9.}
--------------------------------------------------
a. (A) 0
i. (B) head
b. (A) data
i. (B) p->data
c. (A) data
i. (B) p->next
102. **** FILL THE BLANK ****
____float large;
____//Update the data at each target position one by one, from right to left
____{
____large = x[ 0 ];//<--TODO
____large_index = 0;
____{
________large = x[ i ]; //<--TODO
____}
0.Insertion-Sort(A)
3.________ i = j-1;
5.________ { A[i+1] = A[ i ];
6.________ i = i – 1;
7.____ }
8.____ A[ i + 1 ] = key ;
9.}
{
______ int down, up, a, temp;
______ a = x[idLeftMost];
______ up = idRightMost;
______ {
____________temp = x[down];
____________x[up] = temp ;
______ }
______ }
______x[up] = a;
______*pj = up;
}
//MERGE SORT:
//sort the subarrays by recursive applications of Mergesort and merge the sorted subarray
______ {
______ }
//THIS FUNCTION IS TO MOVE the root value to make the whole tree a max-heap
// If replacement is not necessary then don’t do it, stop trickling otherwise replace.
______ id2Down = 0;
______ {
__________________ idReplace -- ;
__________________ break;
______ }
//=======================================
p= (NodePtr)malloc(sizeof(struct node));
p->info = value;
p->right = NULL;
p->left = NULL;
return(p);
{ if (p==NULL)
printf("void insertion\n");
printf("invalid insertion");
else
{ if (p==NULL)
printf("void insertion\n");
printf("invalid insertion");
else
____________ return( 0 );
____________ return( 1 );
______ else
//definition: intrav is the function to print all tree nodes using in-order, which follows the rules
defined in lecture.
struct node {
int info;
{ if (tree != NULL)
{ intrav(tree-> left );
ntrav(tree-> info );
//definition: posttrav is the function to print all tree nodes using post-order, which follows the
rules defined in lecture.
struct node {
int info;
{ if (tree != NULL)
{ posttrav(tree-> left );
posttrav(tree-> right );
//-------------------------------- …
//GIVEN:
//====================================================
struct node
{ int info;
NodePtr left;
NodePtr right;
};
void setleft(NodePtr p, int value) {..} //create a new left child of a given node
void setright(NodePtr p, int value) {..} //create a new right child of a given node
void main()
______ for(i=1;i<12;i++)
____________ p=T;
________________________ if (p->left==NULL)
________________________ bNewNodeCreated=TRUE;
________________________ break;
__________________ }
__________________ else
________________________ p=p->left;
__________________ else
__________________ if (p->right==NULL)
__________________ { setright (p, seq[i] );
________________________ bNewNodeCreated=TRUE;
________________________ break;
__________________ }
________________________ else
______________________________ p=p->right;
__________________}
__________________if (!bNewNodeCreated)
__________________printf("%d is a duplicate\n",seq[i]);
______ }
//-------------------------------------------------
1. //Initialize MAX_SIZE=1000
3. Queue()
4. { int front = 0;
5. int rear = 0;
6. int data[MAX_SIZE];
7. };
8. boolean isEmpty()
9. {
11. }
//------------------------------------------------
int delete()
{ int rtn_val;
if (isEmpty())
return ( rtn_val );
---------------------------------------------------
-----------------------------------------------------------
1. public stack()
2.{
4.};
5.
8. {
setNext(top)
9. x. AAA = BBB ;
10. CCC = x;
top
11. }
---------------------------------------------------
-----------------------------------------------------------
1. public stack()
2.{
4.};
int count = 0;
9. while(current != null )
10. {
11. count++ ;
16. }