Department: Computer Science & IT
Program: MCS 2nd Evening-B (Fall 2019-2021)
Subject Name: Data Structure and Algorithms
Subject Title: CS-21201(s20)-CSIT192-MCS-2ND-2E
Teacher Name: Dr. Mujtaba Husnain
If p = 5 is an integer variable and its address is saved in pointer variable
q. In how many ways we can display value of p
A. cout<<*p
B. cout<<q
C. cout<<*q
D. None of above
ANSWER: C
Which of the following statement(s) about a pointer variable is/are TRUE.
A. Pointer variable has ability to save both the data and address
B. Pointer variable saves address only
C. Pointer variable saves data only
D. Pointer can save more than one address at same time
ANSWER: B
Consider the following code. What will be the output.
int *ptr
int x[2] = {56, 57}
ptr = &x
cout<<*(ptr) + 1 << *(ptr + 1).
A. 57, 56
B. 57, 57
C. 57, 58
D. 56, 57
ANSWER: B
What will the output of following code.
void main()
{
int p; /*Suppose address of var is 1024 */
int *q = &p
p = 5
*q = *q * 3
cout<<"value of p=”<<p<<”value by pointer is =”<<*q
}.
A. 15 15
B. 15 5
C. 5 5
D. 5 15
ANSWER: A
What will be the output of following code.
int i = 5, j = 10
int *p = &i
j = *p + 4
cout<<*p + j.
A. 15
B. 9
C. 14
D. None of above
ANSWER: C
Which operator is not considered while computing cost of an algorithm.
A. Addition (+) operator
B. Assignment (=) operator
C. Comparison (==) operator
D. None of above
Answer: B
Consider following algorithm. What will be its cost? Assume IF condition is
TRUE.
ALGO ABC()
{
s = a + b – c
PRINT “IUB”
IF (s >= 0 and b <=9)
{
j = j - 2
PRINT s + 5
}
}.
A. 2
B. 4
C. 6
D. 8
Answer: C
Compute the cost of following code. Assume IF condition is TRUE. Also add the
cost when FOR loop is terminated.
FOR (i = 1 to 10)
IF (s == i)
answer = 0.
A. 20
B. 21
C. 10
D. 11
Answer: B
What will be the cost of following group of statements.
a = a + b – 9
s = a / 6 – 4
PRINT s + a – 9.
A. 6
B. 3
C. 4
D. All of above
Answer: A
Can we swap the values of two variables without using third variable.
A. TRUE
B. FALSE
Answer: A
Which of the following code adds the numbers of the array a[10] having some
integer values.
A. s = 0
for (i = 0; i <= 9 i++)
s = a[i] + a{i+1]
B. s = 0
for (i = 0; i <= 9 i++)
s = s + a[i]
C. for (i =0; i <= 9 i++)
a[i] = a[i] + a{i+1]
D. None of above
Answer: B
Consider an array arr[5] and a pointer variable ptr. Which of the following C
statement about saving address of 3rd location of array in pointer is correct.
A. ptr = arr
B. ptr = &arr[3]
C. ptr = arr[3]
D. ptr = &arr
Answer: B
Which of the following is the major advantage of link list over arrays.
A. Arrays have contiguous locations while link list is collection of non-
contiguous nodes
B. Arrays has limited space for storing objects as compared to link list
C. Arrays has single name as compared with link list
D. Both A and B
Answer: B
How do you initialize an array in C.
A. int arr[5] = (5, 4, 3, 2, 1)
B. int arr(5) = {1, 2, 3, 4, 5}
C. int arr[5] = {1, 2, 3, 4, 5}
D. int arr(5) = (1, 2, 3, 4, 5)
Answer: C
Assuming int is of 2 bytes, what is the size of int arr[10].
A. 10 bytes
B. 12 bytes
C. 40 bytes
D. 20 bytes
Answer: D
In array, the elements are accessed in ______ order.
A. Ascending order
B. Sequential order
C. Random order
D. Both A and B
Answer: B
In a single link list, each node has minimum of two fields. One is called as
data field. What other field contains.
A. Pointer to character
B. Pointer to integer
C. Pointer to node
D. None of above
Answer: C
Which of the following operations can be applied on single link list.
A. Sorting the list
B. Searching in the list
C. Copying the list to other list
D. All of above
Answer: D
Which of the searching algorithm works on the array having the elements in
arranged order.
A. Bubble Sort
B. Binary Search
C. Insertion Sort
D. Binary Sort.
Answer: B
Which sorting algorithm works better when array is already sorted.
A. Insertion sort
B. Selection sort
C. Quick sort
D. Merge sort
Answer: A
The selection sort algorithms works on which of the following techniques.
A. It compares the adjacent elements throughout the array and swaps them if
they are in wrong order
B. It sorts the array by repeatedly finding the minimum element and place in
its exact position
C. It sorts the array by dividing the array and then merge these elements by
placing then in correct order
D. None of above
Answer: B
How many times the loop will run? Also include when loop terminates.
for (j = 22 to 56)
j = j + 2.
A. 18 times
B. 17 times
C. 56 times
D. 36 times
Answer: A
Which of the data structure works in FIFO order.
A. Stacks
B. Queues
C. Arrays
D. Link list
Answer: B
Inserting an element into an already filled stack of size 5, then stack
becomes.
A. Overflow
B. Crash
C. Underflow
D. All of above
Answer: A
If the elements ‘1’, ‘3’, ‘4’ and ‘2’ are inserted in a queue a queue and are
removed one by one, what will be the order of the elements that were removed.
A. 1 2 3 4
B. 1 3 4 2
C. 4 3 2 1
D. 2 4 3 1
Answer: B
In data structure, the queue follows __________ order.
A. Inorder
B. LIFO order
C. First come First serve order
D. None of above
Answer: C
Number of comparison needed to merge two sorted arrays of size m and n are.
A. m + n - 1
B. m * n
C. m / n
D. m – n
Answer: A
Which of the following are not tress.
(I) (II) (III) (IV)
A. I and II only
B. II and IV only
C. I and III only
D. None of above
Answer: C
What are the properties of pseudo graphs.
A. The graphs having multiple edges only.
B. The graphs having disconnected vertices.
C. The graphs having loops on the vertices.
D. None of above
Answer: C
Every graph is a tree but every tree is not a graph. True or False.
A. TRUE
B. FALSE
Answer: B
In graphs, simple path is defined as.
A. Sequences of vertices from one vertex to other vertex with no repeating
vertex
B. Sequences of vertices from one vertex to other vertex with repeating
vertex
C. Sequences of edges from one vertex to other vertex with no repeating
vertex
D. None of above
Answer: A
In how many ways, the graph can be represented in computer system.
A. Adjacency list
B. Adjacency Matrix
C. Stack
D. Both A and B
Answer: A
What is the difference between Binary Tree and Binary Search Tree (BST).
A. BST has numbers less than the root on the left of root and greater numbers
on the right of root
B. Binary tree has two root nodes but BST has only one root node
C. BST must have two child nodes at every node
D. Both A and C
Answer: A
Maximum number of nodes at level i of the Binary tree must be.
A. 3i + 1
B. 2i + 1
C. 2 + i
D. 2i
Answer: D
What is the correct order of Post-order traversal of Binary tree.
A. Right subtree, left subtree, root
B. Left subtree, Right subtree, root
C. Root, Left subtree, Right subtree
D. Left subtree, Root, Right subtree
Answer: B
Which of the following is the prefix notation of (A + B) * C.
A. AB+C*
B. +ABC*
C. +AB*C
D. *+ABC
Answer: D
Which of the following is the correct representation of A+B*C/(E-F) in to
postfix.
A. ABC*EF-/+
B. AB+C*EF-
C. EF-C*AB+
D. None of above
Answer: A
Which of the following is the correct inorder traversal of BST given below.
A. C D E B A
B. B A D C E
C. B D E C A
D. D C E B A
Answer: B
Which traversal of BST gives the elements in ascending order.
A. Post order
B. Pre-Order
C. Depth First
D. Inorder
Answer: D
What is the procedure of Depth First Search (DFS) of tree or graph.
A. The algorithm starts at the root node and explores as far as possible
along each branch
B. The algorithm starts at the root node and explores the neighboring nodes
first before going as far as the branch goes on
C. The algorithm starts at the root node and traverse the left subtree and
then subtree
D. Both A and C
Answer: A
Which of the following is NOT the Depth First Search of the graph given
below.
A. 1 3 2 7 6 5 4
B. 1 2 4 5 3 6 7
C. 1 3 2 7 6 5 4
D. Both B and C
Answer: D
How Breadth First Search (BFS) works.
A. It starts at the tree root, and explores all of the neighbor nodes at
the present depth prior to moving on to the nodes at the next depth
level
B. It starts at the tree root, and explores all of nodes by going as far as
possible the neighbor nodes at the present depth prior to moving on to
the nodes at the next depth level
C. It starts from the right subtree and then visit the root after visiting
left subtree
D. None of above
Answer: A
Which node you will consider to replace with the target node if we want to
delete 40 from the following BST.
A. 38
B. 28
C. Both A and B
D. None of above
Answer: C
What is the cost of following code? Also include the cost when
for loop terminates.
for (j = 1 to 10) //suppose increment is 1
{
PRINT j
}.
A. 10
B. 9
C. 100
D. 11
Answer: D
What is the cost of following code? Also include the cost when
for loop terminates.
for (j = 1 to 10)
{
PRINT j
j = j + 2
}.
A. 10
B. 11
C. 12
D. 13
Answer: B
Which of the following are disadvantages of using arrays.
A. Slow insertion and deletion
B. Memory wastage
C. Quick access
D. Both A and B
Answer: D
What are the disadvantages of link list.
A. Slower search time
B. Memory is free to assign to nodes
C. Adjacent location of nodes in memory
D. All of above
Answer: A
If integerr takes 2 bytes of memory, what will be the maximum
positive value stored in integer.
A. 65535
B. 12345
C. 54321
D. -9876
Answer: A
Assigning integer address to float type pointer will give.
A. Compile error
B. Run time error
C. Syntax error
D. None of above
Answer: A
If we add and integer and a float data, what will be the answer.
A. Integer
B. Character
C. Float
D. Both B and C
Answer: C
The most important part of single link is.
A. Data part
B. Address part
C. Both A and B
D. Name of the last node
Answer: B