Data Structure and Algorithm
Data Structure and Algorithm
MCQS
3rd Semester
By
Shoaib Malik
Topic 1: Review of PF (Procedural Programming) and Explanation: Encapsulation hides data inside a
OOP Concepts class and exposes only required methods.
4. Which feature of OOP allows hiding the 8. Which of the following is true about objects?
internal details of an object? A) They are independent entities combining
A) Inheritance data and behavior
B) Encapsulation B) They only store data
C) Polymorphism C) They are only functions
D) Overloading D) They cannot interact with each other
Answer: B Answer: A
Explanation: Objects combine data (attributes) 13. In PF, the primary focus is on:
and methods (behavior) into one entity. A) Objects
B) Functions or procedures
9. Abstraction in OOP means:
C) Classes
A) Hiding irrelevant details and showing only
D) Messages
essential features
Answer: B
B) Inheriting properties from parent class
Explanation: PF emphasizes procedures or
C) Overloading methods
functions to process data.
D) Using arrays
Answer: A 14. Which of the following OOP concepts reduces
Explanation: Abstraction hides internal code redundancy?
complexity and exposes a simple interface. A) Inheritance
B) Looping
10. Which of these is a benefit of OOP over PF?
C) Conditional statements
A) Code reuse through inheritance
D) Recursion
B) Linear code execution
Answer: A
C) No need for memory management
Explanation: Inheritance allows reuse of
D) No modularity
existing code in derived classes.
Answer: A
Explanation: OOP allows reusing code via 15. Which is NOT a feature of procedural
inheritance, unlike PF. programming?
A) Top-down approach
11. Which concept allows new classes to be based
B) Modular code
on existing classes?
C) Objects
A) Encapsulation
D) Function calls
B) Abstraction
Answer: C
C) Inheritance
Explanation: PF does not use objects; it relies
D) Polymorphism
on functions and procedures.
Answer: C
Explanation: Inheritance allows new classes to 16. Polymorphism can be achieved by:
derive properties and methods from existing A) Overloading
classes. B) Overriding
C) Both A and B
12. Which of the following is a real-world example
D) Inheritance only
of OOP?
Answer: C
A) Function to calculate sum
Explanation: Both method overloading and
B) Class Car with properties and methods
overriding are forms of polymorphism.
C) Sequential code in a C program
D) Batch script 17. Which of the following is the best definition of
Answer: B a method in OOP?
Explanation: Classes model real-world entities A) A variable
with data and behavior. B) A procedure associated with a class
C) A loop
D) A memory unit A) Class
Answer: B B) Integer
Explanation: Methods define behaviors of C) Struct
objects within a class. D) Object
Answer: B
18. OOP encourages which type of programming
Explanation: Primitive data types are basic
style?
built-in types such as integers, floats,
A) Top-down
characters, and booleans.
B) Bottom-up
C) Linear 2. Which of the following is NOT a primitive data
D) Functional type?
Answer: B A) Float
Explanation: OOP often uses a bottom-up B) Char
approach: build objects first, then integrate C) Array
them. D) Boolean
Answer: C
19. Which of the following is an example of
Explanation: Arrays are derived or composite
encapsulation?
types, not primitive types.
A) Making class data private and accessing via
getters/setters 3. What is the size of an int in most 32-bit
B) Inheriting properties systems?
C) Using loops inside a class A) 1 byte
D) Overloading functions B) 2 bytes
Answer: A C) 4 bytes
Explanation: Encapsulation protects data and D) 8 bytes
provides controlled access through methods. Answer: C
Explanation: On most 32-bit systems, an int
20. Why is OOP preferred for large software
occupies 4 bytes.
systems?
A) Easier maintenance and reusability 4. Which data type is suitable for storing
B) Faster execution than PF always true/false values?
C) Less memory usage A) Int
D) No need for debugging B) Boolean
Answer: A C) Char
Explanation: OOP's modularity and code reuse D) Float
make it ideal for large and complex systems. Answer: B
Explanation: Boolean data type stores logical
values: true or false.
Topic 2: Primitive Data Types and User-Defined Data
5. Which primitive type is used to store decimal
Types
numbers?
1. Which of the following is a primitive data type A) Int
in most programming languages? B) Char
C) Float or Double D) Less memory usage
D) Boolean Answer: C
Answer: C Explanation: User-defined types allow grouping
Explanation: Float and double are used for real of different variables into a single unit, like a
numbers with fractional parts. struct or class.
6. Which of the following is a user-defined data 10. Which of the following is an example of an
type? enumeration (enum) in C++?
A) Int A) enum Colors {RED, GREEN, BLUE};
B) Struct B) int x = 5;
C) Char C) float pi = 3.14;
D) Boolean D) char letter = 'A';
Answer: B Answer: A
Explanation: User-defined types allow Explanation: Enums are user-defined types that
programmers to define new types such as assign names to integer constants.
structs, classes, and enums.
11. Which of the following is true about primitive
7. In C++, which of the following can be types?
considered a user-defined type? A) They can store multiple values
A) Integer B) They are built into the programming
B) Class language
C) Boolean C) They require class definitions
D) Float D) They are always objects
Answer: B Answer: B
Explanation: Classes are user-defined data Explanation: Primitive types are basic types
types that combine data and functions. provided by the programming language itself.
8. Which keyword is used in C++ to define a 12. In Java, which of the following is a primitive
structure? data type?
A) class A) String
B) struct B) Boolean
C) typedef C) ArrayList
D) enum D) Class
Answer: B Answer: B
Explanation: The struct keyword defines a user- Explanation: Java has 8 primitive types,
defined data type composed of different data including boolean. String and ArrayList are
members. objects.
9. What is the main advantage of user-defined 13. What is the size of a char in most programming
types over primitive types? languages?
A) Faster execution A) 8 bits
B) Easier to read B) 16 bits
C) Ability to group multiple data types together C) 32 bits
D) 64 bits Explanation: Primitive types are simple, fast,
Answer: A and form the building blocks for complex
Explanation: A char typically stores a single structures.
character and occupies 1 byte (8 bits).
18. Which of the following is NOT a characteristic
14. Which of the following allows defining a new of user-defined types?
name for an existing data type? A) Can group multiple data items
A) typedef B) Can have methods/functions
B) struct C) Always built-in
C) enum D) Enhances code readability
D) class Answer: C
Answer: A Explanation: User-defined types are created by
Explanation: typedef in C/C++ creates an alias the programmer, not built into the language.
for a data type.
19. Which type of data structure is primitive in
15. A structure in C++ can contain: most languages?
A) Only integers A) Array
B) Only floats B) Integer
C) Multiple data types (int, float, char, etc.) C) Struct
D) Only arrays D) Linked List
Answer: C Answer: B
Explanation: Structures can combine different Explanation: Integer is a primitive type; arrays
types of data members. and linked lists are derived/complex types.
16. Which of the following best describes a union? 20. Which of the following is true about enums in
A) Stores multiple data types simultaneously C++?
B) Stores one of many types in the same A) Can only store integers with symbolic names
memory location B) Can store strings
C) A function C) Can store floats
D) A primitive type D) Cannot be used in switch statements
Answer: B Answer: A
Explanation: A union allows storing different Explanation: Enums assign symbolic names to
types, but only one value at a time, sharing integer constants and improve code readability.
memory.
2. Which of the following best defines the 6. Which of these is NOT part of project
“scope” of a project? planning?
A) The variables used A) Defining scope
B) The limitations and boundaries of the project B) Setting objectives
C) The functions used C) Choosing colors for syntax
D) The programming language D) Understanding motivation
Answer: B Answer: C
Explanation: Scope defines what the project Explanation: Project planning involves aim,
will and will not cover, its boundaries and objectives, scope, and motivation, not syntax
limitations. colors.
1. Which of the following is a linear data 5. Which data structure uses FIFO (First In First
structure? Out) principle?
A) Array A) Stack
B) Tree B) Queue
C) Graph C) Tree
D) Heap D) Hash Table
Answer: B Answer: B
Explanation: Queue processes elements in the Explanation: Stack stores operations in LIFO
order they arrive, following FIFO. order, allowing undo of the most recent action
first.
6. Which data structure allows efficient insertion
and deletion from both ends? 10. Which of the following is true about a circular
A) Queue queue?
B) Stack A) Elements are stored in a straight line
C) Deque (Double-ended Queue) B) The last position is connected to the first
D) Array position
Answer: C C) It uses LIFO
Explanation: A deque allows insertion and D) It cannot be implemented in arrays
deletion at both front and rear. Answer: B
Explanation: Circular queues connect the end
7. A linked list differs from an array in that:
to the beginning, allowing efficient use of
A) Arrays store elements dynamically, linked
space.
lists store statically
B) Linked lists are dynamic in size, arrays have 11. In which data structure is binary search most
fixed size efficiently performed?
C) Arrays use pointers, linked lists don’t A) Linked List
D) Linked lists are linear, arrays are non-linear B) Array
Answer: B C) Queue
Explanation: Linked lists can grow or shrink at D) Stack
runtime, whereas arrays have fixed size. Answer: B
Explanation: Binary search requires random
8. Which of the following is the most appropriate
access, which arrays provide, but linked lists
data structure for implementing a priority
don’t.
queue?
A) Stack 12. Which data structure is best suited for
B) Linked List representing hierarchical relationships?
C) Heap A) Array
D) Array B) Stack
Answer: C C) Tree
Explanation: A heap allows efficiently finding D) Queue
and removing the element with the highest Answer: C
priority. Explanation: Trees are ideal for hierarchical
structures, like file systems or organizational
9. Which data structure is ideal for undo
charts.
operations in software?
A) Queue 13. Graphs are mainly used to represent:
B) Stack A) Sequential data
C) Tree B) Hierarchical data
D) Graph C) Network connections
D) Mathematical formulas C) Array
Answer: C D) Graph
Explanation: Graphs model networks, such as Answer: B
social networks, computer networks, or Explanation: Queues manage processes in FIFO
transport systems. order, like in round-robin scheduling.
14. Which data structure is efficient for 18. Which of the following is an application of
implementing a breadth-first search (BFS) in a hash tables?
graph? A) Memory management
A) Stack B) Storing sorted data
B) Queue C) Fast search and retrieval
C) Array D) Implementing stacks
D) Linked List Answer: C
Answer: B Explanation: Hash tables provide fast insertion,
Explanation: BFS uses a queue to explore nodes deletion, and search operations using keys.
level by level.
19. Which data structure is used in depth-first
15. Which of the following data structures search (DFS) of a graph?
supports random access of elements? A) Queue
A) Linked List B) Stack
B) Stack C) Linked List
C) Array D) Array
D) Queue Answer: B
Answer: C Explanation: DFS uses a stack (either explicit or
Explanation: Arrays allow direct access to any via recursion) to explore nodes deeply before
element using an index. backtracking.
16. Which data structure is preferred when 20. Which data structure is best for implementing
frequent insertions and deletions occur in the undo/redo functionality and browser history?
middle of the structure? A) Queue
A) Array B) Stack
B) Linked List C) Linked List
C) Stack D) Graph
D) Queue Answer: B
Answer: B Explanation: Stack allows storing operations
Explanation: Linked lists allow efficient sequentially and supports LIFO access for
insertion/deletion without shifting elements undo/redo.
like in arrays.
9. Which of the following is true about recursive 13. The step-by-step approach to problem-solving
algorithms? is known as:
A) They never terminate A) Compilation
B) They call themselves to solve smaller sub- B) Algorithm
problems C) Linking
C) They cannot solve factorials D) Debugging
D) They are slower than loops in all cases Answer: B
Answer: B Explanation: Algorithms define the procedure
Explanation: Recursive algorithms solve to solve a problem step-by-step.
problems by calling themselves on smaller
14. Which of the following is NOT a property of a
instances.
good algorithm?
10. What is the first step in designing an A) Finiteness
algorithm? B) Efficiency
A) Writing code C) Ambiguity
B) Defining the problem D) Correctness
C) Debugging Answer: C
D) Choosing a compiler Explanation: Algorithms must be clear and
Answer: B unambiguous to be effective.
Explanation: Defining the problem is essential
15. Divide and Conquer algorithms:
before creating an algorithm.
A) Solve the problem by breaking it into smaller
11. Which of the following is an advantage of sub-problems
algorithms? B) Solve only linear problems
A) Reusability C) Use stacks exclusively
B) Clarity D) Are slow for all problems
C) Efficiency Answer: A
D) All of the above Explanation: Divide and Conquer breaks
problems into smaller, manageable sub- 20. Which statement is correct about algorithms?
problems. A) Every program has an algorithm
B) Algorithms always require a computer
16. Which algorithmic technique is used in Merge
C) Algorithms cannot be written in natural
Sort?
language
A) Dynamic Programming
D) Algorithms do not require inputs
B) Divide and Conquer
Answer: A
C) Greedy
Explanation: Every program is based on an
D) Brute Force
underlying algorithm, even if not explicitly
Answer: B
written.
Explanation: Merge Sort splits the array
recursively, sorts, and merges, following Divide
and Conquer.
Topic 2: Analysis of Algorithms.
17. What does “input” in an algorithm mean?
A) Data provided to the algorithm to process
B) Output of the algorithm Topic 2: Analysis of Algorithms
C) Memory allocation
1. What is the main purpose of algorithm
D) Compiler option
analysis?
Answer: A
A) To write code faster
Explanation: Input is the data given to the
B) To determine the efficiency of an algorithm
algorithm to generate output.
in terms of time and space
18. The output of an algorithm is: C) To debug the program
A) Steps of the algorithm D) To choose a compiler
B) The result produced after processing input Answer: B
C) Compiler messages Explanation: Algorithm analysis evaluates
D) Runtime errors performance, focusing on time (speed) and
Answer: B space (memory) efficiency.
Explanation: Output is the solution or result
2. Which of the following describes “time
obtained by executing the algorithm.
complexity”?
19. Which of the following algorithms is used for A) The amount of memory an algorithm uses
shortest path problems in graphs? B) The number of steps an algorithm takes
A) Bubble sort relative to input size
B) Dijkstra’s algorithm C) The time to compile the program
C) Merge sort D) The execution time of the compiler
D) Insertion sort Answer: B
Answer: B Explanation: Time complexity measures how
Explanation: Dijkstra’s algorithm finds the the number of steps grows with input size.
shortest path from a source node to all other
3. Which of the following describes “space
nodes.
complexity”?
A) The runtime of the algorithm 7. Which notation is commonly used for
B) Memory required by an algorithm to execute asymptotic analysis?
C) CPU cycles per second A) C notation
D) Input size B) Big O, Big Θ, Big Ω
Answer: B C) Pascal notation
Explanation: Space complexity measures the D) Small o notation only
amount of memory needed for an algorithm to Answer: B
run. Explanation: Big O, Theta, and Omega notations
describe upper bound, tight bound, and lower
4. Best-case analysis refers to:
bound complexities.
A) When the algorithm performs maximum
steps 8. If an algorithm has O(n²) time complexity, it
B) When the algorithm performs minimum means:
steps A) Execution time grows linearly with input size
C) Average steps B) Execution time grows quadratically with
D) Memory usage input size
Answer: B C) Execution time is constant
Explanation: Best-case represents the scenario D) Execution time decreases as input increases
where the algorithm executes in minimum Answer: B
possible time. Explanation: O(n²) indicates execution steps
grow proportional to the square of input size.
5. Worst-case analysis refers to:
A) The fastest execution scenario 9. Which of the following is an example of
B) The maximum number of steps the algorithm constant time complexity?
takes A) Accessing an element in an array by index
C) The average number of steps B) Bubble sort
D) Memory requirement C) Binary search
Answer: B D) Merge sort
Explanation: Worst-case represents the Answer: A
scenario where the algorithm takes the most Explanation: Accessing an array element by
steps to complete. index takes the same time regardless of array
size → O(1).
6. Average-case analysis is important because:
A) It represents the most likely performance in 10. Linear time complexity (O(n)) means:
real applications A) Time grows logarithmically
B) It ignores memory usage B) Time grows directly proportional to input size
C) It measures compiler efficiency C) Time is constant
D) It uses recursion D) Time grows exponentially
Answer: A Answer: B
Explanation: Average-case analysis provides Explanation: O(n) indicates that doubling input
expected performance for typical inputs. roughly doubles execution time.
11. Which of the following affects time 15. Bubble sort has which time complexity in the
complexity? worst case?
A) Number of instructions executed A) O(n)
B) Input size B) O(log n)
C) Algorithm design C) O(n²)
D) All of the above D) O(1)
Answer: D Answer: C
Explanation: Time complexity depends on Explanation: Nested loops in bubble sort cause
algorithm design, input size, and number of quadratic growth → O(n²) in the worst case.
operations executed.
16. Why is worst-case analysis important?
12. Space complexity includes: A) To estimate maximum time required
A) Input data storage B) To reduce memory
B) Auxiliary memory used by the algorithm C) To choose variable names
C) Function call stack memory D) To debug faster
D) All of the above Answer: A
Answer: D Explanation: Worst-case analysis ensures the
Explanation: Space complexity accounts for algorithm meets time constraints under all
input, extra storage, and memory for recursion conditions.
or function calls.
17. What does Big-O notation represent?
13. Which of the following is more important in A) Minimum running time
embedded systems? B) Upper bound of running time
A) Time complexity only C) Exact execution time
B) Space complexity only D) Memory usage only
C) Both time and space complexity Answer: B
D) None Explanation: Big-O provides the upper bound
Answer: C on time or space complexity as input size
Explanation: Embedded systems often have grows.
limited memory and need fast execution, so
18. Which of the following is true about recursive
both complexities matter.
algorithms and complexity?
14. Binary search has which time complexity in the A) They always have O(1) complexity
worst case? B) Recursive calls add to both time and space
A) O(n) complexity
B) O(log n) C) Recursion reduces memory usage
C) O(n²) D) Recursion has no effect on analysis
D) O(1) Answer: B
Answer: B Explanation: Each recursive call consumes stack
Explanation: Binary search divides the input in memory and adds to total execution time.
half at each step → logarithmic time O(log n).
19. If an algorithm’s time complexity is O(n log n),
it means:
A) Time grows faster than O(n²) D) Compiler efficiency
B) Time grows slower than O(n²) but faster than Answer: B
O(n) Explanation: Space complexity includes
C) Time is constant memory used for input, auxiliary variables, and
D) Time is logarithmic recursion stack.
Answer: B
3. Which of the following is considered constant
Explanation: O(n log n) lies between linear and
time complexity?
quadratic growth rates.
A) O(1)
20. Which of the following is true about algorithm B) O(n)
efficiency? C) O(n²)
A) Faster algorithms always use more memory D) O(log n)
B) Efficiency can be analyzed using time and Answer: A
space complexity Explanation: O(1) means the algorithm takes
C) Complexity depends on the programming the same time regardless of input size.
language only
4. Which of the following is linear time
D) Efficiency cannot be measured
complexity?
Answer: B
A) O(1)
Explanation: Efficiency is measured by how an
B) O(n)
algorithm uses time and memory relative to
C) O(n²)
input size.
D) O(log n)
Answer: B
Topic 3: Time/Space Complexity. Explanation: O(n) grows proportionally to the
input size.
5. Backtracking algorithms:
A) Try partial solutions and backtrack on failure
Topic 5: Classes of Algorithms
B) Use recursion only
1. Which of the following is a brute-force C) Are always O(n²)
algorithm? D) Never terminate
A) Linear search Answer: A
B) Binary search Explanation: Backtracking explores all
C) Merge sort possibilities, abandoning paths that fail.
D) Dijkstra’s algorithm
6. Which algorithm class uses a priority queue?
Answer: A
A) Greedy
Explanation: Brute-force algorithms try all
B) Divide and Conquer
possibilities without optimization.
C) Brute Force
2. Divide and Conquer algorithms work by: D) Dynamic Programming
A) Splitting the problem into smaller sub- Answer: A
problems Explanation: Greedy algorithms like Prim’s or
B) Checking all possibilities Dijkstra’s often use priority queues.
C) Using dynamic programming
7. Merge Sort belongs to which class?
D) Using greedy choice
A) Divide and Conquer
Answer: A
B) Greedy
Explanation: Divide-and-conquer splits, solves,
C) Brute Force
and merges sub-problems.
D) Backtracking
3. Which of the following is a greedy algorithm Answer: A
example? Explanation: Merge Sort splits arrays and
A) Huffman coding merges sorted subarrays.
B) Merge sort
8. Which of the following is true about brute-
C) Binary search
force algorithms?
D) DFS
A) Simple to implement but often inefficient
Answer: A
B) Always optimal
Explanation: Greedy algorithms make locally
C) Use recursion only
optimal choices, e.g., Huffman coding for data
D) Ignore input
compression.
Answer: A
4. Dynamic programming is used when: Explanation: Brute-force methods are easy but
A) Subproblems overlap can be slow for large inputs.
B) Only single solution exists
9. Greedy algorithms:
C) Memory is unlimited
A) Always produce optimal solutions
D) Input is sorted
B) Use a series of local optimal choices
Answer: A
C) Are used for sorting only Explanation: Backtracking can explore all
D) Never use recursion possibilities → exponential time.
Answer: B
14. Greedy algorithms are not always:
Explanation: They rely on local decisions to
A) Efficient
attempt to reach global optimum.
B) Optimal
10. Dynamic programming avoids: C) Simple
A) Iteration D) Recursive
B) Redundant computation Answer: B
C) Sorting Explanation: Greedy may fail to produce
D) Searching globally optimal results.
Answer: B
15. Which class is often used for shortest path
Explanation: DP stores intermediate results to
problems?
reduce repeated work.
A) Greedy
11. Backtracking is commonly used in: B) Divide and Conquer
A) N-Queens problem C) Dynamic Programming
B) Bubble sort D) Brute Force
C) Binary search Answer: A
D) Merge sort Explanation: Dijkstra’s algorithm is a greedy
Answer: A method for shortest paths.
Explanation: Backtracking systematically
16. Dynamic programming is useful when:
searches for valid solutions in combinatorial
A) Problem has optimal substructure
problems.
B) Problem is linear
12. Which algorithm class solves problems by C) Input is sorted
reducing size recursively? D) Problem is trivial
A) Divide and Conquer Answer: A
B) Greedy Explanation: DP requires optimal solutions to
C) Brute Force subproblems to build overall solution.
D) Backtracking
17. Which algorithm class is used for
Answer: A
combinatorial problems?
Explanation: Divide-and-conquer breaks
A) Backtracking
problems into smaller subproblems.
B) Binary Search
13. Which class is typically exponential in worst- C) Merge Sort
case complexity? D) Heap Sort
A) Backtracking Answer: A
B) Merge Sort Explanation: Combinatorial problems like
C) Binary Search permutations, subsets, or puzzles use
D) Heap Sort backtracking.
Answer: A
18. Which of the following uses memoization? C) Average complexity
A) Dynamic Programming D) Constant time
B) Brute Force Answer: B
C) Greedy Explanation: Big Omega represents the
D) Backtracking minimum steps required (best-case).
Answer: A
3. Big Θ notation represents:
Explanation: Memoization stores results of
A) Exact asymptotic behavior
subproblems to avoid recomputation.
B) Only best-case
19. Brute-force is suitable for: C) Only worst-case
A) Small input sizes D) Memory usage
B) Large input sizes Answer: A
C) Sorting only Explanation: Theta provides a tight bound
D) Searching only (both upper and lower) on growth.
Answer: A
4. Which notation ignores constants and lower-
Explanation: Simple brute-force works for small
order terms?
datasets but is inefficient for large inputs.
A) Big O
20. Which algorithm class is used in Huffman B) Big Ω
coding? C) Big Θ
A) Greedy D) All of the above
B) Divide and Conquer Answer: D
C) Dynamic Programming Explanation: Asymptotic notations focus on
D) Backtracking dominant terms for large input sizes.
Answer: A
5. If T(n) = 5n² + 3n + 10, its Big O is:
Explanation: Huffman coding chooses shortest
A) O(n)
codes greedily for compression.
B) O(n²)
C) O(n³)
D) O(1)
Topic 6: Asymptotic Notations
Answer: B
1. Big O notation describes: Explanation: The dominant term n² determines
A) Upper bound of complexity growth → O(n²).
B) Lower bound of complexity
6. If T(n) = 2n³ + 7n², Big Ω is:
C) Exact complexity
A) Ω(n²)
D) Memory only
B) Ω(n³)
Answer: A
C) Ω(n)
Explanation: Big O gives the worst-case or
D) Ω(1)
upper bound growth of an algorithm.
Answer: B
2. Big Ω notation represents: Explanation: Lower bound is also dominated by
A) Upper bound the highest-order term → Ω(n³).
B) Lower bound
7. Which notation is used for average-case D) Not defined
analysis? Answer: D
A) Big O Explanation: Θ requires tight bounds (same for
B) Big Θ upper and lower); here they differ → Θ not
C) Big Ω defined.
D) None
12. Which notation is used to express lower bound
Answer: B
of running time?
Explanation: Theta gives a tight bound, often
A) Big O
representing average-case growth.
B) Big Ω
8. Binary search complexity is: C) Big Θ
A) O(n) D) Small o
B) O(log n) Answer: B
C) O(n²) Explanation: Big Omega defines the minimum
D) O(1) steps required.
Answer: B
13. For T(n) = n² + 100n + 50, Big Θ is:
Explanation: Binary search divides input in half
A) Θ(n)
each step → logarithmic growth.
B) Θ(n²)
9. Merge sort has which asymptotic notations? C) Θ(n³)
A) O(n log n), Ω(n log n), Θ(n log n) D) Θ(1)
B) O(n²), Ω(n²), Θ(n²) Answer: B
C) O(n), Ω(1), Θ(n²) Explanation: Highest-order term dominates →
D) O(log n), Ω(log n), Θ(n) Θ(n²).
Answer: A
14. Big O notation ignores:
Explanation: Merge sort has the same
A) Constants
complexity in all cases.
B) Lower-order terms
10. Which notation is commonly used for worst- C) Both
case analysis? D) Input size
A) Big O Answer: C
B) Big Θ Explanation: Asymptotic notations focus on
C) Big Ω growth rate, ignoring constants and minor
D) None terms.
Answer: A
15. Which notation would you use to guarantee an
Explanation: Big O provides the upper bound,
algorithm won’t exceed a certain time?
typically representing worst-case.
A) Big O
11. If an algorithm has O(n²) worst-case and Ω(n) B) Big Ω
best-case, Θ is: C) Big Θ
A) Θ(n²) D) Small o
B) Θ(n) Answer: A
C) Θ(n log n)
Explanation: Big O gives an upper bound, B) Big Ω
ensuring algorithm won’t exceed that time. C) Big Θ
D) Small o
16. Which of the following represents tight
Answer: A
bound?
A) Big Θ
B) Big O
C) Big Ω
D) Small o
Answer: A
Explanation: Theta tightly bounds the function
Week 3: Array
from above and below.
12. Which of the following is useful for storing 16. Time complexity for traversing an m × n 2D
tabular data? array is:
A) 1D array A) O(1)
B) 2D array B) O(m+n)
C) 3D array C) O(m×n)
D) None D) O(log n)
Answer: B Answer: C
Explanation: 2D arrays map naturally to rows Explanation: Traversal requires visiting all
and columns of tables. elements → O(rows × columns).
13. Which of the following can represent a cube of 17. Which operation is complex in multi-
data? dimensional arrays?
A) 1D array A) Access by index
B) 2D array B) Traversal
C) 3D array C) Insertion at arbitrary position
D) None D) Direct access
Answer: C Answer: C
Explanation: Inserting into multi-dimensional
arrays may require shifting rows/columns.
19. Traversal helps in inserting at nth position Topic 1: Deletion Operations on Singly Linked List
because:
A) Finds previous node 1. Which pointer is updated when deleting the
B) Allocates memory first node in a singly linked list?
C) Updates head A) Tail
D) Updates tail B) Head
Answer: A C) Next of second node
Explanation: Need to traverse to the (n-1)th D) Previous of head
node to update pointers. Answer: B
Explanation: Head moves to the second node;
20. Traversal is essential in: the first node is removed.
A) Displaying elements
B) Searching 2. Time complexity for deleting the first node in a
C) Deletion singly linked list:
D) All of the above A) O(1)
Answer: D B) O(n)
Explanation: Traversal is fundamental to all C) O(log n)
linked list operations. D) O(n²)
Answer: A
Explanation: Deletion at the head does not 7. Deleting a node by value requires:
require traversal → constant time. A) Traversal to find node
B) Update previous node’s next pointer
3. To delete the last node of a singly linked list:
C) Free target node memory
A) Update head to next node
D) All of the above
B) Traverse to second-last node, update its next
Answer: D
to NULL, free last node
Explanation: Must locate node, bypass it, and
C) Free tail directly
deallocate memory.
D) None of the above
Answer: B 8. Memory leak occurs during deletion if:
Explanation: Must find second-last node to A) Node is freed properly
remove last node safely. B) Node is bypassed but memory not freed
C) Head updated
4. Time complexity for deleting the last node
D) Tail updated
without tail pointer:
Answer: B
A) O(1)
Explanation: Dynamically allocated memory
B) O(n)
must be freed; otherwise, it leaks.
C) O(log n)
D) O(n²) 9. After deleting a node, the previous node's next
Answer: B pointer should point to:
Explanation: Must traverse the list to reach A) Deleted node
second-last node. B) NULL
C) Deleted node’s next node
5. Deleting a node at nth position requires:
D) Head
A) Traversal to nth node
Answer: C
B) Traversal to (n-1)th node, update pointers
Explanation: Maintains list continuity by
C) Update head only
bypassing the deleted node.
D) Direct access
Answer: B 10. Deleting a node by value not present in the
Explanation: Previous node’s next pointer must list:
point to node → next to remove nth node. A) Free head
B) Do nothing / error message
6. What happens if you delete from an empty
C) Free tail
list?
D) Delete random node
A) Head is updated
Answer: B
B) Nothing happens / handled gracefully
Explanation: Node not found → nothing to
C) Tail is updated
delete.
D) Memory freed automatically
Answer: B 11. Deleting all nodes in a singly linked list
Explanation: Head = NULL → no nodes to requires:
delete. A) Head pointer update only
B) Traversal freeing each node
C) Tail pointer update
D) None Answer: B
Answer: B Explanation: Dynamically allocated node
Explanation: Must free each node dynamically memory must be released to prevent leaks.
to prevent memory leaks.
16. Deleting a node in singly linked list without
12. Deleting the first node in a circular singly head pointer:
linked list: A) Not possible
A) Update head to next, last node points to new B) O(1)
head C) O(n)
B) Free tail D) O(log n)
C) Update next of head only Answer: A
D) None Explanation: Head is needed to start traversal;
Answer: A without it, deletion is impossible.
Explanation: Circular property maintained by
17. What pointer does the second-last node
updating last node’s next.
update when deleting the last node?
13. Deleting the last node in circular singly linked A) Previous
list requires: B) Next → NULL
A) Update head only C) Head
B) Traverse to second-last node, update next to D) Tail
head, free last node Answer: B
C) Allocate new node Explanation: Its next should be NULL to indicate
D) None new list end.
Answer: B
18. Time complexity to delete a node by value in
Explanation: Second-last node’s next must
worst case:
point to head to maintain circularity.
A) O(1)
14. Which deletion operation is fastest in singly B) O(n)
linked list? C) O(log n)
A) Delete head D) O(n²)
B) Delete last node Answer: B
C) Delete nth node Explanation: Entire list may need traversal to
D) Delete by value find the node.
Answer: A
19. Deleting all nodes effectively involves:
Explanation: Deleting head does not require
A) Updating head to NULL
traversal → O(1) time.
B) Freeing each node one by one
15. Deleting a node requires updating pointers C) Both A and B
and: D) None
A) Node value Answer: C
B) Memory deallocation (free/delete) Explanation: Prevents dangling pointers and
C) Head pointer memory leaks.
D) None
20. Deleting a node at nth position requires: C) Insert/delete at both ends efficiently
A) Traversal to (n-1)th node D) All of the above
B) Direct access Answer: D
C) Updating tail only Explanation: Previous pointer enhances
D) None operations.
Answer: A
5. Circular doubly linked list traversal:
Explanation: Previous node pointer is required
A) Forward only
to bypass the target node.
B) Backward only
C) Both directions infinitely
D) None
Topic 2: Variations of Linked Lists
Answer: C
1. Which is a standard variation of linked list? Explanation: Circularity + previous/next
A) Singly linked list pointers allow infinite bidirectional traversal.
B) Doubly linked list
6. Memory usage per node in doubly linked list:
C) Circular linked list
A) Less than singly linked list
D) All of the above
B) More than singly linked list
Answer: D
C) Same
Explanation: All three are standard linked list
D) Variable
types.
Answer: B
2. Doubly linked list node contains: Explanation: Extra previous pointer consumes
A) Data only additional memory.
B) Data + next pointer
7. Stack implementation uses:
C) Data + next + previous pointer
A) Singly linked list
D) None
B) Doubly linked list
Answer: C
C) Circular list
Explanation: Allows forward and backward
D) None
traversal.
Answer: A
3. Singly circular linked list differs from singly Explanation: Singly linked list supports LIFO
linked list in: efficiently.
A) Last node points to head
8. Queue implementation uses:
B) Head points to NULL
A) Singly linked list with head/tail pointers
C) Nodes have previous pointer
B) Doubly linked list
D) None
C) Circular singly linked list
Answer: A
D) All of the above
Explanation: Circularity ensures last node links
Answer: D
back to head.
Explanation: Various linked list variations
4. Advantages of doubly linked list include: support queues.
A) Forward and backward traversal
B) Easier insertion/deletion anywhere
9. Circular singly linked list is ideal for: Explanation: No previous pointer; need
A) Round-robin scheduling stack/recursion.
B) Image storage
14. Traversal in circular singly linked list stops
C) Graph implementation
when:
D) Arrays
A) Current pointer = NULL
Answer: A
B) Current pointer = head (after first cycle)
Explanation: Circular structure allows
C) Infinite loop
continuous iteration.
D) None
10. Doubly linked list allows: Answer: B
A) Forward traversal only Explanation: To avoid infinite loop, stop after
B) Backward traversal only visiting head again.
C) Both forward and backward traversal
15. Insertion/deletion efficiency at both ends:
D) None
A) Best in doubly linked list with head/tail
Answer: C
B) Best in singly linked list
Explanation: Previous and next pointers enable
C) Array
two-way traversal.
D) Stack
11. Memory-efficient linked list variation: Answer: A
A) Singly linked list Explanation: Head/tail pointers allow O(1)
B) Doubly linked list operations.
C) Circular doubly linked list
16. Traversal backward in circular doubly linked
D) Array
list:
Answer: A
A) Start at tail
Explanation: Single pointer per node uses least
B) Start at head
memory.
C) Start at middle
12. Complex linked list variation to implement: D) None
A) Singly linked list Answer: A
B) Doubly circular linked list Explanation: Tail → previous pointers allow
C) Circular singly linked list backward traversal.
D) None
17. Circular property helps in:
Answer: B
A) Continuous iteration
Explanation: Must maintain two pointers +
B) Memory reduction
circularity → complex.
C) Direct indexing
13. Backward traversal in singly linked list: D) Sorting
A) Possible directly Answer: A
B) Not possible without extra memory Explanation: Circular lists loop infinitely
C) Constant time without NULL termination.
D) None
18. Deletion of arbitrary node easier in:
Answer: B
A) Singly linked list
B) Doubly linked list Answer: B
C) Array Explanation: Head → next pointer moves
D) Stack forward.
Answer: B
3. Backward traversal starts at:
Explanation: Previous pointer allows O(1)
A) Head
deletion after traversal.
B) Tail
19. Which variation is chosen based on traversal C) Any node
and memory requirements? D) NULL
A) Singly linked list Answer: B
B) Doubly linked list Explanation: Tail → previous pointer moves
C) Circular linked list backward.
D) All of the above
4. Insertion at beginning:
Answer: D
A) Update new node’s next to head, head
Explanation: Each has trade-offs; selection
previous to new node, head = new node
depends on application.
B) Only head update
20. Tail pointer in circular singly linked list: C) Only tail update
A) Helps efficient insertion at end D) None
B) Used for deletion at head Answer: A
C) Both A and B Explanation: Both next and previous pointers
D) None are updated.
Answer: C
5. Insertion at end:
Explanation: Tail allows O(1) insertion at end
A) Update new node previous = tail, tail next =
and easy access to head.
new node, tail = new node
B) Update head only
C) Update next only
Topic 3: Operations on Doubly Linked Lists
D) None
1. Node structure in doubly linked list includes: Answer: A
A) Data only Explanation: Tail and previous pointers
B) Data + next pointer adjusted.
C) Data + next + previous pointer
6. Deletion of head node:
D) None
A) Head = head → next, new head previous =
Answer: C
NULL
Explanation: Two pointers enable bidirectional
B) Tail deleted
traversal.
C) Traverse list
2. Forward traversal starts at: D) None
A) Tail Answer: A
B) Head Explanation: Maintains forward link
C) Middle consistency.
D) NULL
7. Deletion of tail node: Explanation: Extra previous pointer increases
A) Tail = tail → previous, tail next = NULL memory.
B) Head deleted
12. Efficient insertion/deletion anywhere:
C) Allocate memory
A) Only doubly linked list
D) None
B) Singly linked list
Answer: A
C) Array
Explanation: Previous node becomes new tail;
D) Stack
next pointer set to NULL.
Answer: A
8. Insertion/deletion at beginning or end time Explanation: Both pointers allow O(1)
complexity: insert/delete after traversal.
A) O(1)
13. Insertion after given node requires:
B) O(n)
A) Adjust new node’s next/previous and
C) O(log n)
neighbors’ pointers
D) O(n²)
B) Update head only
Answer: A
C) Tail only
Explanation: Direct pointer updates → constant
D) None
time.
Answer: A
9. Searching for a node by value: Explanation: Both forward and backward links
A) O(n) must be correct.
B) O(1)
14. Deletion of a node:
C) O(log n)
A) Update previous node next, next node
D) O(n²)
previous, free target
Answer: A
B) Update head only
Explanation: Sequential traversal needed.
C) Tail only
10. Backward traversal possible due to: D) None
A) Previous pointer Answer: A
B) Next pointer Explanation: Proper pointer updates maintain
C) Both list structure.
D) None
15. Traversal of empty list:
Answer: A
A) Nothing happens
Explanation: Previous pointer enables reverse
B) Error occurs
movement.
C) Delete head
11. Memory per node: D) Delete tail
A) Higher than singly linked list Answer: A
B) Less than singly linked list Explanation: Head = NULL → traversal ends
C) Same immediately.
D) Variable
16. Backward traversal in circular doubly linked
Answer: A
list:
A) Start at tail Explanation: Memory and complexity trade off
B) Start at head for flexibility.
C) Start at middle
D) None
Answer: A
Explanation: Tail → previous pointers enable
backward traversal.
11. Circular queue condition for full queue: 16. Which queue allows both FIFO and priority-
A) rear == size – 1 based behavior?
B) front == rear A) Circular queue
B) Simple queue
C) Priority queue
D) Deque
Answer: C
Explanation: Priority determines service order.
13. Complete binary tree means: 18. Maximum nodes in binary tree of height h:
A) All levels completely filled A) 2^h
B) All levels filled except last, filled left to right B) 2^h − 1
C) Only leaf nodes exist C) h^2
D) Tree with two children per node D) h − 1
Answer: B Answer: B
Explanation: Last level may be incomplete but Explanation: Formula for binary tree nodes.
left-aligned.
19. Which tree is used for expression evaluation?
14. Full binary tree is a tree where: A) Heap
A) Each node has two children B) Binary tree
B) Each node has either 0 or 2 children C) B-tree
C) Tree is complete D) AVL tree
D) Tree is balanced Answer: B
Answer: B Explanation: Expression tree is a binary tree.
Explanation: Nodes have either two or no
20. Tree edges are:
children.
A) Cyclic
15. Balanced tree helps in: B) Directed
A) Faster searching C) Acyclic
B) Reduced height D) Weighted
C) Efficient operations Answer: C
D) All of the above Explanation: Trees do not contain cycles.
Answer: D
Explanation: Balanced trees optimize
performance. Topic 2: Tree Traversal (Preorder, Inorder, Postorder,
Level-order)
16. Which is NOT a tree application?
A) Expression evaluation 1. Tree traversal means:
B) File system A) Inserting nodes
C) Sorting B) Deleting nodes
C) Visiting each node once Answer: B
D) Sorting nodes Explanation: Queue processes nodes level by
Answer: C level.
Explanation: Traversal visits all nodes
7. Preorder traversal is useful for:
systematically.
A) Copying tree
2. Preorder traversal order: B) Deleting tree
A) Left, Root, Right C) Expression evaluation
B) Root, Left, Right D) Sorting
C) Left, Right, Root Answer: A
D) Root, Right, Left Explanation: Preorder copies root first.
Answer: B
8. Postorder traversal is useful for:
Explanation: Root is visited first.
A) Searching
3. Inorder traversal order: B) Copying
A) Root, Left, Right C) Deleting tree
B) Left, Right, Root D) Sorting
C) Left, Root, Right Answer: C
D) Right, Root, Left Explanation: Children deleted before parent.
Answer: C
9. Recursive traversal uses:
Explanation: Root visited between children.
A) Heap
4. Postorder traversal order: B) Queue
A) Root, Left, Right C) Stack
B) Left, Root, Right D) Graph
C) Left, Right, Root Answer: C
D) Right, Left, Root Explanation: Function call stack manages
Answer: C recursion.
Explanation: Root visited last.
10. Traversal time complexity:
5. Which traversal gives sorted order in BST? A) O(1)
A) Preorder B) O(log n)
B) Inorder C) O(n)
C) Postorder D) O(n²)
D) Level-order Answer: C
Answer: B Explanation: Every node is visited once.
Explanation: Inorder traversal of BST is sorted.
11. Traversal space complexity (recursive):
6. Level-order traversal uses: A) O(1)
A) Stack B) O(log n)
B) Queue C) O(n)
C) Recursion D) O(n²)
D) Array only Answer: B
Explanation: Stack space depends on tree 17. Traversal without recursion uses:
height. A) Queue only
B) Stack
12. Which traversal is non-recursive by nature?
C) Heap
A) Inorder
D) Tree
B) Preorder
Answer: B
C) Postorder
Explanation: Stack simulates recursion.
D) Level-order
Answer: D 18. Preorder traversal of single-node tree gives:
Explanation: Level-order uses queue. A) Empty
B) Root
13. Inorder traversal of binary tree is:
C) Error
A) Always sorted
D) NULL
B) Sorted only for BST
Answer: B
C) Never sorted
D) Random 19. Traversal is essential for:
Answer: B A) Accessing elements
Explanation: Sorting property applies only to B) Searching
BST. C) Processing nodes
D) All of the above
14. Which traversal visits root last?
Answer: D
A) Preorder
B) Inorder 20. Level-order traversal visits nodes:
C) Postorder A) Depth-wise
D) Level-order B) Height-wise
Answer: C C) Level-wise
D) Randomly
15. Which traversal visits root first?
Answer: C
A) Inorder
B) Postorder
C) Preorder
Topic 3: Binary Search Tree (BST) – Insertion,
D) Level-order
Searching, Deletion
Answer: C
1. Binary Search Tree property:
16. Which traversal is best for evaluating
A) Left < Root < Right
expression tree?
B) Left > Root > Right
A) Preorder
C) Root < Left < Right
B) Inorder
D) Random
C) Postorder
Answer: A
D) Level-order
Explanation: BST maintains ordering property.
Answer: C
Explanation: Postorder evaluates operands 2. Searching in BST depends on:
before operator. A) Level-order
B) Key comparison B) Replace node with child
C) Stack C) Replace with root
D) Queue D) Not possible
Answer: B Answer: B
3. Time complexity of searching in balanced BST: 9. Deletion of node with two children requires:
A) O(1) A) Leaf removal
B) O(log n) B) Inorder successor or predecessor
C) O(n) C) Level-order replacement
D) O(n²) D) Stack
Answer: B Answer: B
4. Which rotation is used when insertion occurs 9. AVL deletion is more complex because:
in left subtree of left child? A) Node replacement
A) RR B) Multiple rebalancing required
B) RL C) Search time
C) LL D) Memory issues
D) LR Answer: B
Answer: C Explanation: Deletion may cause multiple
Explanation: Left-Left case needs single right imbalances.
rotation.
10. AVL tree guarantees:
5. Which rotation fixes Right-Right imbalance? A) Minimum height
A) Left rotation B) Fast searching
B) Right rotation C) Balanced structure
C) Double rotation D) All of the above
D) No rotation Answer: D
Answer: A
11. Worst-case height of AVL tree is:
Explanation: RR case is corrected by left
A) n
rotation.
B) log n
6. LR rotation consists of: C) n log n
A) Left then right rotation D) √n
B) Right then left rotation Answer: B
C) Two left rotations
12. AVL tree was invented by:
D) Two right rotations
A) Knuth
Answer: A
B) Adelson-Velsky and Landis
Explanation: LR = left rotation on child, right
C) Huffman
rotation on node.
D) Dijkstra
7. RL rotation consists of: Answer: B
A) Right then left rotation
13. AVL tree is preferred over BST when:
B) Left then right rotation
A) Data is static
C) Two right rotations
B) Frequent searching required
D) Two left rotations
C) Memory is limited
Answer: A
Explanation: RL is opposite of LR.
D) No deletion 20. AVL tree improves:
Answer: B A) Worst-case search time
B) Memory usage
14. Which traversal gives sorted order in AVL tree?
C) Traversal time
A) Preorder
D) Input size
B) Inorder
Answer: A
C) Postorder
D) Level order
Answer: B
Topic 2: Heap Tree – Types and Operations
15. AVL tree maintains balance using:
1. Heap is a:
A) Heap property
A) Linear structure
B) Rotations
B) Complete binary tree
C) Rehashing
C) BST
D) Sorting
D) Graph
Answer: B
Answer: B
16. Maximum imbalance allowed in AVL tree: Explanation: Heap must be complete.
A) 2
2. Heap property ensures:
B) 1
A) Sorted order
C) 0
B) Parent-child priority
D) Unlimited
C) Balanced tree
Answer: B
D) BST property
17. Rotation changes: Answer: B
A) Tree height
3. Types of heap:
B) Node relationships
A) Binary and AVL
C) Balance factor
B) Min heap and Max heap
D) All of the above
C) BST and Heap
Answer: D
D) Graph and Tree
18. AVL tree is a type of: Answer: B
A) Graph
4. In a max heap:
B) Heap
A) Parent ≤ children
C) BST
B) Parent ≥ children
D) Trie
C) Left < right
Answer: C
D) Random
19. Insertion in AVL tree always starts like: Answer: B
A) Heap insertion
5. In a min heap:
B) BST insertion
A) Parent ≤ children
C) Random insertion
B) Parent ≥ children
D) Queue insertion
C) Root is maximum
Answer: B
D) Sorted 12. Heap sort time complexity:
Answer: A A) O(n)
B) O(n log n)
6. Root of max heap contains:
C) O(log n)
A) Minimum value
D) O(n²)
B) Median
Answer: B
C) Maximum value
D) Random value 13. Heap is best suited for:
Answer: C A) Searching
B) Sorting
7. Heap insertion time complexity:
C) Priority handling
A) O(1)
D) Traversing
B) O(log n)
Answer: C
C) O(n)
D) O(n²) 14. Priority queue is implemented using:
Answer: B A) Stack
B) Queue
8. Heap deletion usually removes:
C) Heap
A) Any node
D) Array
B) Leaf
Answer: C
C) Root
D) Middle node 15. Heap does NOT support:
Answer: C A) Efficient max/min access
B) Efficient insertion
9. Heap deletion time complexity:
C) Efficient search
A) O(1)
D) Efficient deletion
B) O(n)
Answer: C
C) O(log n)
D) O(n log n) 16. Last level of heap is filled:
Answer: C A) Right to left
B) Left to right
10. Heap is commonly implemented using:
C) Randomly
A) Linked list
D) Completely
B) Array
Answer: B
C) Stack
D) Queue 17. Heapify operation time complexity:
Answer: B A) O(1)
B) O(log n)
11. Heap sort uses:
C) O(n)
A) BST
D) O(n log n)
B) Min heap
Answer: B
C) Max heap
D) AVL tree 18. Which traversal gives sorted heap?
Answer: C A) Inorder
B) Preorder 4. Characters with higher frequency get:
C) Postorder A) Longer codes
D) None B) No codes
Answer: D C) Shorter codes
D) Same codes
19. Heap property is maintained using:
Answer: C
A) Rotations
B) Heapify 5. Huffman algorithm is:
C) Traversal A) Greedy
D) Sorting B) Divide and conquer
Answer: B C) Dynamic programming
D) Backtracking
20. Complete binary tree property is required for:
Answer: A
A) AVL
B) Heap 6. Huffman tree is a:
C) BST A) BST
D) Huffman B) Binary tree
Answer: B C) AVL tree
D) Heap
Answer: B
Topic 3: Huffman Tree – Construction and Applications
7. Huffman coding ensures:
1. Huffman tree is used for: A) Minimum redundancy
A) Searching B) Maximum redundancy
B) Sorting C) Fixed codes
C) Data compression D) Sorted output
D) Scheduling Answer: A
Answer: C
8. Internal nodes of Huffman tree store:
2. Huffman coding is: A) Characters
A) Fixed-length coding B) Frequencies
B) Variable-length coding C) Operators
C) Binary search D) Data only
D) Encryption Answer: B
Answer: B
9. Leaf nodes of Huffman tree store:
3. Huffman tree is based on: A) Frequencies
A) Frequency of characters B) Operators
B) ASCII values C) Characters
C) Alphabetical order D) Indices
D) Length of string Answer: C
Answer: A
10. Huffman tree construction uses:
A) Stack
B) Queue D) Numeric
C) Priority queue Answer: A
D) Array
17. Time complexity of Huffman construction:
Answer: C
A) O(n)
11. Huffman tree is optimal because: B) O(n log n)
A) Balanced C) O(log n)
B) Uses greedy choice D) O(n²)
C) Produces shortest average code length Answer: B
D) Sorted
18. Huffman tree improves:
Answer: C
A) Storage efficiency
12. Left edge is usually labeled as: B) Transmission speed
A) 1 C) Compression ratio
B) 0 D) All of the above
C) −1 Answer: D
D) 2
19. Huffman coding works best when:
Answer: B
A) Equal frequency
13. Right edge is usually labeled as: B) Variable frequency
A) 0 C) Small data
B) 1 D) Numeric data
C) −1 Answer: B
D) 2
20. Huffman tree is NOT used for:
Answer: B
A) Data compression
14. Huffman coding is used in: B) File encoding
A) JPEG C) Searching
B) MP3 D) Multimedia compression
C) ZIP Answer: C
D) All of the above
Answer: D
11. Which data structure is fastest for exact 17. Hash function output range is:
search? A) 0 to n−1
A) Array B) −∞ to +∞
B) BST C) 1 to n
C) Hash table D) Random
D) Linked list Answer: A
Answer: C
18. Example of hash function:
12. Hash table size should be: A) h(k) = k % m
A) Even B) k²
B) Prime number C) log k
C) Power of 2 D) k + 1
D) Random Answer: A
Answer: B
19. Hashing is mostly used in:
Explanation: Prime size reduces collisions.
A) Databases
13. Load factor (α) is defined as: B) Compilers
A) Table size / number of keys C) Symbol tables
B) Number of keys / table size
D) All of the above C) Trees
Answer: D D) Stacks
Answer: B
20. Which operation is fastest in hashing?
A) Traversal 6. In chaining, each table index stores:
B) Sorting A) Single value
C) Searching B) Stack
D) Merging C) Linked list
Answer: C D) Queue
Answer: C
9. Which sorting algorithm is stable? 15. Which sorting does not require extra space?
A) Selection sort A) Merge sort
B) Insertion sort B) Counting sort
C) Heap sort C) In-place sort
D) Quick sort D) External sort
Answer: B Answer: C
11. Sorting complexity is measured in terms of: 17. Sorting algorithms are evaluated by:
A) Memory only A) Stability
B) Time only B) Complexity
C) Time and space C) Space usage
D) CPU speed D) All of the above
Answer: C Answer: D
12. Best-case time complexity of many simple 18. Which order is commonly used?
sorts is: A) Random
A) O(n²) B) Ascending
B) O(n) C) Descending
D) Both B and C C) O(n²)
Answer: D D) O(log n)
Answer: C
19. Sorting reduces:
A) Storage 5. Insertion sort is suitable for:
B) Searching time A) Large datasets
C) Data size B) Small datasets
D) Memory C) External sorting
Answer: B D) Disk-based sorting
Answer: B
20. Main goal of sorting is:
A) Data compression 6. Insertion sort is:
B) Data arrangement A) Unstable
C) Faster access B) Stable
D) Both B and C C) Recursive
Answer: D D) External
Answer: B
3. Radix sort processes digits from: 9. Radix sort uses extra space for:
A) MSB to LSB only A) Recursion
B) LSB to MSB only B) Buckets
C) Either direction C) Hashing
D) Random order D) Trees
Answer: C Answer: B
4. Radix sort commonly uses: 10. Space complexity of radix sort is:
A) Binary search A) O(1)
B) Counting sort B) O(n)
C) Merge sort C) O(log n)
D) Heap sort D) O(n²)
Answer: B Answer: B
11. Radix sort is commonly used in: 17. Radix sort uses which data structure?
A) Database indexing A) Stack
B) String sorting B) Queue
C) Digital systems C) Buckets/arrays
D) All of the above D) Tree
Answer: D Answer: C
12. Radix sort requires keys to be: 18. Major disadvantage of radix sort:
A) Comparable A) High time complexity
B) Numeric or character-based B) Extra memory usage
C) Random C) Unstable
D) Floating-point D) Hard to implement
Answer: B Answer: B
13. Which sorting is faster for large integers? 19. Radix sort avoids comparisons by:
A) Bubble sort A) Using hash functions
B) Selection sort B) Digit-by-digit grouping
C) Radix sort C) Binary search
D) Insertion sort D) Recursion
Answer: C Answer: B
14. Radix sort processes which digit first in LSD 20. Radix sort is preferred when:
method? A) Data size is small
A) Most significant digit B) Keys have limited digits
B) Least significant digit C) Data is nearly sorted
C) Middle digit D) Memory is limited
D) Random digit Answer: B
Answer: B