You are on page 1of 91

ALGORITHMS AND DATA STRUCTURE USING JAVA MCQ BANK

Total No. Of MCQs : 620


Name : Shubham Shivaji Patil

Lecture 1: Problem Solving & Computational Thinking


**1.1 Define the problem**

1. What is the primary purpose of "defining the problem" in problem-solving?


a) To ignore the problem
b) To identify multiple problems
c) To understand the underlying issues and requirements
d) To guess a solution

Answer: c) To understand the underlying issues and requirements

2. When should you define the problem during the problem-solving process?
a) At the end
b) After finding a solution
c) After identifying the problem
d) At the beginning

Answer: d) At the beginning

3. What does "scope" refer to when defining a problem?


a) The difficulty level of the problem
b) The timeline for solving the problem
c) The specific elements and boundaries of the problem
d) The financial cost of solving the problem

Answer: c) The specific elements and boundaries of the problem

4. Which of the following statements is true?


a) A well-defined problem has only one possible solution
b) A well-defined problem has multiple possible solutions
c) A well-defined problem has no solution
d) Problem definition is not essential in problem-solving

Answer: b) A well-defined problem has multiple possible solutions

5. What is the first step in the process of defining a problem?


a) Listing possible solutions
b) Identifying the problem
c) Recognizing the symptoms of the problem
d) Analyzing the consequences of the problem

Answer: b) Identifying the problem

6. How can defining the problem accurately help in problem-solving?


a) It narrows down the scope of the problem
b) It guarantees finding the correct solution
c) It makes the problem more challenging
d) It is not relevant to problem-solving

Answer: a) It narrows down the scope of the problem

7. What is the significance of understanding the problem before attempting to solve it?
a) It reduces the chances of finding a solution
b) It helps in finding irrelevant solutions
c) It ensures the problem is ignored
d) It ensures a more focused and effective problem-solving process

Answer: d) It ensures a more focused and effective problem-solving process

8. Which of the following is NOT a benefit of defining the problem accurately?


a) Saves time and resources
b) Avoids the need for problem-solving
c) Increases the chances of finding a suitable solution
d) Helps in setting clear objectives

Answer: b) Avoids the need for problem-solving

9. How does problem definition contribute to effective communication in problem-solving?


a) It hinders communication among team members
b) It creates confusion and misunderstanding
c) It establishes a common understanding among stakeholders
d) It is not relevant to communication

Answer: c) It establishes a common understanding among stakeholders

10. What happens if the problem is not properly defined in the problem-solving process?
a) It guarantees finding the best solution
b) It reduces the likelihood of finding a solution
c) It eliminates the need for finding a solution
d) It helps in finding all possible solutions

Answer: b) It reduces the likelihood of finding a solution

**1.2 Identify the problem**

1. What is the primary goal of "identifying the problem" in problem-solving?


a) Finding a solution immediately
b) Understanding the context and nature of the problem
c) Ignoring the problem
d) Avoiding the problem

Answer: b) Understanding the context and nature of the problem

2. How is "identifying the problem" different from "defining the problem"?


a) They are the same
b) Identifying the problem comes after defining the problem
c) Defining the problem comes after identifying the problem
d) They are not related to problem-solving

Answer: c) Defining the problem comes after identifying the problem

3. When should you identify the problem during the problem-solving process?
a) At the beginning
b) At the end
c) Somewhere in the middle
d) It is not necessary to identify the problem

Answer: a) At the beginning

4. What is the first step in the process of identifying a problem?


a) Listing possible solutions
b) Analyzing the consequences of the problem
c) Recognizing and acknowledging the existence of the problem
d) Assuming there is no problem

Answer: c) Recognizing and acknowledging the existence of the problem

5. How can problem identification help in the problem-solving process?


a) It guarantees finding the correct solution
b) It makes the problem more complicated
c) It helps in defining the scope of the problem
d) It is not relevant to problem-solving

Answer: c) It helps in defining the scope of the problem

6. What does "identifying the problem" involve?


a) Guessing the solution
b) Focusing only on the symptoms of the problem
c) Analyzing the consequences of the problem
d) Recognizing the underlying causes of the problem

Answer: d) Recognizing the underlying causes of the problem

7. Why is it essential to identify the problem accurately?


a) It guarantees finding the best solution
b) It helps in avoiding the problem
c) It reduces the chances of finding a solution
d) It helps in finding an appropriate solution

Answer: d) It helps in finding an appropriate solution

8. What is the significance of understanding the problem before attempting to solve it?
a) It reduces the chances of finding a solution
b) It helps in finding irrelevant solutions
c) It ensures the problem is ignored
d) It ensures a more focused and effective problem-solving process

Answer: d) It ensures a more focused and effective problem-solving process

9. How does problem identification contribute to effective communication in problem-solving?


a) It hinders communication among team members
b) It creates confusion and misunderstanding
c) It establishes a common understanding among stakeholders
d) It is not relevant to communication

Answer: c) It establishes a common understanding among stakeholders

10. What happens if the problem is not properly identified in the problem-solving process?
a) It guarantees finding the best solution
b) It reduces the likelihood of finding a solution
c) It eliminates the need for finding a solution
d) It helps in finding all possible solutions

Answer: b) It reduces the likelihood of finding a solution

**1.3 Introduction to Problem Solving**

1. What is problem-solving?
a) Avoiding problems
b) Finding multiple solutions to a problem
c) Analyzing the consequences of a problem
d) Process of finding solutions to difficult or complex issues
Answer: d) Process of finding solutions to difficult or complex issues

2. Which of the following is NOT a characteristic of effective problem-solving?


a) Relying solely on intuition without analysis
b) Systematic and logical approach to finding solutions
c) Ignoring the problem-solving process
d) Understanding the problem and gathering relevant information

Answer: c) Ignoring the problem-solving process

3. How can problem-solving be helpful beyond finding solutions?


a) Creating new problems
b) Defining new problems
c) Generating new challenges
d) Understanding the problem, analyzing it, and making decisions

Answer: d) Understanding the problem, analyzing it, and making decisions

4. What is the first step in the problem-solving process?


a) Implementing the solution
b) Identifying the problem
c) Defining the problem
d) Evaluating the outcome

Answer: b) Identifying the problem

5. What are the benefits of effective problem-solving skills?


a) Solving every problem instantly
b) Avoiding challenges altogether
c) Improved decision-making, creativity, and efficiency
d) Ignoring problems and hoping they disappear

Answer: c) Improved decision-making, creativity, and efficiency

6. How can creativity be helpful in problem-solving?


a) It hinders the problem-solving process
b) It brings new perspectives and ideas to find innovative solutions
c) Creativity has no impact on problem-solving
d) It leads to irrelevant solutions

Answer: b) It brings new perspectives and ideas to find innovative solutions

7. Why is it essential to evaluate the outcome of a problem-solving process?


a) To ignore the effectiveness of the solution
b) To determine if the problem was challenging enough
c) To identify areas of improvement and learn from the experience
d) To guarantee that the problem will not reoccur

Answer: c) To identify areas of improvement and learn from the experience

8. What does "thinking outside the box" mean in problem-solving?


a) Limiting yourself to traditional solutions
b) Relying solely on intuition
c) Expanding possibilities and considering unconventional approaches
d) Sticking to the most straightforward solution

Answer: c) Expanding possibilities and considering unconventional approaches

9. How can problem-solving skills be beneficial in various aspects of life?


a) They are only applicable in academic settings
b) They can only be used in specific professions
c) They are essential in decision-making, work, and personal life
d) Problem-solving skills have no practical applications

Answer: c) They are essential in decision-making, work, and personal life

10. What happens if problem-solving skills are not honed or practiced regularly?
a) It ensures immediate success in solving all problems
b) It makes problems more difficult to solve
c) It eliminates the need for problem-solving
d) It reduces the effectiveness of finding solutions

Answer: d) It reduces the effectiveness of finding solutions

**1.4 Problem-solving basics**

1. What does problem-solving involve besides finding solutions?


a) Identifying new problems
b) Implementing the most complex solution
c) Evaluating the outcome
d) Avoiding the problem

Answer: c) Evaluating the outcome

2. How can problem-solving contribute to personal growth and development?


a) It prevents individuals from learning from their experiences
b) It discourages creativity and critical thinking
c) It helps individuals become more efficient and adaptable
d) It guarantees that individuals never encounter challenges

Answer: c) It helps individuals become more efficient and adaptable

3. What is the role of critical thinking in problem-solving?


a) It hinders the problem-solving process
b) It limits the exploration of possible solutions
c) It enhances decision-making and solution evaluation
d) Critical thinking is irrelevant to problem-solving

Answer: c) It enhances decision-making and solution evaluation

4. Why is it important to approach problem-solving systematically?


a) It slows down the problem-solving process
b) It guarantees finding the correct solution
c) It increases the chances of overlooking possible solutions
d) It ensures a structured and organized approach to finding solutions

Answer: d) It ensures a structured and organized approach to finding solutions

5. What is the significance of collaboration in problem-solving?


a) It increases competition and rivalry among team members
b) It leads to conflicts and delays in finding solutions
c) It fosters diverse perspectives and creative problem-solving
d) Collaboration has no impact on problem-solving

Answer: c) It fosters diverse perspectives and creative problem-solving

6. How can effective problem-solving skills be beneficial in professional settings?


a) They are irrelevant in the workplace
b) They improve teamwork and productivity
c) They guarantee immediate promotions
d) They only apply to specific professions

Answer: b) They improve teamwork and productivity

7. Which of the following is NOT a characteristic of successful problem solvers?


a) Adaptability and openness to change
b) Relying solely on intuition and assumptions
c) Willingness to seek help and collaborate with others
d) Persistence and determination

Answer: b) Relying solely on intuition and assumptions

8. How can effective problem-solving positively impact decision-making?


a) It guarantees perfect decision-making
b) It reduces the need for decision-making
c) It enhances the quality of decision-making through better evaluation of alternatives
d) Decision-making is irrelevant to problem-solving

Answer: c) It enhances the quality of decision-making through better evaluation of alternatives

9. Which of the following statements is true?


a) Effective problem-solving skills can only be learned in academic settings
b) Problem-solving is limited to specific professions
c) Problem-solving skills are transferable and applicable in various situations
d) Problem-solving has no relevance beyond finding solutions

Answer: c) Problem-solving skills are transferable and applicable in various situations

10. How does problem-solving contribute to personal and professional growth?


a) It stunts individual growth and development
b) It limits career opportunities and advancements
c) It fosters critical thinking, creativity, and resilience
d) Personal and professional growth is irrelevant to problem-solving

Answer: c) It fosters critical thinking, creativity, and resilience


Lecture 2: Algorithms & Data Structures
**2.1 Objective: Introductory Concepts**

1. What is the primary objective of the "Introductory Concepts" in algorithms?


a) Introduce complex algorithms
b) Explore advanced data structures
c) Familiarize learners with basic algorithmic concepts
d) Teach programming languages

Answer: c) Familiarize learners with basic algorithmic concepts

2. What do "Introductory Concepts" in algorithms typically cover?


a) Advanced mathematical principles
b) Basics of data visualization
c) Fundamental algorithmic ideas and terminology
d) Principles of parallel processing

Answer: c) Fundamental algorithmic ideas and terminology

3. Why is it important to learn introductory concepts in algorithms?


a) It helps in mastering complex programming languages
b) It guarantees immediate success in problem-solving
c) It forms the foundation for understanding advanced algorithms
d) It is not essential in the field of computer science

Answer: c) It forms the foundation for understanding advanced algorithms

4. What is the scope of "Introductory Concepts" in algorithms?


a) Covering only theoretical concepts
b) Focusing exclusively on real-world applications
c) Providing a broad overview of algorithmic principles
d) Ignoring the concept of Big O notation

Answer: c) Providing a broad overview of algorithmic principles

5. Which of the following is NOT a typical topic covered in "Introductory Concepts"?


a) Sorting algorithms
b) Searching algorithms
c) Basic data structures
d) Complex optimization techniques

Answer: d) Complex optimization techniques

6. Which of the following is an example of a common introductory algorithmic concept?


a) Hashing algorithms
b) Graph traversal techniques
c) Selection sort
d) Advanced machine learning algorithms

Answer: c) Selection sort

7. What is the primary goal of learning introductory concepts in algorithms?


a) Mastering a specific programming language
b) Understanding complex data structures
c) Preparing for a career in data analysis
d) Building a strong foundation for further algorithmic studies

Answer: d) Building a strong foundation for further algorithmic studies


8. Why is it important to understand algorithmic concepts before delving into specific algorithms?
a) To increase memorization capacity
b) To appreciate the beauty of mathematics
c) To make informed decisions in algorithm selection
d) To avoid complex mathematical calculations

Answer: c) To make informed decisions in algorithm selection

9. What are some common algorithmic terminologies covered in introductory concepts?


a) Database management terms
b) Hardware-specific jargon
c) Time complexity and space complexity
d) Linguistic syntax in programming languages

Answer: c) Time complexity and space complexity

10. How can familiarity with introductory concepts benefit learners in their programming journey?
a) By memorizing complex algorithms
b) By avoiding data structures in problem-solving
c) By providing a better understanding of algorithm design and analysis
d) By eliminating the need for learning programming languages

Answer: c) By providing a better understanding of algorithm design and analysis

**2.2 Algorithm Constructs**

1. What are algorithm constructs in computer science?


a) Physical components of a computer
b) Fundamental building blocks used to design algorithms
c) Popular programming languages
d) Concepts related to database management

Answer: b) Fundamental building blocks used to design algorithms

2. What is the primary purpose of learning algorithm constructs?


a) To create complex databases
b) To implement machine learning models
c) To design efficient algorithms to solve problems
d) To build user interfaces for software applications

Answer: c) To design efficient algorithms to solve problems

3. Which of the following is an example of an algorithm construct?


a) Database tables
b) Graphical user interface
c) Looping and conditional statements
d) Computer network protocols

Answer: c) Looping and conditional statements

4. How do algorithm constructs contribute to problem-solving?


a) They make problems more challenging to solve
b) They offer ready-made solutions to complex issues
c) They provide a structured approach to designing algorithms
d) They eliminate the need for problem-solving

Answer: c) They provide a structured approach to designing algorithms

5. What is the significance of understanding algorithm constructs in computer science?


a) It is not relevant to computer science
b) It helps in becoming proficient in specific programming languages
c) It aids in optimizing algorithms and improving efficiency
d) It ensures immediate success in all programming tasks

Answer: c) It aids in optimizing algorithms and improving efficiency

6. Which of the following algorithm constructs is used to repeat a sequence of instructions?


a) Conditionals
b) Iterations (loops)
c) Functions
d) Variables

Answer: b) Iterations (loops)

7. What do algorithm constructs do when designing algorithms?


a) They limit creativity and innovation
b) They provide a structure for efficient problem-solving
c) They replace the need for designing algorithms
d) They make problems more difficult to understand

Answer: b) They provide a structure for efficient problem-solving

8. Why do programmers use algorithm constructs while writing code?


a) To make code longer and more complicated
b) To confuse users and create challenges
c) To create algorithms that are easy to read and maintain
d) To ignore problem-solving and programming principles

Answer: c) To create algorithms that are easy to read and maintain

9. How can algorithm constructs contribute to writing modular code?


a) By making code monolithic and complex
b) By promoting tightly coupled code segments
c) By enabling code reuse and maintainability
d) By eliminating the need for code organization

Answer: c) By enabling code reuse and maintainability

10. Which of the following is NOT a common algorithm construct used in programming?
a) Conditional statements
b) Loops
c) Global variables
d) Functions

Answer: c) Global variables

**2.3 Complexity analysis of algorithms (Big O notation)**

1. What is the primary goal of complexity analysis of algorithms using Big O notation?
a) Identifying the smallest algorithms
b) Analyzing the physical size of algorithms
c) Evaluating the efficiency and performance of algorithms
d) Comparing algorithms based on their difficulty level

Answer: c) Evaluating the efficiency and performance of algorithms

2. What does "Big O notation" represent in complexity analysis?


a) The largest possible algorithm
b) The time complexity of an algorithm
c) The physical size of an algorithm's code
d) The number of steps required to solve a problem

Answer: b) The time complexity of an algorithm

3. Why is it essential to analyze the complexity of algorithms?


a) It guarantees finding the most straightforward algorithm
b) It helps in choosing the most complex algorithm
c) It ensures optimal algorithm design and resource management
d) Complexity analysis is irrelevant in computer science

Answer: c) It

ensures optimal algorithm design and resource management

4. What is the significance of using Big O notation in complexity analysis?


a) It simplifies the code of algorithms
b) It helps in reducing the number of steps in algorithms
c) It provides a standardized way to express algorithm efficiency
d) Big O notation is not relevant to complexity analysis

Answer: c) It provides a standardized way to express algorithm efficiency

5. Which of the following time complexities indicates the best-performing algorithm?


a) O(1)
b) O(n)
c) O(n^2)
d) O(log n)

Answer: a) O(1)

6. What is the time complexity of an algorithm with a linear time complexity?


a) O(1)
b) O(n)
c) O(n^2)
d) O(log n)

Answer: b) O(n)

7. How does the time complexity of an algorithm with O(n^2) compare to O(n)?
a) O(n) is more efficient than O(n^2)
b) O(n^2) is more efficient than O(n)
c) O(n^2) and O(n) are equally efficient
d) Both complexities have the same computational cost

Answer: a) O(n) is more efficient than O(n^2)

8. When analyzing the complexity of an algorithm, what does "n" typically represent?
a) The number of steps in the algorithm
b) The physical size of the algorithm
c) The input size or number of elements in the algorithm
d) The number of iterations in the algorithm

Answer: c) The input size or number of elements in the algorithm

9. Which of the following best describes an algorithm with constant time complexity (O(1))?
a) The algorithm takes the same amount of time regardless of the input size
b) The algorithm's performance improves linearly with the input size
c) The algorithm's performance worsens exponentially with the input size
d) The algorithm's performance varies unpredictably with the input size
Answer: a) The algorithm takes the same amount of time regardless of the input size

10. Why is it important to consider both time complexity and space complexity when analyzing
algorithms?
a) To increase the complexity of the algorithm
b) To measure the efficiency of the algorithm's code
c) To make the algorithm more difficult to understand
d) To avoid analyzing the performance of the algorithm

Answer: b) To measure the efficiency of the algorithm's code

**2.4 Object-Oriented Design: Abstract Data Types (ADTs)**

1. What is the primary objective of learning about Abstract Data Types (ADTs) in algorithm design?
a) Creating complex algorithms with unique data structures
b) Ignoring the concept of data structures
c) Implementing physical components of a computer
d) Encapsulating data and operations in a reusable manner

Answer: d) Encapsulating data and operations in a reusable manner

2. How do Abstract Data Types (ADTs) contribute to algorithm design?


a) They make algorithms more difficult to implement
b) They offer ready-made solutions to complex issues
c) They provide a high-level description of data and operations
d) ADTs have no relevance to algorithm design

Answer: c) They provide a high-level description of data and operations

3. What distinguishes an Abstract Data Type (ADT) from a concrete data type?
a) ADTs have no specific operations associated with them
b) ADTs are limited to primitive data types
c) ADTs are solely used in theoretical computer science
d) Concrete data types have no relationship with algorithms

Answer: a) ADTs have no specific operations associated with them

4. How do Abstract Data Types (ADTs) promote modularity in algorithm design?


a) They lead to monolithic and inflexible algorithms
b) They encourage interdependence among data structures
c) They allow algorithms to be designed independently of their implementation details
d) ADTs do not contribute to modularity in algorithm design

Answer: c) They allow algorithms to be designed independently of their implementation details

5. Why is encapsulation essential in the design of Abstract Data Types (ADTs)?


a) Encapsulation hinders data abstraction
b) Encapsulation limits the reuse of code
c) Encapsulation protects the internal details of data structures
d) Encapsulation is irrelevant in data structure design

Answer: c) Encapsulation protects the internal details of data structures

6. Which of the following is NOT a common Abstract Data Type (ADT)?


a) Stack
b) Queue
c) Binary search tree
d) Loop

Answer: d) Loop
7. How does an Abstract Data Type (ADT) differ from a concrete data type in programming?
a) ADTs are only used in theoretical computer science
b) Concrete data types are more versatile than ADTs
c) ADTs provide a high-level description without specifying the implementation
d) Concrete data types are limited to primitive data structures

Answer: c) ADTs provide a high-level description without specifying the implementation

8. What does "data abstraction" mean in the context of Abstract Data Types (ADTs)?
a) Hiding the internal details of data structures
b) Displaying all the details of data structures
c) Ignoring the implementation of data structures
d) Avoiding the use of data structures in algorithms

Answer: a) Hiding the internal details of data structures

9. Why do programmers use Abstract Data Types (ADTs) in algorithm design?


a) To make algorithms less efficient
b) To make algorithms more complicated
c) To encapsulate data and operations for easy reuse and maintenance
d) To reduce the modularity of code

Answer: c) To encapsulate data and operations for easy reuse and maintenance

10. How do Abstract Data Types (ADTs) contribute to the object-oriented programming paradigm?
a) By eliminating the use of objects in programming
b) By promoting procedural programming practices
c) By encapsulating data and behavior into objects
d) ADTs have no relevance to object-oriented programming

Answer: c) By encapsulating data and behavior into objects

**2.5 Basic Data Structures**

**2.5.1 Arrays**

1. What is an array in computer science?


a) A collection of unrelated elements
b) A linear data structure with fixed-size memory allocation
c) A method for solving complex mathematical problems
d) A representation of a computer network

Answer: b) A linear data structure with fixed-size memory allocation

2. How are elements arranged in an array?


a) Randomly
b) In a linear sequence
c) In a hierarchical manner
d) According to priority levels

Answer: b) In a linear sequence

3. What is the index of the first element in an array?


a) -1
b) 0
c) 1
d) It depends on the programming language

Answer: b) 0
4. How can you access the element at index

"i" in an array?
a) array[i]
b) array(index i)
c) array(i)
d) element[array(i)]

Answer: a) array[i]

5. What is the time complexity for accessing an element in an array with "n" elements?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: a) O(1)

6. What is the size of a fixed-size array with 10 elements?


a) 10
b) 9
c) 0
d) It depends on the data type

Answer: a) 10

7. What happens when you try to access an element outside the valid index range in an array?
a) The program crashes
b) The value at the invalid index is set to 0
c) The element at the valid index is returned
d) It depends on the programming language

Answer: a) The program crashes

8. What is the time complexity for inserting an element at the end of an array with "n" elements?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: a) O(1)

9. How can you initialize an array with all elements set to zero in many programming languages?
a) array(0)
b) array = []
c) array = [0]
d) It depends on the programming language

Answer: d) It depends on the programming language

10. What are some advantages of using arrays?


a) They provide dynamic memory allocation
b) They allow efficient element access and modification
c) They are suitable for storing complex data structures
d) They automatically resize based on the number of elements

Answer: b) They allow efficient element access and modification

**2.5.2 Stacks**
1. What is a stack in computer science?
a) A linear data structure with variable size
b) A collection of unrelated elements
c) A hierarchical data structure
d) A method for sorting data

Answer: a) A linear data structure with variable size

2. How are elements added to a stack?


a) Elements are randomly added
b) Elements are inserted at the front
c) Elements are inserted at the end
d) Elements are inserted at the top

Answer: d) Elements are inserted at the top

3. What is the term used to describe the process of adding an element to a stack?
a) Insertion
b) Push
c) Append
d) Enqueue

Answer: b) Push

4. What happens when you try to remove an element from an empty stack?
a) The program crashes
b) The top element is removed
c) The stack becomes double-ended
d) A new element is added

Answer: a) The program crashes

5. What is the time complexity for adding an element to a stack?


a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: a) O(1)

6. What is the term used to describe the process of removing an element from a stack?
a) Removal
b) Pop
c) Remove
d) Dequeue

Answer: b) Pop

7. What happens when you try to add an element to a full stack?


a) The program crashes
b) The oldest element is removed to make space
c) The stack automatically resizes to accommodate the new element
d) The element is added to a different data structure

Answer: a) The program crashes

8. What is the time complexity for removing an element from a stack?


a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: a) O(1)

9. What is the last-in, first-out (LIFO) property of a stack?


a) The last element added is the first to be removed
b) The first element added is the first to be removed
c) Elements are removed in random order
d) Elements are removed based on their values

Answer: a) The last element added is the first to be removed

10. What are some common applications of stacks in computer science?


a) Sorting algorithms
b) Implementing recursive functions
c) Graph traversal algorithms
d) Database management

Answer: b) Implementing recursive functions

**2.5.3 Queues**

1. What is a queue in computer science?


a) A linear data structure with variable size
b) A collection of unrelated elements
c) A hierarchical data structure
d) A method for sorting data

Answer: a) A linear data structure with variable size

2. How are elements added to a queue?


a) Elements are randomly added
b) Elements are inserted at the front
c) Elements are inserted at the end
d) Elements are inserted at the top

Answer: c) Elements are inserted at the end

3. What is the term used to describe the process of adding an element to a queue?
a) Insertion
b) Push
c) Append
d) Enqueue

Answer: d) Enqueue

4. What happens when you try to remove an element from an empty queue?
a) The program crashes
b) The front element is removed
c) The queue becomes double-ended
d) A new element is added

Answer: a) The program crashes

5. What is the time complexity for adding an element to a queue?


a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: a) O(1)

6. What is the term used to describe the process of removing an element from a queue?
a) Removal
b) Pop
c) Remove
d) Dequeue

Answer: d) Dequeue

7. What happens when you try to add an element to a full queue?


a) The program crashes
b) The oldest element is removed to make space
c) The queue automatically resizes to accommodate the new element
d) The element is added to a different data structure

Answer: a) The program crashes

8. What is the time complexity for removing an element from a queue?


a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: a) O(1)

9. What is the first-in, first-out (FIFO) property of a queue?


a) The last element added is the first to be removed
b) The first element added is the first to be removed
c) Elements are removed in random order
d) Elements are removed based on their values

Answer: b) The first element added is the first to be removed

10. What are some common applications of queues in computer science?

a) Sorting algorithms
b) Implementing recursive functions
c) Graph traversal algorithms
d) Scheduling tasks in operating systems

Answer: d) Scheduling tasks in operating systems

**2.5.4 Circular Queues**

1. What is a circular queue?


a) A queue with no elements
b) A queue that can only contain a fixed number of elements
c) A queue with elements arranged in a circular manner
d) A queue that allows elements to be inserted at the front

Answer: c) A queue with elements arranged in a circular manner

2. How does a circular queue handle the issue of space when adding elements?
a) It automatically resizes to accommodate more elements
b) It overwrites the oldest element to make space for new elements
c) It throws an error when the queue is full
d) It cannot add elements once the queue is full
Answer: b) It overwrites the oldest element to make space for new elements

3. What is the time complexity for adding an element to a circular queue?


a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: a) O(1)

4. What is the time complexity for removing an element from a circular queue?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: a) O(1)

5. What happens when you try to remove an element from an empty circular queue?
a) The program crashes
b) The front element is removed
c) The circular queue becomes double-ended
d) A new element is added

Answer: a) The program crashes

6. What is the term used to describe the process of adding an element to a circular queue?
a) Insertion
b) Push
c) Append
d) Enqueue

Answer: d) Enqueue

7. What is the term used to describe the process of removing an element from a circular queue?
a) Removal
b) Pop
c) Remove
d) Dequeue

Answer: d) Dequeue

8. What is the first-in, first-out (FIFO) property of a circular queue?


a) The last element added is the first to be removed
b) The first element added is the first to be removed
c) Elements are removed in random order
d) Elements are removed based on their values

Answer: b) The first element added is the first to be removed

9. What is the main advantage of using a circular queue over a regular queue?
a) It provides faster insertion and removal of elements
b) It requires less memory for implementation
c) It guarantees a fixed size for the queue
d) It prevents queue overflow and underflow

Answer: d) It prevents queue overflow and underflow


10. In a circular queue, how do you calculate the next position for insertion after reaching the last
position?
a) Move to the first position
b) Stay at the last position
c) Move to the position after the last position
d) It depends on the implementation

Answer: a) Move to the first position


Lecture 3: Linked List Data Structures
**3.1 Linked Lists**

1. What is a linked list in computer science?


a) A collection of unrelated elements
b) A linear data structure with fixed-size memory allocation
c) A hierarchical data structure
d) A linear data structure with dynamic memory allocation

Answer: d) A linear data structure with dynamic memory allocation

2. How are elements organized in a linked list?


a) In a linear sequence
b) In a random order
c) In a hierarchical manner
d) According to priority levels

Answer: a) In a linear sequence

3. What is the primary advantage of using linked lists over arrays?


a) Linked lists are more memory-efficient
b) Linked lists provide faster access to elements
c) Linked lists offer constant-time insertion and deletion
d) Linked lists have a fixed size

Answer: c) Linked lists offer constant-time insertion and deletion

4. What is the time complexity for accessing an element in a singly linked list?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: b) O(n)

5. How are elements connected in a singly linked list?


a) Each element points to the previous element
b) Each element points to the next element
c) Each element points to a random element
d) Each element points to all other elements

Answer: b) Each element points to the next element

6. What is the term used to describe the first element in a linked list?
a) First element
b) Front element
c) Head
d) Top element

Answer: c) Head

7. What is the term used to describe the last element in a linked list?
a) Last element
b) End element
c) Tail
d) Rear element

Answer: c) Tail
8. What happens when you try to access an element outside the valid index range in a linked list?
a) The program crashes
b) The value at the invalid index is set to 0
c) The element at the valid index is returned
d) It depends on the programming language

Answer: a) The program crashes

9. What is the time complexity for inserting an element at the beginning of a singly linked list?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: a) O(1)

10. What is the time complexity for removing an element from the beginning of a singly linked list?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: a) O(1)

**3.1.1 Singly Linked Lists**

1. What is the primary characteristic of a singly linked list?


a) Each element has two pointers - one for the previous element and one for the next element
b) Each element has one pointer pointing to the previous element
c) Each element has one pointer pointing to the next element
d) Elements are organized in a circular manner

Answer: c) Each element has one pointer pointing to the next element

2. How many pointers does the last element in a singly linked list have?
a) One pointing to the next element
b) Two - one for the previous element and one for the next element
c) None - it does not point to any element
d) It depends on the implementation

Answer: c) None - it does not point to any element

3. How do you traverse a singly linked list from the beginning to the end?
a) Move in a random order
b) Follow the pointers from one element to the previous element
c) Follow the pointers from one element to the next element
d) Jump directly to the middle element

Answer: c) Follow the pointers from one element to the next element

4. What is the primary advantage of using a singly linked list over a doubly linked list?
a) Singly linked lists allow constant-time deletion of elements
b) Singly linked lists require less memory per element
c) Singly linked lists provide faster traversal in both directions
d) Singly linked lists are more memory-efficient

Answer: b) Singly linked lists require less memory per element

5. What is the time complexity for accessing an element in a singly linked list at a specific index?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: b) O(n)

6. How do you add an element to the end of

a singly linked list?


a) Change the pointer of the last element to point to the new element
b) Change the pointer of the first element to point to the new element
c) Create a new list with the new element and append it to the existing list
d) Singly linked lists do not support adding elements to the end

Answer: a) Change the pointer of the last element to point to the new element

7. What is the time complexity for inserting an element at the end of a singly linked list?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: b) O(n)

8. How do you remove an element from the middle of a singly linked list?
a) Change the pointer of the previous element to point to the next element
b) Change the pointer of the next element to point to the previous element
c) Remove the element and update the pointers of adjacent elements
d) Singly linked lists do not support removal of elements from the middle

Answer: c) Remove the element and update the pointers of adjacent elements

9. What is the time complexity for removing an element from the middle of a singly linked list?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: b) O(n)

10. What is the main disadvantage of using a singly linked list?


a) It requires more memory per element compared to arrays
b) It does not allow constant-time access to elements at arbitrary positions
c) It is more difficult to implement than other data structures
d) Singly linked lists do not have any disadvantages

Answer: b) It does not allow constant-time access to elements at arbitrary positions

**3.1.2 Doubly Linked Lists**

1. What is the primary characteristic of a doubly linked list?


a) Each element has two pointers - one for the previous element and one for the next element
b) Each element has one pointer pointing to the previous element
c) Each element has one pointer pointing to the next element
d) Elements are organized in a circular manner

Answer: a) Each element has two pointers - one for the previous element and one for the next element

2. How many pointers does the first element in a doubly linked list have?
a) One pointing to the next element
b) Two - one for the previous element and one for the next element
c) None - it does not point to any element
d) It depends on the implementation

Answer: c) None - it does not point to any element

3. How do you traverse a doubly linked list from the beginning to the end?
a) Move in a random order
b) Follow the pointers from one element to the previous element
c) Follow the pointers from one element to the next element
d) Jump directly to the middle element

Answer: c) Follow the pointers from one element to the next element

4. What is the primary advantage of using a doubly linked list over a singly linked list?
a) Doubly linked lists allow constant-time deletion of elements
b) Doubly linked lists require less memory per element
c) Doubly linked lists provide faster traversal in both directions
d) Doubly linked lists are more memory-efficient

Answer: c) Doubly linked lists provide faster traversal in both directions

5. What is the time complexity for accessing an element in a doubly linked list at a specific index?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: b) O(n)

6. How do you add an element to the end of a doubly linked list?


a) Change the pointer of the last element to point to the new element
b) Change the pointer of the first element to point to the new element
c) Create a new list with the new element and append it to the existing list
d) Doubly linked lists do not support adding elements to the end

Answer: a) Change the pointer of the last element to point to the new element

7. What is the time complexity for inserting an element at the end of a doubly linked list?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: a) O(1)

8. How do you remove an element from the middle of a doubly linked list?
a) Change the pointer of the previous element to point to the next element
b) Change the pointer of the next element to point to the previous element
c) Remove the element and update the pointers of adjacent elements
d) Doubly linked lists do not support removal of elements from the middle

Answer: c) Remove the element and update the pointers of adjacent elements

9. What is the time complexity for removing an element from the middle of a doubly linked list?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
Answer: a) O(1)

10. What is the main advantage of using a doubly linked list over a singly linked list?
a) Doubly linked lists require less memory per element
b) Doubly linked lists allow constant-time access to elements at arbitrary positions
c) Doubly linked lists are easier to implement than singly linked lists
d) Doubly linked lists have no advantages over singly linked lists

Answer: b) Doubly linked lists allow constant-time access to elements at arbitrary positions

**3.1.3 Circular Linked Lists**

1. What is the primary characteristic of a circular linked list?


a) Elements are organized in a circular manner
b) Each element has two pointers - one for the previous element and one for the next element
c) Each element has one pointer pointing to the previous element
d) Each element has one pointer pointing to the next element

Answer: a) Elements are organized in a circular manner

2. How are elements connected in a circular linked list?


a) Each element points to the previous element
b) Each element points to the next element
c) Each element points to all other elements
d) Each element does not point to any element

Answer: b) Each element points to the next element

3. What is the term used to describe the first element in a circular linked list?
a) First element
b) Front element
c) Head
d) Top element

Answer: c) Head

4. What is the term used to describe the last element in a circular linked list?
a) Last element
b) End element
c) Tail
d) Rear element

Answer: c) Tail

5. What is the time complexity for accessing an element in a circular linked list at a specific index?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: b) O(n)

6. How do you add an element to the end of a circular linked

list?
a) Change the pointer of the last element to point to the new element
b) Change the pointer of the first element to point to the new element
c) Create a new list with the new element and append it to the existing list
d) Circular linked lists do not support adding elements to the end
Answer: a) Change the pointer of the last element to point to the new element

7. What is the time complexity for inserting an element at the end of a circular linked list?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: a) O(1)

8. How do you remove an element from the middle of a circular linked list?
a) Change the pointer of the previous element to point to the next element
b) Change the pointer of the next element to point to the previous element
c) Remove the element and update the pointers of adjacent elements
d) Circular linked lists do not support removal of elements from the middle

Answer: c) Remove the element and update the pointers of adjacent elements

9. What is the time complexity for removing an element from the middle of a circular linked list?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: b) O(n)

10. What is the main advantage of using a circular linked list over a singly linked list?
a) Circular linked lists require less memory per element
b) Circular linked lists allow constant-time access to elements at arbitrary positions
c) Circular linked lists provide faster traversal in both directions
d) Circular linked lists have no advantages over singly linked lists

Answer: c) Circular linked lists provide faster traversal in both directions

**3.1.4 Node-based Storage with Arrays**

1. What is node-based storage in the context of linked lists?


a) A method of storing linked lists using arrays
b) A method of storing linked lists using nodes
c) A method of storing linked lists using pointers
d) A method of storing linked lists using circular arrays

Answer: b) A method of storing linked lists using nodes

2. What is a node in the context of linked lists?


a) An element in an array
b) A collection of unrelated elements
c) A data structure containing data and a pointer to the next element
d) A hierarchical data structure

Answer: c) A data structure containing data and a pointer to the next element

3. How are elements connected in a node-based storage linked list?


a) Each node points to the previous node
b) Each node points to the next node
c) Each node points to all other nodes
d) Each node does not point to any node

Answer: b) Each node points to the next node


4. What is the time complexity for accessing an element in a node-based storage linked list at a specific
index?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: b) O(n)

5. What is the primary advantage of using node-based storage with arrays over standard arrays?
a) It provides faster access to elements
b) It allows constant-time insertion and deletion
c) It requires less memory per element
d) It provides faster traversal in both directions

Answer: b) It allows constant-time insertion and deletion

6. What is the time complexity for inserting an element at the end of a node-based storage linked list?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: a) O(1)

7. How do you add an element to the beginning of a node-based storage linked list?
a) Change the pointer of the first node to point to the new node
b) Change the pointer of the last node to point to the new node
c) Create a new list with the new element and append it to the existing list
d) Node-based storage linked lists do not support adding elements to the beginning

Answer: a) Change the pointer of the first node to point to the new node

8. What is the time complexity for inserting an element at the beginning of a node-based storage linked
list?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: a) O(1)

9. How do you remove an element from the middle of a node-based storage linked list?
a) Change the pointer of the previous node to point to the next node
b) Change the pointer of the next node to point to the previous node
c) Remove the node and update the pointers of adjacent nodes
d) Node-based storage linked lists do not support removal of elements from the middle

Answer: c) Remove the node and update the pointers of adjacent nodes

10. What is the time complexity for removing an element from the middle of a node-based storage
linked list?
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)

Answer: b) O(n)
Lecture 4: Recursion
**4.1 What is recursion?**

1. Recursion is a programming technique where a function calls itself directly or indirectly until it
reaches a specific condition called the:
a) Loop condition
b) Recursive condition
c) Base condition
d) Termination condition

Answer: c) Base condition

2. In recursion, what happens when a function calls itself?


a) The function is terminated
b) A new function is created with a different name
c) The function executes the same set of statements repeatedly
d) A new instance of the function is created and added to the stack

Answer: d) A new instance of the function is created and added to the stack

3. Recursion provides an alternative approach to solving problems that can also be solved using:
a) Loops
b) Arrays
c) Pointers
d) Switch statements

Answer: a) Loops

4. Which of the following is NOT an essential component of a recursive function?


a) Base condition
b) Recursive call
c) Looping mechanism
d) Exit condition

Answer: c) Looping mechanism

5. What is the main advantage of using recursion in programming?


a) It provides faster execution of code
b) It reduces memory consumption
c) It simplifies the code and problem-solving process
d) It eliminates the need for the base condition

Answer: c) It simplifies the code and problem-solving process

6. What is tail recursion?


a) A type of recursion that involves only one function call
b) A type of recursion that involves multiple function calls
c) A type of recursion that occurs when a function calls itself multiple times
d) A type of recursion that occurs when a function calls another function

Answer: a) A type of recursion that involves only one function call

7. Recursion is used in various algorithms and data structures, such as:


a) Sorting algorithms
b) Arrays
c) Pointers
d) Switch statements

Answer: a) Sorting algorithms


8. What happens if a recursive function does not have a base condition?
a) The program executes the recursive calls indefinitely
b) The program enters an infinite loop
c) The program terminates successfully
d) The program throws a runtime error

Answer: a) The program executes the recursive calls indefinitely

9. What is the time complexity of a recursive algorithm with exponential growth?


a) O(1)
b) O(log n)
c) O(n)
d) O(2^n)

Answer: d) O(2^n)

10. Recursion can be considered as an alternative to which of the following programming constructs?
a) Decision-making statements (if-else)
b) Looping statements (for, while)
c) Function declarations
d) Variable declarations

Answer: b) Looping statements (for, while)

**4.2 What is the base condition in recursion?**

1. The base condition in recursion is also known as the:


a) Terminating condition
b) Halt condition
c) Stopping condition
d) Exit condition

Answer: a) Terminating condition

2. The base condition is crucial in recursion to:


a) Terminate the recursive function
b) Ensure the function calls itself indefinitely
c) Control the order of function execution
d) Allow the recursive function to call other functions

Answer: a) Terminate the recursive function

3. In a recursive function, the base condition is typically expressed using:


a) A loop
b) An if-else statement
c) A switch statement
d) A function call

Answer: b) An if-else statement

4. What happens when the base condition is met in a recursive function?


a) The function starts calling other functions
b) The recursive function stops calling itself and returns a value
c) The function enters an infinite loop
d) The function terminates without returning any value

Answer: b) The recursive function stops calling itself and returns a value

5. The base condition prevents the recursive function from:


a) Starting the recursion process
b) Reaching the recursive call
c) Returning any value
d) Performing any operation

Answer: a) Starting the recursion process

6. How many times does a recursive function call itself when the base condition is met?
a) Zero times
b) One time
c) Multiple times
d) It depends on the implementation

Answer: a) Zero times

7. What is the purpose of the base condition in recursion?


a) To determine the input parameters for the recursive call
b) To set a limit on the number of recursive calls
c) To control the order of function execution
d) To determine the output of the recursive function

Answer: b) To set a limit on the number of recursive calls

8. The absence of a base condition in recursion can lead to:


a) Faster execution of the program
b) Infinite recursion and stack overflow
c) Reduced memory consumption
d) More accurate results

Answer: b) Infinite recursion and stack overflow

9. The base condition is typically defined based on the:


a) Input parameters of the function
b) Output of the recursive function
c) Current state of the program
d) Complexity of the problem being solved

Answer: a) Input parameters of the function

10. What happens if the base condition is not met during recursion?
a) The program terminates successfully
b) The recursive function halts execution
c) The program enters an infinite loop
d) The function returns the default value of its return type

Answer: c) The program enters an infinite loop

**4.3 Direct and Indirect Recursion**

1. Direct recursion refers to a situation where a function calls:


a) Itself directly
b) Another function directly
c) Itself indirectly through another function
d) Multiple functions simultaneously

Answer: a) Itself directly

2. Indirect recursion refers to a situation where a function calls:


a) Itself directly
b) Another function directly
c) Itself indirectly through another function
d) Multiple functions simultaneously

Answer: c) Itself indirectly through another function

3. In direct recursion, a function calls itself:


a) Without involving any other functions
b) With multiple function calls simultaneously
c) Through a separate utility function
d) With different parameters

Answer: a) Without involving any other functions

4. In indirect recursion, multiple functions:


a) Call each other in a loop
b) Call each other directly
c) Call each other indirectly through a chain of function calls
d) Do not interact with each other

Answer: c) Call each other indirectly through a chain of function calls

5. Which of the following statements is true for direct and indirect recursion?
a) Both direct and indirect recursion involve only one function call
b) Direct recursion involves

only one function call, while indirect recursion involves multiple function calls
c) Indirect recursion involves only one function call, while direct recursion involves multiple function
calls
d) Both direct and indirect recursion involve multiple function calls

Answer: d) Both direct and indirect recursion involve multiple function calls

6. Direct recursion is more straightforward to implement than indirect recursion because:


a) It involves fewer function calls
b) It does not require any base condition
c) It does not require the use of other functions
d) It allows for faster execution of code

Answer: c) It does not require the use of other functions

7. Indirect recursion can be useful when:


a) The recursive logic is complex and needs to be split into multiple functions
b) The base condition is not known at the beginning of the recursion
c) The recursive function needs to be called with different parameters
d) There is a limitation on the number of recursive calls

Answer: a) The recursive logic is complex and needs to be split into multiple functions

8. What happens if the base condition is not defined correctly in indirect recursion?
a) The program terminates successfully
b) The recursive function halts execution
c) The program enters an infinite loop
d) The function returns the default value of its return type

Answer: c) The program enters an infinite loop

9. In direct recursion, the control flow remains within the:


a) Base condition
b) Recursive call
c) Main function
d) Recursive function

Answer: d) Recursive function

10. In indirect recursion, the control flow moves between:


a) Two different functions
b) Base condition and recursive call
c) Multiple recursive calls
d) The main function and recursive function

Answer: a) Two different functions

**4.4 Memory is Allocated to Different Function Calls in Recursion**

1. In recursion, each function call creates its own:


a) Local variables
b) Global variables
c) Shared variables
d) Constants

Answer: a) Local variables

2. Each instance of a recursive function call has its own set of:
a) Input parameters
b) Output parameters
c) Local variables
d) Static variables

Answer: c) Local variables

3. The memory for local variables of a recursive function is allocated on the:


a) Heap
b) Stack
c) Data segment
d) Code segment

Answer: b) Stack

4. What happens when a recursive function calls itself multiple times?


a) All function calls share the same local variables
b) All function calls share the same memory address
c) Each function call has its own copy of local variables
d) Each function call updates the memory of previous calls

Answer: c) Each function call has its own copy of local variables

5. The memory allocated to each function call in recursion is deallocated:


a) When the base condition is met
b) After the recursive call
c) Automatically by the compiler
d) Manually by the programmer

Answer: a) When the base condition is met

6. Excessive recursion or recursion with a large number of function calls can lead to:
a) Increased memory consumption
b) Stack overflow and program crash
c) Faster execution of the program
d) Better performance
Answer: b) Stack overflow and program crash

7. What is a potential disadvantage of recursion regarding memory usage?


a) Recursion does not use any memory
b) Recursion consumes a fixed amount of memory
c) Recursion consumes more memory compared to iteration
d) Recursion consumes less memory compared to iteration

Answer: c) Recursion consumes more memory compared to iteration

8. The memory used for recursive function calls is managed by the:


a) Operating system
b) Compiler
c) Programmer
d) Recursive function itself

Answer: a) Operating system

9. What is the purpose of allocating memory separately for each function call in recursion?
a) To ensure faster execution of the program
b) To allow for easy sharing of data between function calls
c) To prevent memory leaks
d) To allow for parallel execution of function calls

Answer: c) To prevent memory leaks

10. When does the memory allocated to a recursive function call get released?
a) When the recursive call is made
b) After the base condition is met
c) When the program terminates
d) When the recursive call is completed

Answer: b) After the base condition is met

**4.5 Pros and Cons of Recursion**

1. What is a major advantage of using recursion in programming?


a) Recursion allows for faster execution of code
b) Recursion reduces memory consumption
c) Recursion simplifies complex problems and algorithms

d) Recursion eliminates the need for loops

Answer: c) Recursion simplifies complex problems and algorithms

2. Recursion can lead to a more concise and readable code compared to:
a) Functions with loops
b) Functions with multiple return statements
c) Functions with many parameters
d) Functions with a single return statement

Answer: a) Functions with loops

3. Recursion is well-suited for solving problems that exhibit a:


a) Linear structure
b) Hierarchical structure
c) Random structure
d) Circular structure
Answer: b) Hierarchical structure

4. In which of the following scenarios would recursion be an appropriate choice?


a) Calculating the sum of elements in an array using a loop
b) Traversing a linked list in reverse using a loop
c) Implementing a search algorithm for a sorted array
d) Sorting elements in an array using the Bubble Sort algorithm

Answer: b) Traversing a linked list in reverse using a loop

5. One of the limitations of recursion is that it may lead to:


a) Slower execution of code
b) Reduced readability of code
c) Excessive memory consumption
d) Inability to handle complex problems

Answer: c) Excessive memory consumption

6. Recursive algorithms can be more intuitive to understand for problems that have a:
a) Linear structure
b) Hierarchical structure
c) Random structure
d) Circular structure

Answer: b) Hierarchical structure

7. The use of recursion can make the code more:


a) Complex and error-prone
b) Concise and readable
c) Dependent on external libraries
d) Dependent on hardware specifications

Answer: b) Concise and readable

8. Which of the following statements is true regarding recursion and iteration?


a) Recursion is always more efficient than iteration
b) Iteration is always more efficient than recursion
c) Recursion and iteration have similar efficiency in most cases
d) The efficiency of recursion and iteration depends on the problem being solved

Answer: d) The efficiency of recursion and iteration depends on the problem being solved

9. Recursion is widely used in solving problems related to:


a) String manipulation
b) Arithmetic operations
c) Graphics rendering
d) Network communication

Answer: a) String manipulation

10. A drawback of recursion is that it may lead to a:


a) Simplified problem-solving process
b) Greater understanding of the problem
c) Stack overflow error for deeply nested recursive calls
d) Decrease in code complexity

Answer: c) Stack overflow error for deeply nested recursive calls

**4.6 Function Complexity During Recursion**


1. The complexity of a recursive function refers to:
a) The number of recursive calls made
b) The number of loops in the function
c) The number of base conditions
d) The time and space requirements of the function

Answer: d) The time and space requirements of the function

2. The time complexity of a recursive function is determined by:


a) The number of parameters passed to the function
b) The number of base conditions in the function
c) The number of loops in the function
d) The number of recursive calls and the time complexity of each call

Answer: d) The number of recursive calls and the time complexity of each call

3. What is the time complexity of a recursive function with multiple recursive calls and a time
complexity of O(n) per call?
a) O(n)
b) O(log n)
c) O(n^2)
d) O(2^n)

Answer: c) O(n^2)

4. The space complexity of a recursive function is determined by:


a) The number of parameters passed to the function
b) The number of base conditions in the function
c) The number of local variables and the maximum depth of the recursion
d) The number of recursive calls and the space complexity of each call

Answer: c) The number of local variables and the maximum depth of the recursion

5. The space complexity of a recursive function with a time complexity of O(1) per call is:
a) O(1)
b) O(n)
c) O(log n)
d) O(2^n)

Answer: b) O(n)

6. What is the impact of increasing the depth of recursion on the space complexity of a recursive
function?
a) The space complexity remains constant
b) The space complexity increases linearly
c) The space complexity increases logarithmically
d) The space complexity decreases

Answer: b) The space complexity increases linearly

7. The space complexity of a recursive function with a time complexity of O(log n) per call is:
a) O(1)
b) O(n)
c) O(log n)
d) O(2^n)

Answer: c) O(log n)

8. The space complexity of a recursive function with a time complexity of O(2^n) per call is:
a) O(1)
b) O(n)
c) O(log n)
d) O(2^n)

Answer: d) O(2^n)

9. Recursive functions that involve backtracking or multiple recursive calls may have:
a) Low time complexity but high space complexity
b) High time complexity but low space complexity
c) Low time complexity and low space complexity
d) High time complexity and high space complexity

Answer: d) High time complexity and high space complexity

10. The time and space complexity of a recursive function can be analyzed using techniques such as:
a) Stack tracing
b) Profiling
c) Debugging
d) Manual calculation

Answer: b) Profiling
Lecture 5: Trees & Applications

**5.1 Introduction to Trees**

1. In data structures, a tree is a hierarchical data structure that consists of:


a) A single node
b) A root node and child nodes
c) A linear sequence of nodes
d) Only leaf nodes

Answer: b) A root node and child nodes

2. The topmost node in a tree is called the:


a) Root node
b) Parent node
c) Leaf node
d) Branch node

Answer: a) Root node

3. In a tree, nodes that have no children are called:


a) Root nodes
b) Internal nodes
c) Leaf nodes
d) Branch nodes

Answer: c) Leaf nodes

4. A node in a tree can have how many parent nodes?


a) None
b) One
c) Two or more
d) It depends on the type of tree

Answer: b) One

5. What is the maximum number of children that a node can have in a binary tree?
a) 1
b) 2
c) 3
d) There is no maximum limit

Answer: b) 2

6. The depth of a node in a tree is the number of edges in the path from the root node to that node.
What is the depth of the root node?
a) 0
b) 1
c) The depth of the root node is not defined
d) It depends on the height of the tree

Answer: a) 0

7. The height of a tree is the maximum depth of any node in the tree. What is the height of a tree with a
single node (no children)?
a) 0
b) 1
c) The height is not defined for a tree with a single node
d) It depends on the type of tree
Answer: a) 0

8. What is a forest in the context of trees?


a) A tree with a large number of nodes
b) A collection of disjoint trees
c) A tree with multiple root nodes
d) A tree with no parent node

Answer: b) A collection of disjoint trees

**5.2 Trees and Terminology**

1. In a binary tree, a node that has at least one child node is called:
a) A leaf node
b) An internal node
c) A root node
d) A branch node

Answer: b) An internal node

2. What is the maximum number of child nodes that an internal node can have in a binary tree?
a) 1
b) 2
c) 3
d) There is no maximum limit

Answer: b) 2

3. The total number of nodes in a binary tree with height h can be at most:
a) h
b) 2^h - 1
c) 2^h
d) h^2

Answer: b) 2^h - 1

4. A node's sibling in a binary tree is defined as:


a) Its parent node
b) Its child node
c) Its left child node
d) Another node with the same parent node

Answer: d) Another node with the same parent node

5. A node's ancestor in a tree is any node that lies on the:


a) Same level as the node
b) Path from the root to that node
c) Left subtree of the node
d) Right subtree of the node

Answer: b) Path from the root to that node

6. A node's descendant in a tree is any node that lies in the:


a) Same level as the node
b) Path from the root to that node
c) Left subtree of the node
d) Right subtree of the node

Answer: c) Left subtree of the node


7. What is the height of a binary tree with only one node (root node)?
a) 0
b) 1
c) The height is not defined for a tree with only one node
d) It depends on the type of tree

Answer: a) 0

8. In a binary tree, the nodes at the same level are also called:
a) Siblings
b) Ancestors
c) Descendants
d) Cousins

Answer: a) Siblings

**5.3 Tree Traversals**

1. Which tree traversal visits the root node first, then the left subtree, and finally the right subtree?
a) Inorder traversal
b) Preorder traversal
c) Postorder traversal
d) Level-order traversal

Answer: b) Preorder traversal

2. In an inorder traversal of a binary tree, the nodes are visited in:


a) Left-to-right order
b) Right-to-left order
c) Random order
d) Level-order

Answer: a) Left-to-right order

3. What is the sequence of nodes visited during a postorder traversal of a binary tree?
a) Root, left subtree, right subtree
b) Left subtree, right subtree, root
c) Right subtree, root, left subtree
d) Left subtree, root, right subtree

Answer: b) Left subtree, right subtree, root

4. Which traversal is commonly used to delete nodes from a binary search tree?
a) Inorder traversal
b) Preorder traversal
c) Postorder

traversal
d) Level-order traversal

Answer: a) Inorder traversal

5. Level-order traversal of a tree visits the nodes:


a) From the root towards the leaves
b) From the leaves towards the root
c) In a zigzag manner
d) In ascending order of their levels

Answer: a) From the root towards the leaves


6. What is the time complexity of performing an inorder traversal of a binary tree with n nodes?
a) O(n)
b) O(log n)
c) O(n^2)
d) O(2^n)

Answer: a) O(n)

7. The level-order traversal of a binary tree is implemented using a:


a) Depth-first search (DFS) algorithm
b) Breadth-first search (BFS) algorithm
c) Preorder traversal algorithm
d) Postorder traversal algorithm

Answer: b) Breadth-first search (BFS) algorithm

8. In a binary tree, which traversal is used to obtain nodes in ascending order (sorted order)?
a) Inorder traversal
b) Preorder traversal
c) Postorder traversal
d) Level-order traversal

Answer: a) Inorder traversal

**5.4 Binary Trees**

1. A binary tree is a tree data structure in which each node can have:
a) Two children
b) Three children
c) More than three children
d) Any number of children

Answer: a) Two children

2. In a binary tree, the node that has no parent is called the:


a) Root node
b) Leaf node
c) Internal node
d) Sibling node

Answer: a) Root node

3. A full binary tree is a binary tree in which:


a) All nodes have two children, except leaf nodes
b) All nodes have one child, except the root node
c) All nodes have exactly two children
d) All nodes have at least two children

Answer: a) All nodes have two children, except leaf nodes

4. What is the minimum height of a binary tree with n nodes?


a) 0
b) 1
c) log2(n)
d) n

Answer: b) 1

5. A binary tree with all leaf nodes at the same level is called a:
a) Full binary tree
b) Perfect binary tree
c) Balanced binary tree
d) Complete binary tree

Answer: b) Perfect binary tree

6. A binary tree with all internal nodes having exactly one child is called a:
a) Full binary tree
b) Perfect binary tree
c) Balanced binary tree
d) Skewed binary tree

Answer: d) Skewed binary tree

7. A binary tree is considered balanced if:


a) All nodes have two children
b) The heights of the left and right subtrees differ by at most one
c) The number of nodes is a power of two
d) It is a complete binary tree

Answer: b) The heights of the left and right subtrees differ by at most one

8. What is the maximum number of nodes at level k in a binary tree?


a) 2^k
b) 2^(k+1) - 1
c) k
d) 2k

Answer: a) 2^k

**5.5 Complete Binary Trees / Almost Complete Binary Tree (ACBT)**

1. A complete binary tree is a binary tree in which:


a) All nodes have two children, except leaf nodes
b) All nodes have one child, except the root node
c) All levels are completely filled with nodes
d) All internal nodes have exactly one child

Answer: c) All levels are completely filled with nodes

2. In a complete binary tree, if a node has an index i (0-based indexing) in the level-order traversal,
then its left child will have an index of:
a) i - 1
b) 2i
c) 2i + 1
d) i + 1

Answer: c) 2i + 1

3. In a complete binary tree, if a node has an index i (0-based indexing) in the level-order traversal,
then its right child will have an index of:
a) i - 1
b) 2i
c) 2i + 1
d) i + 1

Answer: c) 2i + 1

4. In a complete binary tree with n nodes, what is the maximum height of the tree?
a) log2(n)
b) n
c) n - 1
d) n + 1

Answer: a) log2(n)

5. What is the minimum number of nodes in a complete binary tree of height h?


a) 2^h - 1
b) 2^h
c) h
d) h + 1

Answer: b) 2^h

6. An almost complete binary tree (ACBT) is a binary tree that:


a) Has all levels completely filled

with nodes
b) Is a perfect binary tree
c) Is a full binary tree
d) Is a complete binary tree, but some nodes are missing from the last level

Answer: d) Is a complete binary tree, but some nodes are missing from the last level

7. In an almost complete binary tree (ACBT), the last level may not be completely filled, but:
a) All internal nodes have two children
b) The number of nodes at each level is the same
c) The left subtree is completely filled
d) The right subtree is completely filled

Answer: b) The number of nodes at each level is the same

8. What is the key property that distinguishes an almost complete binary tree (ACBT) from a complete
binary tree?
a) The height of the tree
b) The number of nodes
c) The number of children per node
d) The completeness of the last level

Answer: d) The completeness of the last level

**5.6 Array Implementation of ACBT**

1. In an array implementation of an almost complete binary tree (ACBT), if a node is at index i, what
are the indices of its left child and right child, respectively?
a) 2i and 2i + 1
b) i - 1 and i + 1
c) i + 1 and i + 2
d) i and i + 1

Answer: a) 2i and 2i + 1

2. In an array implementation of an almost complete binary tree (ACBT), what is the index of the
parent node of a node at index i?
a) i / 2
b) i - 1
c) i + 1
d) i * 2

Answer: a) i / 2
3. If an array is used to represent an almost complete binary tree (ACBT) of n nodes, what will be the
size of the array?
a) n
b) n + 1
c) 2n
d) 2n + 1

Answer: a) n

4. In an array implementation of an almost complete binary tree (ACBT), the elements of the tree are
stored in the array such that:
a) All elements are stored in ascending order
b) The root element is at the first index (index 0)
c) The elements are stored in a zigzag manner
d) The parent node is always greater than its children

Answer: b) The root element is at the first index (index 0)

5. The array implementation of an almost complete binary tree (ACBT) saves memory compared to a
linked representation because:
a) It requires fewer nodes to represent the tree
b) It eliminates the need for pointers to link nodes
c) It allows for faster tree traversal
d) It has a smaller height

Answer: b) It eliminates the need for pointers to link nodes

6. In an array representation of an almost complete binary tree (ACBT), if a node is at index i, and i is
greater than the size of the array, it indicates that:
a) The tree is not an ACBT
b) The node is a leaf node
c) The node has no children
d) The node is missing from the tree

Answer: d) The node is missing from the tree

7. One disadvantage of using an array to represent an almost complete binary tree (ACBT) is that:
a) It requires more memory compared to linked representation
b) It is difficult to perform insertion and deletion operations
c) It is not possible to find the parent of a node
d) It cannot handle trees with more than 100 nodes

Answer: b) It is difficult to perform insertion and deletion operations

8. When converting an ACBT into an array representation, the nodes are stored in the array in a
specific order to maintain:
a) Balanced height of the tree
b) The heap property of the tree
c) The completeness of the last level
d) The maximum number of nodes at each level

Answer: c) The completeness of the last level

**5.7 Binary Search Trees**

1. In a binary search tree (BST), the key value of the left child is:
a) Greater than the key value of the parent
b) Less than the key value of the parent
c) Equal to the key value of the parent
d) Unrelated to the key value of the parent

Answer: b) Less than the key value of the parent

2. In a binary search tree (BST), the key value of the right child is:
a) Greater than the key value of the parent
b) Less than the key value of the parent
c) Equal to the key value of the parent
d) Unrelated to the key value of the parent

Answer: a) Greater than the key value of the parent

3. The binary search tree (BST) property allows for efficient searching of elements because:
a) All elements are stored in a sorted order
b) All elements have unique key values
c) All elements have the same key value
d) The tree is perfectly balanced

Answer: a) All elements are stored in a sorted order

4. In a binary search tree (BST), the minimum element is found by:


a) Following the left child pointers from the root until a leaf node is reached
b) Following the right child pointers from the root until a leaf node is reached
c) Starting from the root and comparing key values with the left and right children
d) Randomly searching for the minimum element

Answer: a) Following the left child pointers from the root until a leaf node is reached

5. In a binary search tree (BST), the maximum element is found by:


a) Following the left child pointers from the root until a leaf node is reached
b) Following the right child pointers from the root until a leaf node is reached
c) Starting from the root and comparing key values with the left and right children
d) Randomly searching for the maximum element

Answer: b) Following the right child pointers from the root until a leaf node is reached

6. Which operation is commonly used to insert a new element into a binary search tree (BST) while
maintaining the BST property?
a) Left rotation
b) Right rotation
c) Preorder traversal
d) Binary search

Answer: d) Binary search

7. In a binary search tree (BST), if a node with a given key value is not found during the search
operation, it indicates that:
a) The tree is not balanced
b) The tree is not an ACBT
c) The node does not exist in the tree
d) The tree is not sorted

Answer: c) The node does not exist in the tree

8. The worst-case time complexity of searching for an element in a binary search tree (BST) with n
nodes is:
a) O(1)
b

) O(log n)
c) O(n)
d) O(n^2)

Answer: b) O(log n)

**5.8 AVL Tree**

1. An AVL tree is a self-balancing binary search tree, where the balance factor of every node is:
a) Greater than 0
b) Less than 0
c) Equal to 0
d) Between -1 and 1

Answer: d) Between -1 and 1

2. In an AVL tree, the balance factor of a node is defined as the difference between:
a) The height of its left subtree and the height of its right subtree
b) The number of nodes in its left subtree and the number of nodes in its right subtree
c) The key value of its left child and the key value of its right child
d) The depth of its left subtree and the depth of its right subtree

Answer: a) The height of its left subtree and the height of its right subtree

3. What operation is performed to balance an AVL tree after inserting a new node?
a) Right rotation
b) Left rotation
c) Preorder traversal
d) Level-order traversal

Answer: a) Right rotation

4. In an AVL tree, after a right rotation is performed on a node, which node becomes the new parent of
the subtree?
a) The left child of the node
b) The right child of the node
c) The parent of the node
d) The grandparent of the node

Answer: b) The right child of the node

5. The height of an AVL tree with n nodes is guaranteed to be:


a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)

Answer: b) O(log n)

6. In an AVL tree, after a left rotation is performed on a node, which node becomes the new parent of
the subtree?
a) The left child of the node
b) The right child of the node
c) The parent of the node
d) The grandparent of the node

Answer: a) The left child of the node

7. In an AVL tree, the balancing operation is triggered when the balance factor of a node becomes:
a) 0
b) 1
c) -1
d) Outside the range of -1 to 1

Answer: d) Outside the range of -1 to 1

8. The main advantage of using AVL trees over regular binary search trees is that AVL trees:
a) Have faster search operations
b) Require less memory
c) Support more operations
d) Ensure a balanced height, resulting in faster overall operations

Answer: d) Ensure a balanced height, resulting in faster overall operations

**5.9 Multi-way Tree**

1. A multi-way tree is a tree in which each internal node can have:


a) One child
b) Two children
c) Multiple children
d) Only leaf nodes

Answer: c) Multiple children

2. In a multi-way tree, the number of children a node can have is called the:
a) Degree of the node
b) Height of the node
c) Level of the node
d) Depth of the node

Answer: a) Degree of the node

3. The term "m-ary tree" is used to describe a multi-way tree in which:


a) All internal nodes have m children
b) All leaf nodes have m children
c) The root node has m children
d) The tree has exactly m levels

Answer: a) All internal nodes have m children

4. A binary tree is a special case of a multi-way tree where each internal node has:
a) One child
b) Two children
c) Three children
d) Multiple children

Answer: b) Two children

5. In a ternary tree, each internal node has:


a) One child
b) Two children
c) Three children
d) Multiple children

Answer: c) Three children

6. The height of a multi-way tree is the:


a) Number of levels in the tree
b) Number of nodes in the tree
c) Number of children of the root node
d) Number of leaf nodes in the tree
Answer: a) Number of levels in the tree

7. A multi-way tree with all internal nodes having the same number of children is called a:
a) Full multi-way tree
b) Perfect multi-way tree
c) Balanced multi-way tree
d) Complete multi-way tree

Answer: a) Full multi-way tree

8. In a multi-way tree, the number of children of a node is called the:


a) Degree of the

node
b) Height of the node
c) Level of the node
d) Depth of the node

Answer: a) Degree of the node

**5.10 Brief Introduction and Uses Cases of B-Tree / B+Tree**

1. A B-tree is a self-balancing multi-way search tree that is commonly used in:


a) Database indexing
b) Artificial intelligence
c) Graph algorithms
d) Image processing

Answer: a) Database indexing

2. In a B-tree, each node can have:


a) One child
b) Two children
c) Multiple children
d) Only leaf nodes

Answer: c) Multiple children

3. The main advantage of using B-trees in database indexing is that B-trees:


a) Have a fixed height
b) Require less memory
c) Ensure fast search and insertion operations on disk
d) Allow for efficient depth-first search

Answer: c) Ensure fast search and insertion operations on disk

4. B-trees are used to maintain:


a) Sorted arrays
b) Sorted linked lists
c) Sorted binary trees
d) Sorted sequences of records on disk

Answer: d) Sorted sequences of records on disk

5. In a B+ tree, all the data records are stored in:


a) Internal nodes
b) Leaf nodes
c) The root node
d) The parent node
Answer: b) Leaf nodes

6. The main advantage of using B+ trees over B-trees is that B+ trees:


a) Have a smaller height
b) Support faster search operations
c) Allow for dynamic changes in degree
d) Use less memory

Answer: b) Support faster search operations

7. B-trees and B+ trees are particularly well-suited for use in databases because they:
a) Minimize the use of disk storage
b) Provide a constant-time search operation
c) Balance the tree automatically
d) Support efficient range queries and ordered traversals

Answer: d) Support efficient range queries and ordered traversals

8. B-trees and B+ trees are commonly used in scenarios where data is stored on secondary storage
devices like hard disks because they:
a) Reduce the number of disk accesses
b) Minimize the use of main memory
c) Support parallel processing
d) Allow for faster processing of complex algorithms

Answer: a) Reduce the number of disk accesses


Lecture 6: Searching & Sorting Algorithms

**6.1 Objectives of Searching**

1. What is the primary objective of searching algorithms?


a) To sort the data in ascending order
b) To find the minimum value in a list
c) To locate a specific item in a collection of data
d) To count the total number of elements in an array

Answer: c) To locate a specific item in a collection of data

2. What is the time complexity of the sequential search algorithm in the worst case?
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)

Answer: c) O(n)

3. The sequential search algorithm is best suited for searching in which type of data structure?
a) Sorted arrays
b) Linked lists
c) Binary search trees
d) Hash tables

Answer: b) Linked lists

4. What is the primary disadvantage of the sequential search algorithm?


a) It can only search for integers
b) It requires the data to be in sorted order
c) It has a high time complexity for large datasets
d) It can only be used with arrays

Answer: c) It has a high time complexity for large datasets

5. In the sequential search algorithm, if the target element is found early in the list, what is the best-
case time complexity?
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)

Answer: a) O(1)

6. The binary search algorithm requires the input data to be in:


a) Ascending order
b) Descending order
c) Random order
d) Any order

Answer: a) Ascending order

**6.1.1 The Sequential Search**

1. The sequential search algorithm starts searching for the target element from the:
a) Last element of the list
b) Middle element of the list
c) First element of the list
d) Randomly selected element of the list
Answer: c) First element of the list

2. The sequential search algorithm compares the target element with each element in the list until:
a) It finds the target element
b) It reaches the middle element of the list
c) The list becomes empty
d) It reaches the last element of the list

Answer: a) It finds the target element

3. What is the worst-case time complexity of the sequential search algorithm?


a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)

Answer: c) O(n)

4. If the target element is not present in the list, the sequential search algorithm will:
a) Output the index of the target element as -1
b) Output the index of the target element as 0
c) Return an empty list
d) Iterate through the entire list without finding the target element

Answer: d) Iterate through the entire list without finding the target element

5. The sequential search algorithm is an example of a:


a) Divide and conquer algorithm
b) Greedy algorithm
c) Recursive algorithm
d) Linear search algorithm

Answer: d) Linear search algorithm

6.1.2 Analysis of Sequential Search

1. The time complexity of the sequential search algorithm in the best-case scenario is:
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)

Answer: a) O(1)

2. In the worst-case scenario, when the target element is not present in the list, the sequential search
algorithm will perform how many comparisons?
a) 1
b) n
c) n/2
d) n-1

Answer: d) n-1

3. The sequential search algorithm is efficient for searching in:


a) Sorted arrays
b) Linked lists
c) Binary search trees
d) Hash tables
Answer: b) Linked lists

4. The time complexity of the sequential search algorithm in the average-case scenario is:
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)

Answer: c) O(n)

5. The sequential search algorithm works well for small datasets because of its:
a) Low space complexity
b) Low time complexity
c) Ease of implementation
d) Recursive nature

Answer: c) Ease of implementation

6. The sequential search algorithm is classified as a:


a) Recursive algorithm
b) Divide and conquer algorithm
c) Linear search algorithm
d) Greedy algorithm

Answer: c) Linear search algorithm

**6.1.3 The Binary Search**

1. The binary search algorithm is applicable only to:


a) Sorted arrays
b) Linked lists
c) Hash tables
d) Binary search trees

Answer: a) Sorted arrays

2. The binary search algorithm divides the input data into two halves and compares the target element
with the:
a) Middle element of the array
b) First element of the array
c) Last element of the array
d) Randomly selected element of the array

Answer: a) Middle element of the array

3. In each step of the binary search algorithm, half of the remaining elements are:
a) Removed from the search
b) Duplicated for further search
c) Sorted in ascending order
d) Compared with the target element

Answer: a) Removed from the search

4. If the target element is found during the binary search algorithm, it will be at the:
a) First index of the array
b) Last index of the array
c) Middle index of the array
d) Any index of the array

Answer: c) Middle index of the array


5. What is the time complexity of the binary search algorithm in the worst case?
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)

Answer: b) O(log n)

6. In the binary search algorithm, if the target element is greater than the middle element of the array,
the search continues in the:
a) Left half of the array
b) Right half of the array
c) Middle element of the array
d) Any random half of the array

Answer: b) Right half of the array

**6.2 Analysis of Binary Search**

1. The time complexity of the binary search algorithm in the best-case scenario is:
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)

Answer: b) O(log n)

2. In the worst-case scenario, when the target element is not present in the sorted array, the binary
search algorithm will perform how many comparisons?
a) 1
b) log n
c) n
d) n/2

Answer: b) log n

3. The binary search algorithm is efficient for searching in:


a) Unsorted arrays
b

) Linked lists
c) Hash tables
d) Sorted arrays

Answer: d) Sorted arrays

4. The time complexity of the binary search algorithm in the average-case scenario is:
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)

Answer: b) O(log n)

5. The binary search algorithm works well for large datasets because of its:
a) Low space complexity
b) Low time complexity
c) Ease of implementation
d) Recursive nature
Answer: b) Low time complexity

6. The binary search algorithm is classified as a:


a) Recursive algorithm
b) Divide and conquer algorithm
c) Linear search algorithm
d) Greedy algorithm

Answer: b) Divide and conquer algorithm

**6.3 Introduction to Sorting**

1. Sorting is the process of arranging elements in:


a) Random order
b) Ascending order
c) Descending order
d) Any order

Answer: b) Ascending order

2. Which of the following is not an example of a sorting algorithm?


a) QuickSort
b) Bubble Sort
c) Depth-First Search (DFS)
d) Merge Sort

Answer: c) Depth-First Search (DFS)

3. Sorting algorithms are commonly used in various applications, including:


a) Database management systems
b) Image processing
c) Data compression
d) All of the above

Answer: d) All of the above

4. The time complexity of a sorting algorithm is primarily measured by the number of:
a) Comparisons and swaps performed
b) Loops used in the algorithm
c) Recursion calls made
d) Random choices made during the process

Answer: a) Comparisons and swaps performed

5. In a stable sorting algorithm, elements with equal keys maintain their relative order in the:
a) Original array
b) Final sorted array
c) Middle of the array
d) Random positions in the array

Answer: b) Final sorted array

6.3.1 Selection Sort

1. The selection sort algorithm works by repeatedly finding the:


a) Smallest element in the unsorted part of the array
b) Largest element in the unsorted part of the array
c) Middle element in the unsorted part of the array
d) Randomly selected element in the unsorted part of the array
Answer: a) Smallest element in the unsorted part of the array

2. In each iteration of the selection sort algorithm, the selected smallest element is placed at the:
a) Beginning of the array
b) End of the array
c) Middle of the array
d) Random position in the array

Answer: a) Beginning of the array

3. What is the time complexity of the selection sort algorithm in the best case?
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)

Answer: d) O(n^2)

4. Selection sort is an example of a:


a) Divide and conquer algorithm
b) Greedy algorithm
c) Recursive algorithm
d) Linear search algorithm

Answer: b) Greedy algorithm

5. The selection sort algorithm is not suitable for sorting large datasets because of its:
a) Low time complexity
b) Low space complexity
c) High time complexity
d) High space complexity

Answer: c) High time complexity

6. In the selection sort algorithm, the number of comparisons performed is:


a) Equal to the number of elements in the array
b) Equal to half of the number of elements in the array
c) Equal to the number of inversions in the array
d) Equal to the square of the number of elements in the array

Answer: d) Equal to the square of the number of elements in the array

**6.3.2 Insertion Sort**

1. The insertion sort algorithm works by dividing the input array into:
a) Two equal halves
b) Two sorted and unsorted parts
c) Three equal parts
d) Multiple subarrays

Answer: b) Two sorted and unsorted parts

2. In each iteration of the insertion sort algorithm, the algorithm picks an element from the unsorted
part and places it in the correct position within the:
a) Unsorted part of the array
b) Sorted part of the array
c) Middle of the array
d) Random position in the array
Answer: b) Sorted part of the array

3. What is the time complexity of the insertion sort algorithm in the best case?
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)

Answer: c) O(n)

4. Insertion sort is an example of a:


a) Divide and conquer algorithm
b) Greedy algorithm
c) Recursive algorithm
d) Linear search algorithm

Answer: d) Linear search algorithm

5. The insertion sort algorithm is well-suited for:


a) Sorting linked lists
b) Sorting large datasets
c) Sorting arrays with a small number of elements
d) Sorting arrays in descending order

Answer: a) Sorting linked lists

6. In the insertion sort algorithm, the number of swaps performed is:


a) Equal to the number of elements in the array
b) Equal to half of the number of elements in the array
c) Equal to the number of inversions in the array
d) Equal to the square of the number of elements in the array

Answer: c) Equal to the number of inversions in the array

**6.3.3 Bubble Sort**

1. The bubble sort algorithm works by repeatedly comparing adjacent elements and swapping them if
they are in:
a) Random order
b) Ascending order
c) Descending order
d) Any order

Answer: c) Descending order

2. In each iteration of the bubble sort algorithm, the largest element "bubbles up" to the:
a) Beginning of the array
b) End of the array
c) Middle of the array
d) Random position in the

array

Answer: b) End of the array

3. What is the time complexity of the bubble sort algorithm in the best case?
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)
Answer: c) O(n)

4. Bubble sort is an example of a:


a) Divide and conquer algorithm
b) Greedy algorithm
c) Recursive algorithm
d) Linear search algorithm

Answer: d) Linear search algorithm

5. The bubble sort algorithm is well-suited for:


a) Sorting large datasets
b) Sorting arrays with a small number of elements
c) Sorting linked lists
d) Sorting arrays in descending order

Answer: b) Sorting arrays with a small number of elements

6. In the bubble sort algorithm, the number of comparisons performed is:


a) Equal to the number of elements in the array
b) Equal to half of the number of elements in the array
c) Equal to the number of inversions in the array
d) Equal to the square of the number of elements in the array

Answer: d) Equal to the square of the number of elements in the array

**6.3.4 Heapsort**

1. Heapsort is a sorting algorithm based on:


a) Merge of two sorted arrays
b) Divide and conquer approach
c) Building and maintaining a heap data structure
d) Random swapping of elements

Answer: c) Building and maintaining a heap data structure

2. The heap data structure used in heapsort is a:


a) Balanced binary search tree
b) Complete binary tree
c) Linked list
d) Hash table

Answer: b) Complete binary tree

3. In heapsort, the largest element is repeatedly removed from the heap and placed at the:
a) Root of the heap
b) Leaf of the heap
c) Middle of the heap
d) Random position in the heap

Answer: a) Root of the heap

4. What is the time complexity of the heapsort algorithm in the best case?
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)

Answer: c) O(n)
5. Heapsort is an example of a:
a) Divide and conquer algorithm
b) Greedy algorithm
c) Recursive algorithm
d) Linear search algorithm

Answer: a) Divide and conquer algorithm

6. In the heapsort algorithm, the number of swaps performed is:


a) Equal to the number of elements in the array
b) Equal to half of the number of elements in the array
c) Equal to the number of inversions in the array
d) Equal to the height of the heap

Answer: c) Equal to the number of inversions in the array

**6.3.5 Mergesort**

1. Mergesort is a sorting algorithm based on:


a) Divide and conquer approach
b) Building and maintaining a heap data structure
c) Random swapping of elements
d) Sequential search of elements

Answer: a) Divide and conquer approach

2. In mergesort, the input array is divided into smaller subarrays until each subarray contains:
a) One element
b) Two elements
c) Three elements
d) Four elements

Answer: a) One element

3. The process of combining two sorted subarrays into a single sorted array is called:
a) Merge
b) Split
c) Heapify
d) Swap

Answer: a) Merge

4. What is the time complexity of the mergesort algorithm in the best case?
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)

Answer: c) O(n)

5. Mergesort is an example of a:
a) Divide and conquer algorithm
b) Greedy algorithm
c) Recursive algorithm
d) Linear search algorithm

Answer: a) Divide and conquer algorithm

6. In the mergesort algorithm, the number of comparisons performed is:


a) Equal to the number of elements in the array
b) Equal to half of the number of elements in the array
c) Equal to the number of inversions in the array
d) Equal to the height of the tree

Answer: a) Equal to the number of elements in the array

**6.3.6 Quicksort**

1. Quicksort is a sorting algorithm based on:


a) Merge of two sorted arrays
b) Divide and conquer approach
c) Building and maintaining a heap data structure
d) Random swapping of elements

Answer: b) Divide and conquer approach

2. In quicksort, the input array is partitioned into two subarrays such that elements in one subarray are:
a) Smaller than the pivot element
b) Greater than the pivot element
c) Equal to the pivot element
d) In random order with respect to the pivot element

Answer: a) Smaller than the pivot element

3. The pivot element in quicksort is usually chosen as the:


a) First element of the array
b) Middle element of the array
c) Last element of the array
d) Randomly selected element of the array

Answer: c) Last element of the array

4. What is the time complexity of the quicksort algorithm in the best case?
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)

Answer: c) O(n)

5. Quicksort is an example of a:
a) Divide and conquer algorithm
b) Greedy algorithm
c) Recursive algorithm
d) Linear search algorithm

Answer: a) Divide and conquer algorithm

6. In the quicksort algorithm, the number of swaps performed is:


a) Equal to the number of elements in the array
b) Equal to half of the number of elements in the array
c) Equal to the number of inversions in the array
d) Equal to the height of the recursion tree

Answer: c) Equal to the number of inversions in the array

**6.4 Analysis of Sorting Algorithms**

1. The time complexity of sorting algorithms is generally expressed in terms of the number of:
a) Swaps performed
b) Loops used in the algorithm
c) Comparisons performed
d) Recursive calls made

Answer: c) Comparisons performed

2. Which sorting algorithm has the lowest time complexity in the best-case scenario?
a) Selection sort
b) Bubble sort
c) Quick sort
d) Merge sort

Answer: c) Quick sort

3. A stable sorting algorithm maintains the relative order of elements with equal keys in the:
a) Original array
b) Final sorted array
c) Middle of the array
d) Random positions in the array

Answer: b) Final sorted array

4. Which of the following sorting algorithms is not an example of a comparison-based sorting


algorithm?
a) Insertion sort
b) Counting sort
c) Quick sort
d) Merge sort

Answer: b) Counting sort

5. The worst-case time complexity of a sorting algorithm gives the upper bound on the time required to
sort the data when the data is:
a) Sorted in ascending order
b) Sorted in descending order
c) Sorted in any order
d) Sorted in reverse order

Answer: b) Sorted in descending order

6.4.1 Selection Sort

1. The selection sort algorithm has a time complexity of O(n^2) in both the best and worst cases.
a) True
b) False

Answer: a) True

2. Selection sort is an example of a stable sorting algorithm.


a) True
b) False

Answer: b) False

3. Selection sort works well for large datasets due to its efficient time complexity.
a) True
b) False

Answer: b) False
4. The main advantage of selection sort is its low space complexity.
a) True
b) False

Answer: a) True

5. The number of swaps performed by selection sort is proportional to the number of elements in the
array.
a) True
b) False

Answer: a) True

6.4.2 Insertion Sort

1. The insertion sort algorithm has a time complexity of O(n) in the best case.
a) True
b) False

Answer: a) True

2. Insertion sort is an example of a stable sorting algorithm.


a) True
b) False

Answer: a) True

3. Insertion sort is well-suited for sorting linked lists due to its low time complexity.
a) True
b) False

Answer: a) True

4. The number of comparisons performed by insertion sort is proportional to the number of elements in
the array.
a) True
b) False

Answer: a) True

5. The main advantage of insertion sort is its efficient performance on large datasets.
a) True
b) False

Answer: b) False

6.4.3 Bubble Sort

1. The bubble sort algorithm has a time complexity of O(n^2) in the best case.
a) True
b) False

Answer: a) True

2. Bubble sort is an example of a stable sorting algorithm.


a) True
b) False

Answer: a) True
3. Bubble sort is well-suited for sorting arrays with a small number of elements due to its low time
complexity.
a) True
b) False

Answer: a) True

4. The number of swaps performed by bubble sort is proportional to the number of elements in the
array.
a) True
b) False

Answer: a) True

5. The main advantage of bubble sort is its efficient performance on large datasets.
a) True
b) False

Answer: b) False

6.4.4 Heapsort

1. The heapsort algorithm has a time complexity of O(n log n) in the best case.
a) True
b) False

Answer: a) True

2. Heapsort is an example of a stable sorting algorithm.


a) True
b) False

Answer: b) False

3. Heapsort is well-suited for sorting linked lists due to its low time complexity.
a) True
b) False

Answer: b) False

4. The number of comparisons performed by heapsort is proportional to the number of elements in the
array.
a) True
b) False

Answer: a) True

5. The main advantage of heapsort is its efficient performance on large datasets.


a) True
b) False

Answer: a) True

6.4.5 Mergesort

1. The mergesort algorithm has a time complexity of O(n log n) in the best case.
a) True
b) False
Answer: a) True

2. Mergesort is an example of a stable sorting algorithm.


a) True
b) False

Answer: a) True

3. Mergesort is well-suited for sorting arrays with a small number of elements due to its low time
complexity.
a) True
b) False

Answer: b) False

4. The number of swaps performed by mergesort is proportional to the number of elements in the array.
a) True
b) False

Answer: b) False

5. The main advantage of mergesort is its efficient performance on large datasets.


a) True
b) False

Answer: a) True
Lecture 7: Hash Functions and Hash Tables
**7.1 Hashing & Introduction to Hash Tables**

1. Hashing is a technique used to:


a) Sort elements in ascending order
b) Retrieve data from a database
c) Map data to a fixed-size array
d) Create linked lists

Answer: c) Map data to a fixed-size array

2. Hashing is commonly used to improve the efficiency of:


a) Sorting algorithms
b) Searching algorithms
c) Recursive algorithms
d) Greedy algorithms

Answer: b) Searching algorithms

3. The data structure that uses hashing to store and retrieve data is called a:
a) Linked list
b) Binary tree
c) Hash table
d) Stack

Answer: c) Hash table

4. The purpose of a hash function is to:


a) Generate random numbers
b) Convert data into a unique numeric value
c) Sort data in ascending order
d) Merge two arrays

Answer: b) Convert data into a unique numeric value

5. Hash tables use an array to store data, and the array index is determined by the hash function. What
is the term used for the array index?
a) Hash value
b) Hash key
c) Hash code
d) Hash index

Answer: d) Hash index

6. In hashing, what is the name given to the process of converting a key into its corresponding hash
value/index?
a) Hashing
b) Collision resolution
c) Hash function
d) Hashing algorithm

Answer: c) Hash function

7. Which of the following is NOT a common application of hashing?


a) Cryptography
b) Spell-checking
c) Database indexing
d) Sorting
Answer: d) Sorting

8. When two different keys generate the same hash value, it is called:
a) Clustering
b) Hash collision
c) Hash table overflow
d) Linear probing

Answer: b) Hash collision

**7.2 Hash Functions**

1. A good hash function should have the property of:


a) Collisions
b) Determinism
c) Deterministic collisions
d) Uniform distribution

Answer: d) Uniform distribution

2. The output of a hash function is typically a:


a) String
b) Float number
c) Integer value
d) Linked list

Answer: c) Integer value

3. The goal of a hash function is to minimize:


a) Collisions
b) Hash table size
c) Uniform distribution
d) Load factor

Answer: a) Collisions

4. Which of the following is not a requirement for a good hash function?


a) Determinism
b) Uniform distribution
c) Reversibility
d) Efficiency

Answer: c) Reversibility

5. Which of the following is a disadvantage of using a hash function with poor distribution properties?
a) Reduced collision probability
b) Increased load factor
c) Slower hash table resizing
d) Reduced memory usage

Answer: b) Increased load factor

6. Which of the following hash functions is more likely to cause clustering in a hash table?
a) A hash function with uniform distribution
b) A hash function that always returns the same hash value
c) A hash function that multiplies the key by a prime number
d) A hash function that performs bitwise XOR on the key

Answer: b) A hash function that always returns the same hash value
7. One approach to handling hash collisions is to use a separate data structure to store multiple values
that share the same hash index. What is this data structure called?
a) Linked list
b) Binary tree
c) Stack
d) Queue

Answer: a) Linked list

8. Which of the following statements is true about hash functions?


a) A perfect hash function guarantees no collisions.
b) A perfect hash function is always efficient to compute.
c) A perfect hash function is always reversible.
d) A perfect hash function maps all keys to the same hash value.

Answer: a) A perfect hash function guarantees no collisions.

**7.3 Different Types of Hash Functions**

1. The division method is a type of hash function that uses:


a) Bitwise operations
b) Multiplication by a prime number
c) Division by a prime number
d) Exponential functions

Answer: c) Division by a prime number

2. The multiplication method is a type of hash function that involves:


a) Multiplying the key by a prime number and taking the remainder
b) Taking the bitwise XOR of the key and a prime number
c) Dividing the key by a prime number and taking the quotient
d) Adding the key and a prime number

Answer: a) Multiplying the key by a prime number and taking the remainder

3. The folding method is a type of hash function that:


a) Involves bitwise shifting of the key
b) Breaks the key into several parts, adds them, and takes the remainder
c) Multiplies the key by a prime number
d) Involves taking the bitwise OR of the key and a prime number

Answer: b) Breaks the key into several parts, adds them, and takes the remainder

4. The mid-square method is a type of hash function that:


a) Involves taking the square root of the key
b) Multiplies the key by itself and takes the middle digits
c) Adds the key and a prime number
d) Uses bitwise XOR to modify the key

Answer: b) Multiplies the key by itself and takes the middle digits

5. Which of the following is an advantage of using the mid-square method for hashing?
a) It provides a more uniform distribution of hash values.
b) It is computationally less expensive than other methods.
c) It guarantees no collisions for all input keys.
d) It is easy to implement and requires little additional memory.

Answer: a) It provides a more uniform distribution of hash values.

6. Which of the following statements is true about the folding method?


a) It is less prone to clustering compared to the division method.
b) It is not affected by the size of the hash table.
c) It requires the least amount of computation among all hash functions.
d) It always guarantees a unique hash value for each input key.

Answer: a) It is less prone to clustering compared to the division method.

7. The folding method is particularly useful when:


a) The hash table size is fixed.
b) The keys are represented as floating-point numbers.
c) The keys have fixed length and structure.
d) The hash table uses linear probing for collision resolution.

Answer: c) The keys have fixed length and structure.

8. Which of the following statements is true about hash functions?


a) A hash function that produces a unique hash value for each unique key is always a good hash
function.
b) The mid-square method is a deterministic

hash function.
c) All hash functions involve bitwise operations on the input key.
d) Folding method can only be used with positive integer keys.

Answer: b) The mid-square method is a deterministic hash function.

**7.4 Collision Resolution**

1. Collision occurs in a hash table when:


a) The hash function produces the same value for two different keys
b) The hash table is full
c) The hash table is empty
d) The hash function is not deterministic

Answer: a) The hash function produces the same value for two different keys

2. Collision resolution techniques are used to:


a) Increase the size of the hash table
b) Avoid collisions
c) Handle and resolve collisions
d) Reduce the load factor of the hash table

Answer: c) Handle and resolve collisions

3. Which of the following is NOT a common collision resolution technique?


a) Linear probing
b) Quadratic probing
c) Binary search
d) Double hashing

Answer: c) Binary search

4. Collision resolution techniques aim to maintain the property of:


a) Determinism
b) Collisions
c) Load factor
d) Uniform distribution

Answer: d) Uniform distribution


5. Which of the following statements is true about collision resolution techniques?
a) Linear probing always guarantees no collisions in a hash table.
b) Quadratic probing is less prone to clustering than linear probing.
c) Double hashing always requires a larger hash table size than other techniques.
d) Separate chaining uses an additional data structure to store collided elements.

Answer: d) Separate chaining uses an additional data structure to store collided elements.

6. In the separate chaining collision resolution technique, each bucket in the hash table is a:
a) Linked list
b) Binary tree
c) Fixed-size array
d) Circular queue

Answer: a) Linked list

7. The main advantage of separate chaining is:


a) Reduced memory usage
b) Efficient space utilization
c) Lower time complexity for insertion and search
d) Higher load factor for the hash table

Answer: c) Lower time complexity for insertion and search

8. The performance of separate chaining depends on:


a) The size of the hash table
b) The type of hashing algorithm used
c) The number of hash collisions
d) The number of elements in the hash table

Answer: c) The number of hash collisions

**7.5 Linear Probing**

1. Linear probing is a collision resolution technique that:


a) Uses a linked list to store collided elements
b) Searches for an empty slot by incrementing the index linearly
c) Searches for an empty slot by decrementing the index linearly
d) Rehashes the key to resolve collisions

Answer: b) Searches for an empty slot by incrementing the index linearly

2. The main advantage of linear probing is:


a) Efficient space utilization
b) Low time complexity for search operations
c) Low time complexity for insertion operations
d) Uniform distribution of keys

Answer: b) Low time complexity for search operations

3. The primary drawback of linear probing is:


a) Increased likelihood of clustering
b) High time complexity for search operations
c) High time complexity for insertion operations
d) Decreased load factor

Answer: a) Increased likelihood of clustering

4. Linear probing may cause performance degradation when the load factor of the hash table:
a) Is close to 0.5
b) Is close to 1
c) Is greater than 1
d) Is less than 1

Answer: b) Is close to 1

5. Linear probing can lead to a phenomenon called "primary clustering." What does primary clustering
refer to in linear probing?
a) Keys that hash to the same index form a chain
b) Collided elements are placed at the beginning of the table
c) Collided elements are evenly distributed across the table
d) The hash table is resized to accommodate more elements

Answer: a) Keys that hash to the same index form a chain

6. Which of the following statements is true about linear probing?


a) It guarantees no collisions in the hash table.
b) It is faster than quadratic probing for searching.
c) It always requires more space than separate chaining.
d) It is not affected by the initial size of the hash table.

Answer: b) It is faster than quadratic probing for searching.

7. The efficiency of linear probing is highly dependent on:


a) The hash function used
b) The number of elements in the hash table
c) The size of the hash table
d) The number of collisions in the hash table

Answer: c) The size of the hash table

8. The linear probing technique usually requires __________ additional memory compared to separate
chaining.
a) More
b) Less
c) The same amount of
d) No

Answer: b) Less

**7.6 Quadratic Probing**

1. Quadratic probing is a collision resolution technique that:


a) Uses a linked list to store collided elements
b) Searches for an empty slot by incrementing the index quadratically
c) Searches for an empty slot by decrementing the index quadratically
d) Rehashes the key to resolve collisions

Answer: b) Searches for an empty slot by incrementing the index quadratically

2. The main advantage of quadratic probing is:


a) Efficient space utilization
b) Low time complexity for search operations
c) Low time complexity for insertion operations
d) Uniform distribution of keys

Answer: a) Efficient space utilization

3. The primary drawback of quadratic probing is:


a) Increased likelihood of clustering
b) High time complexity for search operations
c) High time complexity for insertion operations
d) Decreased load factor

Answer: a) Increased likelihood of clustering

4. Quadratic probing may cause performance degradation when the load factor of the hash table:
a) Is close to 0.5
b) Is close to 1
c) Is greater than 1
d) Is less than 1

Answer: b) Is close to 1

5. Quadratic probing can mitigate the problem of primary clustering experienced in linear probing.
How does quadratic probing achieve this?
a) By rehashing the keys that cause primary clustering
b) By evenly distributing collided elements across the table
c) By incrementing the index quadratically to find empty slots
d) By using a different hash function for quadratic probing

Answer: c) By incrementing the index quadratically to find empty slots

6. Which of the following statements is true about quadratic probing?


a) It guarantees no collisions in the hash table.
b) It is faster than linear probing for searching.
c) It requires more memory than separate chaining.
d) It does not suffer from secondary clustering.

Answer: d) It does not suffer from secondary clustering.

7. The efficiency of quadratic probing depends on:


a) The initial size of the hash table
b) The number of elements in the hash table
c) The type of keys being hashed
d) The load factor of the hash table

Answer: b) The number of elements in the hash table

8. Quadratic probing

can handle more collisions compared to linear probing before causing primary clustering. What is the
primary advantage of this property?
a) It allows for faster search operations.
b) It requires less memory for the hash table.
c) It reduces the need for hash table resizing.
d) It guarantees a lower load factor.

Answer: c) It reduces the need for hash table resizing.

**7.7 Double Hashing**

1. Double hashing is a collision resolution technique that:


a) Uses a linked list to store collided elements
b) Uses two different hash functions to find an empty slot
c) Uses the same hash function for the first and second probes
d) Rehashes the key to resolve collisions

Answer: b) Uses two different hash functions to find an empty slot


2. In double hashing, the second hash function is used to calculate:
a) The offset for the primary cluster
b) The step size for the linear probe
c) The index to probe for an empty slot
d) The initial hash value for the key

Answer: c) The index to probe for an empty slot

3. The main advantage of double hashing is:


a) Efficient space utilization
b) Low time complexity for search operations
c) Low time complexity for insertion operations
d) Uniform distribution of keys

Answer: d) Uniform distribution of keys

4. Double hashing may cause performance degradation when the load factor of the hash table:
a) Is close to 0.5
b) Is close to 1
c) Is greater than 1
d) Is less than 1

Answer: b) Is close to 1

5. Double hashing can handle primary clustering that occurs in linear probing. How does double
hashing achieve this?
a) By using two different hash functions to distribute collided elements
b) By rehashing the keys that cause primary clustering
c) By using a quadratic step size for the linear probe
d) By creating a separate linked list for collided elements

Answer: a) By using two different hash functions to distribute collided elements

6. Which of the following statements is true about double hashing?


a) It guarantees no collisions in the hash table.
b) It is faster than linear probing for searching.
c) It requires more memory than separate chaining.
d) It is immune to primary clustering.

Answer: d) It is immune to primary clustering.

7. The performance of double hashing is dependent on:


a) The size of the hash table
b) The number of elements in the hash table
c) The type of keys being hashed
d) The load factor of the hash table

Answer: a) The size of the hash table

8. Which of the following is an advantage of using double hashing over linear probing?
a) Lower likelihood of collisions
b) Faster search operations
c) Reduced primary clustering
d) Better space utilization

Answer: c) Reduced primary clustering

**7.8 Inserting and Deleting an Element from a Hash Table**


1. When inserting a new element into a hash table using separate chaining, where should the element be
placed?
a) At the first available slot in the hash table
b) At the beginning of the linked list in the corresponding bucket
c) At the end of the linked list in the corresponding bucket
d) At the position determined by the second hash function

Answer: c) At the end of the linked list in the corresponding bucket

2. In separate chaining, if the load factor of the hash table is high, what can be done to avoid hash table
overflow?
a) Resize the hash table to increase its size
b) Use linear probing for collision resolution
c) Use quadratic probing for collision resolution
d) Use a different hash function

Answer: a) Resize the hash table to increase its size

3. When deleting an element from a hash table using separate chaining, what should be done with the
linked list in the corresponding bucket?
a) Delete the linked list
b) Remove the element from the linked list
c) Rehash the linked list
d) Reverse the linked list

Answer: b) Remove the element from the linked list

4. In double hashing, how is the step size for the linear probe determined?
a) By the first hash function
b) By the second hash function
c) By the difference between the hash values generated by the two hash functions
d) By the load factor of the hash table

Answer: b) By the second hash function

5. Which collision resolution technique has the least likelihood of causing secondary clustering?
a) Linear probing
b) Quadratic probing
c) Double hashing
d) Separate chaining

Answer: c) Double hashing

6. When using quadratic probing for collision resolution, what happens if the computed index for the
next probe exceeds the size of the hash table?
a) The probe continues from the beginning of the hash table.
b) The probe continues from the last available slot in the hash table.
c) The probe wraps around to the initial position and starts again.
d) The element is placed in the next available slot in the hash table.

Answer: c) The probe wraps around to the initial position and starts again.

7. In double hashing, what is the primary purpose of using two different hash functions?
a) To reduce the number of collisions
b) To ensure uniform distribution of keys
c) To avoid hash table overflow
d) To improve search efficiency

Answer: a) To reduce the number of collisions


8. Which of the following is a common approach to handle hash table overflow when using separate
chaining?
a) Rehashing the entire hash table
b) Increasing the size of the hash table
c) Using a different hash function
d) Implementing linear probing

Answer: b) Increasing the size of the hash table


Lecture 8: Graphs & Applications

**8.1 Introduction to graph theory**

1. Graph theory is the study of:


a) Mathematical functions and equations
b) Relationships between objects and their connections
c) Data analysis and visualization techniques
d) Artificial intelligence and machine learning

Answer: b) Relationships between objects and their connections

2. A graph in graph theory consists of:


a) Vertices and edges
b) Equations and variables
c) Rows and columns
d) Points and lines

Answer: a) Vertices and edges

3. In a graph, vertices represent:


a) The paths between edges
b) The connections or entities
c) The mathematical functions
d) The axis labels

Answer: b) The connections or entities

4. What is the purpose of using graph theory?


a) To solve numerical equations
b) To analyze large datasets
c) To visualize complex relationships
d) To perform statistical analysis

Answer: c) To visualize complex relationships

5. Which of the following is NOT a real-world application of graph theory?


a) Social network analysis
b) Route planning and optimization
c) Image and speech recognition
d) Computer networks and communication

Answer: c) Image and speech recognition

**8.2 Graph Terminology**

6. The degree of a vertex in a graph is:


a) The number of edges connected to that vertex
b) The sum of all the vertex values in the graph
c) The total number of vertices in the graph
d) The number of connected components in the graph

Answer: a) The number of edges connected to that vertex

7. A graph is called "undirected" when:


a) It has no cycles
b) It has multiple connected components
c) The edges have direction or arrows
d) The edges have no direction or arrows
Answer: d) The edges have no direction or arrows

8. What does a "cycle" in a graph mean?


a) A set of vertices without any edges
b) A path that starts and ends at the same vertex
c) A collection of disconnected components
d) A set of edges without any vertices

Answer: b) A path that starts and ends at the same vertex

9. A graph with all its vertices connected and no cycles is called:


a) Disconnected graph
b) Directed graph
c) Tree
d) Complete graph

Answer: c) Tree

10. A "subgraph" of a graph is:


a) A graph with fewer vertices than the original graph
b) A graph with additional vertices and edges
c) A graph with the same vertices but different edges
d) A graph with all its vertices having the same degree

Answer: a) A graph with fewer vertices than the original graph

**8.3 Different types of Graphs**

11. A graph is called "connected" when:


a) It has a cycle
b) It has no cycles
c) It has only one vertex
d) There is a path between every pair of vertices

Answer: d) There is a path between every pair of vertices

12. A "directed graph" is a graph where:


a) All edges have the same weight
b) All edges have direction or arrows
c) All vertices have the same degree
d) The graph has no cycles

Answer: b) All edges have direction or arrows

13. In a "weighted graph," the edges:


a) Have no direction
b) Have no weight or value
c) Have direction but no weight
d) Have numerical values or weights

Answer: d) Have numerical values or weights

14. A "complete graph" is a graph where:


a) All vertices have the same degree
b) There is an edge between every pair of vertices
c) There are no cycles
d) All edges have the same weight

Answer: b) There is an edge between every pair of vertices


15. A graph with two or more disconnected components is called:
a) Bipartite graph
b) Connected graph
c) Disconnected graph
d) Cyclic graph

Answer: c) Disconnected graph

**8.4 Representation of Graphs**

**8.4.1 Adjacency Matrix**

16. In an adjacency matrix representation, the value at matrix[i][j] indicates:


a) The weight of the edge between vertex i and vertex j
b) The number of edges between vertex i and vertex j
c) The presence of an edge between vertex i and vertex j
d) The number of neighbors of vertex i

Answer: c) The presence of an edge between vertex i and vertex j

17. The space complexity of an adjacency matrix for an undirected graph with n vertices is:
a) O(n)
b) O(n^2)
c) O(n log n)
d) O(1)

Answer: b) O(n^2)

18. Which statement is true about an adjacency matrix?


a) It is more memory-efficient for sparse graphs
b) It is suitable for graphs with variable-sized vertices
c) It requires less time for graph traversal
d) It is less efficient for adding or removing edges

Answer: d) It is less efficient for adding or removing edges

19. An adjacency matrix representation is ideal for:


a) Unweighted graphs
b) Directed graphs with cycles
c) Graphs with large numbers of disconnected components
d) Graphs with a small number of edges

Answer: c) Graphs with large numbers of disconnected components

20. An adjacency matrix for an undirected graph is:


a) Always symmetric with respect to the main diagonal
b) Symmetric if the graph has no cycles
c) Symmetric if the graph has no isolated vertices
d) Symmetric if all edges have the same weight

Answer: a) Always symmetric with respect to the main diagonal

**8.4.2 Adjacency List**

21. In an adjacency list representation, each vertex maintains:


a) A list of its neighbors
b) A list of its adjacent edges
c) A list of its parent and child vertices
d) A list of its degrees and connections
Answer: a) A list of its neighbors

22. The space complexity of an adjacency list for a graph with n vertices and e edges is:
a) O(n)
b) O(e)
c) O(n + e)
d) O(n * e)

Answer: c) O(n + e)

23. Which statement is true about an adjacency list?


a) It is more memory-efficient for dense graphs
b) It is suitable for graphs with a large number of isolated vertices
c) It requires more time for graph traversal compared to an adjacency matrix
d) It is less efficient for finding the degree of a vertex

Answer: a) It is more memory-efficient for dense graphs

24. An adjacency list representation is ideal for:


a) Graphs with a small number of edges
b) Directed graphs with cycles

c) Graphs with a large number of isolated vertices


d) Unweighted graphs

Answer: a) Graphs with a small number of edges

25. In an adjacency list representation, the time complexity to check if there is an edge between two
vertices is:
a) O(1)
b) O(log n)
c) O(n)
d) O(e)

Answer: a) O(1)

**8.4.3 Graph Traversal Algorithms (Breadth First Search, Depth First Search)**

26. Breadth First Search (BFS) explores the graph in which order?
a) From the deepest nodes to the root
b) From the first encountered vertex to the last
c) From the source vertex to the farthest vertices
d) From the last encountered vertex to the first

Answer: c) From the source vertex to the farthest vertices

27. Depth First Search (DFS) uses a:


a) Queue data structure
b) Stack data structure
c) Priority queue data structure
d) Heap data structure

Answer: b) Stack data structure

28. In BFS, the shortest path between two vertices in an unweighted graph is found by:
a) Maintaining a priority queue of vertices
b) Exploring all possible paths from the source to the destination
c) Exploring the graph level by level
d) Using Dijkstra's algorithm
Answer: c) Exploring the graph level by level

29. DFS is used to:


a) Find the shortest path in a graph
b) Find the longest path in a graph
c) Explore all possible paths in a graph
d) Only traverse connected components of the graph

Answer: c) Explore all possible paths in a graph

30. Which traversal algorithm is more suitable for finding the shortest path in an unweighted graph?
a) BFS (Breadth First Search)
b) DFS (Depth First Search)
c) Both BFS and DFS are equally suitable
d) Neither BFS nor DFS can find the shortest path

Answer: a) BFS (Breadth First Search)

**8.5 Shortest Path**

**8.5.1 Level Setting: Dijkstra's algorithm**

31. Dijkstra's algorithm is used to find the shortest path in:


a) Unweighted graphs
b) Directed graphs only
c) Connected graphs with no cycles
d) Graphs with non-negative edge weights

Answer: d) Graphs with non-negative edge weights

32. The priority queue is a crucial data structure used in Dijkstra's algorithm to:
a) Store all the vertices of the graph
b) Keep track of visited vertices
c) Maintain the distances to each vertex from the source
d) Ensure that the graph has no cycles

Answer: c) Maintain the distances to each vertex from the source

33. In Dijkstra's algorithm, what happens when a shorter path to a vertex is discovered?
a) The vertex is marked as visited and added to the shortest path tree
b) The vertex is removed from the priority queue
c) The distance to the vertex is updated in the priority queue
d) The algorithm backtracks to the previous vertex

Answer: c) The distance to the vertex is updated in the priority queue

34. Which statement is true about Dijkstra's algorithm?


a) It is a greedy algorithm that selects the vertex with the maximum distance at each step.
b) It is guaranteed to find the shortest path in graphs with negative edge weights.
c) It can handle graphs with cycles.
d) It requires the graph to be connected.

Answer: c) It can handle graphs with cycles.

35. Dijkstra's algorithm may not work correctly on graphs with:


a) Non-negative edge weights
b) Cycles
c) Sparse vertices
d) Unconnected components
Answer: b) Cycles

**8.5.2 Level Correcting: All-pairs shortest path, Floyd-Warshall algorithm**

36. Floyd-Warshall algorithm is used to find:


a) The shortest path between all pairs of vertices in a weighted graph
b) The shortest path between two specified vertices in an unweighted graph
c) The longest path in a directed graph
d) The shortest cycle in a graph

Answer: a) The shortest path between all pairs of vertices in a weighted graph

37. The Floyd-Warshall algorithm works for graphs with:


a) Non-negative edge weights only
b) Negative edge weights only
c) Non-negative and negative edge weights
d) Non-negative edge weights and cycles only

Answer: c) Non-negative and negative edge weights

38. The time complexity of the Floyd-Warshall algorithm for a graph with V vertices is:
a) O(V)
b) O(V^2)
c) O(V^3)
d) O(log V)

Answer: c) O(V^3)

39. The Floyd-Warshall algorithm uses a dynamic programming approach to find the shortest path.
What does "dynamic programming" mean in this context?
a) Solving a problem by breaking it into smaller subproblems and storing their solutions
b) Using random values to update the distance matrix
c) Always selecting the shortest path at each step
d) Simulating all possible paths in the graph

Answer: a) Solving a problem by breaking it into smaller subproblems and storing their solutions

40. The Floyd-Warshall algorithm can handle graphs with:


a) Negative cycles
b) Disconnected components
c) Only a single vertex
d) Vertices with no edges

Answer: a) Negative cycles

**8.6 Spanning Trees**

**8.6.1 Minimum spanning tree algorithms**

41. A minimum spanning tree (MST) of a graph is:


a) The tree with the smallest number of edges
b) The tree with the smallest total edge weight
c) The tree with the smallest number of vertices
d) The tree with the smallest maximum degree of vertices

Answer: b) The tree with the smallest total edge weight

42. Prim's algorithm is used to find the:


a) Shortest path in a graph
b) Longest path in a graph
c) Minimum spanning tree of a graph
d) Maximum spanning tree of a graph

Answer: c) Minimum spanning tree of a graph

43. The time complexity of Prim's algorithm for finding the minimum spanning tree in a graph with V
vertices is:
a) O(V)
b) O(V^2)
c) O(V^3)
d) O(V log V)

Answer: b) O(V^2)

44. Prim's algorithm starts with:


a) The first vertex of the graph
b) The vertex with the maximum degree
c) The vertex with the minimum degree
d) Any arbitrary vertex of the graph

Answer: d) Any arbitrary vertex of the graph

45. In Prim's algorithm, what happens when two disconnected components are present in the graph?
a) The algorithm enters an infinite loop

b) The algorithm outputs an error message


c) The algorithm connects the components with a minimum weight edge
d) The algorithm cannot handle disconnected components

Answer: c) The algorithm connects the components with a minimum weight edge

**8.6.2 Prim's Algorithm**

46. When using Prim's algorithm, the initial vertex for the minimum spanning tree is chosen:
a) Arbitrarily
b) As the vertex with the smallest degree
c) As the vertex with the largest degree
d) As the vertex with the smallest total edge weight

Answer: a) Arbitrarily

47. Prim's algorithm grows the minimum spanning tree by adding:


a) The edge with the smallest weight from the current tree to a new vertex
b) The edge with the largest weight from the current tree to a new vertex
c) The edge with the smallest weight among all edges
d) The edge with the largest weight among all edges

Answer: a) The edge with the smallest weight from the current tree to a new vertex

48. Which statement is true about Prim's algorithm for finding the minimum spanning tree?
a) It can handle graphs with negative edge weights
b) It always starts with the vertex having the smallest degree
c) It may not work correctly for disconnected graphs
d) It guarantees the maximum spanning tree of the graph

Answer: c) It may not work correctly for disconnected graphs

49. Prim's algorithm terminates when:


a) All vertices are added to the minimum spanning tree
b) The maximum weight edge is added to the tree
c) There is no vertex left in the graph
d) There are no more edges left in the graph

Answer: a) All vertices are added to the minimum spanning tree

50. The minimum spanning tree found by Prim's algorithm is unique if:
a) The graph has a cycle
b) The graph has multiple disconnected components
c) The graph has at least one negative weight edge
d) The graph has unique edge weights

**8.6.3 Kruskal's Algorithm**

51. Kruskal's algorithm is used to find the:


a) Shortest path in a graph
b) Longest path in a graph
c) Maximum spanning tree of a graph
d) Minimum spanning tree of a graph

Answer: d) Minimum spanning tree of a graph

52. Kruskal's algorithm sorts the edges of the graph based on:
a) The vertices they connect
b) The edge weights in non-decreasing order
c) The edge weights in non-increasing order
d) The total number of edges

Answer: b) The edge weights in non-decreasing order

53. The time complexity of Kruskal's algorithm for finding the minimum spanning tree in a graph
with E edges and V vertices is:
a) O(E)
b) O(E log V)
c) O(V^2)
d) O(V log V)

Answer: b) O(E log V)

54. Kruskal's algorithm starts with:


a) The first vertex of the graph
b) The smallest edge of the graph
c) The largest edge of the graph
d) Any arbitrary vertex of the graph

Answer: b) The smallest edge of the graph

55. In Kruskal's algorithm, what happens when two disconnected components are present in the
graph?
a) The algorithm enters an infinite loop
b) The algorithm outputs an error message
c) The algorithm connects the components with a minimum weight edge
d) The algorithm cannot handle disconnected components

Answer: c) The algorithm connects the components with a minimum weight edge
Lecture 9: Algorithm Designs

**9.1 What are the different classes of algorithms**

56. Which class of algorithms is used to find the shortest path in a graph with non-negative edge
weights?
a) Divide and Conquer algorithm
b) Greedy algorithm
c) Dynamic Programming algorithm
d) Shortest Path algorithm

Answer: d) Shortest Path algorithm

57. The class of algorithms that breaks a problem into smaller subproblems and solves each
subproblem independently is called:
a) Divide and Conquer algorithm
b) Greedy algorithm
c) Dynamic Programming algorithm
d) Brute force algorithm

Answer: a) Divide and Conquer algorithm

58. The "Greedy algorithm" always makes the locally optimal choice at each step, with the hope of
finding a global optimum. Which statement is true about Greedy algorithms?
a) Greedy algorithms always guarantee the global optimum for all problems.
b) Greedy algorithms are usually more time-efficient than other algorithm classes.
c) Greedy algorithms can sometimes lead to suboptimal solutions for some problems.
d) Greedy algorithms are only applicable to problems with a small number of variables.

Answer: c) Greedy algorithms can sometimes lead to suboptimal solutions for some problems.

59. Dynamic Programming algorithms are particularly useful for solving problems that exhibit:
a) Overlapping subproblems and optimal substructure
b) Low complexity and small input size
c) Independent subproblems and no overlapping
d) Linear data structures and one-dimensional arrays

Answer: a) Overlapping subproblems and optimal substructure

60. Brute force algorithms:


a) Always guarantee the optimal solution
b) Are the most efficient for large-scale problems
c) Examine all possible solutions and select the best one
d) Are suitable only for problems with a small number of variables

Answer: c) Examine all possible solutions and select the best one

**9.2 How to write efficient Algorithm**

61. Writing an efficient algorithm involves:


a) Solving the problem in the shortest amount of time
b) Minimizing the number of steps in the algorithm
c) Optimizing the use of memory and computational resources
d) Reducing the input size of the problem

Answer: c) Optimizing the use of memory and computational resources

62. An algorithm that has a time complexity of O(log n) is considered more efficient than an algorithm
with time complexity:
a) O(1)
b) O(n)
c) O(n^2)
d) O(n log n)

Answer: d) O(n log n)

63. Which strategy is NOT typically used to improve the efficiency of an algorithm?
a) Divide and Conquer
b) Brute force
c) Dynamic Programming
d) Memoization

Answer: b) Brute force

64. The concept of "memoization" in algorithm design refers to:


a) Optimizing the algorithm for memory usage
b) Caching and reusing intermediate results to avoid redundant computations
c) Applying the greedy strategy to all possible solutions
d) Using only the most basic data structures

Answer: b) Caching and reusing intermediate results to avoid redundant computations

65. Which statement is true about the efficiency of an algorithm?


a) An efficient algorithm always has the smallest code size.
b) An efficient algorithm always guarantees the optimal solution.
c) The efficiency of an algorithm is solely determined by the programming language used.
d) The efficiency of an algorithm can be measured by its time and space complexity.

Answer: d) The efficiency of an algorithm can be measured by its time and space complexity.

**9.3 Introduction to algorithm design techniques**

66. The primary goal of algorithm design techniques is to:


a) Write algorithms with the least number of steps
b) Create algorithms that always yield the correct result
c) Develop efficient algorithms to solve specific problems
d) Minimize the use of data structures in the algorithm

Answer: c) Develop efficient algorithms to solve specific problems

67. Algorithm design techniques help in:


a) Generating random solutions to problems
b) Transforming complex problems into simple ones
c) Maximizing the number of steps in an algorithm
d) Avoiding the use of mathematical concepts in algorithms

Answer: b) Transforming complex problems into simple ones

68. Which of the following algorithm design techniques emphasizes breaking a problem into smaller
subproblems and solving each subproblem independently?
a) Greedy algorithm
b) Divide and Conquer algorithm
c) Brute force algorithm
d) Dynamic Programming algorithm

Answer: b) Divide and Conquer algorithm

69. Algorithm design techniques involve the use of:


a) Randomized approaches to problem-solving
b) Only a single approach for all types of problems
c) Domain-specific heuristics for problem-solving
d) A combination of methods and strategies tailored to the problem

Answer: d) A combination of methods and strategies tailored to the problem

70. The main purpose of using algorithm design techniques is to:


a) Increase the difficulty of the algorithm
b) Implement the most complex algorithms for a problem
c) Improve the code readability and maintainability
d) Optimize the algorithm's efficiency for a specific problem

Answer: d) Optimize the algorithm's efficiency for a specific problem

**9.4 Algorithm Design techniques**

71. The "Greedy algorithm" always makes the locally optimal choice at each step, with the hope of
finding a global optimum. Which statement is true about Greedy algorithms?
a) Greedy algorithms always guarantee the global optimum for all problems.
b) Greedy algorithms are usually more time-efficient than other algorithm classes.
c) Greedy algorithms can sometimes lead to suboptimal solutions for some problems.
d) Greedy algorithms are only applicable to problems with a small number of variables.

Answer: c) Greedy algorithms can sometimes lead to suboptimal solutions for some problems.

72. Dynamic Programming algorithms are particularly useful for solving problems that exhibit:
a) Overlapping subproblems and optimal substructure
b) Low complexity and small input size
c

) Independent subproblems and no overlapping


d) Linear data structures and one-dimensional arrays

Answer: a) Overlapping subproblems and optimal substructure

73. Brute force algorithms:


a) Always guarantee the optimal solution
b) Are the most efficient for large-scale problems
c) Examine all possible solutions and select the best one
d) Are suitable only for problems with a small number of variables

Answer: c) Examine all possible solutions and select the best one

74. Divide and Conquer algorithms break a problem into:


a) Random subproblems
b) Smaller subproblems of equal size
c) Independent subproblems
d) Overlapping subproblems

Answer: b) Smaller subproblems of equal size

75. Backtracking algorithms are used to solve problems that involve:


a) Finding the shortest path in a graph
b) Searching for an element in a sorted array
c) Exploring all possible solutions and making choices along the way
d) Dividing the problem into two smaller subproblems

Answer: c) Exploring all possible solutions and making choices along the way

**9.5 Analysis of an Algorithm**


**9.5.1 Asymptotic Analysis**

76. Asymptotic analysis of an algorithm evaluates its performance as:


a) The input size approaches infinity
b) The input size remains constant
c) The algorithm runs on random inputs
d) The algorithm handles edge cases

Answer: a) The input size approaches infinity

77. In asymptotic analysis, the term "Big O notation" is used to represent the:
a) Best-case time complexity of the algorithm
b) Average-case time complexity of the algorithm
c) Worst-case time complexity of the algorithm
d) Space complexity of the algorithm

Answer: c) Worst-case time complexity of the algorithm

78. The Big O notation O(n) represents an algorithm with:


a) Constant time complexity
b) Linear time complexity
c) Quadratic time complexity
d) Logarithmic time complexity

Answer: b) Linear time complexity

79. Which statement is true about the "Big O notation" in asymptotic analysis?
a) It provides an exact measure of the algorithm's execution time.
b) It represents the average-case time complexity of the algorithm.
c) It gives a lower bound on the algorithm's time complexity.
d) It helps analyze how the algorithm's performance scales with the input size.

Answer: d) It helps analyze how the algorithm's performance scales with the input size.

80. The "Big O notation" O(1) indicates an algorithm with:


a) Constant time complexity
b) Linear time complexity
c) Quadratic time complexity
d) Exponential time complexity

Answer: a) Constant time complexity

**9.5.2 Algorithm Analysis**

81. Algorithm analysis involves determining the:


a) Exact number of steps an algorithm takes to complete
b) Maximum number of steps an algorithm takes to complete
c) Average number of steps an algorithm takes to complete
d) Minimum number of steps an algorithm takes to complete

Answer: b) Maximum number of steps an algorithm takes to complete

82. In algorithm analysis, the term "average-case analysis" considers the algorithm's performance based
on:
a) The best possible input
b) The worst possible input
c) Randomly distributed inputs
d) All possible inputs

Answer: c) Randomly distributed inputs


83. Which statement is true about the "worst-case analysis" of an algorithm?
a) It provides an average measure of the algorithm's execution time.
b) It considers the best possible input for the algorithm.
c) It gives a lower bound on the algorithm's time complexity.
d) It helps analyze how the algorithm performs on the least favorable input.

Answer: d) It helps analyze how the algorithm performs on the least favorable input.

84. The time complexity of an algorithm is usually expressed using:


a) Exact number of steps the algorithm takes to execute
b) Best-case analysis
c) The "Big O notation"
d) Random inputs for analysis

Answer: c) The "Big O notation"

85. When analyzing an algorithm, we are primarily interested in its performance concerning:
a) The total execution time
b) The number of conditional statements used
c) The maximum input size it can handle
d) How the execution time grows with the input size

Answer: d) How the execution time grows with the input size

**9.6 Analysis of different types of Algorithms**

**9.6.1 Divide and Conquer Algorithm**

86. The "Divide and Conquer" algorithm technique is based on the principle of:
a) Iterative problem-solving
b) Exploring all possible solutions simultaneously
c) Breaking a problem into smaller subproblems and solving them independently
d) Reducing the problem size by increasing the input size

Answer: c) Breaking a problem into smaller subproblems and solving them independently

87. The "Merge Sort" algorithm is an example of which technique?


a) Divide and Conquer algorithm
b) Greedy algorithm
c) Dynamic Programming algorithm
d) Brute force algorithm

Answer: a) Divide and Conquer algorithm

88. Which of the following best describes the "Divide and Conquer" algorithm?
a) It divides the problem into overlapping subproblems and combines their solutions.
b) It recursively breaks the problem into smaller independent subproblems.
c) It uses random choices to explore the solution space.
d) It uses a single approach to solve problems of different sizes.

Answer: b) It recursively breaks the problem into smaller independent subproblems.

89. A Divide and Conquer algorithm reduces the problem size by:
a) Increasing the input size
b) Combining all subproblems into one
c) Dividing the problem into subproblems of equal size
d) Ignoring subproblems that do not contribute to the final solution

Answer: c) Dividing the problem into subproblems of equal size


90. Merge Sort has a time complexity of O(n log n). What does this mean?
a) The algorithm always performs n log n operations.
b) The algorithm is most efficient for small input sizes.
c) The algorithm's performance grows at a linear rate with the input size.
d) The algorithm's performance grows at a logarithmic rate with the input size.

Answer: c) The algorithm's performance grows at a linear rate with the input size.

**9.6.2 Greedy algorithm**

91. Greedy algorithms make decisions based on:


a) Random choices
b) The optimal choice at each step
c) The minimum possible solution
d) The maximum possible solution

Answer: b) The optimal choice at each step

92. The "Knapsack Problem" is a classic example of a problem solved using which technique?
a) Divide and Conquer algorithm
b) Greedy algorithm
c) Dynamic Programming algorithm
d) Brute force algorithm

Answer: b) Greedy algorithm

93. Which statement is true about greedy algorithms?

a) Greedy algorithms always guarantee the global optimum for all problems.
b) Greedy algorithms are usually more time-efficient than other algorithm classes.
c) Greedy algorithms can sometimes lead to suboptimal solutions for some problems.
d) Greedy algorithms are only applicable to problems with a small number of variables.

Answer: c) Greedy algorithms can sometimes lead to suboptimal solutions for some problems.

94. The "Huffman Coding" algorithm uses a greedy approach to:


a) Find the shortest path in a graph
b) Optimize the use of memory in data compression
c) Divide a problem into smaller subproblems
d) Find the optimal solution to a linear programming problem

Answer: b) Optimize the use of memory in data compression

95. Greedy algorithms are particularly suitable for problems where:


a) The optimal solution can be found by combining solutions to subproblems
b) The problem can be divided into overlapping subproblems
c) The optimal solution can be reached by making locally optimal choices at each step
d) The problem can be solved iteratively through backtracking

Answer: c) The optimal solution can be reached by making locally optimal choices at each step

**9.6.3 Dynamic Programming algorithm**

96. Dynamic Programming algorithms are particularly useful for solving problems that exhibit:
a) Overlapping subproblems and optimal substructure
b) Low complexity and small input size
c) Independent subproblems and no overlapping
d) Linear data structures and one-dimensional arrays
Answer: a) Overlapping subproblems and optimal substructure

97. The "Fibonacci sequence" is a classic problem solved using which technique?
a) Divide and Conquer algorithm
b) Greedy algorithm
c) Dynamic Programming algorithm
d) Brute force algorithm

Answer: c) Dynamic Programming algorithm

98. Which statement best describes the dynamic programming technique?


a) It explores all possible solutions simultaneously to find the optimal one.
b) It divides the problem into smaller independent subproblems.
c) It uses a greedy approach to find the global optimum.
d) It solves subproblems recursively and stores their solutions to avoid redundant computations.

Answer: d) It solves subproblems recursively and stores their solutions to avoid redundant
computations.

99. In the context of dynamic programming, the term "memoization" refers to:
a) Storing data in one-dimensional arrays
b) Storing intermediate results to avoid redundant calculations
c) Solving the problem iteratively using a bottom-up approach
d) Using a divide and conquer approach to solve subproblems

Answer: b) Storing intermediate results to avoid redundant calculations

100. Dynamic Programming is more suitable for problems that have:


a) A small number of variables
b) Subproblems with overlapping solutions
c) Randomly distributed inputs
d) A fixed set of possible solutions

Answer: b) Subproblems with overlapping solutions

**9.6.4 Brute force algorithm**

101. Brute force algorithms:


a) Always guarantee the optimal solution
b) Are the most efficient for large-scale problems
c) Examine all possible solutions and select the best one
d) Are suitable only for problems with a small number of variables

Answer: c) Examine all possible solutions and select the best one

102. Which statement best describes the brute force algorithm?


a) It breaks a problem into smaller subproblems and solves each independently.
b) It always guarantees the optimal solution for all problems.
c) It uses random choices to explore the solution space.
d) It explores all possible solutions to find the best one.

Answer: d) It explores all possible solutions to find the best one.

103. Brute force algorithms are most appropriate for problems where:
a) The optimal solution can be found by combining solutions to subproblems
b) The problem can be divided into smaller independent subproblems
c) The problem size is small, and all possible solutions can be checked
d) The problem involves dynamic programming and memoization
Answer: c) The problem size is small, and all possible solutions can be checked

104. The main drawback of using brute force algorithms is that they:
a) Require sophisticated data structures
b) Are not suitable for problems with overlapping subproblems
c) Have high time and space complexity for large input sizes
d) Are only applicable to problems with a small number of variables

Answer: c) Have high time and space complexity for large input sizes

105. The "Traveling Salesman Problem" is an example of a problem often solved using which
technique?
a) Divide and Conquer algorithm
b) Greedy algorithm
c) Dynamic Programming algorithm
d) Brute force algorithm

Answer: d) Brute force algorithm

**9.6.5 Backtracking algorithms**

106. Backtracking algorithms are used to solve problems that involve:


a) Finding the shortest path in a graph
b) Searching for an element in a sorted array
c) Exploring all possible solutions and making choices along the way
d) Dividing the problem into two smaller subproblems

Answer: c) Exploring all possible solutions and making choices along the way

107. The "N-Queens Problem" is an example of a problem often solved using which technique?
a) Divide and Conquer algorithm
b) Greedy algorithm
c) Dynamic Programming algorithm
d) Backtracking algorithm

Answer: d) Backtracking algorithm

108. Backtracking is most suitable for problems where:


a) The optimal solution can be found by combining solutions to subproblems
b) The problem can be divided into smaller independent subproblems
c) The problem involves exploring all possible solutions and making choices
d) The problem can be solved iteratively using dynamic programming

Answer: c) The problem involves exploring all possible solutions and making choices

109. The main advantage of using backtracking algorithms is that they:


a) Always guarantee the optimal solution
b) Have low time complexity for large input sizes
c) Can solve problems with overlapping subproblems
d) Explore only a subset of possible solutions

Answer: d) Explore only a subset of possible solutions

110. Which statement is true about backtracking algorithms?


a) Backtracking algorithms are primarily used for sorting problems.
b) Backtracking always finds the optimal solution to any problem.
c) Backtracking uses a greedy approach to explore the solution space.
d) Backtracking is a form of recursion that explores all possible paths until a solution is found.

Answer: d) Backtracking is a form of recursion that explores all possible paths until a solution is found.
**9.6.6 Branch-and-bound algorithms**

111. Branch-and-bound algorithms:


a) Always guarantee the optimal solution
b) Are the most efficient for large-scale problems
c) Divide the problem into smaller subproblems
d) Explore only a subset of possible solutions while eliminating suboptimal paths

Answer: d) Explore only a subset of possible solutions while eliminating suboptimal paths

112. Which statement best describes branch-and-bound algorithms?


a) They solve subproblems independently and combine their solutions.
b) They use a greedy approach to explore the solution space.
c) They explore all possible solutions to find the best one.
d) They eliminate suboptimal paths during the search.

Answer: d) They eliminate suboptimal paths during the search.

113. Branch-and-bound algorithms are most appropriate for problems where:


a) The optimal solution can be found by combining solutions to subproblems
b) The problem can be divided into smaller independent subproblems
c) The problem involves exploring all possible solutions and making choices
d) The problem involves finding the shortest path in a graph

Answer: d) The problem involves finding the shortest path in a graph

114. The "Traveling Salesman Problem" can also be solved using branch-and-bound algorithms. What
is the main benefit of using this technique?
a) It guarantees the optimal solution in all cases.
b) It explores all possible solutions in a short amount of time.
c) It significantly reduces the time complexity compared to other techniques.
d) It prunes suboptimal paths and eliminates redundant computations.

Answer: d) It prunes suboptimal paths and eliminates redundant computations.

115. The main drawback of using branch-and-bound algorithms is that they:


a) Are computationally expensive for large-scale problems
b) Require a large amount of memory to store intermediate results
c) Cannot handle problems with overlapping subproblems
d) Only work for problems with a small number of variables

Answer: a) Are computationally expensive for large-scale problems

**9.6.7 Stochastic algorithms**

116. Stochastic algorithms are used to solve problems that involve:


a) Finding the shortest path in a graph
b) Exploring all possible solutions and making choices along the way
c) Random choices and probability distributions
d) Solving problems with overlapping subproblems

Answer: c) Random choices and probability distributions

117. The "Simulated Annealing" algorithm is an example of a

problem solved using which technique?


a) Divide and Conquer algorithm
b) Greedy algorithm
c) Stochastic algorithm
d) Brute force algorithm

Answer: c) Stochastic algorithm

118. Stochastic algorithms are most suitable for problems where:


a) The optimal solution can be found by combining solutions to subproblems
b) The problem can be divided into smaller independent subproblems
c) The problem involves exploring all possible solutions and making choices
d) The problem can benefit from random exploration and probabilistic selection

Answer: d) The problem can benefit from random exploration and probabilistic selection

119. The main advantage of using stochastic algorithms is that they:


a) Always guarantee the optimal solution
b) Have low time complexity for large input sizes
c) Can solve problems with overlapping subproblems
d) Introduce randomness, which can lead to better solutions in some cases

Answer: d) Introduce randomness, which can lead to better solutions in some cases

120. Which statement is true about stochastic algorithms?


a) Stochastic algorithms are less effective than other techniques for solving optimization problems.
b) Stochastic algorithms use a deterministic approach to explore the solution space.
c) Stochastic algorithms are primarily used for sorting problems.
d) Stochastic algorithms use random choices and probability distributions to search for solutions.

Answer: d) Stochastic algorithms use random choices and probability distributions to search for
solutions.

**9.7 Complexity**

**9.7.1 Complexity Analysis**

121. Complexity analysis of an algorithm involves:


a) Determining the average execution time for all inputs
b) Estimating the best-case execution time for a given input
c) Analyzing the algorithm's performance as the input size increases
d) Measuring the total number of steps the algorithm takes to complete

Answer: c) Analyzing the algorithm's performance as the input size increases

122. Which statement is true about the "space complexity" of an algorithm?


a) It measures the maximum number of recursive calls in the algorithm.
b) It represents the amount of memory used by the algorithm to store data.
c) It gives a lower bound on the algorithm's time complexity.
d) It helps analyze how the algorithm's performance scales with the input size.

Answer: b) It represents the amount of memory used by the algorithm to store data.

123. The "space complexity" of an algorithm is usually expressed using:


a) The total number of steps the algorithm takes to execute
b) The "Big O notation"
c) The maximum amount of memory used by the algorithm
d) The best-case execution time for a given input

Answer: c) The maximum amount of memory used by the algorithm

124. The "time complexity" of an algorithm is a measure of:


a) The maximum number of recursive calls in the algorithm
b) The amount of memory used by the algorithm to store data
c) The number of conditional statements in the algorithm
d) The total number of steps the algorithm takes to complete

Answer: d) The total number of steps the algorithm takes to complete

125. In time complexity analysis, the term "Big O notation" is used to represent the:
a) Best-case time complexity of the algorithm
b) Average-case time complexity of the algorithm
c) Worst-case time complexity of the algorithm
d) Space complexity of the algorithm

Answer: c) Worst-case time complexity of the algorithm

**9.7.2 Space complexity of the algorithm**

126. The space complexity of an algorithm is determined by:


a) The maximum number of recursive calls in the algorithm
b) The total number of steps the algorithm takes to complete
c) The amount of memory used by the algorithm to store data
d) The number of conditional statements in the algorithm

Answer: c) The amount of memory used by the algorithm to store data

127. The space complexity of an algorithm is usually expressed using:


a) The total number of steps the algorithm takes to execute
b) The "Big O notation"
c) The maximum amount of memory used by the algorithm
d) The best-case execution time for a given input

Answer: c) The maximum amount of memory used by the algorithm

128. The space complexity of an algorithm is important to consider when:


a) The algorithm contains a large number of conditional statements
b) The input size is small
c) The algorithm is implemented using recursive function calls
d) The algorithm has a small number of variables

Answer: c) The algorithm is implemented using recursive function calls

129. Which statement is true about space complexity analysis?


a) Space complexity measures the average memory used by the algorithm.
b) Space complexity analysis is only applicable to algorithms with low time complexity.
c) Space complexity is independent of the input size.
d) Space complexity helps determine how much memory an algorithm needs to execute.

Answer: d) Space complexity helps determine how much memory an algorithm needs to execute.

130. The "space complexity" of an algorithm can be reduced by:


a) Adding more variables to store intermediate results
b) Using recursion to solve subproblems
c) Employing data structures with high memory overhead
d) Avoiding redundant data storage

Answer: d) Avoiding redundant data storage

**9.7.3 Time complexity of the algorithm**

131. The time complexity of an algorithm is determined by:


a) The maximum number of recursive calls in the algorithm
b) The amount of memory used by the algorithm to store data
c) The number of conditional statements in the algorithm
d) The total number of steps the algorithm takes to complete

Answer: d) The total number of steps the algorithm takes to complete

132. The time complexity of an algorithm is usually expressed using:


a) The total number of steps the algorithm takes to execute
b) The "Big O notation"
c) The maximum amount of memory used by the algorithm
d) The best-case execution time for a given input

Answer: b) The "Big O notation"

133. The time complexity of an algorithm is important to consider when:


a) The algorithm contains a large number of conditional statements
b) The input size is small
c) The algorithm is implemented using recursive function calls
d) The algorithm has a small number of variables

Answer: a) The algorithm contains a large number of conditional statements

134. Which statement is true about time complexity analysis?


a) Time complexity measures the average execution time of the algorithm.
b) Time complexity analysis is only applicable to algorithms with high space complexity.
c) Time complexity is independent of the input size.
d) Time complexity helps determine the efficiency of an algorithm concerning the input size.

Answer: d) Time complexity helps determine the efficiency of an algorithm concerning the input size.

135. The "time complexity" of an algorithm can be reduced by:


a) Increasing the number of conditional statements in the algorithm
b) Using recursion to solve subproblems
c) Employing data structures with low time overhead
d) Optimizing the algorithm to minimize the number of steps

Answer: d) Optimizing the algorithm to minimize the number of steps

**9.8 Case study on Algorithm Design techniques**

136. A case study on algorithm design techniques involves:


a) Analyzing the space and time complexity of an algorithm
b) Comparing the efficiency of different algorithm classes
c) Applying different algorithms to a specific problem and evaluating their performance
d) Identifying the optimal solution to a given problem

Answer: c) Applying different algorithms to a specific problem and evaluating their performance

137. In a case study on algorithm design techniques, the goal is to:


a) Prove the correctness of a particular algorithm
b) Determine the best algorithm class for a given problem
c) Find the most efficient algorithm for all input sizes
d) Test the algorithm's performance under various conditions

Answer: b) Determine the best algorithm class for a given problem

138. The main purpose of conducting a case study on algorithm design techniques is to:
a) Identify the best algorithm for a specific problem
b) Determine the average execution time of an algorithm
c) Explore different data structures used in algorithms
d) Analyze the space complexity of an algorithm
Answer: a) Identify the best algorithm for a specific problem

139. Which statement is true about a case study on algorithm design techniques?
a) The case study involves comparing algorithms based on their code complexity.
b) The case study helps determine the most optimal solution for any given problem.
c) The case study focuses on finding the average execution time of an algorithm.
d) The case study evaluates algorithm performance using real-world scenarios.

Answer: d) The case study evaluates algorithm performance using real-world scenarios.

140. The results of a case study on algorithm design techniques can be used to:
a) Prove the correctness of a particular algorithm
b) Determine the best algorithm for a specific problem under certain conditions
c) Establish the average execution time of an algorithm
d) Explore the mathematical properties of different algorithms

Answer: b) Determine the best algorithm for a specific problem under certain conditions

**9.9 Application of Data structures**

141. Data structures are used in algorithm design to:


a) Optimize the space complexity of an algorithm
b) Improve the readability of algorithm code
c) Store and organize data efficiently during algorithm execution
d) Reduce the number of steps an algorithm takes to complete

Answer: c) Store and organize data efficiently during algorithm execution

142. The primary purpose of using data structures in algorithm design is to:
a) Reduce the time complexity of the algorithm
b) Provide a visual representation of the algorithm's execution
c) Optimize the algorithm's performance for large input sizes
d) Facilitate the storage and retrieval of data during algorithm execution

Answer: d) Facilitate the storage and retrieval of data during algorithm execution

143. Which statement best describes the relationship between data structures and algorithms?
a) Data structures represent the steps in an algorithm's execution.
b) Data structures are the algorithms used to process data.
c) Data structures and algorithms are separate entities with no connection.
d) Data structures provide the foundation for algorithm design and execution.

Answer: d) Data structures provide the foundation for algorithm design and execution.

144. The choice of data structure in algorithm design is influenced by:


a) The programming language used to implement the algorithm
b) The availability of built-in data structures in the programming language
c) The input size and the specific operations required by the algorithm
d) The level of code complexity in the algorithm

Answer: c) The input size and the specific operations required by the algorithm

145. Data structures used in algorithm design can include:


a) All types of conditional statements used in the algorithm
b) Arrays and loops for repetitive tasks
c) Mathematical formulas for efficient calculations
d) Lists, queues, stacks, and trees to store and organize data

Answer: d) Lists, queues, stacks, and trees to store and organize data

You might also like