Q. In a level-order traversal, which data structure is typically used to keep track of nodes?
A.
Stack
B.
Queue
C.
Array
D.
Linked List
Show solution
Solution
A queue is used in level-order traversal to keep track of nodes at the current level.
Correct Answer:
B
— Queue
Learn More →
Q. In a recursive function, what is the purpose of the return statement?
A.
To terminate the program
B.
To return control to the caller
C.
To call the function again
D.
To print the output
Show solution
Solution
The return statement is used to return control to the caller along with any computed value.
Correct Answer:
B
— To return control to the caller
Learn More →
Q. In a stack, what is the result of the operation 'push(5)', followed by 'push(10)', and then 'pop()'?
A.
5
B.
10
C.
Both 5 and 10
D.
Stack is empty
Show solution
Solution
The 'pop()' operation will return 10, as it is the last element pushed onto the stack.
Correct Answer:
B
— 10
Learn More →
Q. In DFS, what is the primary data structure used?
A.
Queue
B.
Stack
C.
Array
D.
Hash Table
Show solution
Solution
DFS uses a Stack data structure, either explicitly or through recursion, to keep track of the nodes to be explored.
Correct Answer:
B
— Stack
Learn More →
Q. In the coin change problem, which approach does a greedy algorithm use?
A.
Always take the largest denomination first
B.
Take the smallest denomination first
C.
Randomly select coins
D.
Take coins in pairs
Show solution
Solution
A greedy algorithm for the coin change problem typically takes the largest denomination first to minimize the number of coins.
Correct Answer:
A
— Always take the largest denomination first
Learn More →
Q. In the context of greedy algorithms, what does 'local optimum' refer to?
A.
The best solution overall
B.
The best solution in a local neighborhood
C.
The worst solution possible
D.
A solution that is not feasible
Show solution
Solution
A local optimum is the best solution within a local neighborhood, which may not lead to the global optimum.
Correct Answer:
B
— The best solution in a local neighborhood
Learn More →
Q. In which data structure is the breadth-first search (BFS) algorithm typically implemented?
A.
Stack
B.
Queue
C.
Array
D.
Linked List
Show solution
Solution
BFS is typically implemented using a queue data structure.
Correct Answer:
B
— Queue
Learn More →
Q. In which scenario would you prefer the Bellman-Ford algorithm over Dijkstra's algorithm?
A.
When all edge weights are positive
B.
When the graph is dense
C.
When there are negative weight edges
D.
When you need the shortest path in constant time
Show solution
Solution
You would prefer the Bellman-Ford algorithm when the graph contains negative weight edges, as Dijkstra's algorithm cannot handle them.
Correct Answer:
C
— When there are negative weight edges
Learn More →
Q. In which scenario would you prefer using a stack over a queue?
A.
When you need to process tasks in the order they arrive
B.
When you need to backtrack through a series of operations
C.
When you need to manage tasks with priority
D.
When you need to store data persistently
Show solution
Solution
Stacks are useful for backtracking scenarios, such as undo operations in applications.
Correct Answer:
B
— When you need to backtrack through a series of operations
Learn More →
Q. What does BFS stand for in graph algorithms?
A.
Binary First Search
B.
Breadth First Search
C.
Best First Search
D.
Backtracking First Search
Show solution
Solution
BFS stands for Breadth First Search, which is an algorithm for traversing or searching tree or graph data structures.
Correct Answer:
B
— Breadth First Search
Learn More →
Q. What does recursion mean in programming?
A.
A function calling itself
B.
A loop that iterates
C.
A data structure
D.
A variable declaration
Show solution
Solution
Recursion in programming refers to a function that calls itself to solve a problem.
Correct Answer:
A
— A function calling itself
Learn More →
Q. What does the 'malloc' function do in C?
A.
Allocates memory on the stack
B.
Allocates memory on the heap
C.
Frees allocated memory
D.
Initializes a pointer
Show solution
Solution
'malloc' allocates a specified number of bytes of memory on the heap and returns a pointer to the allocated memory.
Correct Answer:
B
— Allocates memory on the heap
Learn More →
Q. What does the term 'memory leak' refer to?
A.
Not freeing allocated memory
B.
Accessing uninitialized memory
C.
Using too much stack space
D.
Overwriting memory
Show solution
Solution
A memory leak occurs when allocated memory is not freed, leading to wasted memory resources.
Correct Answer:
A
— Not freeing allocated memory
Learn More →
Q. What happens if a recursive function does not have a base case?
A.
It will run indefinitely
B.
It will return a default value
C.
It will throw an error
D.
It will terminate successfully
Show solution
Solution
If a recursive function does not have a base case, it will run indefinitely, leading to a stack overflow.
Correct Answer:
A
— It will run indefinitely
Learn More →
Q. What happens when you try to pop an element from an empty stack?
A.
It returns null
B.
It throws an exception
C.
It returns the last element added
D.
It does nothing
Show solution
Solution
Attempting to pop from an empty stack typically results in an exception being thrown.
Correct Answer:
B
— It throws an exception
Learn More →
Q. What is a dangling pointer?
A.
A pointer that points to a valid memory location
B.
A pointer that points to a memory location that has been freed
C.
A pointer that is not initialized
D.
A pointer that points to itself
Show solution
Solution
A dangling pointer is one that points to a memory location that has been freed, leading to undefined behavior if accessed.
Correct Answer:
B
— A pointer that points to a memory location that has been freed
Learn More →
Q. What is a greedy algorithm?
A.
An algorithm that makes the best choice at each step
B.
An algorithm that explores all possible solutions
C.
An algorithm that uses dynamic programming
D.
An algorithm that always finds the optimal solution
Show solution
Solution
A greedy algorithm makes the best choice at each step with the hope of finding the global optimum.
Correct Answer:
A
— An algorithm that makes the best choice at each step
Learn More →
Q. What is a key characteristic of DFS compared to BFS?
A.
DFS uses less memory than BFS.
B.
DFS explores all neighbors before going deeper.
C.
DFS can be implemented using recursion.
D.
DFS guarantees the shortest path.
Show solution
Solution
A key characteristic of DFS is that it can be implemented using recursion, allowing it to explore as far as possible along each branch before backtracking.
Correct Answer:
C
— DFS can be implemented using recursion.
Learn More →
Q. What is a pointer in programming?
A.
A variable that stores a memory address
B.
A type of loop
C.
A function that returns a value
D.
A data structure
Show solution
Solution
A pointer is a variable that stores the memory address of another variable.
Correct Answer:
A
— A variable that stores a memory address
Learn More →
Q. What is dynamic programming primarily used for?
A.
To solve problems with overlapping subproblems
B.
To sort data efficiently
C.
To manage memory allocation
D.
To perform binary search
Show solution
Solution
Dynamic programming is used to solve problems that can be broken down into overlapping subproblems, allowing for the reuse of previously computed results.
Correct Answer:
A
— To solve problems with overlapping subproblems
Learn More →
Q. What is tail recursion?
A.
Recursion where the last operation is a recursive call
B.
Recursion that does not use any stack
C.
Recursion that calls itself multiple times
D.
Recursion that has no base case
Show solution
Solution
Tail recursion is when the last operation of a function is a recursive call, allowing for optimization.
Correct Answer:
A
— Recursion where the last operation is a recursive call
Learn More →
Q. What is the correct syntax to include a header file in C?
A.
#include <header.h>
B.
#include 'header.h'
C.
#include header.h
D.
#include <header>
Show solution
Solution
The correct syntax to include a header file in C is #include <header.h>.
Correct Answer:
A
— #include <header.h>
Learn More →
Q. What is the key difference between greedy algorithms and dynamic programming?
A.
Greedy algorithms use recursion
B.
Dynamic programming considers all possible solutions
C.
Greedy algorithms are always optimal
D.
Dynamic programming is faster
Show solution
Solution
The key difference is that dynamic programming considers all possible solutions, while greedy algorithms make local optimal choices.
Correct Answer:
B
— Dynamic programming considers all possible solutions
Learn More →
Q. What is the main advantage of Dijkstra's algorithm over the Bellman-Ford algorithm?
A.
It can handle negative weights
B.
It is faster for graphs with non-negative weights
C.
It is simpler to implement
D.
It can find all pairs shortest paths
Show solution
Solution
Dijkstra's algorithm is generally faster than the Bellman-Ford algorithm for graphs with non-negative weights.
Correct Answer:
B
— It is faster for graphs with non-negative weights
Learn More →
Q. What is the main difference between a stack and a queue?
A.
Stack is LIFO, Queue is FIFO
B.
Stack is FIFO, Queue is LIFO
C.
Both are LIFO
D.
Both are FIFO
Show solution
Solution
The main difference is that a stack operates in a Last In First Out (LIFO) manner, while a queue operates in a First In First Out (FIFO) manner.
Correct Answer:
A
— Stack is LIFO, Queue is FIFO
Learn More →
Q. What is the main difference between depth-first and breadth-first traversal?
A.
Order of node visits
B.
Data structure used
C.
Time complexity
D.
Space complexity
Show solution
Solution
Depth-first traversal visits nodes by going deep into the tree, while breadth-first visits level by level.
Correct Answer:
A
— Order of node visits
Learn More →
Q. What is the main drawback of greedy algorithms?
A.
They are too slow
B.
They may not produce the optimal solution
C.
They require more memory
D.
They are difficult to implement
Show solution
Solution
The main drawback of greedy algorithms is that they may not produce the optimal solution for all problems.
Correct Answer:
B
— They may not produce the optimal solution
Learn More →
Q. What is the output of the Bellman-Ford algorithm?
A.
A single shortest path
B.
A list of all shortest paths from the source
C.
The shortest path tree
D.
The shortest path length only
Show solution
Solution
The Bellman-Ford algorithm outputs a list of shortest path distances from the source to all vertices in the graph.
Correct Answer:
B
— A list of all shortest paths from the source
Learn More →
Q. What is the output of the following code snippet: 'print(2 ** 3)'?
Show solution
Solution
The expression 2 ** 3 calculates 2 raised to the power of 3, which equals 8.
Correct Answer:
B
— 8
Learn More →
Q. What is the output of the following code: printf("%d", 10 / 3);?
Show solution
Solution
The output is 3 because in C, dividing two integers results in an integer, truncating any decimal.
Correct Answer:
A
— 3
Learn More →
Showing 1 to 30 of 66 (3 Pages)