0% found this document useful (0 votes)
2 views103 pages

Data Structure and Algorithm

The document contains multiple-choice questions (MCQs) focused on Data Structures and Algorithms, covering topics such as Procedural Programming (PF), Object-Oriented Programming (OOP), primitive data types, user-defined data types, and project management concepts like motivation, scope, aim, and objectives. Each question is accompanied by answers and explanations to clarify the concepts. This resource is designed for students in their 3rd semester to test their understanding of these programming fundamentals.

Uploaded by

ua1768437
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views103 pages

Data Structure and Algorithm

The document contains multiple-choice questions (MCQs) focused on Data Structures and Algorithms, covering topics such as Procedural Programming (PF), Object-Oriented Programming (OOP), primitive data types, user-defined data types, and project management concepts like motivation, scope, aim, and objectives. Each question is accompanied by answers and explanations to clarify the concepts. This resource is designed for students in their 3rd semester to test their understanding of these programming fundamentals.

Uploaded by

ua1768437
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Data Structure & Algorithms

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.

1. Which of the following is a characteristic of 5. Procedural programming is also known as:


Procedural Programming? A) Structured programming
A) Inheritance B) Modular programming
B) Encapsulation C) Functional programming
C) Modular functions and procedures D) Event-driven programming
D) Polymorphism Answer: A
Answer: C Explanation: Procedural programming is
Explanation: Procedural programming focuses structured and focuses on procedures and
on sequences of instructions and modular sequences of instructions.
functions, not OOP features like inheritance or
6. Which OOP concept allows an object to take
polymorphism.
multiple forms?
2. Which of the following is NOT an object- A) Inheritance
oriented programming concept? B) Polymorphism
A) Abstraction C) Abstraction
B) Encapsulation D) Encapsulation
C) Functions Answer: B
D) Polymorphism Explanation: Polymorphism allows methods to
Answer: C behave differently based on the object calling
Explanation: Functions exist in both procedural them.
and OOP, but as a concept, they are not
7. What is the main difference between PF and
exclusive to OOP.
OOP?
3. In OOP, a class is: A) PF uses objects, OOP uses functions
A) A function B) PF is structured, OOP is object-based
B) A blueprint for creating objects C) PF is slower than OOP
C) A variable D) OOP does not use memory
D) A memory location Answer: B
Answer: B Explanation: PF focuses on procedures and
Explanation: A class defines attributes and sequences; OOP is based on objects and their
methods that its objects will have. interactions.

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.

17. Why are primitive data types important?


Topic 3: Motivation, Scope, Aim, Objectives
A) They are easy to use and form the
foundation of all programming 1. What is the main purpose of defining the
B) They are slow “aim” of a program or project?
C) They cannot be stored in memory A) To decide the programming language
D) They are not supported by modern B) To define the overall goal or purpose
languages C) To create variables
Answer: A D) To debug the code
Answer: B Explanation: Motivation clarifies why the
Explanation: The aim states the overall goal the project is being undertaken and what problem
program or project intends to achieve. it addresses.

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.

3. Motivation in programming primarily refers to: 7. A well-defined scope helps in:


A) The reason behind developing a solution A) Reducing project complexity and avoiding
B) The syntax of the language unnecessary work
C) The hardware required B) Increasing code execution speed
D) The debugging process C) Avoiding programming errors
Answer: A D) Choosing variables
Explanation: Motivation explains why the Answer: A
program or system is needed or what problem Explanation: Scope clarifies project boundaries,
it solves. helping avoid unnecessary features or
complexity.
4. Which of the following statements correctly
describes objectives? 8. Which of the following is an example of a
A) Broad goals of a project project aim?
B) Specific measurable outcomes to achieve the A) Implement a login system for a website
aim B) Declare an integer variable
C) Programming syntax C) Use a for loop
D) User interface design D) Print “Hello World”
Answer: B Answer: A
Explanation: Objectives are specific steps or Explanation: The aim describes the overall goal,
measurable outcomes to fulfill the aim. like creating a login system.

5. Why is it important to define the motivation 9. Objectives should be:


before starting a project? A) Vague
A) To select the programming language B) Measurable and achievable
B) To clarify the problem being solved C) Optional
C) To write faster code D) Only broad statements
D) To avoid loops and conditions Answer: B
Answer: B Explanation: Objectives must be specific,
measurable, and achievable to track project 14. Which of the following is an example of an
progress. objective?
A) Develop a login page with username and
10. Motivation can be described as:
password validation
A) The “why” behind a project
B) Learn programming
B) The coding standard
C) Choose a language
C) The programming language choice
D) Install a compiler
D) The compiler used
Answer: A
Answer: A
Explanation: Objectives are specific, actionable
Explanation: Motivation answers why the
steps that achieve the aim.
project is needed or what problem it solves.
15. If a project aim is “Create an online store,” a
11. The aim of a program is:
related objective could be:
A) A detailed step-by-step procedure
A) Implement product catalog, shopping cart,
B) A general statement of the project’s purpose
and payment system
C) The programming language used
B) Write C++ code
D) The compiler choice
C) Understand loops
Answer: B
D) Use a compiler
Explanation: The aim provides a high-level view
Answer: A
of what the project intends to achieve.
Explanation: Objectives break the aim into
12. Scope helps in defining: specific, achievable parts.
A) What features the system will include and
16. Which of the following best describes
exclude
“limitations” in a project scope?
B) How the system will compile
A) Features not included in the project
C) Syntax rules
B) Syntax rules
D) Programming style
C) Execution speed
Answer: A
D) Data types used
Explanation: Scope outlines the boundaries,
Answer: A
limitations, and deliverables of a project.
Explanation: Limitations define what the
13. Why is motivation important for students project will NOT do, helping to manage
learning programming? expectations.
A) It reduces syntax errors
17. A clearly defined aim helps in:
B) It helps them understand the purpose and
A) Directing all efforts toward a common goal
relevance of what they are learning
B) Avoiding loops
C) It increases CPU speed
C) Faster compilation
D) It chooses data types automatically
D) Choosing data types
Answer: B
Answer: A
Explanation: Motivation clarifies why learning
Explanation: The aim focuses the project team
certain concepts or developing programs is
on a common purpose.
useful.
18. Motivation, aim, scope, and objectives are Answer: A
part of: Explanation: Linear data structures organize
A) Project planning data sequentially, such as arrays, lists, and
B) Writing loops queues.
C) Syntax checking
2. Which data structure is used to implement
D) Compiler optimization
recursion?
Answer: A
A) Stack
Explanation: These components form the
B) Queue
foundation for planning and managing a project
C) Linked List
effectively.
D) Graph
19. Which of the following is NOT true about Answer: A
objectives? Explanation: Stack follows LIFO (Last In First
A) They are specific Out) order, which is used to handle recursive
B) They are measurable function calls.
C) They are broad statements
3. Which of the following is a non-linear data
D) They help achieve the aim
structure?
Answer: C
A) Array
Explanation: Objectives are specific and
B) Linked List
measurable; broad statements describe the
C) Tree
aim.
D) Queue
20. Which of the following sequences is correct for Answer: C
project planning? Explanation: Non-linear structures like trees
A) Scope → Aim → Motivation → Objectives and graphs do not store data sequentially.
B) Motivation → Aim → Objectives → Scope
4. What is the time complexity of searching an
C) Aim → Motivation → Scope → Objectives
element in an unsorted array?
D) Motivation → Objectives → Aim → Scope
A) O(1)
Answer: B
B) O(n)
Explanation: First understand the motivation
C) O(log n)
(why), then define the aim (what), then set
D) O(n²)
objectives (how), and finally define the scope
Answer: B
(boundaries).
Explanation: In an unsorted array, you may
Topic 4: Different Data Structures Overview and Their have to check every element, giving O(n)
Applications complexity.

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.

17. Which data structure is commonly used in


operating system process scheduling?
A) Stack
B) Queue
D) Its space usage
Answer: B
Explanation: An algorithm is correct if it
produces the expected result for all valid inputs.

4. Which of the following is an example of an


algorithm?
A) A C++ program
B) Steps to calculate factorial
C) Variable declaration
D) Printing text
Answer: B
Week 2: Algorithms Analysis. Explanation: Steps to solve a problem, like
calculating factorial, define an algorithm.

5. Algorithms can be represented in which of the


Topic 1: Introduction to Algorithms following ways?
1. What is an algorithm? A) Flowcharts
A) A programming language B) Pseudocode
B) A step-by-step procedure to solve a problem C) Natural language
C) A data structure D) All of the above
D) A type of compiler Answer: D
Answer: B Explanation: Algorithms can be described in
Explanation: An algorithm is a finite sequence multiple ways, including flowcharts,
of well-defined instructions to solve a specific pseudocode, or plain language.
problem. 6. Which of these is a simple sorting algorithm?
2. Which of the following is NOT a characteristic A) Bubble sort
of an algorithm? B) Quick sort
A) Finiteness C) Merge sort
B) Definiteness D) Hashing
C) Ambiguity Answer: A
D) Input and Output Explanation: Bubble sort repeatedly compares
Answer: C and swaps adjacent elements, making it a
Explanation: Algorithms must be unambiguous; simple sorting algorithm.
each step should be clear and precise. 7. An algorithm should always terminate after a
3. The “correctness” of an algorithm refers to: finite number of steps. This property is called:
A) Whether it compiles A) Correctness
B) Whether it produces the intended output for B) Termination
all inputs C) Finiteness
C) Its programming language D) Efficiency
Answer: C
Explanation: Finiteness ensures that the Answer: D
algorithm completes after a finite number of Explanation: Well-designed algorithms are
steps. reusable, clear, and efficient.

8. Which of the following is NOT a type of 12. A greedy algorithm:


algorithm? A) Makes the globally optimal choice at each
A) Brute-force algorithm step
B) Divide and conquer algorithm B) Always uses recursion
C) Recursive algorithm C) Never produces optimal results
D) Compiler algorithm D) Uses stacks
Answer: D Answer: A
Explanation: Brute-force, divide-and-conquer, Explanation: Greedy algorithms make the best
and recursive are algorithm types; compiler is choice locally, hoping to find the global
software. optimum.

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. Which of the following is logarithmic time


Topic 3: Time/Space Complexity
complexity?
1. What is time complexity? A) O(n)
A) Amount of memory used by an algorithm B) O(log n)
B) Number of operations executed as a function C) O(n²)
of input size D) O(1)
C) CPU speed Answer: B
D) Input size Explanation: Logarithmic time occurs in divide-
Answer: B and-conquer algorithms like binary search.
Explanation: Time complexity measures how
6. Which time complexity is considered most
the number of operations grows as input size
efficient for large input sizes?
increases.
A) O(n²)
2. What is space complexity? B) O(n log n)
A) Time taken by the program C) O(n³)
B) Amount of memory an algorithm uses D) O(2^n)
C) Number of CPU cycles Answer: B
Explanation: O(n log n) grows slower than 11. Binary search has which time complexity in
quadratic or exponential complexities for large worst case?
inputs. A) O(n)
B) O(log n)
7. Space complexity includes:
C) O(n²)
A) Memory for input data
D) O(1)
B) Memory for auxiliary variables
Answer: B
C) Memory for recursion stack
Explanation: Binary search divides the input in
D) All of the above
half each step → logarithmic time.
Answer: D
Explanation: Space complexity accounts for all 12. Which of the following is an example of
memory used during execution. exponential time complexity?
A) O(n log n)
8. Recursive algorithms generally require more
B) O(2^n)
space due to:
C) O(n²)
A) Compiler overhead
D) O(n)
B) Function call stack
Answer: B
C) Loop counters
Explanation: Exponential algorithms double in
D) None of the above
execution time with each additional input
Answer: B
element.
Explanation: Each recursive call is stored in the
stack until execution completes. 13. Space complexity of iterative factorial
algorithm is:
9. Which of the following sorting algorithms has
A) O(n)
O(n²) worst-case time complexity?
B) O(log n)
A) Merge sort
C) O(1)
B) Quick sort
D) O(n²)
C) Bubble sort
Answer: C
D) Heap sort
Explanation: Iterative factorial uses a fixed
Answer: C
number of variables, independent of input size.
Explanation: Bubble sort uses nested loops,
resulting in quadratic time complexity. 14. Time complexity of linear search is:
A) O(log n)
10. Merge sort has which space complexity?
B) O(1)
A) O(1)
C) O(n)
B) O(log n)
D) O(n²)
C) O(n)
Answer: C
D) O(n²)
Explanation: Linear search checks each
Answer: C
element, giving O(n) complexity.
Explanation: Merge sort requires additional
arrays to store subarrays, leading to O(n) space. 15. Which of the following reduces space
complexity in algorithms?
A) Using recursion
B) Using in-place algorithms Answer: A
C) Creating additional arrays Explanation: Inserting at the head of a linked
D) Increasing input size list is constant time, independent of list size.
Answer: B
20. Which of the following is true about
Explanation: In-place algorithms reuse existing
complexity analysis?
memory instead of allocating extra space.
A) It predicts program execution time and
16. Which notation is used to describe worst-case memory usage
time complexity? B) It depends only on compiler efficiency
A) Big O C) It can only be done after running the
B) Big Ω program
C) Big Θ D) It ignores input size
D) Small o Answer: A
Answer: A Explanation: Complexity analysis predicts
Explanation: Big O notation expresses an upper performance based on algorithm design and
bound, usually representing worst-case input size, independent of implementation.
performance.

17. Which notation represents best-case


Topic 4: Order of Growth
complexity?
A) Big O 1. What does “order of growth” refer to in
B) Big Ω algorithms?
C) Big Θ A) Rate at which execution time increases with
D) Small o input size
Answer: B B) Memory usage only
Explanation: Big Omega (Ω) describes the lower C) Programming language speed
bound, often representing best-case time. D) Input format
Answer: A
18. In-place algorithms require:
Explanation: Order of growth measures how an
A) Extra memory proportional to input size
algorithm’s running time or operations scale as
B) Minimal extra memory
input size increases.
C) Exponential memory
D) Infinite memory 2. Which of the following is a linear order of
Answer: B growth?
Explanation: In-place algorithms perform A) O(n²)
operations using minimal additional memory. B) O(n log n)
C) O(n)
19. Time complexity of inserting an element at the
D) O(log n)
beginning of a linked list is:
Answer: C
A) O(1)
Explanation: Linear growth means time
B) O(n)
increases proportionally with input size.
C) O(log n)
D) O(n²)
3. O(n²) indicates: B) Input size
A) Constant growth C) Compiler used
B) Quadratic growth D) Variable names
C) Linear growth Answer: B
D) Logarithmic growth Explanation: Growth rate is a function of input
Answer: B size, independent of implementation details.
Explanation: O(n²) indicates the number of
8. If an algorithm has O(2^n) growth, it is:
operations grows with the square of the input
A) Constant time
size.
B) Exponential
4. Which order of growth is slower for large C) Linear
inputs? D) Logarithmic
A) O(n log n) Answer: B
B) O(n²) Explanation: Exponential growth doubles for
C) O(n) each input increment, becoming very slow.
D) O(log n)
9. Which of the following is true about
Answer: B
polynomial time algorithms?
Explanation: Quadratic growth becomes much
A) O(n^k) for some constant k
slower than linear or logarithmic as input size
B) Exponential
increases.
C) Constant
5. Which of the following algorithms has O(n log D) Logarithmic
n) growth? Answer: A
A) Merge Sort Explanation: Polynomial-time algorithms grow
B) Bubble Sort as a fixed power of input size.
C) Linear Search
10. Which algorithm would become impractical for
D) Constant-time Access
n > 1000?
Answer: A
A) O(n)
Explanation: Merge Sort uses divide-and-
B) O(n²)
conquer → O(n log n) time complexity.
C) O(log n)
6. Which of the following is fastest for very large D) O(1)
inputs? Answer: B
A) O(n²) Explanation: Quadratic growth becomes too
B) O(n log n) slow for large n.
C) O(n)
11. Which of the following is an example of
D) O(log n)
sublinear growth?
Answer: D
A) O(n²)
Explanation: Logarithmic growth increases very
B) O(log n)
slowly with input size.
C) O(n)
7. The order of growth depends on: D) O(n log n)
A) Programming language Answer: B
Explanation: Sublinear growth increases slower A) Operations increase linearly
than input size; e.g., logarithmic time. B) Operations double with every input
increment
12. If two algorithms have O(n) and O(n²) growth,
C) They use recursion
which one is faster for large n?
D) They use loops
A) O(n)
Answer: B
B) O(n²)
Explanation: Exponential growth causes
C) Both equal
runtime to explode as input increases.
D) Depends on language
Answer: A 17. Which order of growth is more scalable?
Explanation: Linear growth is faster than A) O(n²)
quadratic for large inputs. B) O(n log n)
C) O(n³)
13. Order of growth does NOT consider:
D) O(2^n)
A) Input size
Answer: B
B) Constant factors
Explanation: O(n log n) scales better for larger
C) How steps increase
inputs than quadratic or exponential.
D) Algorithm efficiency
Answer: B 18. Linearithmic growth refers to:
Explanation: Big-O ignores constants and A) O(n²)
lower-order terms, focusing on dominant B) O(n log n)
behavior. C) O(log n)
D) O(1)
14. O(n log n) is better than O(n²) because:
Answer: B
A) Execution grows slower with input
Explanation: Linearithmic time combines linear
B) Memory usage is constant
and logarithmic growth.
C) It always uses recursion
D) None of the above 19. Which of the following statements is correct?
Answer: A A) O(n) < O(n log n) < O(n²) < O(2^n) for large n
Explanation: O(n log n) grows slower than O(n²) B) O(n²) < O(n log n) < O(n) < O(1)
for large input sizes. C) O(2^n) < O(n²) < O(n log n) < O(n)
D) O(n log n) = O(n²)
15. Which of these is fastest for n = 1,000,000?
Answer: A
A) O(n²)
Explanation: This shows the typical growth
B) O(n log n)
hierarchy for large inputs.
C) O(n)
D) O(1) 20. Order of growth analysis focuses on:
Answer: D A) Exact execution time in seconds
Explanation: Constant time is independent of B) How algorithm runtime scales with input size
input size → fastest possible growth. C) Memory usage only
D) Compiler type
16. Exponential algorithms become inefficient
Answer: B
because:
Explanation: It abstracts away constants and Explanation: DP stores results of overlapping
focuses on how performance grows with input. subproblems to avoid recomputation.

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.

17. Bubble sort best-case complexity:


A) O(n²) Topic 1: Introduction to Array Data Structure (Syntax,
B) Ω(n) Applications, Operations)
C) Θ(n²)
1. What is an array?
D) O(log n)
A) A collection of variables of different types
Answer: B
B) A collection of elements of the same data
Explanation: If the array is already sorted, only
type stored in contiguous memory
one pass → Ω(n).
C) A dynamic data structure
18. Worst-case Big O for bubble sort: D) A compiler directive
A) O(n) Answer: B
B) O(n²) Explanation: Arrays store elements of the same
C) O(n log n) type in consecutive memory locations for easy
D) O(1) access.
Answer: B
2. Which of the following is the correct syntax for
Explanation: Nested loops cause quadratic
declaring an integer array of size 5 in C++?
growth in the worst case.
A) int arr[5];
19. Quick sort best-case complexity: B) array arr[5];
A) O(n log n) C) int arr();
B) O(n²) D) arr int[5];
C) O(n³) Answer: A
D) O(1) Explanation: Standard syntax is datatype
Answer: A array_name[size];.
Explanation: Balanced partitioning yields
3. Which of the following is an application of
logarithmic recursion depth → O(n log n).
arrays?
20. Which notation is preferred for expressing A) Storing marks of students
scalability? B) Implementing matrices
A) Big O C) Storing sequential data
D) All of the above same-type elements; sizing issues may waste
Answer: D memory.
Explanation: Arrays are used to store sequential
8. Which of the following is the correct syntax for
data, matrices, or multiple similar items.
initializing an array at declaration in C++?
4. Which operation is NOT typically performed A) int arr[3] = {1,2,3};
on arrays? B) int arr = {1,2,3};
A) Traversal C) int arr(3) = {1,2,3};
B) Insertion D) arr int[3] = {1,2,3};
C) Deletion Answer: A
D) Compilation Explanation: Curly braces are used to initialize
Answer: D array elements at the time of declaration.
Explanation: Compilation is unrelated to array
9. The operation of visiting each element in an
operations.
array is called:
5. How are elements in an array accessed? A) Searching
A) By value B) Traversal
B) By index C) Sorting
C) By pointer only D) Deletion
D) By memory address manually Answer: B
Answer: B Explanation: Traversal means accessing each
Explanation: Array elements are accessed using element to read or process it.
zero-based indices.
10. If an array has 10 elements, what is the index
6. What is the index of the first element in an of the last element?
array? A) 9
A) 0 B) 10
B) 1 C) 0
C) -1 D) 1
D) Depends on compiler Answer: A
Answer: A Explanation: Arrays are zero-indexed, so last
Explanation: Most programming languages use element index = size - 1.
0-based indexing.
11. Searching for a specific element in an array can
7. Which of the following is a disadvantage of be done using:
arrays? A) Linear search
A) Fixed size B) Binary search
B) Elements of different types cannot be stored C) Both A and B
C) Memory wastage if size is overestimated D) None
D) All of the above Answer: C
Answer: D Explanation: Linear search works on unsorted
Explanation: Arrays are static and store only arrays, binary search requires sorted arrays.
12. Insertion in an array at a specific position may Answer: D
require: Explanation: Arrays allow handling multiple
A) Shifting elements to the right values efficiently with indexing and loops.
B) Swapping elements
17. Which of the following is NOT a valid array
C) Changing datatype
operation?
D) None
A) Sorting
Answer: A
B) Traversal
Explanation: To insert, elements from the
C) Multiplication
position onward need to shift to create space.
D) Searching
13. Deletion from an array requires: Answer: C
A) Replacing with NULL Explanation: Multiplication is not a direct array
B) Shifting elements left to fill the gap operation; it applies to elements.
C) Increasing array size
18. Which data type can be used to declare an
D) Both A and C
array?
Answer: B
A) int
Explanation: To maintain order, elements are
B) float
shifted left after deletion.
C) char
14. Arrays are useful for: D) All of the above
A) Static data storage Answer: D
B) Random access Explanation: Arrays can store any
C) Performing sequential operations homogeneous data type.
D) All of the above
19. The time complexity of accessing an element
Answer: D
by index in an array is:
Explanation: Arrays allow efficient storage,
A) O(1)
indexing, and sequential operations.
B) O(n)
15. Which statement is true for arrays in C++? C) O(log n)
A) Array size can change dynamically D) O(n²)
B) Array elements are contiguous in memory Answer: A
C) Arrays can store multiple data types Explanation: Direct access by index takes
D) Arrays automatically resize constant time.
Answer: B
20. Arrays are stored in:
Explanation: Arrays occupy contiguous memory
A) Stack memory only
and are of fixed type and size.
B) Heap memory only
16. What is the advantage of arrays over C) Contiguous memory locations
individual variables? D) Random memory locations
A) Easier to store multiple values Answer: C
B) Allows iterative processing Explanation: Arrays use contiguous memory for
C) Easier memory management efficient indexing and traversal.
D) All of the above
5. Which of the following is an example of a 3D
array declaration?
Topic 2: One-Dimensional, Two-Dimensional, and
A) int arr[2][3][4];
Multi-Dimensional Arrays
B) int arr[2,3,4];
1. What is a 1D array? C) int arr (4);
A) Array of arrays D) arr int[2][3][4];
B) Linear array storing elements sequentially Answer: A
C) 3D structure Explanation: 3D arrays are declared with three
D) None sets of brackets representing dimensions.
Answer: B
6. Time complexity to access an element in a 2D
Explanation: 1D arrays store elements in a
array by index is:
single line with indices from 0 to n-1.
A) O(n²)
2. Which of the following declares a 2D array in B) O(1)
C++? C) O(n)
A) int arr[3][4]; D) O(log n)
B) int arr[3,4]; Answer: B
C) arr int[3][4]; Explanation: Index-based access is direct →
D) int arr ; constant time.
Answer: A
7. Which operation is common on all arrays?
Explanation: Two sets of square brackets define
A) Traversal
rows and columns.
B) Sorting
3. The element at 2nd row, 3rd column in arr[3] C) Searching
[4] is accessed as: D) All of the above
A) arr[1][2] Answer: D
B) arr[2][3] Explanation: Arrays support traversal,
C) arr[2,3] searching, sorting, insertion, and deletion
D) arr[3][2] operations.
Answer: A
8. Number of elements in a 2D array arr[3][5] is:
Explanation: Arrays are 0-indexed → 2nd row =
A) 3
1, 3rd column = 2.
B) 5
4. A multi-dimensional array is: C) 15
A) 1D array only D) 8
B) Array of arrays (2D, 3D, etc.) Answer: C
C) Linear linked list Explanation: Total elements = rows × columns =
D) Tree 3 × 5 = 15.
Answer: B
9. Which of the following is true for multi-
Explanation: Multi-dimensional arrays
dimensional arrays?
generalize 2D arrays to 3D, 4D, etc.
A) Memory is contiguous
B) Elements can be accessed using multiple
indices Explanation: 3D arrays represent layers, rows,
C) Can be extended to n-dimensions and columns → cube-like structure.
D) All of the above
14. Accessing the 1st element of a 3D array arr[2]
Answer: D
[3][4] is:
Explanation: Multi-dimensional arrays use
A) arr[0][0][0]
contiguous memory and multiple indices.
B) arr[1][1][1]
10. Matrix multiplication can be implemented C) arr[2][3][4]
using: D) arr[0][1][1]
A) 1D array only Answer: A
B) 2D arrays Explanation: Arrays are 0-indexed in all
C) 3D arrays dimensions.
D) None
15. Which of the following is an advantage of
Answer: B
multi-dimensional arrays?
Explanation: 2D arrays represent matrices with
A) Represent complex data like matrices and
rows and columns.
grids
11. The element arr[i][j][k] belongs to: B) Easy traversal using nested loops
A) 1D array C) Fixed memory allocation
B) 2D array D) All of the above
C) 3D array Answer: D
D) 4D array Explanation: Multi-dimensional arrays
Answer: C efficiently represent grids and complex
Explanation: Three indices indicate a 3D array. structures.

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.

18. Which data structure can simulate a 2D array?


A) 1D array with calculated index
B) Linked list
C) Stack
D) Queue
Answer: A
Explanation: 2D arrays can be stored in 1D
arrays using index = row × columns + col.

19. Which of the following represents jagged


arrays? Week 4: Linked List
A) 2D arrays with equal column size
B) 2D arrays with varying column sizes
C) 3D arrays Topic 1: Linked List – Introduction, Types, Applications
D) 1D arrays 1. What is a linked list?
Answer: B A) A collection of contiguous memory locations
Explanation: Jagged arrays are arrays of arrays B) A linear data structure where elements are
with different lengths for each row. connected via pointers
20. Multi-dimensional arrays are used in: C) A type of array
A) Image processing D) A stack implementation
B) Game development Answer: B
C) Scientific simulations Explanation: In a linked list, elements (nodes)
D) All of the above are stored non-contiguously and linked using
Answer: D pointers.
Explanation: Multi-dimensional arrays model 2. Each node in a linked list contains:
grids, matrices, and spatial data in multiple A) Data only
applications. B) Data and a pointer to the next node
C) Pointer only
D) None
Answer: B
Explanation: A node stores data and a
reference (pointer) to the next node.

3. Which of the following is NOT a type of linked


list?
A) Singly linked list
B) Doubly linked list
C) Circular linked list
D) Fixed linked list 8. Which of the following is a disadvantage of
Answer: D linked lists?
Explanation: Fixed linked list is not a standard A) Sequential access required for search
type; main types are singly, doubly, and circular B) Extra memory for pointers
linked lists. C) Random access not possible
D) All of the above
4. In a singly linked list, traversal is possible:
Answer: D
A) Forward only
Explanation: Linked lists require traversal to
B) Backward only
access elements, use extra memory for
C) Both forward and backward
pointers, and lack direct indexing.
D) Not possible
Answer: A 9. A linked list node in C++ can be defined as:
Explanation: Singly linked lists have pointers A) struct Node { int data; Node* next; };
only to the next node → forward traversal only. B) struct Node { int data; int next; };
C) struct Node { int next; };
5. Doubly linked list nodes have:
D) int node;
A) One pointer to next node
Answer: A
B) Two pointers: next and previous nodes
Explanation: Node contains data and a pointer
C) Three pointers
to the next node.
D) No pointers
Answer: B 10. Applications of linked lists include:
Explanation: Doubly linked list allows traversal A) Implementing stacks and queues
in both directions. B) Dynamic memory allocation
C) Polynomial arithmetic
6. In a circular linked list:
D) All of the above
A) Last node points to NULL
Answer: D
B) Last node points back to the first node
Explanation: Linked lists are used in stacks,
C) Nodes are stored in an array
queues, graphs, and dynamic structures.
D) None
Answer: B 11. Which linked list allows traversal from any
Explanation: Circular linked lists have the last node both forward and backward?
node pointing back to the head, forming a loop. A) Singly linked list
B) Doubly linked list
7. Which of the following is an advantage of
C) Circular singly linked list
linked lists over arrays?
D) None
A) Dynamic size
Answer: B
B) Efficient insertion/deletion
Explanation: Doubly linked lists store previous
C) No memory wastage
and next pointers.
D) All of the above
Answer: D 12. Which type of linked list has no end node
Explanation: Linked lists grow/shrink pointing to NULL?
dynamically and allow efficient A) Singly linked list
insertion/deletion compared to arrays. B) Circular linked list
C) Doubly linked list 17. Inserting in the middle of a linked list requires:
D) None A) Traversal to the previous node
Answer: B B) Only updating head
Explanation: Circular lists have the last node C) Direct access
pointing to the first node, forming a loop. D) None
Answer: A
13. Linked lists are preferable over arrays when:
Explanation: Need to traverse to the node
A) Size is fixed
before insertion to update pointers.
B) Frequent insertion and deletion are required
C) Random access is needed 18. Linked list is a linear data structure because:
D) Elements are primitive types only A) Nodes are sequential in memory
Answer: B B) Each node points to the next node forming a
Explanation: Linked lists allow O(1) sequence
insertion/deletion if pointers are known. C) It uses arrays internally
D) None
14. What does head pointer in a linked list
Answer: B
represent?
Explanation: Logical sequence is maintained via
A) Last node
pointers, even if memory is non-contiguous.
B) First node
C) Middle node 19. Which of the following is used in operating
D) NULL system implementations?
Answer: B A) Arrays
Explanation: Head points to the first node of B) Linked lists
the list. C) Both
D) None
15. The next pointer in the last node of a singly
Answer: B
linked list contains:
Explanation: Linked lists are used for managing
A) Address of head
processes, memory, and job scheduling.
B) NULL
C) Random value 20. The time complexity of searching an element
D) Address of middle node in a linked list is:
Answer: B A) O(1)
Explanation: Last node’s next pointer is NULL to B) O(n)
indicate the end. C) O(log n)
D) O(n²)
16. Linked list memory allocation is:
Answer: B
A) Static
Explanation: Sequential traversal is required, so
B) Dynamic
complexity is O(n).
C) Contiguous
D) Fixed size
Answer: B
Topic 2: Adding Node at First, Last, nth Position
Explanation: Nodes are dynamically allocated in
memory during runtime.
1. Adding a node at the beginning of a linked list C) Updating tail
involves: D) None
A) Allocating new node, updating its next to Answer: A
head, updating head Explanation: Need to update the (n-1)th node’s
B) Updating tail pointer next pointer to point to the new node.
C) Traversing list
6. Adding a node at nth position is:
D) None
A) O(1)
Answer: A
B) O(n)
Explanation: New node becomes the head;
C) O(log n)
next pointer points to the previous head.
D) O(n²)
2. Time complexity for inserting at the beginning: Answer: B
A) O(n) Explanation: Traversal to the previous node
B) O(1) requires linear time.
C) O(log n)
7. In a doubly linked list, insertion at the
D) O(n²)
beginning requires:
Answer: B
A) Allocating node, updating next and previous
Explanation: No traversal is required; constant
pointers
time insertion.
B) Only next pointer update
3. To insert at the end of a singly linked list: C) Traversing the list
A) Allocate new node, traverse to last node, D) None
update last node’s next pointer Answer: A
B) Update head only Explanation: Both next and previous pointers
C) Swap nodes need correct assignment.
D) None
8. Insertion in circular linked list at beginning
Answer: A
requires:
Explanation: Need to traverse to the last node
A) Updating last node’s next pointer to new
to update its next pointer.
head
4. Time complexity of inserting at the end in a B) Only head pointer update
singly linked list without tail pointer: C) Traversing entire list
A) O(1) D) None
B) O(n) Answer: A
C) O(log n) Explanation: Circular property requires last
D) O(n²) node to point to the new head.
Answer: B
9. To insert after a given node, you need:
Explanation: Traversal through n nodes is
A) Pointer to previous node
required → O(n).
B) Only head pointer
5. Inserting at the nth position requires: C) Tail pointer
A) Traversal to (n-1)th node D) None
B) Direct access Answer: A
Explanation: The new node’s next pointer B) Traversal to nth node
points to previous node’s next; previous node’s C) Traversal to last node
next updated to new node. D) None
Answer: A
10. Memory allocation for a new node uses:
Explanation: Need pointer to previous node to
A) Static memory
insert before nth node.
B) Dynamic memory (malloc/new)
C) Array indexing 15. Inserting at end of circular singly linked list:
D) None A) New node’s next points to head
Answer: B B) Update tail pointer
Explanation: Linked list nodes are dynamically C) Both A and B
allocated at runtime. D) None
Answer: C
11. Adding a node in an empty list:
Explanation: Circular property and tail pointer
A) Head and tail updated to new node
must be updated.
B) Only tail updated
C) Only head updated 16. Time complexity to insert at nth position in
D) None doubly linked list:
Answer: A A) O(1)
Explanation: New node becomes both head B) O(n)
and tail if list is empty. C) O(log n)
D) O(n²)
12. Inserting multiple nodes at the beginning:
Answer: B
A) O(1) each time
Explanation: Need to traverse n nodes to reach
B) O(n) each time
position.
C) O(log n) each time
D) O(n²) 17. Inserting at first position in doubly linked list:
Answer: A A) Update new node’s next to old head, old
Explanation: Each insertion at head is head’s previous to new node, head = new node
independent → constant time. B) Only head update
C) Only tail update
13. Which pointer is updated when adding at end
D) None
in singly linked list with tail pointer?
Answer: A
A) Head
Explanation: Both next and previous pointers
B) Tail → next
are adjusted for doubly linked list.
C) Previous node
D) NULL pointer 18. Memory leak occurs when:
Answer: B A) New node is allocated but pointer lost
Explanation: Tail pointer updated to point to B) Node inserted correctly
new node for O(1) insertion. C) Node deleted correctly
D) None
14. Adding a node before nth position requires:
Answer: A
A) Traversal to (n-1)th node
Explanation: If allocated memory is not linked, 3. Traversal in a singly linked list:
it cannot be freed → memory leak. A) Forward only
B) Backward only
19. Insertion in a sorted linked list requires:
C) Both directions
A) Traversal to find position
D) Random order
B) Head update only
Answer: A
C) Tail update only
Explanation: Single pointer to next allows only
D) None
forward traversal.
Answer: A
Explanation: Correct position is determined by 4. Traversal in a doubly linked list:
traversal. A) Forward and backward
B) Forward only
20. Insertion at arbitrary position is generally:
C) Backward only
A) O(1)
D) None
B) O(n)
Answer: A
C) O(log n)
Explanation: Previous pointer allows backward
D) O(n²)
traversal.
Answer: B
Explanation: Traversal to position takes linear 5. Traversal in a circular linked list requires:
time; pointer update is O(1). A) Stop when [Link] = NULL
B) Stop when back to head
C) Stop after n/2 nodes
Topic 3: Traversing a Linked List D) Infinite loop
Answer: B
1. What is traversing a linked list?
Explanation: Circular list traversal stops when
A) Deleting nodes
we revisit head.
B) Visiting each node to access/process data
C) Inserting nodes 6. During traversal, which pointer is used in
D) Sorting nodes singly linked list?
Answer: B A) Head pointer only
Explanation: Traversal means visiting each node B) Current pointer
from head to end. C) Tail pointer
D) Previous pointer
2. Time complexity of traversing a linked list with
Answer: B
n nodes:
Explanation: A current pointer moves node by
A) O(1)
node to visit each element.
B) O(n)
C) O(log n) 7. Which of the following is required for traversal
D) O(n²) in doubly linked list?
Answer: B A) Head pointer
Explanation: Each node is visited once → O(n). B) Tail pointer for backward traversal
C) Current pointer
D) All of the above
Answer: D 12. Which pointer is updated during traversal?
Explanation: Forward traversal uses A) Head
head/current; backward traversal uses tail. B) Current
C) Tail
8. Traversal is commonly used for:
D) None
A) Searching
Answer: B
B) Printing
Explanation: Current moves from node to node
C) Counting nodes
during traversal.
D) All of the above
Answer: D 13. Traversing a doubly linked list backward starts
Explanation: Traversal is fundamental for from:
accessing and processing nodes. A) Head
B) Tail
9. Traversing a linked list with n nodes and
C) Middle node
printing data requires:
D) NULL
A) O(n) time
Answer: B
B) O(1) time
Explanation: Tail points to the last node →
C) O(log n) time
backward traversal starts here.
D) O(n²) time
Answer: A 14. Traversal of a linked list cannot:
Explanation: Each node must be visited once. A) Search elements
B) Modify elements
10. Which loop is commonly used for traversal?
C) Delete nodes
A) For loop
D) Directly access nth element in O(1)
B) While loop
Answer: D
C) Do-while loop
Explanation: Linked lists do not allow random
D) Any of the above
indexing; must traverse sequentially.
Answer: D
Explanation: Any loop can be used, typically 15. Traversal is used to count nodes:
while loop with current pointer. A) True
B) False
11. Traversal in a circular singly linked list may
Answer: A
result in:
Explanation: Visiting each node and
A) Infinite loop if termination condition is
incrementing a counter counts nodes.
incorrect
B) Correct output always 16. To traverse and print all elements of a singly
C) Memory leak linked list:
D) None A) Use current pointer initialized to head, move
Answer: A current = [Link] until NULL
Explanation: Must stop when current pointer B) Only print head
reaches head again. C) Only print tail
D) None
Answer: A
Explanation: Sequential access requires moving
along next pointers.

17. Backward traversal in singly linked list is:


A) Easy using previous pointers
B) Not possible without additional data
structures
C) Constant time
D) O(1)
Answer: B
Explanation: Singly linked lists have no previous
pointer → cannot traverse backward without
extra space.

18. Traversal of empty list:


A) Visit head node
B) No operation performed
C) Error occurs
D) Infinite loop
Answer: B
Explanation: Empty list has head = NULL → Week 5: Linked List
nothing to traverse.

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.

17. Insertion at nth position:


A) Traverse to nth node, adjust pointers
B) Direct access
C) Update head only
D) None
Answer: A
Explanation: Both previous and next pointers
adjusted.

18. Deletion at nth position:


A) Traverse to nth node, update neighbors, free
node
B) Update head only
C) Tail only
D) None
Answer: A
Explanation: Proper pointer adjustments
required.

19. Advantages of doubly linked list:


A) Bidirectional traversal
B) Efficient insert/delete
C) Flexibility
D) All of the above
Answer: D Week 6: Stack
Explanation: Extra pointer provides operational
advantages.
Topic 1: Stack – Introduction, Operations, and
20. Disadvantages of doubly linked list:
Applications
A) Extra memory
B) More pointer adjustments 1. A stack is a:
C) Slightly slower for simple operations A) Linear data structure
D) All of the above B) Non-linear data structure
Answer: D C) Graph
D) Tree
Answer: A 6. Which data structure is used to implement
Explanation: Stack stores elements linearly; recursion in programming?
operations are performed at one end (top). A) Queue
B) Stack
2. Stack follows which principle?
C) Linked List
A) FIFO (First In First Out)
D) Array
B) LIFO (Last In First Out)
Answer: B
C) Random Access
Explanation: Function calls are stored in the call
D) Priority-based
stack (LIFO).
Answer: B
Explanation: Last element inserted is the first to 7. Push operation on an empty stack:
be removed. A) Creates new top
B) Deletes old top
3. Which of the following is NOT a stack
C) Traverses stack
operation?
D) None
A) Push
Answer: A
B) Pop
Explanation: Top pointer is updated to new
C) Enqueue
element.
D) Peek/Top
Answer: C 8. Pop operation on an empty stack causes:
Explanation: Enqueue is for queues; stack uses A) Stack overflow
push, pop, and peek. B) Stack underflow
C) Normal operation
4. Time complexity for push operation in stack
D) None
using array:
Answer: B
A) O(n)
Explanation: Cannot remove elements from
B) O(1)
empty stack → underflow.
C) O(log n)
D) O(n²) 9. Peek/top operation returns:
Answer: B A) Bottom element
Explanation: Adding at the top is a constant- B) Top element without removing it
time operation. C) Removes top element
D) All elements
5. Time complexity for pop operation in stack
Answer: B
using array:
Explanation: Peek allows viewing the top
A) O(1)
element without modification.
B) O(n)
C) O(log n) 10. Stack can be implemented using:
D) O(n²) A) Array
Answer: A B) Linked List
Explanation: Removing the top element is C) Both A and B
constant time. D) Queue only
Answer: C
Explanation: Both arrays and linked lists can D) All of the above
efficiently implement stacks. Answer: D
Explanation: Stack supports these algorithms
11. Dynamic size stack is implemented using:
efficiently.
A) Array
B) Linked List 16. Top pointer in stack points to:
C) Static memory A) Bottom element
D) Queue B) Next element to pop
Answer: B C) Middle element
Explanation: Linked list allows stack to D) NULL
grow/shrink dynamically. Answer: B
Explanation: Top always indicates the current
12. Stack overflow occurs when:
last inserted element.
A) Stack is full and push is attempted
B) Stack is empty and pop is attempted 17. Pop operation does which of the following?
C) Peek operation fails A) Returns top element and removes it
D) None B) Returns top element without removing
Answer: A C) Adds element
Explanation: Cannot add element beyond D) Traverses stack
allocated memory → overflow. Answer: A
Explanation: Pop removes and returns the top
13. Applications of stack include:
element.
A) Expression evaluation
B) Function calls 18. Stack using array has fixed size because:
C) Undo mechanisms in editors A) Memory is pre-allocated
D) All of the above B) Dynamic memory used
Answer: D C) Pointer updates
Explanation: Stack is widely used for temporary D) None
storage and reversal operations. Answer: A
Explanation: Array size is fixed at compile-time.
14. In recursion, local variables are stored in:
A) Queue 19. Linked list-based stack does not have:
B) Stack A) Stack overflow (unless memory exhausted)
C) Array B) Stack underflow
D) Heap C) Push operation
Answer: B D) Pop operation
Explanation: Each function call gets a stack Answer: A
frame for its local variables. Explanation: Dynamic memory allows flexible
size → overflow unlikely.
15. Stack can be used for:
A) Infix to postfix conversion 20. Stack is best suited for which type of
B) Parentheses matching operation?
C) Depth-First Search A) Sequential access
B) Last element access B) O(1)
C) Random access C) O(log n)
D) None D) O(n²)
Answer: B Answer: A
Explanation: LIFO operations access the most Explanation: Each node stores data + pointer →
recent element first. O(n) space.

5. Stack implemented with linked list can grow


beyond array limit because:
Topic 2: Analysis of Stack Data Structure
A) Array memory allocated
1. Time complexity for push/pop in stack using B) Heap memory dynamically allocated
array: C) Fixed memory used
A) O(1) D) None
B) O(n) Answer: B
C) O(log n) Explanation: Memory allocated dynamically at
D) O(n²) runtime → flexible size.
Answer: A
6. Worst-case time complexity of push operation
Explanation: Top element accessed directly →
in stack using linked list:
constant time.
A) O(n)
2. Time complexity for searching an element in B) O(1)
stack: C) O(log n)
A) O(1) D) O(n²)
B) O(n) Answer: B
C) O(log n) Explanation: Node added at head → constant
D) O(n²) time.
Answer: B
7. Stack implemented with array may cause
Explanation: Sequential search required →
overflow when:
linear time.
A) Top = size-1
3. Space complexity for stack implemented with B) Top = 0
array of size n: C) Stack empty
A) O(1) D) Tail pointer updated
B) O(n) Answer: A
C) O(log n) Explanation: No more space to insert →
D) O(n²) overflow.
Answer: B
8. Stack underflow occurs when:
Explanation: Memory allocated proportional to
A) Pop on empty stack
number of elements.
B) Push on full stack
4. Dynamic stack implemented with linked list C) Peek operation
space complexity: D) None
A) O(n) Answer: A
Explanation: Cannot remove element from C) O(log n)
empty stack. D) O(n²)
Answer: B
9. Top pointer in array-based stack helps in:
Explanation: Each element occupies memory →
A) Tracking next push location
O(n).
B) Tracking current top element
C) Both A and B 14. Dynamic stack avoids overflow unless:
D) None A) Memory exhausted
Answer: C B) Array full
Explanation: Top index indicates next push C) Tail pointer null
position and current top. D) Head null
Answer: A
10. Comparing array vs linked list stack:
Explanation: Heap memory may still be
A) Array: fixed size, faster access
exhausted in extreme cases.
B) Linked list: dynamic size, extra memory for
pointers 15. Array-based stack: push/pop requires:
C) Both of the above A) Index updates
D) None B) Pointer traversal
Answer: C C) Heap allocation each time
Explanation: Each has advantages depending D) None
on memory and size needs. Answer: A
Explanation: Top index increment/decrement
11. Time complexity for peek/top operation:
for operations.
A) O(1)
B) O(n) 16. Linked list stack: push operation requires:
C) O(log n) A) Allocate node, update head
D) O(n²) B) Increment top index
Answer: A C) Allocate array memory
Explanation: Top element accessed directly. D) None
Answer: A
12. Searching element in stack (linear scan) time
Explanation: New node added at head, pointer
complexity:
updated.
A) O(1)
B) O(n) 17. Analysis helps in:
C) O(log n) A) Estimating runtime
D) O(n²) B) Comparing memory usage
Answer: B C) Choosing implementation
Explanation: Must scan up to n elements. D) All of the above
Answer: D
13. Worst-case space usage of stack with n
Explanation: Time and space analysis guides
elements:
efficient stack usage.
A) O(1)
B) O(n)
18. Pop operation time complexity in both array D) Calls only main function
and linked list stack: Answer: A
A) O(n) Explanation: A recursive function is defined in
B) O(1) terms of itself.
C) O(log n)
2. Base case in recursion is:
D) O(n²)
A) The stopping condition
Answer: B
B) The first recursive call
Explanation: Removing top element is constant
C) Memory allocation step
time.
D) None
19. Space overhead higher in: Answer: A
A) Array-based stack Explanation: Prevents infinite recursion; defines
B) Linked list stack termination.
C) Both equal
3. Recursive call without base case causes:
D) None
A) Normal termination
Answer: B
B) Infinite recursion / stack overflow
Explanation: Each node stores extra pointer →
C) Immediate return
extra memory.
D) Compile-time error
20. Which implementation is better for unknown Answer: B
stack size? Explanation: Recursion continues indefinitely
A) Array until memory is exhausted.
B) Linked list
4. Each recursive call uses:
C) Both equally good
A) Same stack frame
D) None
B) New stack frame
Answer: B
C) Heap memory
Explanation: Dynamic memory allocation
D) Global memory
allows stack to grow as needed.
Answer: B
Explanation: A separate stack frame stores local
variables and return address.
Perfect! Let’s continue Week 6: Stack with the next
two topics: Recursive Function and Expression 5. Time complexity of factorial recursive function
Evaluation (Infix, Postfix, Prefix). I’ll create 20 MCQs (n!):
for each with detailed explanations. A) O(1)
B) O(n)
C) O(n²)
Topic 3: Recursive Function D) O(log n)
Answer: B
1. Recursion is a function that:
Explanation: Function called n times → linear
A) Calls itself
time.
B) Calls another function
C) Loops infinitely
6. Stack memory for recursion is used for: Answer: D
A) Local variables Explanation: Simplifies code for naturally
B) Function parameters recursive problems.
C) Return addresses
11. Base case missing in recursion leads to:
D) All of the above
A) Correct result
Answer: D
B) Infinite loop / stack overflow
Explanation: Each call stores info in stack until
C) Compiler error
returned.
D) Immediate termination
7. Recursive Fibonacci function has time Answer: B
complexity: Explanation: No stopping condition → infinite
A) O(n) recursion.
B) O(n²)
12. Recursive function can be converted to
C) O(2^n)
iterative:
D) O(log n)
A) Using explicit stack
Answer: C
B) Using loops
Explanation: Exponential growth due to
C) Both A and B
repeated subproblems.
D) Impossible
8. Tail recursion is: Answer: C
A) Recursive call is last statement Explanation: Iterative solution can replace
B) Recursive call occurs first recursion using loops or stack.
C) Multiple recursive calls
13. Depth of recursion determines:
D) Infinite recursion
A) Memory used
Answer: A
B) Stack size required
Explanation: Can be optimized by compiler to
C) Performance
iterative form.
D) All of the above
9. Non-tail recursion requires: Answer: D
A) Stack frame until recursive call completes Explanation: Each call consumes stack →
B) No stack frame memory and performance impacted.
C) Constant memory
14. Factorial of 0 in recursion:
D) Immediate return
A) 1
Answer: A
B) 0
Explanation: Further computation occurs after
C) Undefined
recursive call → frame must remain.
D) Infinity
10. Recursion is preferred when: Answer: A
A) Problem has repetitive substructure Explanation: Base case: 0! = 1.
B) Iterative solution is complex
15. Recursive function calling itself multiple times
C) Problem is naturally recursive (e.g., tree
is called:
traversal)
A) Linear recursion
D) All of the above
B) Tree recursion 20. Recursion is often used in:
C) Tail recursion A) Tree traversal
D) Infinite recursion B) Graph DFS
Answer: B C) Divide and conquer algorithms
Explanation: Each call spawns multiple calls → D) All of the above
tree structure. Answer: D
Explanation: Recursion naturally fits
16. Recursion depth is limited by:
hierarchical or repeated substructure problems.
A) Heap memory
B) Stack memory
C) CPU speed
Topic 4: Expression Evaluation – Infix, Postfix, Prefix
D) Data type
Notations and Conversions
Answer: B
Explanation: Stack stores call frames → limited 1. Infix expression format:
by memory. A) Operator before operands (e.g., + A B)
B) Operator after operands (e.g., A B +)
17. Advantages of recursion include:
C) Operator between operands (e.g., A + B)
A) Simpler code
D) None
B) Natural solution for divide-and-conquer
Answer: C
C) Easy to understand
Explanation: Standard notation used in
D) All of the above
arithmetic expressions.
Answer: D
Explanation: Recursive code is often cleaner for 2. Postfix (Reverse Polish) notation format:
complex problems. A) Operator before operands
B) Operator after operands
18. Disadvantages of recursion include:
C) Operator between operands
A) Higher memory usage
D) None
B) Slower execution due to call overhead
Answer: B
C) Risk of stack overflow
Explanation: Eliminates need for parentheses;
D) All of the above
evaluates left-to-right using stack.
Answer: D
Explanation: Recursive calls require stack and 3. Prefix (Polish) notation format:
extra processing. A) Operator before operands
B) Operator after operands
19. Recursive call of Fibonacci(4) results in how
C) Operator between operands
many calls (approx)?
D) None
A) 4
Answer: A
B) 7
Explanation: Operator precedes operands →
C) 9
easy for stack-based evaluation.
D) 8
Answer: C 4. Postfix expression A B + C * evaluates using:
Explanation: Fibonacci tree: Fib(4) calls A) Stack
Fib(3)+Fib(2) → total 9 calls. B) Queue
C) Array only 9. Evaluation of prefix expression uses:
D) Linked list only A) Right-to-left scanning
Answer: A B) Left-to-right scanning
Explanation: Push operands, pop for operator C) Queue
evaluation. D) Array
Answer: A
5. Infix to postfix conversion requires:
Explanation: Start from rightmost symbol for
A) Stack for operators
prefix evaluation.
B) Stack for operands
C) Queue for operands 10. Postfix expression A B C * + evaluates as:
D) Array A) A + (B * C)
Answer: A B) (A + B) * C
Explanation: Operators pushed onto stack; C) A * B + C
output generates postfix. D) None
Answer: A
6. Infix to prefix conversion requires:
Explanation: Operator applies to last two
A) Stack for operators
operands → B*C then +A.
B) Stack for operands
C) Both 11. Stack is used in expression evaluation to:
D) None A) Store operands
Answer: C B) Store operators
Explanation: Stack used to hold operators; C) Manage temporary results
operands combined for prefix. D) All of the above
Answer: D
7. Postfix expression avoids:
Explanation: Stack facilitates efficient
A) Parentheses
expression evaluation.
B) Stack
C) Operands 12. Conversion of infix to postfix: operator
D) Operators precedence handled using:
Answer: A A) Queue
Explanation: Order of operations maintained by B) Stack
postfix → parentheses unnecessary. C) Array
D) Linked list
8. Algorithm to evaluate postfix expression:
Answer: B
A) Push operands, pop 2 for operator, push
Explanation: Stack ensures higher precedence
result
operators evaluated first.
B) Convert to infix first
C) Use queue only 13. Associativity of operators matters in:
D) None A) Infix to postfix conversion
Answer: A B) Infix to prefix conversion
Explanation: Stack holds operands; operator C) Both
pops 2, computes, pushes back. D) None
Answer: C
Explanation: Left or right associativity D) None
determines operator order in output. Answer: C
Explanation: Convert respecting precedence
14. Postfix evaluation steps for 5 6 + 2 :
and parentheses.
A) 5+6=11 → 112=22
B) 6+2 → 58 19. Infix to prefix: (A+B)*(C-D)
C) 56+2 A) +AB-CD
D) None B) +ABCD-
Answer: A C) *AB+CD-
Explanation: Sequential stack evaluation. D) None
Answer: A
15. Prefix evaluation of * + 5 6 2:
Explanation: Operator before operands
A) 5+6=11 → 112=22
respecting precedence.
B) 6+2 → 58
C) 5*6+2 20. Expression evaluation using stack ensures:
D) None A) Correct operator precedence
Answer: A B) Correct associativity
Explanation: Evaluate from right-to-left, C) Efficient computation
operands combined with operator. D) All of the above
Answer: D
16. Stack helps in recursive expression evaluation
Explanation: Stack maintains order of
by:
operations and supports evaluation.
A) Holding operands temporarily
B) Managing nested operations
C) Both A and B
D) None
Answer: C
Explanation: Nested expressions evaluated
efficiently using stack.

17. Advantages of postfix/prefix over infix:


A) No parentheses needed
B) Easier for computers to evaluate
C) Simplified parsing
D) All of the above
Answer: D
Explanation: Operator order inherent →
simplifies computation.

18. Infix expression (A+B)*(C-D) postfix:


A) AB+CD-*
B) ABCD-+*
C) AB+CD*-
5. Which operation inserts an element into a
queue?
Week 7: Queue
A) Pop
B) Push
C) Enqueue
Topic 1: Queue – Introduction with Operations
D) Dequeue
1. A queue is a: Answer: C
A) Non-linear data structure Explanation: Enqueue adds an element to the
B) Linear data structure queue.
C) Hierarchical structure
6. Which operation removes an element from a
D) Graph
queue?
Answer: B
A) Pop
Explanation: Queue stores elements in a linear
B) Push
order.
C) Enqueue
2. Queue follows which principle? D) Dequeue
A) LIFO Answer: D
B) FIFO Explanation: Dequeue removes the front
C) FILO element.
D) Random access
7. Queue underflow occurs when:
Answer: B
A) Queue is full
Explanation: First element inserted is the first
B) Queue is empty and dequeue is attempted
one removed.
C) Queue is empty and enqueue is attempted
3. Insertion in a queue is done at: D) None
A) Front Answer: B
B) Middle Explanation: Removing from an empty queue
C) Rear causes underflow.
D) Any position
8. Queue overflow occurs when:
Answer: C
A) Queue is empty
Explanation: New elements are always added
B) Queue is full and enqueue is attempted
at the rear.
C) Queue is full and dequeue is attempted
4. Deletion in a queue is done from: D) None
A) Rear Answer: B
B) Middle Explanation: Cannot insert into a full queue.
C) Front
9. Which pointer is used to track deletion in
D) Any position
queue?
Answer: C
A) Rear
Explanation: Elements are removed from the
B) Top
front.
C) Front
D) Middle
Answer: C 14. Queue is best suited for:
Explanation: Front pointer indicates the A) Recursive calls
element to be removed. B) Scheduling tasks
C) Expression evaluation
10. Which pointer is used to track insertion in
D) Backtracking
queue?
Answer: B
A) Front
Explanation: FIFO nature suits scheduling and
B) Rear
resource sharing.
C) Top
D) Head 15. Which data structure is used in BFS (Breadth
Answer: B First Search)?
Explanation: Rear pointer indicates where new A) Stack
element is added. B) Queue
C) Tree
11. Queue can be implemented using:
D) Graph
A) Array
Answer: B
B) Linked list
Explanation: BFS explores level-wise using
C) Both A and B
queue.
D) Stack
Answer: C 16. Dequeue operation updates:
Explanation: Both array and linked list A) Rear only
implementations are possible. B) Front only
C) Both front and rear
12. Which queue operation returns the front
D) None
element without removing it?
Answer: B
A) Peek
Explanation: Front moves to next element after
B) Enqueue
deletion.
C) Dequeue
D) Push 17. Queue is also known as:
Answer: A A) Waiting line
Explanation: Peek allows viewing front B) Stack
element. C) Tree
D) Graph
13. In array-based queue, rear initially is:
Answer: A
A) 0
Explanation: Similar to real-life waiting queues.
B) -1
C) 1 18. Accessing elements in a queue is:
D) NULL A) Random
Answer: B B) Sequential
Explanation: Rear starts at -1 before any C) Direct
insertion. D) Binary
Answer: B
Explanation: Elements are accessed 3. Space complexity of array-based queue of size
sequentially from front. n:
A) O(1)
19. If front == rear + 1, the queue is:
B) O(log n)
A) Full
C) O(n)
B) Empty
D) O(n²)
C) Half-full
Answer: C
D) Overflow
Explanation: Memory allocated proportional to
Answer: B
n.
Explanation: Condition indicates empty queue
in some implementations. 4. Queue implemented using linked list has space
complexity:
20. Queue does not support:
A) O(1)
A) Random insertion
B) O(n)
B) FIFO access
C) O(log n)
C) Enqueue
D) O(n²)
D) Dequeue
Answer: B
Answer: A
Explanation: Each node occupies memory.
Explanation: Queue allows insertion only at
rear. 5. Which queue implementation avoids wasted
space?
A) Linear queue
Topic 2: Analysis of Queue Performance B) Circular queue
C) Priority queue
1. Time complexity of enqueue operation:
D) Deque
A) O(n)
Answer: B
B) O(1)
Explanation: Circular queue reuses freed
C) O(log n)
spaces.
D) O(n²)
Answer: B 6. Worst-case time for searching an element in
Explanation: Enqueue only updates rear queue:
pointer. A) O(1)
B) O(n)
2. Time complexity of dequeue operation:
C) O(log n)
A) O(n)
D) O(n²)
B) O(1)
Answer: B
C) O(log n)
Explanation: Sequential traversal required.
D) O(n²)
Answer: B 7. Array-based queue suffers from:
Explanation: Dequeue only updates front A) Overflow only
pointer. B) Underflow only
C) Wasted space problem
D) Slow operations
Answer: C B) O(1)
Explanation: Deleted spaces cannot be reused C) O(log n)
in linear queue. D) O(n²)
Answer: B
8. Linked list queue performance depends on:
Explanation: Most operations are constant
A) Size of list
time.
B) Heap memory availability
C) Pointer manipulation 13. Queue is inefficient for:
D) All of the above A) Scheduling
Answer: D B) BFS
Explanation: Dynamic memory affects C) Random access
performance. D) Buffering
Answer: C
9. Front and rear pointers help in:
Explanation: Queue does not support random
A) Faster access
access.
B) O(1) enqueue/dequeue
C) Reducing memory 14. Worst-case memory usage of queue storing n
D) Sorting elements:
Answer: B A) O(1)
Explanation: Direct access enables constant- B) O(log n)
time operations. C) O(n)
D) O(n²)
10. Queue overflow in linked list occurs when:
Answer: C
A) Queue is empty
Explanation: Each element occupies memory.
B) Heap memory is exhausted
C) Front = rear 15. Dequeuing all elements from queue takes:
D) None A) O(1)
Answer: B B) O(log n)
Explanation: Dynamic allocation fails if memory C) O(n)
exhausted. D) O(n²)
Answer: C
11. Queue performance is best when:
Explanation: Each dequeue is O(1), repeated n
A) Implemented using array
times.
B) Implemented using linked list
C) Depends on application 16. Queue performance mainly depends on:
D) Always same A) Front pointer
Answer: C B) Rear pointer
Explanation: Choice depends on size and C) Implementation method
memory constraints. D) Data type
Answer: C
12. Amortized time complexity of circular queue
Explanation: Array or linked list choice affects
operations:
efficiency.
A) O(n)
17. Linked list queue avoids which issue of array Explanation: Last position connects back to
queue? first.
A) Overflow
2. Main advantage of circular queue:
B) Underflow
A) Faster access
C) Wasted space
B) Reuse of memory
D) Slow insertion
C) Easy sorting
Answer: C
D) Dynamic size
Explanation: No fixed size, dynamic memory.
Answer: B
18. Queue operations are: Explanation: Eliminates wasted space problem.
A) Constant time
3. Priority queue removes element based on:
B) Linear time
A) FIFO
C) Logarithmic time
B) LIFO
D) Exponential time
C) Priority
Answer: A
D) Index
Explanation: Enqueue and dequeue are O(1).
Answer: C
19. Queue is preferred over stack in: Explanation: Higher priority element is
A) DFS dequeued first.
B) BFS
4. In priority queue, elements with same priority
C) Recursion
are served:
D) Expression evaluation
A) Randomly
Answer: B
B) LIFO
Explanation: BFS uses FIFO ordering.
C) FIFO
20. Performance analysis helps in: D) None
A) Choosing right data structure Answer: C
B) Predicting runtime Explanation: Order is maintained for same
C) Estimating memory usage priority.
D) All of the above
5. Circular queue is also known as:
Answer: D
A) Ring buffer
Explanation: Analysis guides efficient
B) Linear queue
implementation.
C) Double queue
D) Priority queue
Answer: A
Topic 3: Variations of Queue (Circular, Priority, etc.)
Explanation: Data wraps around like a ring.
1. Circular queue connects:
6. Double-ended queue (Deque) allows insertion
A) Front to NULL
and deletion at:
B) Rear to front
A) Front only
C) Middle to front
B) Rear only
D) None
C) Both ends
Answer: B
D) Middle C) (rear + 1) % size == front
Answer: C D) front == -1
Explanation: Deque supports both-end Answer: C
operations. Explanation: Standard full condition for circular
queue.
7. Input-restricted deque allows insertion at:
A) Both ends 12. Circular queue condition for empty queue:
B) Front only A) front == rear
C) Rear only B) front == -1
D) Middle C) rear == size
Answer: C D) None
Explanation: Insertion restricted to one end. Answer: B
Explanation: No elements present.
8. Output-restricted deque allows deletion from:
A) One end only 13. Deque is useful in:
B) Both ends A) Sliding window problems
C) Middle B) Palindrome checking
D) None C) Task scheduling
Answer: B D) All of the above
Explanation: Deletion allowed from both ends. Answer: D
Explanation: Flexible insert/delete operations.
9. Priority queue can be implemented using:
A) Array 14. Priority queue is used in:
B) Linked list A) CPU scheduling
C) Heap B) Dijkstra’s algorithm
D) All of the above C) Event-driven simulation
Answer: D D) All of the above
Explanation: Different structures support Answer: D
priority queues. Explanation: Priority-based processing
required.
10. Heap-based priority queue has dequeue time
complexity: 15. Circular queue avoids which drawback of
A) O(1) linear queue?
B) O(n) A) Overflow
C) O(log n) B) Underflow
D) O(n²) C) Wasted memory
Answer: C D) Slow operations
Explanation: Heap reordering takes logarithmic Answer: C
time. Explanation: Freed spaces are reused.

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.

17. Deque is also called:


A) Priority queue
B) Double-ended queue
C) Circular queue
D) Linear queue
Answer: B
Explanation: Supports operations at both ends.

18. Implementation of circular queue uses:


A) Modulo operation
B) Division
C) Multiplication
D) Sorting
Answer: A
Explanation: Modulo helps wrap indices.

19. Priority queue differs from simple queue


because:
A) Uses FIFO
B) Uses LIFO
C) Uses priority for deletion
D) Uses random access
Week 8: Tree
Answer: C
Explanation: Element with highest priority is
served first.
Topic 1: Tree – Introduction, Types, Concepts,
20. Which queue is most memory efficient? Applications
A) Linear queue
1. A tree is a:
B) Circular queue
A) Linear data structure
C) Priority queue
B) Non-linear data structure
D) Deque
C) Sequential structure
Answer: B
D) Static structure
Explanation: Circular queue reuses available
Answer: B
memory effectively.
Explanation: Tree represents hierarchical (non-
linear) relationships.
2. The topmost node in a tree is called: 7. Level of root node is:
A) Leaf A) 0
B) Root B) 1
C) Parent C) 2
D) Child D) -1
Answer: B Answer: B
Explanation: Root node has no parent. Explanation: Root is at level 1 (by convention in
many syllabi).
3. Nodes with no children are called:
A) Root 8. Binary tree is a tree in which each node has at
B) Parent most:
C) Internal nodes A) 1 child
D) Leaf nodes B) 2 children
Answer: D C) 3 children
Explanation: Leaf nodes terminate the tree. D) Unlimited children
Answer: B
4. Degree of a node is:
Explanation: Binary tree allows at most two
A) Number of parents
children.
B) Number of children
C) Number of siblings 9. A tree with no nodes is called:
D) Level of node A) Root tree
Answer: B B) Null tree
Explanation: Degree = total children of a node. C) Binary tree
D) Empty graph
5. Degree of a tree is:
Answer: B
A) Minimum degree of nodes
Explanation: Null tree has no elements.
B) Maximum degree of nodes
C) Average degree 10. A subtree is:
D) Root degree A) Independent tree
Answer: B B) Tree formed from a node and its
Explanation: Tree degree is the maximum node descendants
degree. C) Only leaf nodes
D) Root only
6. Height of a tree is:
Answer: B
A) Number of nodes
Explanation: Every node forms a subtree.
B) Number of edges on longest path from root
to leaf 11. Forest is:
C) Number of leaf nodes A) Set of trees
D) Number of levels B) Set of nodes
Answer: B C) Graph
Explanation: Height measures maximum depth. D) Linked list
Answer: A
Explanation: Removing root of tree results in a D) Scheduling
forest. Answer: D
Explanation: Scheduling mainly uses queues.
12. Which tree is used in hierarchical file systems?
A) Binary tree 17. Maximum nodes at level L in binary tree:
B) AVL tree A) 2L
C) General tree B) 2^L
D) Heap C) L^2
Answer: C D) 2^(L-1)
Explanation: File systems follow general tree Answer: D
structure. Explanation: Level L has max 2^(L-1) nodes.

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. Worst-case search time in BST: 10. Inorder successor is:


A) O(log n) A) Maximum in left subtree
B) O(1) B) Minimum in right subtree
C) O(n) C) Root
D) O(n²) D) Parent
Answer: C Answer: B
Explanation: Degenerate BST behaves like
11. Inorder predecessor is:
linked list.
A) Minimum in right subtree
5. Insertion in BST is based on: B) Maximum in left subtree
A) Random placement C) Root
B) FIFO D) Child
C) Key comparison Answer: B
D) Level-order
12. BST inorder traversal gives:
Answer: C
A) Random order
6. BST insertion always occurs at: B) Descending order
A) Root C) Sorted order
B) Leaf D) Reverse order
C) Middle Answer: C
D) Random node
13. BST insertion time (average case):
Answer: B
A) O(1)
7. Deletion of leaf node in BST: B) O(log n)
A) Simple removal C) O(n)
B) Replace by successor D) O(n²)
C) Replace by predecessor Answer: B
D) Not allowed
14. Degenerate BST resembles:
Answer: A
A) Stack
8. Deletion of node with one child: B) Queue
A) Remove entire tree C) Linked list
D) Graph Answer: B
Answer: C Explanation: AVL tree is self-balancing.

15. Balanced BST ensures:


A) Minimum height
B) Faster operations
C) O(log n) complexity
D) All of the above
Answer: D

16. Which operation is fastest in BST?


A) Traversal
B) Searching
C) Insertion
D) All are similar
Answer: D

17. BST does not allow:


A) Duplicate keys (usually)
Week 10: Tree (Continued…)
B) Searching
C) Insertion
D) Deletion
Topic 1: AVL Tree – Construction, Insertion, Deletion,
Answer: A
Rotations
18. Deleting root node with two children uses:
1. AVL tree is a:
A) Leaf deletion
A) Linear data structure
B) Inorder successor/predecessor
B) Self-balancing Binary Search Tree
C) Stack
C) Complete binary tree
D) Queue
D) Heap
Answer: B
Answer: B
19. BST is mainly used for: Explanation: AVL maintains balance
A) Sorting automatically after insertions/deletions.
B) Searching
2. Balance factor of a node is:
C) Dynamic data storage
A) Height of node
D) All of the above
B) Height of left subtree − height of right
Answer: D
subtree
20. Which tree improves BST worst-case C) Number of children
performance? D) Depth of node
A) Binary tree Answer: B
B) AVL tree Explanation: Balance factor ensures height
C) Heap difference ≤ 1.
D) Trie
3. Allowed balance factor values in AVL tree: 8. AVL insertion time complexity:
A) −2, −1, 0, 1, 2 A) O(1)
B) −1, 0, 1 B) O(n)
C) 0, 1 C) O(log n)
D) −1, 1 D) O(n²)
Answer: B Answer: C
Explanation: AVL strictly allows only −1, 0, or 1. Explanation: Height remains logarithmic.

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

15. Huffman tree avoids:


A) Fixed-length codes Week 11: Graph
B) Prefix ambiguity
C) Sorting
D) Traversal Topic 1: Introduction to Graph & Basic Concepts
Answer: B
1. A graph consists of:
16. Huffman codes are: A) Nodes only
A) Prefix-free B) Edges only
B) Suffix-free C) Vertices and edges
C) Fixed-length D) Trees
Answer: C 7. Sum of degrees of all vertices in undirected
Explanation: Graph is defined as G(V, E), where graph equals:
V = vertices, E = edges. A) Number of edges
B) 2 × number of edges
2. Vertices in a graph represent:
C) n
A) Connections
D) n²
B) Data items
Answer: B
C) Relationships
Explanation: Each edge contributes 2 degrees.
D) Directions
Answer: B 8. Graph with no edges is called:
Explanation: Vertices store data or represent A) Null graph
entities. B) Complete graph
C) Cyclic graph
3. Edges in a graph represent:
D) Connected graph
A) Data
Answer: A
B) Nodes
C) Relationships between vertices 9. Complete graph is a graph where:
D) Weight A) All vertices are connected
Answer: C B) Graph has no cycle
C) Graph has one vertex
4. Graph is a:
D) Graph has no edges
A) Linear data structure
Answer: A
B) Non-linear data structure
C) Static structure 10. Which graph has maximum edges?
D) Sequential structure A) Null graph
Answer: B B) Tree
C) Complete graph
5. Maximum number of edges in simple
D) Directed graph
undirected graph with n vertices:
Answer: C
A) n
B) n² 11. Path in a graph is:
C) n(n−1)/2 A) Random traversal
D) 2n B) Sequence of vertices connected by edges
Answer: C C) Set of edges only
Explanation: Every vertex can connect to n−1 D) Closed loop only
others. Answer: B

6. Degree of a vertex in undirected graph is: 12. Length of a path is:


A) Number of vertices A) Number of vertices
B) Number of edges incident on it B) Number of edges
C) Number of outgoing edges C) Degree of vertices
D) Number of incoming edges D) Weight
Answer: B Answer: B
13. Simple graph does NOT allow: 19. Subgraph is:
A) Loops A) Complete graph
B) Multiple edges B) Graph with more edges
C) Both A and B C) Part of another graph
D) Directed edges D) Directed graph
Answer: C Answer: C

14. Loop in a graph is: 20. Graph is used in:


A) Edge connecting two different vertices A) Networking
B) Edge connecting vertex to itself B) Social media
C) Cycle C) Navigation systems
D) Path D) All of the above
Answer: B Answer: D

15. Weighted graph has:


A) Directions
Topic 2: Directed & Undirected Graph, Cycle, Acyclic
B) Values on edges
Graph
C) Loops
D) Cycles only 1. In directed graph, edges have:
Answer: B A) Weight only
B) No direction
16. Graph G(V, E) where V is finite and E is infinite
C) Direction
is:
D) Length
A) Possible
Answer: C
B) Not possible
C) Tree 2. In undirected graph, edges are:
D) DAG A) One-way
Answer: B B) Two-way
C) Directed
17. Adjacent vertices are:
D) Weighted
A) Vertices with common edge
Answer: B
B) Vertices with same degree
C) Vertices with same value 3. Directed graph is also called:
D) Vertices with no edge A) Tree
Answer: A B) DAG
C) Digraph
18. Isolated vertex has:
D) Forest
A) Degree 0
Answer: C
B) Degree 1
C) Degree 2 4. Cycle in a graph is:
D) Degree n A) Path with no repeated vertex
Answer: A B) Path starting and ending at same vertex
C) Graph with no edges
D) Tree 11. Sum of in-degrees equals:
Answer: B A) Vertices
B) Edges
5. Graph without cycles is called:
C) Twice edges
A) Cyclic graph
D) Zero
B) Complete graph
Answer: B
C) Acyclic graph
D) Null graph 12. Which graph can have self-loops?
Answer: C A) Simple graph
B) Multigraph
6. Directed Acyclic Graph (DAG) is used in:
C) Tree
A) Scheduling
D) DAG
B) Deadlock detection
Answer: B
C) File systems
D) Sorting 13. Which graph is always connected?
Answer: A A) DAG
B) Tree
7. Tree is a special case of:
C) Directed graph
A) Directed cyclic graph
D) Null graph
B) Undirected acyclic graph
Answer: B
C) Complete graph
D) Directed graph 14. Which graph can be disconnected?
Answer: B A) Tree
B) Complete graph
8. Number of edges in tree with n vertices:
C) Undirected graph
A) n
D) Connected graph
B) n−1
Answer: C
C) n+1
D) n² 15. DAG cannot have:
Answer: B A) Direction
B) Root
9. In-degree of a vertex in digraph is:
C) Cycle
A) Total edges
D) Edge
B) Outgoing edges
Answer: C
C) Incoming edges
D) Loops 16. A graph with exactly one cycle is called:
Answer: C A) Tree
B) DAG
10. Out-degree of a vertex is:
C) Unicyclic graph
A) Incoming edges
D) Forest
B) Outgoing edges
Answer: C
C) Total edges
D) Loops 17. If graph has cycle, it is:
Answer: B A) Tree
B) Acyclic D) Base First Search
C) Cyclic Answer: B
D) Complete
3. DFS uses:
Answer: C
A) Queue
18. Which representation is best for sparse graph? B) Stack
A) Adjacency matrix C) Heap
B) Adjacency list D) Array
C) Incidence matrix Answer: B
D) Array
4. BFS uses:
Answer: B
A) Stack
19. Which representation uses more memory? B) Queue
A) Adjacency list C) Heap
B) Adjacency matrix D) Tree
C) Edge list Answer: B
D) Linked list
5. DFS traversal goes:
Answer: B
A) Level by level
20. Which graph has edges with direction and no B) Depth-wise
cycles? C) Randomly
A) Tree D) Sorted
B) DAG Answer: B
C) Undirected graph
6. BFS traversal goes:
D) Forest
A) Depth-wise
Answer: B
B) Random
C) Level by level
D) Sorted
Topic 3: Depth First Search (DFS) & Breadth First
Answer: C
Search (BFS)
7. Time complexity of DFS:
1. DFS stands for:
A) O(V + E)
A) Data First Search
B) O(V)
B) Depth First Search
C) O(E)
C) Directed First Search
D) O(V²)
D) Double First Search
Answer: A
Answer: B
8. Time complexity of BFS:
2. BFS stands for:
A) O(V)
A) Binary First Search
B) O(E)
B) Breadth First Search
C) O(V + E)
C) Balanced First Search
D) O(V²)
Answer: C
9. DFS can be implemented using: B) DFS
A) Recursion C) Both
B) Stack D) None
C) Both A and B Answer: B
D) Queue
16. DFS is used in:
Answer: C
A) Topological sort
10. BFS finds shortest path in: B) Finding connected components
A) Weighted graph C) Cycle detection
B) Unweighted graph D) All of the above
C) Directed graph only Answer: D
D) Tree only
17. BFS uses which data structure internally?
Answer: B
A) Array
11. DFS is preferred for: B) Stack
A) Shortest path C) Queue
B) Cycle detection D) Tree
C) Level traversal Answer: C
D) Sorting
18. DFS explores a branch completely before:
Answer: B
A) Moving sideways
12. BFS is preferred for: B) Backtracking
A) Deep traversal C) Stopping
B) Cycle detection D) Restarting
C) Shortest path Answer: B
D) Backtracking
19. BFS explores neighbors:
Answer: C
A) One by one
13. DFS space complexity depends on: B) All at same level
A) Vertices C) Random
B) Edges D) Deep first
C) Height of recursion stack Answer: B
D) Degree
20. Which traversal guarantees minimum number
Answer: C
of edges path?
14. BFS space complexity depends on: A) DFS
A) Stack height B) BFS
B) Queue size C) Both
C) Tree height D) None
D) Recursion Answer: B
Answer: B

15. Which traversal may cause stack overflow?


A) BFS
5. Which searching technique does NOT require
sorted data?
A) Binary search
B) Linear search
C) Interpolation search
D) Fibonacci search
Answer: B
Week 12: Searching Algorithms 6. Which searching technique is simplest?
A) Binary search
B) Hash search
Topic 1: Introduction to Searching Algorithms & Basic C) Linear search
Concepts D) Tree search
1. Searching means: Answer: C
A) Arranging data 7. Searching algorithms are classified into:
B) Finding a specific element in data A) Static and dynamic
C) Deleting data B) Linear and non-linear
D) Traversing data C) Sequential and interval
Answer: B D) Sorting and searching
Explanation: Searching locates a target element Answer: C
in a data set.
8. Which search method is suitable for small
2. Searching algorithms are used to: datasets?
A) Store data A) Binary search
B) Retrieve data B) Linear search
C) Sort data C) Hashing
D) Compress data D) AVL search
Answer: B Answer: B
3. Which factor affects searching performance? 9. Best case of a searching algorithm means:
A) Input size A) Element found at last position
B) Data structure B) Element found at first position
C) Search method C) Element not found
D) All of the above D) Random position
Answer: D Answer: B
4. Searching can be performed on: 10. Worst case of a search algorithm occurs when:
A) Arrays A) Element is at beginning
B) Linked lists B) Element is in middle
C) Trees C) Element is at end or absent
D) All of the above D) Element is sorted
Answer: D Answer: C
11. Which metric is used to compare searching D) Tree search
algorithms? Answer: C
A) Time complexity
17. Searching algorithms are important for:
B) Space complexity
A) Databases
C) Number of comparisons
B) File systems
D) All of the above
C) Information retrieval
Answer: D
D) All of the above
12. Which data structure supports fastest Answer: D
searching?
18. Which of the following is NOT a searching
A) Array
algorithm?
B) Stack
A) Linear search
C) Hash table
B) Binary search
D) Queue
C) Merge sort
Answer: C
D) Hash search
13. Searching in unsorted data generally uses: Answer: C
A) Binary search
19. Searching efficiency improves if data is:
B) Linear search
A) Unsorted
C) DFS
B) Reversed
D) BFS
C) Sorted
Answer: B
D) Random
14. Which searching algorithm works on divide Answer: C
and conquer?
20. Searching algorithms aim to minimize:
A) Linear search
A) Memory usage
B) Binary search
B) Comparisons
C) Sequential search
C) Data size
D) Hash search
D) Sorting
Answer: B
Answer: B
15. Search key is:
A) Data structure
B) Value to be found Topic 2: Linear Search Algorithm (with Examples)
C) Algorithm
1. Linear search is also called:
D) Index
A) Interval search
Answer: B
B) Sequential search
16. Which searching method compares key with C) Binary search
every element? D) Hash search
A) Binary search Answer: B
B) Hashing
2. Linear search works on:
C) Linear search
A) Sorted data only
B) Unsorted data only D) Stack
C) Both sorted and unsorted data Answer: C
D) Trees only
9. Linear search stops when:
Answer: C
A) End of array is reached
3. Linear search compares key with: B) Element is found
A) First element only C) Both A and B
B) Middle element only D) Array is sorted
C) Last element only Answer: C
D) Each element sequentially
10. Number of comparisons in worst case for n
Answer: D
elements:
4. Best-case time complexity of linear search: A) 1
A) O(n) B) n/2
B) O(log n) C) n
C) O(1) D) log n
D) O(n²) Answer: C
Answer: C
11. Linear search is inefficient for:
5. Worst-case time complexity of linear search: A) Small lists
A) O(1) B) Unsorted lists
B) O(log n) C) Large lists
C) O(n) D) Linked lists
D) O(n²) Answer: C
Answer: C
12. Searching 10 in [2, 4, 6, 8, 10] using linear
6. Average-case time complexity of linear search: search will take:
A) O(1) A) 1 comparison
B) O(n) B) 3 comparisons
C) O(log n) C) 5 comparisons
D) O(n log n) D) 2 comparisons
Answer: B Answer: C
Explanation: Linear search checks each element
7. Linear search is suitable when:
sequentially.
A) Dataset is large
B) Data is frequently sorted 13. Linear search in linked list is:
C) Dataset is small A) Faster than array
D) Data is indexed B) Slower than array
Answer: C C) Same as array
D) Impossible
8. Linear search can be implemented using:
Answer: C
A) Recursion
B) Iteration 14. Space complexity of linear search:
C) Both A and B A) O(n)
B) O(log n) C) Data is large
C) O(1) D) Data is indexed
D) O(n²) Answer: B
Answer: C

15. Linear search does not require:


Topic 3: Binary Search Algorithm (with Examples)
A) Sorting
B) Traversal 1. Binary search requires data to be:
C) Comparisons A) Unsorted
D) Key B) Sorted
Answer: A C) Random
D) Linked
16. If element is not present, linear search:
Answer: B
A) Returns index
B) Returns error or -1 2. Binary search works on principle of:
C) Sorts array A) Brute force
D) Crashes B) Divide and conquer
Answer: B C) Greedy
D) Backtracking
17. Linear search algorithm is:
Answer: B
A) Recursive only
B) Divide and conquer 3. Binary search divides the array into:
C) Brute force A) Three parts
D) Greedy B) Two equal parts
Answer: C C) Random parts
D) Multiple parts
18. Which case gives minimum comparisons in
Answer: B
linear search?
A) Element at end 4. Time complexity of binary search (worst case):
B) Element at beginning A) O(1)
C) Element absent B) O(n)
D) Element in middle C) O(log n)
Answer: B D) O(n²)
Answer: C
19. Linear search checks elements:
A) Randomly 5. Best-case time complexity of binary search:
B) From start to end A) O(log n)
C) From end to start only B) O(n)
D) Middle outward C) O(1)
Answer: B D) O(n log n)
Answer: C
20. Linear search is best choice when:
A) Data is sorted 6. Binary search compares the key with:
B) Data is small and unsorted A) First element
B) Last element 12. Binary search fails if:
C) Middle element A) Array size is large
D) Random element B) Array is sorted
Answer: C C) Array is unsorted
D) Array is indexed
7. Binary search cannot be efficiently applied on:
Answer: C
A) Sorted array
B) Sorted linked list 13. Searching 25 in [5,10,15,20,25,30] using binary
C) Unsorted array search will take:
D) Sorted file A) 1 comparison
Answer: C B) 2 comparisons
C) 3 comparisons
8. Binary search in linked list is inefficient
D) 4 comparisons
because:
Answer: B
A) Extra memory
Explanation: 25 found after two divisions.
B) No direct access
C) Too many nodes 14. Binary search space complexity (iterative):
D) Uses recursion A) O(n)
Answer: B B) O(log n)
C) O(1)
9. Binary search can be implemented using:
D) O(n²)
A) Iteration
Answer: C
B) Recursion
C) Both A and B 15. Binary search space complexity (recursive):
D) Stack only A) O(1)
Answer: C B) O(log n)
C) O(n)
10. Number of comparisons in worst case for
D) O(n²)
binary search:
Answer: B
A) n
B) n/2 16. Binary search is NOT suitable for:
C) log₂ n A) Static data
D) n² B) Sorted data
Answer: C C) Frequently changing data
D) Large datasets
11. Binary search is faster than linear search
Answer: C
because:
A) Uses recursion 17. Binary search is mainly used in:
B) Reduces search space A) Databases
C) Uses array B) Dictionaries
D) Uses pointers C) File systems
Answer: B D) All of the above
Answer: D
18. Binary search reduces time complexity by: Explanation: Hashing provides fast data
A) Sorting data retrieval.
B) Eliminating half of data
2. A hash function maps:
C) Using recursion
A) Key to value
D) Using loops
B) Value to key
Answer: B
C) Key to index
19. Binary search terminates when: D) Index to key
A) Low > High Answer: C
B) Element is found Explanation: Hash function converts a key into
C) Both A and B an array index.
D) Array ends
3. Hash table is implemented using:
Answer: C
A) Linked list
20. Binary search is also called: B) Tree
A) Sequential search C) Array
B) Half-interval search D) Graph
C) Hash search Answer: C
D) Tree search
4. Main advantage of hashing is:
Answer: B
A) Ordered data
B) Fast access
C) Low memory
D) Data compression
Answer: B

5. Average-case time complexity of hash search:


A) O(n)
B) O(log n)
C) O(1)
Week 13: Hashing D) O(n²)
Answer: C

6. Worst-case time complexity of hashing:


Topic 1: Hashing – Introduction & Basic Concepts A) O(1)
(with Examples) B) O(log n)
1. Hashing is a technique used for: C) O(n)
A) Sorting data D) O(n log n)
B) Searching data Answer: C
C) Compressing data Explanation: Occurs due to collisions.
D) Encrypting data 7. Key in hashing refers to:
Answer: B A) Index value
B) Data value to be stored
C) Hash function C) Collisions / keys
D) Address D) Keys × size
Answer: B Answer: B

8. Hash function should be: 14. High load factor causes:


A) Slow A) Faster search
B) Complex B) Fewer collisions
C) Simple and uniform C) More collisions
D) Recursive D) No effect
Answer: C Answer: C

9. Uniform hashing means: 15. Hash table stores data in:


A) Same key always maps to same index A) Sorted order
B) Keys distributed evenly B) Random order
C) No collisions C) Sequential order
D) Sorted keys D) Hierarchical order
Answer: B Answer: B

10. Hashing is best suited for: 16. Hashing avoids:


A) Range queries A) Comparisons
B) Exact match queries B) Traversals
C) Sorting C) Searching
D) Traversal D) Storage
Answer: B Answer: A

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

7. Open addressing stores keys:


Topic 2: Problems in Hashing (Collisions of Hashes)
A) Outside table
1. Collision occurs when: B) In separate list
A) Hash table is full C) In hash table itself
B) Two keys map to same index D) In tree
C) Hash function fails Answer: C
D) Key is large
8. Linear probing resolves collision by:
Answer: B
A) Random search
2. Collision is: B) Checking next available slot
A) Avoidable completely C) Using linked list
B) Unavoidable D) Rehashing
C) Rare Answer: B
D) Illegal
9. Major problem with linear probing:
Answer: B
A) Secondary clustering
3. Primary cause of collision: B) Primary clustering
A) Small table size C) Infinite loop
B) Poor hash function D) Data loss
C) High load factor Answer: B
D) All of the above
10. Quadratic probing avoids:
Answer: D
A) Collisions
4. Collision resolution techniques are used to: B) Primary clustering
A) Avoid hashing C) Secondary clustering
B) Store multiple keys D) Hashing
C) Handle collisions Answer: B
D) Resize table
11. Double hashing uses:
Answer: C
A) One hash function
5. Chaining resolves collision using: B) Two hash functions
A) Arrays C) Linked list
B) Linked lists
D) Recursion 18. Collision increases:
Answer: B A) Search time
B) Efficiency
12. Best collision resolution method:
C) Memory
A) Linear probing
D) Speed
B) Quadratic probing
Answer: A
C) Double hashing
D) Depends on application 19. Load factor should be kept:
Answer: D A) High
B) Equal to 1
13. Clustering means:
C) Low
A) Random placement
D) Infinite
B) Grouping of filled slots
Answer: C
C) Deleting keys
D) Sorting 20. Worst-case search in hashing is:
Answer: B A) O(1)
B) O(log n)
14. Secondary clustering occurs in:
C) O(n)
A) Linear probing
D) O(n²)
B) Quadratic probing
Answer: C
C) Double hashing
D) Chaining
Answer: B
Topic 3: Types of Hashing Algorithms
15. Chaining performance depends on:
1. Division method hash function is:
A) Hash function
A) h(k) = k / m
B) Load factor
B) h(k) = k % m
C) List length
C) h(k) = k²
D) All of the above
D) h(k) = log k
Answer: D
Answer: B
16. Open addressing fails when:
2. Mid-square hashing uses:
A) Table is empty
A) First digits
B) Table is full
B) Last digits
C) Table is large
C) Middle digits of square
D) Hash function is good
D) Random digits
Answer: B
Answer: C
17. Deletion in open addressing is:
3. Folding method works by:
A) Easy
A) Squaring key
B) Difficult
B) Splitting key into parts
C) Impossible
C) Dividing key
D) Not allowed
Answer: B
D) Random mapping 10. Perfect hashing guarantees:
Answer: B A) Collisions
B) No collisions
4. Multiplication method uses:
C) High load factor
A) Prime number
D) Random placement
B) Constant value
Answer: B
C) Random value
D) Division 11. Rehashing means:
Answer: B A) Deleting table
B) Changing hash function
5. Which method is simplest?
C) Sorting keys
A) Mid-square
D) Traversing table
B) Folding
Answer: B
C) Division
D) Multiplication 12. Dynamic hashing allows:
Answer: C A) Fixed table size
B) Table resizing
6. Good hash function minimizes:
C) No collisions
A) Keys
D) No rehashing
B) Collisions
Answer: B
C) Memory
D) Time 13. Static hashing has:
Answer: B A) Variable table size
B) Fixed table size
7. Hash function must be:
C) Dynamic keys
A) One-to-one
D) No keys
B) One-to-many
Answer: B
C) Many-to-one
D) Many-to-many 14. Which hashing is used in databases?
Answer: C A) Static hashing
B) Dynamic hashing
8. Which hashing uses prime numbers?
C) Perfect hashing
A) Division method
D) Folding
B) Folding method
Answer: B
C) Mid-square
D) Random 15. Which hash method is best for numeric keys?
Answer: A A) Division
B) Folding
9. Universal hashing uses:
C) Mid-square
A) Fixed hash function
D) All
B) Set of hash functions
Answer: D
C) Random keys
D) Trees 16. Which hashing method reduces dependency
Answer: B on key pattern?
A) Division Week 14: Sorting Algorithms
B) Mid-square
C) Folding
D) Linear probing Topic 1: Sorting Algorithms – Introduction
Answer: B
1. Sorting means:
17. Double hashing belongs to: A) Deleting data
A) Hash functions B) Arranging data in order
B) Collision resolution C) Searching data
C) Sorting D) Copying data
D) Searching Answer: B
Answer: B Explanation: Sorting arranges elements in
ascending or descending order.
18. Hash algorithm efficiency depends on:
A) Key distribution 2. Which is NOT a sorting algorithm?
B) Hash function A) Bubble sort
C) Table size B) Insertion sort
D) All of the above C) Binary search
Answer: D D) Selection sort
Answer: C
19. Hashing does NOT guarantee:
A) Fast search 3. Sorting improves efficiency of:
B) Sorted data A) Searching
C) Constant access time B) Deletion
D) Unique index C) Traversal
Answer: B D) Storage
Answer: A
20. Best hashing algorithm is:
A) Division 4. Sorted data helps in:
B) Folding A) Binary search
C) Universal B) Fast merging
D) Application dependent C) Data analysis
Answer: D D) All of the above
Answer: D

5. Sorting algorithms are classified as:


A) Stable and unstable
B) Comparison and non-comparison
C) Internal and external
D) All of the above
Answer: D

6. Internal sorting means:


A) Data stored on disk
B) Data fits in main memory C) O(log n)
C) Data stored externally D) O(1)
D) Network sorting Answer: B
Answer: B
13. Worst-case time complexity of comparison
7. External sorting is used when: sorting is:
A) Data fits in RAM A) O(n)
B) Data is small B) O(n log n)
C) Data does not fit in RAM C) O(n²)
D) Data is sorted D) O(log n)
Answer: C Answer: C

8. Stable sorting algorithm preserves: 14. Sorting is essential in:


A) Order of unequal elements A) Databases
B) Order of equal elements B) Operating systems
C) Data size C) Data analytics
D) Memory D) All of the above
Answer: B Answer: D

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

10. Which sorting is comparison-based? 16. In-place sorting means:


A) Counting sort A) Using extra array
B) Radix sort B) Using minimal extra memory
C) Insertion sort C) Sorting on disk
D) Bucket sort D) Using recursion
Answer: C Answer: B

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

7. Insertion sort is an example of:


Topic 2: Insertion Sort – Concepts & Examples
A) Divide and conquer
1. Insertion sort works similar to: B) Greedy algorithm
A) Queue C) Incremental approach
B) Stack D) Dynamic programming
C) Sorting playing cards Answer: C
D) Binary search
8. Insertion sort uses:
Answer: C
A) Swapping only
2. Insertion sort builds sorted array: B) Shifting elements
A) From right to left C) Hashing
B) One element at a time D) Recursion
C) All at once Answer: B
D) Using recursion
9. Space complexity of insertion sort:
Answer: B
A) O(n)
3. Best-case time complexity of insertion sort: B) O(log n)
A) O(n²) C) O(1)
B) O(n) D) O(n²)
C) O(log n) Answer: C
D) O(1)
10. Insertion sort is best when array is:
Answer: B
A) Reverse sorted
4. Worst-case time complexity of insertion sort: B) Random
A) O(n) C) Nearly sorted
B) O(n log n)
D) Large 17. Insertion sort maintains:
Answer: C A) Sorted sublist
B) Heap
11. Insertion sort is an in-place algorithm:
C) Tree
A) True
D) Stack
B) False
Answer: A
Answer: A
18. Insertion sort complexity is affected by:
12. Insertion sort compares element with:
A) Number of inversions
A) All elements
B) Table size
B) Only next element
C) Hashing
C) Previous sorted elements
D) Load factor
D) Random elements
Answer: A
Answer: C
19. Insertion sort is NOT suitable for:
13. Number of passes in insertion sort is:
A) Small arrays
A) n
B) Large arrays
B) n−1
C) Sorted arrays
C) n/2
D) Online input
D) log n
Answer: B
Answer: B
20. Insertion sort is commonly used in:
14. Insertion sort performance depends on:
A) Hybrid sorting algorithms
A) Input order
B) Searching algorithms
B) Input size
C) Hashing
C) Both A and B
D) Graphs
D) Memory
Answer: A
Answer: C

15. Insertion sort is efficient for:


A) Real-time systems Topic 3: Selection Sort – Concepts & Examples
B) Online sorting
1. Selection sort works by:
C) Small inputs
A) Repeated swapping
D) All of the above
B) Selecting minimum element
Answer: D
C) Using recursion
16. Which case gives maximum comparisons? D) Dividing array
A) Sorted array Answer: B
B) Reverse sorted array
2. Selection sort selects:
C) Nearly sorted
A) Largest element always
D) Single element
B) Smallest element always
Answer: B
C) Either smallest or largest
D) Random element 9. Selection sort is preferred when:
Answer: C A) Memory writes are expensive
B) Data is large
3. Time complexity of selection sort (best case):
C) Data is nearly sorted
A) O(n)
D) External sorting
B) O(n log n)
Answer: A
C) O(n²)
D) O(log n) 10. Selection sort performance depends on:
Answer: C A) Input order
B) Input size only
4. Worst-case time complexity of selection sort:
C) Data type
A) O(n)
D) Memory
B) O(n²)
Answer: B
C) O(n log n)
D) O(log n) 11. Selection sort repeatedly selects:
Answer: B A) Minimum element from unsorted part
B) Maximum element from sorted part
5. Selection sort is:
C) Random element
A) Stable
D) Middle element
B) Unstable
Answer: A
C) Recursive
D) External 12. Selection sort uses:
Answer: B A) Shifting
B) Swapping
6. Space complexity of selection sort:
C) Hashing
A) O(n)
D) Recursion
B) O(log n)
Answer: B
C) O(1)
D) O(n²) 13. Selection sort is best suited for:
Answer: C A) Large datasets
B) Small datasets
7. Selection sort is an in-place algorithm:
C) External files
A) True
D) Disk sorting
B) False
Answer: B
Answer: A
14. Selection sort always performs:
8. Selection sort makes how many swaps?
A) n comparisons
A) O(n²)
B) n−1 passes
B) O(n)
C) log n passes
C) O(log n)
D) Random passes
D) O(1)
Answer: B
Answer: B
15. Selection sort does NOT preserve:
A) Sorted order
B) Relative order of equal elements 1. Bubble sort works by:
C) Data integrity A) Selecting minimum element
D) Memory B) Repeatedly swapping adjacent elements
Answer: B C) Dividing the array
D) Using recursion
16. Selection sort belongs to:
Answer: B
A) Divide and conquer
Explanation: Adjacent elements are compared
B) Comparison-based sorting
and swapped if out of order.
C) Non-comparison sorting
D) Recursive sorting 2. Why is it called Bubble sort?
Answer: B A) Elements pop randomly
B) Largest element “bubbles” to the end
17. Selection sort is slower than insertion sort for:
C) Smallest element goes to middle
A) Nearly sorted data
D) Uses bubbles
B) Random data
Answer: B
C) Reverse sorted data
D) All cases 3. Best-case time complexity of bubble sort:
Answer: A A) O(n²)
B) O(n log n)
18. Selection sort requires:
C) O(n)
A) Extra memory
D) O(1)
B) Linked list
Answer: C
C) Constant memory
Explanation: Occurs when array is already
D) Stack
sorted (with optimized version).
Answer: C
4. Worst-case time complexity of bubble sort:
19. Selection sort is easy to implement because:
A) O(n)
A) Simple logic
B) O(n log n)
B) No recursion
C) O(n²)
C) Fixed number of comparisons
D) O(log n)
D) All of the above
Answer: C
Answer: D
5. Bubble sort is:
20. Major disadvantage of selection sort:
A) Stable
A) Uses extra space
B) Unstable
B) Slow for large datasets
C) External
C) Complex implementation
D) Recursive
D) Unstable behavior
Answer: A
Answer: B
6. Space complexity of bubble sort:
A) O(n)
Topic 4: Bubble Sort – Concepts & Examples B) O(log n)
C) O(1)
D) O(n²) 13. Bubble sort is an in-place algorithm:
Answer: C A) True
B) False
7. Bubble sort is an example of:
Answer: A
A) Divide and conquer
B) Comparison-based sort 14. Bubble sort is easy to implement because:
C) Non-comparison sort A) Simple logic
D) Hash-based sort B) No extra memory
Answer: B C) Few variables
D) All of the above
8. Number of passes in bubble sort is:
Answer: D
A) n
B) n−1 15. Bubble sort is inefficient due to:
C) log n A) High number of comparisons
D) n/2 B) Extra space
Answer: B C) Complex logic
D) Recursion
9. Bubble sort is best suited for:
Answer: A
A) Large datasets
B) Nearly sorted datasets 16. Worst-case input for bubble sort is:
C) External sorting A) Sorted array
D) Disk-based sorting B) Nearly sorted array
Answer: B C) Reverse sorted array
D) Single element
10. Bubble sort performance depends on:
Answer: C
A) Input size
B) Input order 17. Bubble sort is commonly used for:
C) Both A and B A) Teaching concepts
D) Memory B) Large databases
Answer: C C) Real-time systems
D) External sorting
11. Optimized bubble sort stops early when:
Answer: A
A) Array is full
B) No swaps occur in a pass 18. Bubble sort does NOT use:
C) Half array is sorted A) Swapping
D) Memory is full B) Comparisons
Answer: B C) Recursion
D) Loops
12. Bubble sort always compares:
Answer: C
A) First and last element
B) Adjacent elements 19. Bubble sort preserves:
C) Random elements A) Relative order of equal elements
D) Middle elements B) Data size
Answer: B C) Memory
D) Hashing 5. Radix sort is best suited for:
Answer: A A) Floating numbers
B) Integers with fixed length
20. Major disadvantage of bubble sort:
C) Strings of varying length
A) Unstable
D) Graph data
B) Uses extra memory
Answer: B
C) Very slow for large inputs
D) Complex implementation 6. Time complexity of radix sort is:
Answer: C A) O(n log n)
B) O(n²)
C) O(d(n + k))
Topic 5: Radix Sort – Concepts & Examples D) O(log n)
Answer: C
1. Radix sort is a:
Explanation: d = number of digits, k = range of
A) Comparison-based sort
digits.
B) Non-comparison-based sort
C) Recursive sort 7. Radix sort is stable because:
D) In-place sort A) Uses comparisons
Answer: B B) Uses stable sub-sorting
Explanation: It does not compare elements C) Uses recursion
directly. D) Uses heap
Answer: B
2. Radix sort works by sorting elements based
on: 8. Radix sort is NOT suitable when:
A) Value A) Keys are long
B) Digits B) Fixed digit length
C) Index C) Small range of digits
D) Position D) Uniform length keys
Answer: B Answer: A

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

15. Radix sort is an example of:


A) Stable sort
B) Unstable sort
C) In-place sort
D) External sort
Answer: A

16. Radix sort fails when:


A) Keys have different lengths
B) Keys are integers
C) Counting sort is used
D) Buckets are used
Answer: A
Week 15: Sorting Algorithms
C) O(n²)
D) O(log n)
Topic 1: Shell Sort – Concepts & Examples
Answer: B
1. Shell sort is an improvement of:
7. Worst-case time complexity of shell sort:
A) Bubble sort
A) O(n log n)
B) Insertion sort
B) O(n²)
C) Selection sort
C) O(n)
D) Merge sort
D) O(log n)
Answer: B
Answer: B
Explanation: Shell sort improves insertion sort
by allowing distant comparisons. 8. Shell sort is an example of:
A) Divide and conquer
2. Shell sort uses:
B) Comparison-based sorting
A) Hashing
C) Non-comparison sorting
B) Gap sequence
D) Hash-based sorting
C) Recursion
Answer: B
D) Heap
Answer: B 9. Shell sort reduces:
A) Comparisons
3. Shell sort sorts elements:
B) Large shifts in insertion sort
A) One by one
C) Memory usage
B) Using fixed gaps
D) Swaps
C) Using random swaps
Answer: B
D) Using recursion
Answer: B 10. Shell sort works best when:
A) Data is large
4. Final gap value in shell sort is:
B) Data is nearly sorted
A) n
C) Data is reversed
B) n/2
D) External sorting
C) 2
Answer: B
D) 1
Answer: D 11. Shell sort space complexity:
A) O(n)
5. Shell sort is:
B) O(log n)
A) Stable
C) O(1)
B) Unstable
D) O(n²)
C) External
Answer: C
D) Recursive
Answer: B 12. Shell sort is an in-place algorithm:
A) True
6. Best-case time complexity of shell sort:
B) False
A) O(n)
Answer: A
B) O(n log n)
13. Performance of shell sort depends on: B) Donald Shell
A) Gap sequence C) Hoare
B) Input size D) Heap
C) Input order Answer: B
D) All of the above
20. Main disadvantage of shell sort:
Answer: D
A) Extra memory
14. Shell sort does NOT guarantee: B) Complex gap selection
A) Fast sorting C) Slow for small data
B) Stability D) Recursive overhead
C) In-place sorting Answer: B
D) Comparison-based sorting
Answer: B
Topic 2: Merge Sort – Concepts & Examples
15. Shell sort compares elements that are:
A) Adjacent 1. Merge sort follows:
B) Far apart A) Greedy method
C) Random B) Divide and conquer
D) Equal C) Dynamic programming
Answer: B D) Backtracking
Answer: B
16. Shell sort becomes insertion sort when gap =:
A) n 2. Merge sort divides array into:
B) n/2 A) Fixed size parts
C) 2 B) Two halves
D) 1 C) Three parts
Answer: D D) Random parts
Answer: B
17. Shell sort is better than insertion sort for:
A) Small arrays 3. Merge sort is:
B) Large arrays A) Stable
C) Sorted arrays B) Unstable
D) Single element C) In-place
Answer: B D) Iterative only
Answer: A
18. Shell sort is also called:
A) Diminishing increment sort 4. Time complexity of merge sort (best case):
B) Heap-based sort A) O(n)
C) Stable sort B) O(n log n)
D) Divide sort C) O(n²)
Answer: A D) O(log n)
Answer: B
19. Shell sort was proposed by:
A) Knuth
5. Worst-case time complexity of merge sort: B) Auxiliary array
A) O(n) C) Hash table
B) O(n log n) D) Stack only
C) O(n²) Answer: B
D) O(log n)
12. Merge sort on linked list is efficient because:
Answer: B
A) No shifting required
6. Space complexity of merge sort: B) No extra memory
A) O(1) C) Faster recursion
B) O(log n) D) Hashing
C) O(n) Answer: A
D) O(n²)
13. Merge sort recursion depth is:
Answer: C
A) n
7. Merge sort works best for: B) log n
A) Small arrays C) n²
B) Linked lists D) Constant
C) In-place sorting Answer: B
D) Hashing
14. Merge sort is not in-place due to:
Answer: B
A) Recursion
8. Merge operation combines: B) Extra memory usage
A) Sorted subarrays C) Comparisons
B) Unsorted arrays D) Stack
C) Random elements Answer: B
D) Trees
15. Merge sort is preferred when:
Answer: A
A) Stability is required
9. Merge sort is suitable for: B) Memory is limited
A) Internal sorting only C) Data is small
B) External sorting D) In-place sort needed
C) Small data Answer: A
D) Real-time systems
16. Merge sort divides until subarray size
Answer: B
becomes:
10. Merge sort always performs: A) 2
A) Same number of comparisons B) 1
B) Random comparisons C) n
C) No comparisons D) 0
D) Few comparisons Answer: B
Answer: A
17. Merge sort is slower than quick sort due to:
11. Merge sort requires: A) More comparisons
A) No extra space B) Extra memory
C) Recursion B) O(n log n)
D) Stability C) O(n²)
Answer: B D) O(log n)
Answer: B
18. Merge sort guarantees:
A) O(n²) 4. Worst-case time complexity of quick sort:
B) O(n log n) A) O(n log n)
C) O(log n) B) O(n²)
D) O(n) C) O(n)
Answer: B D) O(log n)
Answer: B
19. Merge sort is best for:
A) Arrays only 5. Average-case time complexity of quick sort:
B) Linked lists A) O(n²)
C) Stacks B) O(n)
D) Queues C) O(n log n)
Answer: B D) O(log n)
Answer: C
20. Major disadvantage of merge sort:
A) Unstable 6. Quick sort is generally faster because:
B) High space complexity A) Less comparisons
C) Slow speed B) Cache-friendly
D) Hard to implement C) In-place
Answer: B D) All of the above
Answer: D

7. Worst case occurs in quick sort when array is:


Topic 3: Quick Sort – Concepts & Examples
A) Random
1. Quick sort is based on: B) Sorted
A) Greedy approach C) Nearly sorted
B) Divide and conquer D) Small
C) Dynamic programming Answer: B
D) Backtracking
8. Quick sort is:
Answer: B
A) Stable
2. Quick sort selects a: B) Unstable
A) Root C) External
B) Pivot element D) Non-recursive
C) Minimum element Answer: B
D) Maximum element
9. Space complexity of quick sort (average):
Answer: B
A) O(1)
3. Best-case time complexity of quick sort: B) O(log n)
A) O(n) C) O(n)
D) O(n²) 16. Quick sort is preferred when:
Answer: B A) Stability required
B) Average performance matters
10. Partitioning arranges elements:
C) Memory is unlimited
A) Smaller than pivot on left
D) External sorting
B) Larger on right
Answer: B
C) Both A and B
D) Randomly 17. Quick sort is not suitable for:
Answer: C A) Arrays
B) Linked lists
11. Quick sort is in-place:
C) Large datasets
A) True
D) Internal sorting
B) False
Answer: B
Answer: A
18. Tail recursion optimization improves:
12. Quick sort uses recursion for:
A) Speed
A) Searching
B) Memory usage
B) Partitioning
C) Stability
C) Dividing subarrays
D) Sorting order
D) Merging
Answer: B
Answer: C
19. Quick sort is fastest for:
13. Quick sort does not guarantee:
A) Random data
A) Stability
B) Sorted data
B) Speed
C) Reverse sorted data
C) Correctness
D) Small arrays
D) Partitioning
Answer: A
Answer: A
20. Major drawback of quick sort:
14. Pivot selection affects:
A) Uses extra space
A) Time complexity
B) Worst-case O(n²)
B) Space complexity
C) Hard to implement
C) Correctness
D) Unstable memory
D) Data type
Answer: B
Answer: A

15. Median-of-three improves:


A) Worst case Topic 4: Heap Sort – Concepts & Examples
B) Pivot selection
1. Heap sort uses:
C) Stability
A) Stack
D) Memory
B) Queue
Answer: B
C) Binary heap
D) Linked list 8. Heap property ensures:
Answer: C A) Sorted tree
B) Parent ≥ children (max heap)
2. Heap sort is based on:
C) Balanced tree
A) Divide and conquer
D) Random order
B) Selection method
Answer: B
C) Greedy method
D) Dynamic programming 9. Heap sort repeatedly removes:
Answer: B A) Minimum element
B) Maximum element
3. Heap sort first builds a:
C) Random element
A) Min heap
D) Middle element
B) Max heap
Answer: B
C) Binary tree
D) BST 10. Heapify operation takes:
Answer: B A) O(1)
B) O(log n)
4. Heap sort time complexity:
C) O(n)
A) O(n²)
D) O(n²)
B) O(n log n)
Answer: B
C) O(log n)
D) O(n) 11. Building heap takes:
Answer: B A) O(n)
B) O(log n)
5. Heap sort is:
C) O(n log n)
A) Stable
D) O(n²)
B) Unstable
Answer: A
C) Recursive
D) External 12. Heap sort is in-place:
Answer: B A) True
B) False
6. Heap sort space complexity:
Answer: A
A) O(n)
B) O(log n) 13. Heap sort is preferred when:
C) O(1) A) Stability required
D) O(n²) B) Guaranteed O(n log n) needed
Answer: C C) Data is small
D) External sorting
7. Heap is a:
Answer: B
A) Complete binary tree
B) Full binary tree 14. Heap sort does NOT require:
C) BST A) Recursion
D) Graph B) Extra memory
Answer: A C) Heap structure
D) Comparisons
Answer: B
Thank You
15. Heap sort performance depends on:
A) Input order
B) Heap operations
C) Pivot
D) Hashing
Answer: B

16. Heap sort is slower than quick sort because:


A) Cache inefficiency
B) Extra memory
C) Recursion
D) Instability
Answer: A

17. Heap sort is suitable for:


A) Real-time systems
B) Large datasets
C) Priority queues
D) All of the above
Answer: D

18. Heap sort guarantees:


A) O(n²)
B) O(n log n)
C) O(n)
D) O(log n)
Answer: B

19. Heap sort is not stable because:


A) Swapping occurs
B) Uses heap
C) Recursive
D) In-place
Answer: A

20. Major disadvantage of heap sort:


A) High memory
B) Not stable
C) Hard to implement
D) Worst-case time
Answer: B

You might also like