1What is the primary definition of an algorithm in the context of computer science?
A.A step-by-step procedure or set of rules to solve a specific problem
B.A hardware component used to process data
C.A random sequence of operations
D.A programming language syntax
Correct Answer: A step-by-step procedure or set of rules to solve a specific problem
Explanation:
An algorithm is a finite sequence of well-defined, computer-implementable instructions, typically to solve a class of problems or to perform a computation.
Incorrect! Try again.
2Which of the following factors is not typically considered when analyzing the asymptotic running time of an algorithm?
A.The number of basic operations performed
B.The size of the input
C.The growth rate of the function
D.The programming language used
Correct Answer: The programming language used
Explanation:
Asymptotic analysis focuses on the mathematical growth of complexity relative to input size, abstracting away hardware and language implementation details.
Incorrect! Try again.
3If an algorithm processes an input of size using a single loop that runs from to , what is its time complexity?
A.
B.
C.
D.
Correct Answer:
Explanation:
A single loop iterating times performs operations linear to the input size, denoted as .
Incorrect! Try again.
4What does Space Complexity refer to?
A.The amount of memory required by an algorithm to run as a function of input size
B.The number of lines of code in the program
C.The amount of time the CPU takes to execute instructions
D.The bandwidth consumed during execution
Correct Answer: The amount of memory required by an algorithm to run as a function of input size
Explanation:
Space complexity quantifies the amount of working storage (RAM) an algorithm needs, usually expressed in terms of .
Incorrect! Try again.
5In algorithm analysis, which case provides an upper bound on the execution time?
A.Average-case
B.Worst-case
C.Null-case
D.Best-case
Correct Answer: Worst-case
Explanation:
The worst-case analysis considers the input for which the algorithm takes the longest time, providing a guarantee that the algorithm will not take longer than this bound.
Incorrect! Try again.
6Which of the following functions has the highest rate of growth as ?
A.
B.
C.
D.
Correct Answer:
Explanation:
Factorial growth () grows faster than exponential (), polynomial (), and linearithmic () growth.
Incorrect! Try again.
7Consider the function . What is the Big-O notation for this function?
A.
B.
C.
D.
Correct Answer:
Explanation:
In asymptotic notation, we drop lower-order terms and constants. The dominant term is , so the complexity is .
Incorrect! Try again.
8What is the Big-O complexity of a nested loop where the outer loop runs times and the inner loop runs times?
A.
B.
C.
D.
Correct Answer:
Explanation:
Since the inner loop runs times for each iteration of the outer loop, the total operations are .
Incorrect! Try again.
9What does the notation formally imply?
A. for some constant and
B. grows strictly slower than
C. for some constant and
D. for some constant
Correct Answer: for some constant and
Explanation:
Big-O notation describes an asymptotic upper bound. It means does not grow faster than multiplied by a constant.
Incorrect! Try again.
10Which asymptotic notation represents the lower bound of an algorithm's running time?
A. (Big-Theta)
B. (Big-Omega)
C. (Little-o)
D. (Big-O)
Correct Answer: (Big-Omega)
Explanation:
is used to describe the asymptotic lower bound, meaning the algorithm takes at least this much time.
Incorrect! Try again.
11If and , then:
A.
B.
C.This condition is impossible
D.
Correct Answer:
Explanation:
If a function is both bounded above () and bounded below () by the same function , it is a tight bound, denoted by .
Incorrect! Try again.
12Which of the following represents constant time complexity?
A.
B.
C.
D.
Correct Answer:
Explanation:
denotes that the running time does not depend on the input size .
Incorrect! Try again.
13What is the typical time complexity of Binary Search?
A.
B.
C.
D.
Correct Answer:
Explanation:
Binary search divides the search space in half with each step, resulting in a logarithmic time complexity.
Incorrect! Try again.
14In the analysis of algorithms, what happens to the constant factors (e.g., the in ) when using Big-O notation?
A.They are added to the exponent
B.They are squared
C.They are ignored/dropped
D.They become the base of the logarithm
Correct Answer: They are ignored/dropped
Explanation:
Big-O analysis focuses on the rate of growth. Constant multipliers do not change the class of growth (e.g., linear remains linear), so they are dropped.
Incorrect! Try again.
15If Algorithm A is and Algorithm B is , which algorithm is generally preferred for very large inputs?
A.Algorithm A
B.It depends on the computer hardware
C.Both are equal
D.Algorithm B
Correct Answer: Algorithm A
Explanation:
For very large inputs, grows much slower than , making Algorithm A significantly more efficient.
Incorrect! Try again.
16What is the recurrence relation for the Merge Sort algorithm?
A.
B.
C.
D.
Correct Answer:
Explanation:
Merge sort divides the problem into two halves () and takes linear time to merge them ().
Incorrect! Try again.
17What is the defining characteristic of a Recursive function?
A.It always returns 0
B.It uses a for loop
C.It uses pointers
D.It calls itself
Correct Answer: It calls itself
Explanation:
Recursion occurs when a function calls itself directly or indirectly to solve a smaller instance of the problem.
Incorrect! Try again.
18In recursion, what is the Base Case?
A.The condition that stops the recursion
B.The most complex part of the problem
C.The first line of the code
D.The variable with the largest value
Correct Answer: The condition that stops the recursion
Explanation:
The base case provides a direct solution without further recursion, preventing infinite loops.
Incorrect! Try again.
19If a recursive function lacks a base case, what runtime error is likely to occur?
A.Syntax Error
B.Null Pointer Exception
C.Index Out of Bounds
D.Stack Overflow Error
Correct Answer: Stack Overflow Error
Explanation:
Infinite recursion consumes stack memory for each call until the space is exhausted, causing a Stack Overflow.
Incorrect! Try again.
20Which algorithmic technique systematically searches for a solution by trying options and undoing them if they fail?
A.Backtracking
B.Greedy Method
C.Dynamic Programming
D.Divide and Conquer
Correct Answer: Backtracking
Explanation:
Backtracking builds candidates for the solution incrementally and abandons ('backtracks') a candidate as soon as it determines the candidate cannot lead to a valid solution.
Incorrect! Try again.
21The N-Queens problem is a classic example solved using which technique?
A.Greedy Algorithm
B.Backtracking
C.Sorting
D.Hashing
Correct Answer: Backtracking
Explanation:
N-Queens places queens one by one and backtracks if a queen is placed under attack, exploring the state space tree.
Incorrect! Try again.
22In the context of Backtracking, what does pruning mean?
A.Reducing the size of the input array
B.Cutting off branches of the state-space tree that do not lead to a solution
C.Removing syntax errors
D.Optimizing the compiler
Correct Answer: Cutting off branches of the state-space tree that do not lead to a solution
Explanation:
Pruning avoids visiting states that are known not to yield a valid solution, significantly speeding up the search.
Incorrect! Try again.
23What is Tail Recursion?
A.When the recursive call is the first statement
B.Recursion used only for sorting
C.Recursion with two base cases
D.When the recursive call is the last operation performed
Correct Answer: When the recursive call is the last operation performed
Explanation:
In tail recursion, nothing is left to do after the recursive call returns. Compilers can optimize this to prevent stack overflow.
Incorrect! Try again.
24Which of the following problems is typically NOT solved efficiently by recursion due to overlapping subproblems?
A.Calculating the -th Fibonacci number (naive approach)
B.Merge Sort
C.Tree Traversal
D.Quick Sort
Correct Answer: Calculating the -th Fibonacci number (naive approach)
Explanation:
Naive recursive Fibonacci re-calculates the same values many times (overlapping subproblems), resulting in exponential time complexity.
Incorrect! Try again.
25Dynamic Programming is mainly used for optimization problems that possess which two properties?
A.Greedy Choice and Randomization
B.Recursion and Iteration
C.Overlapping Subproblems and Optimal Substructure
D.Encapsulation and Inheritance
Correct Answer: Overlapping Subproblems and Optimal Substructure
Explanation:
DP is effective when a problem can be broken into optimal sub-solutions and these sub-problems recur multiple times.
Incorrect! Try again.
26In Dynamic Programming, what is Memoization?
A.A bottom-up approach using iteration
B.Deleting unused memory
C.A top-down approach that stores results of expensive function calls
D.Using a greedy strategy
Correct Answer: A top-down approach that stores results of expensive function calls
Explanation:
Memoization caches the result of a computed subproblem (usually in a recursion) to return it immediately if called again.
Incorrect! Try again.
27What is the difference between Tabulation and Memoization?
A.Memoization is not a DP technique
B.Tabulation is Bottom-Up; Memoization is Top-Down
C.Tabulation is Top-Down; Memoization is Bottom-Up
D.Tabulation uses more memory
Correct Answer: Tabulation is Bottom-Up; Memoization is Top-Down
Explanation:
Tabulation solves all subproblems iteratively starting from the base case (bottom-up), while memoization solves them recursively on demand (top-down).
Incorrect! Try again.
28The 0/1 Knapsack Problem is best solved using:
A.Binary Search
B.Greedy Algorithm
C.Dynamic Programming
D.Bubble Sort
Correct Answer: Dynamic Programming
Explanation:
The Greedy approach fails for 0/1 Knapsack (indivisible items). DP is required to find the optimal combination.
Incorrect! Try again.
29What is the time complexity of the Dynamic Programming solution for the Longest Common Subsequence (LCS) of two strings of length and ?
A.
B.
C.
D.
Correct Answer:
Explanation:
LCS builds a table of size , filling each cell in constant time, leading to complexity.
Incorrect! Try again.
30Which algorithm finds the shortest paths from a single source to all other vertices in a graph with negative edge weights (but no negative cycles)?
A.Kruskal's Algorithm
B.Prim's Algorithm
C.Bellman-Ford Algorithm
D.Dijkstra's Algorithm
Correct Answer: Bellman-Ford Algorithm
Explanation:
Bellman-Ford uses a dynamic programming approach capable of handling negative weights, unlike Dijkstra's greedy approach.
Incorrect! Try again.
31The Floyd-Warshall algorithm for All-Pairs Shortest Paths is an example of:
A.Divide and Conquer
B.Dynamic Programming
C.Greedy Algorithm
D.Backtracking
Correct Answer: Dynamic Programming
Explanation:
Floyd-Warshall iteratively improves the path estimate between any two nodes using an intermediate node, a classic DP strategy.
Incorrect! Try again.
32What defines a Greedy Algorithm?
A.It looks ahead to see the final outcome before deciding
B.It makes the locally optimal choice at each step hoping to find the global optimum
C.It tries all possible solutions
D.It solves subproblems and stores their results
Correct Answer: It makes the locally optimal choice at each step hoping to find the global optimum
Explanation:
Greedy algorithms make the best immediate decision at the current stage without reconsidering previous choices.
Incorrect! Try again.
33Which problem can be solved optimally using a Greedy Algorithm?
A.0/1 Knapsack Problem
B.Traveling Salesman Problem
C.Longest Common Subsequence
D.Fractional Knapsack Problem
Correct Answer: Fractional Knapsack Problem
Explanation:
In Fractional Knapsack, items can be divided. Choosing the item with the highest value-to-weight ratio first always yields the optimal solution.
Incorrect! Try again.
34Huffman Coding uses a greedy strategy to construct:
A.A Maximum Spanning Tree
B.A shortest path graph
C.A sorted array
D.An optimal prefix-free binary tree for data compression
Correct Answer: An optimal prefix-free binary tree for data compression
Explanation:
Huffman coding builds a tree by repeatedly combining the two least frequent characters, a greedy choice that ensures optimal compression.
Incorrect! Try again.
35The Activity Selection Problem (selecting max non-overlapping activities) is solved by sorting activities by their:
A.Start times
B.Durations
C.Priority
D.Finish times
Correct Answer: Finish times
Explanation:
Greedy strategy: Always pick the next activity that finishes earliest and is compatible with the previous one. This maximizes the remaining time for other activities.
Incorrect! Try again.
36Which of the following algorithms is used to find the Minimum Spanning Tree (MST)?
A.Binary Search
B.Prim's Algorithm
C.Strassen's Algorithm
D.Merge Sort
Correct Answer: Prim's Algorithm
Explanation:
Prim's Algorithm (and Kruskal's) is a greedy algorithm designed to find the MST of a connected, undirected graph.
Incorrect! Try again.
37In Kruskal’s Algorithm for MST, edges are processed in what order?
A.Increasing order of weight
B.Random order
C.Decreasing order of weight
D.Based on the node index
Correct Answer: Increasing order of weight
Explanation:
Kruskal's algorithm sorts edges by weight and iteratively adds the smallest edge that does not form a cycle.
Incorrect! Try again.
38Dijkstra's Algorithm is a greedy algorithm. Why does it fail with negative edge weights?
A.It runs out of memory
B.It assumes that adding an edge never decreases the total path distance
C.It cannot handle cycles
D.It is too slow
Correct Answer: It assumes that adding an edge never decreases the total path distance
Explanation:
Dijkstra's 'greedily' finalizes a node's distance once visited. Negative edges could make a previously finalized 'longer' path actually shorter later, which Dijkstra misses.
Incorrect! Try again.
39The Coin Change Problem (finding min coins) can be solved greedily only if:
A.We want the maximum number of coins
B.The coins are all the same value
C.The coin system is 'canonical' (e.g., US currency)
D.The total value is negative
Correct Answer: The coin system is 'canonical' (e.g., US currency)
Explanation:
For arbitrary coin systems (e.g., {1, 3, 4} to make 6), greedy fails (chooses 4+1+1, optimal is 3+3). It works for canonical systems where greedy implies optimal.
Incorrect! Try again.
40Which data structure is often used to efficiently implement Prim's Algorithm or Dijkstra's Algorithm?
A.Priority Queue (Min-Heap)
B.Stack
C.Queue
D.Hash Table
Correct Answer: Priority Queue (Min-Heap)
Explanation:
A Priority Queue allows efficient retrieval of the vertex with the minimum edge weight/distance, essential for the greedy choice step.
Incorrect! Try again.
41What is the key difference between Prim's and Kruskal's algorithms?
A.Prim's is for directed graphs; Kruskal's is for undirected
B.Prim's grows a tree from a source node; Kruskal's grows a forest of edges
C.Prim's uses recursion; Kruskal's uses iteration
D.There is no difference
Correct Answer: Prim's grows a tree from a source node; Kruskal's grows a forest of edges
Explanation:
Prim's builds one connected component, while Kruskal's adds edges globally, potentially maintaining multiple disjoint sets until they merge.
Incorrect! Try again.
42Which concept explains why Merge Sort is ?
A.It sorts in place without extra memory
B.It uses a greedy approach
C.The height of the recursion tree is and work per level is
D.It runs loops inside loops
Correct Answer: The height of the recursion tree is and work per level is
Explanation:
The Divide and Conquer strategy creates a tree of depth . At each level, merging takes linear time . Total = .
Incorrect! Try again.
43In the Matrix Chain Multiplication problem (DP), what are we trying to minimize?
A.The determinant of the result
B.The number of matrices
C.The total number of scalar multiplications
D.The size of the matrices
Correct Answer: The total number of scalar multiplications
Explanation:
The goal is to find the optimal parenthesization order to minimize the computational cost (scalar multiplications) of multiplying a chain of matrices.
Incorrect! Try again.
44What is the time complexity of calculating the -th Fibonacci number using DP with Memoization?
A.
B.
C.
D.
Correct Answer:
Explanation:
Memoization ensures each of the Fibonacci numbers is calculated exactly once, reducing the exponential naive complexity to linear.
Incorrect! Try again.
45Which of the following is true regarding Optimal Substructure?
A.It means an optimal solution to the problem contains optimal solutions to its subproblems
B.It is only found in sorting algorithms
C.It means the problem can be solved using a greedy heuristic only
D.It implies the solution is unique
Correct Answer: It means an optimal solution to the problem contains optimal solutions to its subproblems
Explanation:
This property is a prerequisite for both Greedy and Dynamic Programming approaches.
Incorrect! Try again.
46What is the complexity of sorting an array using Quick Sort in the worst case?
A.
B.
C.
D.
Correct Answer:
Explanation:
In the worst case (e.g., sorted array with first element as pivot), the partition is unbalanced, leading to . Average case is .
Incorrect! Try again.
47Which notation represents the strict upper bound (rarely used in basic analysis)?
A. (Little-o)
B. (Big-O)
C. (Theta)
D. (Omega)
Correct Answer: (Little-o)
Explanation:
Little-o notation denotes that grows strictly slower than , unlike Big-O which allows equality in growth rate.
Incorrect! Try again.
48In algorithm analysis, a 'Basic Operation' is:
A.A comment in the code
B.The operation contributing most to the running time
C.A complex function call
D.The entire program
Correct Answer: The operation contributing most to the running time
Explanation:
We count the frequency of the basic operation (e.g., comparison in sorting, addition in matrix mult) to determine time complexity.
Incorrect! Try again.
49Which strategy does Binary Search use?
A.Backtracking
B.Divide and Conquer
C.Dynamic Programming
D.Greedy
Correct Answer: Divide and Conquer
Explanation:
Binary Search divides the problem instance into a smaller instance (half the size) at each step.
Incorrect! Try again.
50The Travelling Salesman Problem (TSP) is generally considered hard because:
A.It is NP-Hard and no polynomial time algorithm is known
B.It has complexity
C.It requires negative edge weights
D.It can be solved easily with Greedy
Correct Answer: It is NP-Hard and no polynomial time algorithm is known
Explanation:
Exact solutions to TSP require checking factorial permutations or exponential DP approaches, making it computationally intractable for large .
Incorrect! Try again.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill.
The rest comes out of a student's own pocket: the domain, the storage,
and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it.
What it pays for →