Q. What is the output of the following code: printf("%d", 5 + 10 * 2);?
Solution
The output is 25 because of operator precedence: 10 * 2 is evaluated first, then 5 is added.
Correct Answer:
C
— 15
Learn More →
Q. What is the purpose of the 'free' function in C?
-
A.
To allocate memory
-
B.
To release allocated memory
-
C.
To initialize a pointer
-
D.
To check memory usage
Solution
'free' is used to release memory that was previously allocated with 'malloc' or similar functions.
Correct Answer:
B
— To release allocated memory
Learn More →
Q. What is the purpose of the 'return' statement in a function?
-
A.
To end the program
-
B.
To return a value from a function
-
C.
To declare a variable
-
D.
To create a loop
Solution
The 'return' statement is used to return a value from a function to the caller.
Correct Answer:
B
— To return a value from a function
Learn More →
Q. What is the result of dereferencing a null pointer?
-
A.
It returns zero
-
B.
It causes a segmentation fault
-
C.
It returns a random value
-
D.
It is valid and returns a pointer
Solution
Dereferencing a null pointer causes a segmentation fault, as it attempts to access an invalid memory location.
Correct Answer:
B
— It causes a segmentation fault
Learn More →
Q. What is the size of a pointer on a 64-bit system?
-
A.
2 bytes
-
B.
4 bytes
-
C.
8 bytes
-
D.
16 bytes
Solution
On a 64-bit system, the size of a pointer is typically 8 bytes, as it needs to store a 64-bit memory address.
Correct Answer:
C
— 8 bytes
Learn More →
Q. What is the space complexity of a recursive function that uses O(n) space for its call stack?
-
A.
O(1)
-
B.
O(n)
-
C.
O(n^2)
-
D.
O(log n)
Solution
The space complexity of a recursive function that uses O(n) space for its call stack is O(n).
Correct Answer:
B
— O(n)
Learn More →
Q. What is the time complexity of a recursive function that divides the problem size by half at each step?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(2^n)
Solution
The time complexity is O(log n) because the problem size is halved at each recursive call.
Correct Answer:
B
— O(log n)
Learn More →
Q. What is the time complexity of an in-order traversal of a binary tree?
-
A.
O(n)
-
B.
O(log n)
-
C.
O(n log n)
-
D.
O(1)
Solution
In-order traversal visits each node exactly once, resulting in a time complexity of O(n).
Correct Answer:
A
— O(n)
Learn More →
Q. What is the time complexity of Prim's algorithm for finding the minimum spanning tree using an adjacency matrix?
-
A.
O(V^2)
-
B.
O(E log V)
-
C.
O(V + E)
-
D.
O(V^3)
Solution
Prim's algorithm has a time complexity of O(V^2) when using an adjacency matrix.
Correct Answer:
A
— O(V^2)
Learn More →
Q. What will be the output of the following code: 'for i in range(3): print(i)'?
-
A.
0 1 2
-
B.
1 2 3
-
C.
0 1 2 3
-
D.
3
Solution
The loop iterates from 0 to 2, so the output will be '0 1 2'.
Correct Answer:
A
— 0 1 2
Learn More →
Q. Which algorithm is guaranteed to find the shortest path in a graph with negative weight edges?
-
A.
Dijkstra's algorithm
-
B.
A* algorithm
-
C.
Bellman-Ford algorithm
-
D.
Floyd-Warshall algorithm
Solution
The Bellman-Ford algorithm is guaranteed to find the shortest path in graphs with negative weight edges, unlike Dijkstra's algorithm.
Correct Answer:
C
— Bellman-Ford algorithm
Learn More →
Q. Which greedy algorithm is used to solve the activity selection problem?
-
A.
Dijkstra's algorithm
-
B.
Kruskal's algorithm
-
C.
Interval scheduling maximization
-
D.
Prim's algorithm
Solution
The activity selection problem is solved using the interval scheduling maximization greedy algorithm.
Correct Answer:
C
— Interval scheduling maximization
Learn More →
Q. Which of the following data structures is commonly used to implement BFS?
-
A.
Stack
-
B.
Queue
-
C.
Linked List
-
D.
Array
Solution
BFS uses a Queue data structure to keep track of the nodes that need to be explored next.
Correct Answer:
B
— Queue
Learn More →
Q. Which of the following is a base case in a recursive function?
-
A.
The case that leads to infinite recursion
-
B.
The case that stops the recursion
-
C.
The case that calls the function again
-
D.
The case that doubles the input size
Solution
A base case is the condition under which the recursion stops, preventing infinite recursion.
Correct Answer:
B
— The case that stops the recursion
Learn More →
Q. Which of the following is a characteristic of dynamic programming?
-
A.
It always uses recursion
-
B.
It requires a greedy approach
-
C.
It stores results of subproblems
-
D.
It is only applicable to optimization problems
Solution
Dynamic programming is characterized by storing the results of subproblems to avoid redundant calculations, which improves efficiency.
Correct Answer:
C
— It stores results of subproblems
Learn More →
Q. Which of the following is a common application of a queue?
-
A.
Function call management
-
B.
Undo functionality in text editors
-
C.
Breadth-first search in graphs
-
D.
Expression evaluation
Solution
Queues are commonly used in breadth-first search algorithms to manage the nodes to be explored.
Correct Answer:
C
— Breadth-first search in graphs
Learn More →
Q. Which of the following is a common application of greedy algorithms?
-
A.
Sorting data
-
B.
Finding the shortest path
-
C.
Job scheduling
-
D.
All of the above
Solution
Job scheduling is a common application of greedy algorithms, particularly in maximizing resource utilization.
Correct Answer:
C
— Job scheduling
Learn More →
Q. Which of the following is a valid variable declaration in C?
-
A.
int 1number;
-
B.
float number1;
-
C.
char number#;
-
D.
double number@;
Solution
The valid variable declaration in C is float number1; as variable names cannot start with a digit or contain special characters.
Correct Answer:
B
— float number1;
Learn More →
Q. Which of the following is an example of a problem that can be solved using divide and conquer?
-
A.
Binary search
-
B.
Fibonacci sequence
-
C.
Linear search
-
D.
Bubble sort
Solution
Binary search is an example of a divide and conquer algorithm, as it divides the search space in half.
Correct Answer:
A
— Binary search
Learn More →
Q. Which of the following is an example of a problem that can be solved using dynamic programming?
-
A.
Finding the maximum sum of a contiguous subarray
-
B.
Finding the maximum element in an array
-
C.
Sorting an array of integers
-
D.
Searching for an element in an unsorted array
Solution
Finding the maximum sum of a contiguous subarray can be solved using dynamic programming, specifically with Kadane's algorithm.
Correct Answer:
A
— Finding the maximum sum of a contiguous subarray
Learn More →
Q. Which of the following is not a characteristic of a linked list?
-
A.
Dynamic size
-
B.
Random access
-
C.
Efficient insertions/deletions
-
D.
Non-contiguous memory allocation
Solution
Linked lists do not support random access; elements must be accessed sequentially.
Correct Answer:
B
— Random access
Learn More →
Q. Which of the following is NOT a characteristic of greedy algorithms?
-
A.
They make decisions based on current information
-
B.
They do not reconsider previous decisions
-
C.
They guarantee an optimal solution for all problems
-
D.
They are often faster than other algorithms
Solution
Greedy algorithms do not guarantee an optimal solution for all problems; they work well for specific types of problems.
Correct Answer:
C
— They guarantee an optimal solution for all problems
Learn More →
Q. Which of the following is NOT a step in the dynamic programming approach?
-
A.
Characterizing the structure of an optimal solution
-
B.
Recursively solving the problem
-
C.
Storing the results of subproblems
-
D.
Constructing a solution from optimal subsolutions
Solution
While recursion can be used in dynamic programming, it is not a necessary step; dynamic programming can also be implemented iteratively.
Correct Answer:
B
— Recursively solving the problem
Learn More →
Q. Which of the following is not a valid pointer declaration in C?
-
A.
int *ptr;
-
B.
float ptr;
-
C.
char *ptr;
-
D.
double *ptr;
Solution
The declaration float ptr; is not a pointer declaration; it is a regular float variable.
Correct Answer:
B
— float ptr;
Learn More →
Q. Which of the following is NOT a valid tree traversal method?
-
A.
In-order
-
B.
Pre-order
-
C.
Post-order
-
D.
Side-order
Solution
Side-order is not a recognized tree traversal method.
Correct Answer:
D
— Side-order
Learn More →
Q. Which of the following is true about pointers?
-
A.
Pointers can only point to integers
-
B.
Pointers can point to any data type
-
C.
Pointers cannot be reassigned
-
D.
Pointers are always initialized to zero
Solution
Pointers can point to any data type, allowing for flexible memory management.
Correct Answer:
B
— Pointers can point to any data type
Learn More →
Q. Which of the following is true about recursive algorithms?
-
A.
They always run faster than iterative algorithms
-
B.
They can be less memory efficient due to call stack
-
C.
They cannot be used for sorting
-
D.
They are always easier to understand
Solution
Recursive algorithms can be less memory efficient due to the overhead of maintaining the call stack.
Correct Answer:
B
— They can be less memory efficient due to call stack
Learn More →
Q. Which of the following operations can be performed in constant time on a queue?
-
A.
Enqueue
-
B.
Dequeue
-
C.
Peek
-
D.
All of the above
Solution
All of the operations (Enqueue, Dequeue, and Peek) can be performed in constant time, O(1), in a properly implemented queue.
Correct Answer:
D
— All of the above
Learn More →
Q. Which of the following operations is NOT typically associated with a queue?
-
A.
Enqueue
-
B.
Dequeue
-
C.
Peek
-
D.
Push
Solution
The 'Push' operation is associated with stacks, while queues use 'Enqueue' to add and 'Dequeue' to remove elements.
Correct Answer:
D
— Push
Learn More →
Q. Which of the following problems can be solved using a greedy algorithm?
-
A.
Knapsack problem
-
B.
Minimum spanning tree
-
C.
Shortest path in a graph
-
D.
All of the above
Solution
The minimum spanning tree can be solved using a greedy algorithm, while the knapsack problem is not always solvable by greedy methods.
Correct Answer:
B
— Minimum spanning tree
Learn More →
Showing 31 to 60 of 66 (3 Pages)