VND Openxmlformats-Officedocument Wordprocessingml Document&rendition 1
VND Openxmlformats-Officedocument Wordprocessingml Document&rendition 1
int x = 5, y = 3;
printf("%d", x + y);
a) 53
b) 8
c) 5
d) Error
Answer: b
int a = 5, b = 3;
if (a > b) {
printf("Greater");
} else {
printf("Smaller");
}
a) Greater
b) Smaller
c) Error
d) None of the above
Answer: a
int i = 0;
for (i = 0; i < 5; i++) {
if (i == 3) {
continue;
}
printf("%d ", i);
}
a) 0 1 2 3 4
b) 0 1 2 4
c) 1 2 3 4
d) 0 1 3 4
Answer: b
Unit V: Pointers
int a = 5;
int *ptr = &a;
printf("%d", *ptr);
a) 5
b) 0
c) Address of a
d) Error
Answer: a
44. Which operator is used to access the value stored in the memory address a
pointer is pointing to?
a) *
b) &
c) ->
d) @
Answer: a
45. What does the following code do?
int x = 10;
int *ptr = &x;
ptr++;
printf("%p", ptr);
a) It increments the pointer by 1 byte.
b) It increments the pointer by the size of an integer.
c) It points to x.
d) It causes a segmentation fault.
Answer: b
int x = 5;
int *ptr = &x;
*ptr = 10;
printf("%d", x);
a) Prints 10
b) Prints 5
c) Prints address of x
d) Causes a runtime error
Answer: a
a) B
b) 66
c) A1
d) Error
Answer: a
int i = 0;
while (i < 5) {
if (i == 3) {
break;
}
printf("%d ", i);
i++;
}
a) 0 1 2 3 4
b) 0 1 2
c) 1 2 3 4
d) 0 1 2 3
Answer: b
a) Prints 1
b) Prints 2
c) Prints 3
d) Prints 4
Answer: c
70. What is the return type of a function that does not return any value in C?
a) int
b) void
c) char
d) None of the above
Answer: b
6. A relation R on a set A is a:
a) Subset of A
b) Set of ordered pairs
c) Set of elements
d) Power set of A
Answer: b
7. Which of the following is an equivalence relation?
a) Reflexive
b) Symmetric
c) Transitive
d) All of the above
Answer: d
8. What is the domain of the function f(x) = x + 2?
a) Real numbers
b) Natural numbers
c) Complex numbers
d) None of the above
Answer: a
9. The inverse of a function is defined if the function is:
a) Surjective
b) Injective
c) Bijective
d) None of the above
Answer: c
10. Which of the following defines a function?
a) A set of ordered pairs
b) A mapping from elements of one set to another set
c) A relationship between elements of two sets
d) All of the above
Answer: d
a) p ∧ ¬p
12. Which of the following is a tautology?
b) p ∨ ¬p
c) p ∧ p
d) p ∨ p
a) Same as p ∧ q
b) Same as p ∨ q
c) Same as p ∨ q ∨ r
d) None of the above
Answer: c
14. The contrapositive of the statement "If p, then q" is:
a) If q, then p
b) If not p, then not q
c) If not q, then not p
d) None of the above
Answer: c
15. Which of the following is an example of a logical operator?
a) AND
b) OR
c) NOT
d) All of the above
Answer: d
16. A formula in normal form is:
a) A formula that can be expressed in terms of conjunctions and disjunctions
b) A formula that has no logical equivalence
c) A formula in the form of an implication
d) None of the above
Answer: a
a) p ∧ ¬p
17. Which of the following is a contradiction?
b) p ∨ ¬p
c) p → p
d) None of the above
a) OR
b) AND
c) NOT
d) IMPLIES
19. Which of the following is the negation of the statement "p ∨ q"?
Answer: b
a) ¬p ∨ q
b) ¬p ∧ ¬q
c) p ∧ q
d) None of the above
20. The truth value of (p ∧ q) ∨ (¬p ∧ r) when p = true, q = false, and r = true is:
Answer: b
a) true
b) false
c) undefined
d) None of the above
Answer: a
42. If f(x) = x², what is the range of the function for x ∈ {1, 2, 3}?
Answer: b
a) {1, 4, 9}
b) {1, 2, 3}
c) {0, 1, 4}
d) {1, 4, 8}
Answer: a
43. What is the domain of the function f(x) = 1/x?
a) All real numbers except 0
b) All positive real numbers
c) All real numbers
d) All non-negative real numbers
Answer: a
44. Which of the following describes a bijective function?
a) A function that is both injective and surjective
b) A function that is only surjective
c) A function that is only injective
d) None of the above
a) ∧
46. Which of the following logical operators represents "if and only if"?
b) ∨
c) →
d) ↔
a) True
b) False
c) Undefined
d) None of the above
Answer: b
48. Which of the following is the negation of the statement "If p, then q"?
a) p → ¬q
c) p ∧ ¬q
b) ¬p → q
d) p ∧ q
Answer: c
a) p ∨ ¬p
49. Which of the following is a contradiction?
b) p ∧ ¬p
c) p → q
d) None of the above
Answer: b
50. In a truth table, a tautology is a statement that is:
a) Always true
b) Always false
c) True for some values of p and false for others
d) None of the above
Answer: a
51. Which of the following is an example of a normal form?
a) Conjunctive Normal Form (CNF)
b) Disjunctive Normal Form (DNF)
c) Both a and b
d) None of the above
Answer: c
52. Which of the following is true for logical equivalence?
a) Two statements are logically equivalent if they have the same truth table
b) Two statements are logically equivalent if one is true and the other is false
c) Two statements are logically equivalent if one is false and the other is true
d) None of the above
Answer: a
53. What is the result of the logical expression p → (q → p)?
a) True
b) False
c) Depends on the truth values of p and q
d) None of the above
Answer: a
54. The statement p → (q → r) is logically equivalent to:
a) (p → q) → r
c) (p ∧ q) → r
b) (p → q) → (q → r)
11. What is the time complexity for push and pop operations in a stack?
a) O(n)
b) O(log n)
c) O(1)
d) O(n²)
Answer: c
12. Which of the following expressions is valid in stack-based operations?
a) Push(10)
b) Pop(20)
c) Stack[10]
d) None of the above
Answer: a
13. Which of the following is NOT an application of stacks?
a) Undo mechanism in text editors
b) Expression evaluation
c) Finding the shortest path in a graph
d) Backtracking algorithms
Answer: c
14. How do we convert an infix expression to a postfix expression?
a) By using a stack
b) By using a queue
c) By recursively evaluating the expression
d) None of the above
Answer: a
15. Which of the following is true about a priority queue?
a) The element with the highest priority is dequeued first
b) The element with the lowest priority is dequeued first
c) Elements are dequeued in the order they were added
d) None of the above
Answer: a
16. In a circular queue, the last element points to:
a) NULL
b) The first element
c) A random element
d) The middle element
Answer: b
17. Which operation is NOT supported by a deque?
a) Insertion at the front
b) Insertion at the rear
c) Deletion from the front
d) Deletion from the middle
Answer: d
18. Which of the following is the correct sequence for evaluating an arithmetic
expression in postfix notation?
a) Left to right
b) Right to left
c) In order of precedence
d) None of the above
Answer: a
19. What is the time complexity for accessing an element in a queue?
a) O(1)
b) O(log n)
c) O(n)
d) O(n²)
Answer: a
20. A queue is useful for:
a) Depth-first search
b) Breadth-first search
c) Sorting
d) Backtracking
Answer: b
Unit V: Searching
41. Which search algorithm is the fastest for a large sorted array?
a) Linear search
b) Binary search
c) Hashing
d) Jump search
Answer: b
42. What is the time complexity of binary search in the worst case?
a) O(1)
b) O(log n)
c) O(n)
d) O(n²)
Answer: b
43. Which of the following sorting algorithms is an unstable sort?
a) Bubble sort
b) Merge sort
c) Quick sort
d) Insertion sort
Answer: c
44. Which sorting algorithm has the best average case performance?
a) Bubble sort
b) Selection sort
c) Merge sort
d) Quick sort
Answer: c
45. In which sorting algorithm does the time complexity improve with smaller input
sizes?
a) Bubble sort
b) Merge sort
c) Selection sort
d) Quick sort
Answer: a
46. Which of the following is a property of radix sort?
a) It works only for numerical data
b) It uses comparisons to sort elements
c) It sorts elements based on digit significance
d) All of the above
Answer: c
47. Which type of hashing technique is used for collision resolution in hash tables?
a) Separate chaining
b) Linear probing
c) Quadratic probing
d) All of the above
Answer: d
48. What is the advantage of using extendible hashing over linear hashing?
a) It reduces overflow
b) It increases the speed of insertions
c) It improves memory utilization
d) All of the above
Answer: d
49. In separate chaining, collisions are resolved by:
a) Storing colliding elements in a linked list
b) Rehashing the table
c) Using a different hash function
d) None of the above
Answer: a
50. Which of the following is true about the binary search algorithm?
a) It works only on sorted arrays
b) It can be applied to linked lists
c) It has a time complexity of O(n)
d) It requires a linear scan of the array
Answer: a
51. Which of the following operations can be efficiently implemented using a stack?
a) Undo operation in editors
b) Traversing a graph
c) Sorting
d) Finding the maximum value in an array
Answer: a
52. In a singly linked list, how do you insert a new node at the beginning?
a) Change the next pointer of the last node
b) Create a new node and make it point to the head
c) Make the last node point to the first node
d) None of the above
Answer: b
53. Which of the following is a common application of a circular linked list?
a) Implementing the undo functionality in an editor
b) Implementing round-robin scheduling in operating systems
c) Finding the middle element in a list
d) Sorting data
Answer: b
54. Which of the following is the time complexity of deleting a node from a singly
linked list (given the node is known)?
a) O(1)
b) O(n)
c) O(log n)
d) O(n²)
Answer: a
55. What is the primary difference between a singly and doubly linked list?
a) A doubly linked list allows traversal in both directions, while a singly linked list
allows only one direction.
b) A doubly linked list is slower than a singly linked list.
c) A singly linked list contains extra pointers.
d) None of the above
Answer: a
61. Which of the following traversal methods is used to search for a node in a binary
search tree?
a) Inorder traversal
b) Preorder traversal
c) Postorder traversal
d) All of the above
Answer: a
62. In a binary search tree (BST), what is the time complexity of the search
operation in the worst case?
a) O(1)
b) O(log n)
c) O(n)
d) O(n²)
Answer: c
63. Which tree structure balances itself automatically after each insertion or
deletion?
a) Binary Search Tree (BST)
b) AVL Tree
c) Binary Heap
d) B-tree
Answer: b
64. In an AVL tree, what must be true for it to remain balanced?
a) The height of the left and right subtrees of any node must differ by at most 1.
b) The left subtree must be smaller than the right subtree.
c) The height difference between subtrees must be 2 or greater.
d) The root must always be a leaf node.
Answer: a
65. What is the height of a balanced binary search tree with n nodes?
a) O(n)
b) O(log n)
c) O(n²)
d) O(n log n)
Answer: b
66. Which of the following is NOT true for a threaded binary tree?
a) It allows for efficient in-order traversal without using a stack.
b) It stores a reference to the in-order predecessor or successor for each node.
c) The threads make traversal slower than a regular binary tree.
d) It is used to efficiently traverse a binary tree in a non-recursive manner.
Answer: c
67. What is the time complexity of a Breadth-First Search (BFS) on a graph with n
vertices and m edges?
a) O(n + m)
b) O(n log n)
c) O(m²)
d) O(n²)
Answer: a
68. Which of the following is a feature of a directed acyclic graph (DAG)?
a) It contains at least one cycle.
b) It has directed edges and no cycles.
c) All edges are undirected.
d) It is a tree.
Answer: b
69. Which of the following graph traversal algorithms is used for finding the
shortest path in an unweighted graph?
a) Dijkstra’s algorithm
b) Depth-First Search (DFS)
c) Breadth-First Search (BFS)
d) A* algorithm
Answer: c
70. What is the minimum number of edges in a connected graph with n vertices?
a) n-1
b) n
c) 2n
d) n²
Answer: a
71. In a topological sort of a directed acyclic graph (DAG), the vertices are ordered:
a) By their incoming edges
b) By their outgoing edges
c) From the root to the leaves
d) Based on the in-degree
Answer: a
1. Which of the following is the binary representation of the decimal number 12?
A) 1100
B) 1011
C) 1001
D) 1111
76. 6. The Gray code equivalent of the binary number 1011 is:
A) 1111
B) 1101
C) 1001
D) 1011
77. 7. Which of the following gates is a universal gate?
A) AND
B) OR
C) NOR
D) XOR
78. 8. The NOR gate is the combination of which gates?
A) OR and NOT
B) AND and NOT
C) AND and OR
D) NAND and NOT
79. 9. The output of an AND gate is 1 when:
A) At least one input is 1
B) Both inputs are 1
C) Both inputs are 0
D) At least one input is 0
80. 10. What is the Boolean expression for the output of an OR gate?
A) A + B
B) A . B
C) A' + B'
D) A' . B'
81. 11. Which of the following is NOT a digital code?
A) ASCII
B) BCD
C) Roman numeral
D) Excess-3
82. 12. The 2's complement of the binary number 1010 is:
A) 0101
B) 1101
C) 0110
D) 1011
83. 13. What does the Gray code help in?
A) Reducing errors during digital signal processing
B) Representing negative numbers
C) Storing decimal numbers
D) Enabling fast multiplication
84. 14. A NOT gate is also known as:
A) Inverter
B) AND gate
C) OR gate
D) NAND gate
85. 15. Which of the following is a universal logic gate?
A) OR
B) AND
C) XOR
D) NAND
25. What is the Boolean expression for the simplified result of the expression A'B + AB?
A) A
B) B
C) A + B
D) A' + B
26. Which of the following circuits is used to select one of many inputs?
A) Multiplexer
B) Decoder
C) Encoder
D) Demultiplexer