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

Cs301mid Term MCQ File

The document contains multiple-choice questions related to data structures, their importance, and efficient programming practices. It covers topics such as selecting appropriate data structures, understanding arrays, and the implications of memory allocation. The quizzes aim to test knowledge on the benefits, operations, and challenges associated with various data structures in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views166 pages

Cs301mid Term MCQ File

The document contains multiple-choice questions related to data structures, their importance, and efficient programming practices. It covers topics such as selecting appropriate data structures, understanding arrays, and the implications of memory allocation. The quizzes aim to test knowledge on the benefits, operations, and challenges associated with various data structures in programming.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 166

CS301

Multiple choice questions.


Quiz: Introduction to Data Structures

1. Why are data structures important in computer programming?

a) They make the program run faster

b) They help organize data for efficient access and usage

c) They require less memory

d) They increase CPU speed

2. What is one of the main benefits of using an efficient data structure?

a) It requires more memory

b) It decreases CPU speed

c) It helps solve problems within resource constraints

d) It makes the computer more powerful

3. What does organizing data in a computer typically involve?

a) Buying a new computer

b) Arranging data so it is easily accessible

c) Increasing the speed of the CPU

d) Maximizing disk space

---

**4. Which of the following is NOT typically a result of a poorly chosen data structure?**

a) Slow program execution

b) Increased CPU speed


c) Inefficient use of memory

d) Longer computation times

---

**5. What should be considered when writing programs to solve problems?**

a) The time required for the solution

b) The color of the computer screen

c) The speed of the network connection

d) The keyboard layout

---

**6. What can be a consequence of not using a suitable data structure?**

a) The application will use less memory

b) The application may take a longer time to execute

c) The application will automatically speed up

d) The application will consume less disk space

---

**7. In what scenario might buying a faster computer not resolve a problem?**

a) When the program uses inefficient data structures

b) When the CPU is too slow

c) When there is not enough disk space

d) When the memory is too small

---
**8. Which of the following is a factor that can determine if a solution is efficient?**

a) The brand of the computer

b) The amount of resources used, like memory and time

c) The price of the software

d) The appearance of the program’s interface

**9. Why is time an important factor in determining the efficiency of a solution?**

a) Because faster computers are always available

b) Because users have unlimited patience

c) Because solutions must be achieved within a reasonable time frame

d) Because time is not a significant factor

**10. What should be done if a program is not achieving its advantages?**

a) Buy a new computer

b) Invest in more memory

c) Consider changing the data structure or program

d) Wait for the computer to get faster

### Quiz: Selecting a Data Structure

---

**1. What is the first step in selecting an appropriate data structure for solving a problem?**

a) Determine the available disk space

b) Analyze the problem to determine resource constraints


c) Choose a data structure randomly

d) Ask the client for their preference

**Correct Answer:** b) Analyze the problem to determine resource constraints

---

**2. What should be done if the available disk space is insufficient for the data?**

a) Use a different data structure

b) Compress the data

c) Buy a new disk

d) Optimize the program

**Correct Answer:** c) Buy a new disk

---

**3. When selecting a data structure, why is it important to consider the basic operations that must be
supported?**

a) To minimize the program’s complexity

b) To ensure all necessary operations are efficient

c) To avoid writing code

d) To reduce the need for memory

**Correct Answer:** b) To ensure all necessary operations are efficient

---

**4. What is an example of a basic operation that might be considered when selecting a data
structure?**

a) Changing the color of the interface

b) Inserting, deleting, and searching data


c) Installing new software

d) Writing documentation

**Correct Answer:** b) Inserting, deleting, and searching data

---

**5. Why might inserting data into the beginning or middle of an array require extra steps?**

a) Arrays do not allow insertion

b) Existing data must be shifted to make space

c) Arrays are immutable

d) The array size must be doubled

**Correct Answer:** b) Existing data must be shifted to make space

---

**6. What challenge is associated with deleting data from a specific position in an array?**

a) The array size will increase

b) The deleted space must be managed

c) The array will lose its order

d) Deletion is not possible in arrays

**Correct Answer:** b) The deleted space must be managed

---

**7. What is meant by random access in the context of data structures?**

a) Data is accessed in a sequential order

b) Data can be accessed at any position without following a sequence

c) Data access is unpredictable and difficult to manage

d) Only the first and last elements of the structure can be accessed
**Correct Answer:** b) Data can be accessed at any position without following a sequence

---

**8. Why is it important to consider whether data will be accessed in a well-defined order or
randomly?**

a) It determines how to choose between different data structures

b) It affects the color scheme of the program

c) It influences the programming language selection

d) It determines the client’s satisfaction

**Correct Answer:** a) It determines how to choose between different data structures

---

**9. What is a key factor in the philosophy of data structures?**

a) Every data structure has costs and benefits

b) Data structures are always free to use

c) The more complex the data structure, the better

d) Data structures have no impact on program efficiency

**Correct Answer:** a) Every data structure has costs and benefits

---

**10. What should you consider if your program is not efficient enough for the client?**

a) Change the client’s requirements

b) Choose a more appropriate data structure

c) Purchase more computer resources

d) Abandon the project

**Correct Answer:** b) Choose a more appropriate data structure.


### Quiz: Understanding Data Structures and Their Applications

---

**1. Why is it important to choose the right data structure for a given problem?**

a) Because all data structures perform the same in all situations

b) Because the right data structure can improve efficiency and performance

c) Because data structures do not affect program performance

d) Because clients prefer certain data structures

**Correct Answer:** b) Because the right data structure can improve efficiency and performance

---

**2. What is a key skill this course aims to teach regarding data structures?**

a) How to avoid using data structures

b) How to select and replace data structures without affecting the rest of the program

c) How to use only one data structure for all problems

d) How to write code without using any data structures

**Correct Answer:** b) How to select and replace data structures without affecting the rest of the
program

---

**3. Which of the following is NOT one of the three basic requirements of a data structure?**

a) Space for each data item it stores

b) Time to perform each basic operation

c) Programming effort

d) Color scheme compatibility

**Correct Answer:** d) Color scheme compatibility


---

**4. What should a programmer do if they find two different data structures suitable for the same
problem?**

a) Choose one at random

b) Test both and determine which is more appropriate

c) Use both data structures simultaneously

d) Avoid using any data structure

**Correct Answer:** b) Test both and determine which is more appropriate

---

**5. What does the course emphasize about the costs and benefits of data structures?**

a) Data structures have no associated costs

b) Every data structure has costs and benefits

c) Costs are irrelevant in data structure selection

d) Benefits always outweigh the costs

**Correct Answer:** b) Every data structure has costs and benefits

---

**6. What forms a programmer's basic data structure “toolkit”?**

a) Programming languages

b) Commonly used data structures

c) Integrated development environments (IDEs)

d) Software libraries

**Correct Answer:** b) Commonly used data structures


---

**7. How can a programmer determine which data structure is better?**

a) By randomly picking one

b) By measuring and comparing the performance of both in similar scenarios

c) By using the one that looks better in code

d) By choosing the one that takes up less memory space

**Correct Answer:** b) By measuring and comparing the performance of both in similar scenarios

---

**8. Why might a data structure that is suitable for small data not be suitable for large data?**

a) Small data structures do not scale well for large data

b) Large data requires a different programming language

c) Small data structures are always better for large data

d) There is no difference; they perform equally well

**Correct Answer:** a) Small data structures do not scale well for large data

---

**9. What challenge does a programmer face when deciding which data structure to use for a problem
where data size may change over time?**

a) Determining if the data will increase or decrease in size

b) Finding a data structure that never changes

c) Ensuring the data structure looks aesthetically pleasing

d) Avoiding the use of any data structure

**Correct Answer:** a) Determining if the data will increase or decrease in size

---
**10. What is a key factor in determining the better data structure when dealing with large datasets?**

a) The color of the data structure

b) How well it scales with increasing data size

c) The programming language used

d) The location of the data in memory

**Correct Answer:** b) How well it scales with increasing data size

---

**11. What is an array in programming?**

a) A collection of cells of different types

b) A collection of cells of the same type

c) A single integer value

d) A random memory location

**Correct Answer:** b) A collection of cells of the same type

---

**12. How are elements in an array accessed?**

a) By using the array name and an index

b) By using a pointer to the array

c) By referencing the memory address directly

d) By iterating over a loop until the element is found

**Correct Answer:** a) By using the array name and an index

---

**13. What is the memory layout of an array?**


a) Elements are stored in non-contiguous memory locations

b) Elements are stored in contiguous memory locations

c) The layout is random and unpredictable

d) Elements are stored in reverse order in memory

**Correct Answer:** b) Elements are stored in contiguous memory locations

---

**14. Why is contiguous memory allocation important for arrays?**

a) It improves memory access speed

b) It allows arrays to be of different types

c) It makes the array take up less memory

d) It ensures the array can hold only integers

**Correct Answer:** a) It improves memory access speed

---

**15. What happens if you try to store a different data type in an array?**

a) The array automatically converts the data type

b) The program will compile with warnings

c) The program will result in a type mismatch error

d) The data will be stored as a string

**Correct Answer:** c) The program will result in a type mismatch error

---

**16. How does the array index range relate to the size of the array?**

a) It ranges from 1 to the size of the array

b) It ranges from 0 to one less than the size of the array


c) It ranges from -1 to the size of the array

d) It is always equal to the size of the array

**Correct Answer:** b) It ranges from 0 to one less than the size of the array

---

**17. Why might a programmer prefer to use arrays over other data structures in certain scenarios?**

a) Arrays can store data of different types

b) Arrays allow easy access to elements by index

c) Arrays automatically resize when needed

d) Arrays use less memory than any other data structure

**Correct Answer:** b) Arrays allow easy access to elements by index

---

**18. In which scenario might an array be a less suitable data structure?**

a) When the data size is known and fixed

b) When elements need to be accessed randomly

c) When frequent insertions and deletions are required

d) When memory usage needs to be optimized

**Correct Answer:** c) When frequent insertions and deletions are required

---

**19. What is a potential drawback of using arrays for large datasets?**

a) Arrays cannot store large amounts of data

b) Accessing elements by index is too slow

c) Arrays require contiguous memory, which can be limiting

d) Arrays automatically resize, which is inefficient


**Correct Answer:** c) Arrays require contiguous memory, which can be limiting

---

**20. Why is it important to understand different data structures as a programmer?**

a) To ensure all programs look the same

b) To have a variety of tools available for solving different problems

c) To avoid using any data structures

d) To focus on one data structure for all problems

**Correct Answer:** b) To have a variety of tools available for solving different problems

### Quiz: Understanding Array Manipulation and Memory Allocation

**1. What is the reason that `x` in the array `int x[6];` is not an lvalue?**

a) Because it does not have a memory address

b) Because it is not a variable but a name for the array

c) Because it is a pointer

d) Because it can be used on the left-hand side of an assignment

**Correct Answer:** b) Because it is not a variable but a name for the array

---

**2. Why is the statement `x = 3;` not allowed for the array `int x[6];`?**

a) Because it tries to assign a single value to the entire array

b) Because `x` is not a pointer

c) Because `x` is a constant

d) Because `3` is an invalid value for an array

**Correct Answer:** a) Because it tries to assign a single value to the entire array

---
**3. What does the statement `x[0] = 5;` do in the context of an array `int x[6];`?**

a) Assigns the value 5 to the entire array

b) Assigns the value 5 to the first element of the array

c) Assigns the value 5 to the memory address of `x`

d) It is an invalid statement

**Correct Answer:** b) Assigns the value 5 to the first element of the array

---

**4. Why is the statement `x = a + b;` not allowed?**

a) Because `x` cannot be assigned the sum of `a` and `b`

b) Because arrays cannot hold the result of an addition

c) Because `x` is a constant

d) Because `a + b` is not a valid operation

**Correct Answer:** a) Because `x` cannot be assigned the sum of `a` and `b`

---

**5. What would happen if you tried to execute the statement `x = &n;` in the array `int x[6];`?**

a) The program would assign the memory address of `n` to the array `x`

b) The program would result in a compilation error

c) The array `x` would point to `n`

d) The program would run successfully

**Correct Answer:** b) The program would result in a compilation error

---

**6. Why can't the name of an array (like `x` in `int x[6];`) be changed?**
a) Because it is a constant representing multiple memory locations

b) Because it is a pointer to a single memory location

c) Because it is a variable with a fixed value

d) Because it is dynamically allocated

**Correct Answer:** a) Because it is a constant representing multiple memory locations

---

**7. What problem arises when you declare a very large array but use only a small portion of it?**

a) It leads to compilation errors

b) It wastes valuable memory resources

c) It causes the program to crash

d) It slows down the execution of the program

**Correct Answer:** b) It wastes valuable memory resources

---

**8. When is it appropriate to allocate an array dynamically?**

a) When the size of the array is known at compile time

b) When the size of the array is only known at runtime

c) When the array needs to be resized frequently

d) When the array is very small

**Correct Answer:** b) When the size of the array is only known at runtime

---

**9. Which of the following statements is true regarding array names in C/C++?**

a) Array names can be used as lvalues

b) Array names can be reassigned to different memory locations


c) Array names act as pointers to the first element

d) Array names can be assigned the sum of other variables

**Correct Answer:** c) Array names act as pointers to the first element

---

**10. What is a potential solution to the problem of wasting memory when using arrays?**

a) Declaring a smaller array and resizing it later

b) Allocating memory dynamically based on need

c) Using a fixed-size array regardless of data size

d) Avoiding the use of arrays altogether

**Correct Answer:** b) Allocating memory dynamically based on need

### Quiz: Understanding Arrays, Pointers, and List Data Structures

**1. What does the statement `int* y = new int[20];` do?**

a) Allocates 20 memory locations and stores the address of the first location in `y`

b) Creates a new integer array of size 20 and initializes all elements to zero

c) Allocates 20 contiguous memory locations and assigns the last address to `y`

d) Declares an integer pointer and initializes it with a null pointer

**Correct Answer:** a) Allocates 20 memory locations and stores the address of the first location in `y`

---

**2. Which of the following statements about the variable `y` after executing `int* y = new int[20];` is
true?**

a) `y` cannot be used on the left-hand side of an assignment

b) `y` is a pointer and can hold memory addresses

c) `y` is an array and can be directly indexed without dereferencing


d) `y` stores the number of elements in the array

**Correct Answer:** b) `y` is a pointer and can hold memory addresses

---

**3. Why is the statement `y = x;` allowed when `x` is an array and `y` is a pointer?**

a) Because both `x` and `y` are arrays

b) Because `x` holds the address of its first element and `y` can store addresses

c) Because `y` is an array and can hold multiple values

d) Because `x` and `y` are the same data type

**Correct Answer:** b) Because `x` holds the address of its first element and `y` can store addresses

---

**4. Which of the following operations is not allowed for the array `x` declared as `int x[6];`?**

a) `x[0] = 5;`

b) `x[1] = x[2];`

c) `x = &n;`

d) `x[5] = 10;`

**Correct Answer:** c) `x = &n;`

---

**5. What is the purpose of the `delete[] y;` statement in dynamic memory management?**

a) Deletes the first element of the array pointed to by `y`

b) Releases the memory allocated to the array to avoid memory leaks

c) Removes the pointer `y` from memory

d) Deletes the last element of the array pointed to by `y`

**Correct Answer:** b) Releases the memory allocated to the array to avoid memory leaks
---

**6. What is the primary difference between an array and a list data structure?**

a) Arrays store elements of different types, while lists store elements of the same type

b) Arrays are fixed in size, while lists can dynamically grow and shrink

c) Arrays allow insertion and deletion at any position, while lists do not

d) Arrays store elements in a specific order, while lists do not

**Correct Answer:** b) Arrays are fixed in size, while lists can dynamically grow and shrink

---

**7. Which operation would you use to create an exact copy of a list?**

a) `copy()`

b) `clone()`

c) `duplicate()`

d) `replicate()`

**Correct Answer:** a) `copy()`

---

**8. What does the `length()` function do when applied to a list?**

a) Returns the maximum capacity of the list

b) Returns the number of elements currently in the list

c) Returns the index of the last element in the list

d) Returns the total memory occupied by the list

**Correct Answer:** b) Returns the number of elements currently in the list

---
**9. What does the `insert(X, position)` function do in a list?**

a) Inserts the element `X` at the end of the list

b) Replaces the element at `position` with `X`

c) Inserts the element `X` at the specified `position` in the list

d) Inserts the element `X` only if the list is not full

**Correct Answer:** c) Inserts the element `X` at the specified `position` in the list

---

**10. Which function would you use to check if a specific element `X` is present in a list?**

a) `find(X)`

b) `contains(X)`

c) `search(X)`

d) `locate(X)`

**Correct Answer:** a) `find(X)`

### Quiz: Understanding List Operations and Pointers

**1. What does the `start()` function do in the context of a list?**

a) Initializes the list with default values

b) Moves the "current" pointer to the very first element of the list

c) Inserts a new element at the start of the list

d) Clears all elements in the list

**Correct Answer:** b) Moves the "current" pointer to the very first element of the list

---

**2. Which function moves the "current" pointer to the last element of the list?**
a) `end()`

b) `back()`

c) `tail()`

d) `final()`

**Correct Answer:** c) `tail()`

---

**3. What is the purpose of the `next()` function in a list?**

a) It moves the "current" pointer forward one element

b) It moves the "current" pointer to the first element

c) It swaps the current element with the next one

d) It inserts a new element after the current one

**Correct Answer:** a) It moves the "current" pointer forward one element

---

**4. How does the `back()` function affect the "current" pointer in a list?**

a) Moves it to the first element

b) Moves it backward one element

c) Moves it to the last element

d) Deletes the element at the current position

**Correct Answer:** b) Moves it backward one element

---

**5. If you want to navigate to the first element in a list after moving forward and backward, which
function should you use?**

a) `start()`
b) `tail()`

c) `back()`

d) `next()`

**Correct Answer:** a) `start()

Chapter#2
### Quiz: Implementing and Understanding List Data Structures in C++

---

**1. When implementing a list using an array in C++, why might you start indexing from 1 instead of
0?**
a) To avoid using the zeroth position for simplicity
b) To utilize all positions in the array
c) To improve memory management
d) To follow standard C++ practices
**Correct Answer:** a) To avoid using the zeroth position for simplicity

---

**2. What happens when you call the `add(9)` method when the current position in the list is 3?**
a) The element 9 replaces the current element at position 3
b) The element 9 is added to the end of the list
c) The element 9 is inserted at position 4, and all subsequent elements are shifted one position to the
right
d) The element 9 is inserted at the beginning of the list
**Correct Answer:** c) The element 9 is inserted at position 4, and all subsequent elements are shifted
one position to the right

---
**3. After adding an element to the list using `add()`, what changes occur in the array representation of
the list?**
a) The size of the array is decreased by one
b) The current position is moved forward by one, and the size is increased by one
c) The array is reallocated to accommodate the new element
d) The first element of the list is replaced
**Correct Answer:** b) The current position is moved forward by one, and the size is increased by one

---

**4. What is the function of the `next()` method in the context of list manipulation?**
a) It adds a new element to the list
b) It moves the current position one position forward in the list
c) It removes the last element of the list
d) It resets the current position to the start of the list
**Correct Answer:** b) It moves the current position one position forward in the list

---

**5. How do you handle boundary conditions in a list implemented using an array?**
a) By using dynamic memory allocation to expand the array when needed
b) By writing additional code to check if the current position is at the start or end of the list before
moving it
c) By ensuring that the array size is always large enough to accommodate new elements
d) By resetting the list when the boundary is reached
**Correct Answer:** b) By writing additional code to check if the current position is at the start or end
of the list before moving it

---
**6. What happens if you attempt to move the "current" pointer forward when it is already at the last
element of the array?**
a) The pointer wraps around to the first element
b) An error occurs as the pointer cannot move beyond the last element
c) The list is automatically expanded to add more elements
d) The pointer remains at the last element
**Correct Answer:** b) An error occurs as the pointer cannot move beyond the last element

---

**7. In a list implemented using an array of size 100, what happens if you attempt to add the 101st
element?**
a) The element is added, and the array size is automatically increased
b) The list is cleared and starts from the first element again
c) An error occurs as there is no space available in the array
d) The 101st element replaces the first element
**Correct Answer:** c) An error occurs as there is no space available in the array

---

**8. Why is it important to consider boundary conditions when working with lists in C++?**
a) To ensure that the list operates efficiently
b) To avoid runtime errors and out-of-bounds access
c) To allow for dynamic resizing of the list
d) To maintain the order of elements in the list
**Correct Answer:** b) To avoid runtime errors and out-of-bounds access

---

**9. Which method would you use to move the current position backward in a list?**
a) `start()`
b) `previous()`
c) `back()`
d) `reverse()`
**Correct Answer:** c) `back()`

---

**10. If the current position is at index 1 in a list, what happens if you call the `back()` method?**
a) The current position moves to the last element
b) An error occurs because there is no previous element
c) The current position moves to the zeroth element
d) The list is reversed
**Correct Answer:** b) An error occurs because there is no previous element

### Quiz: List Operations and Methods

**1. What is the result of calling the `remove()` method when the current position is at index 5 and the
element at that position is 7?**
a) The element 7 is removed and the remaining elements are shifted to the right
b) The element 7 is removed and the size of the list is increased by one
c) The element 7 is removed, and all elements to the right are shifted one position to the left
d) The element 7 is replaced with 0 and the size of the list remains unchanged
**Correct Answer:** c) The element 7 is removed, and all elements to the right are shifted one position
to the left

---

**2. After removing an element from the list, what happens to the `current` pointer?**
a) The `current` pointer moves to the next element
b) The `current` pointer moves to the previous element
c) The `current` pointer remains at the same index, pointing to the new element that occupies the
removed element's place
d) The `current` pointer is reset to the start of the list
**Correct Answer:** c) The `current` pointer remains at the same index, pointing to the new element
that occupies the removed element's place

---

**3. How does the `remove()` method affect the size of the list?**
a) It increases the size of the list by one
b) It decreases the size of the list by one
c) It leaves the size of the list unchanged
d) It doubles the size of the list
**Correct Answer:** b) It decreases the size of the list by one

---

**4. What does the `find(x)` function do in a list data structure?**


a) It adds the element `x` to the list
b) It removes the element `x` from the list
c) It searches for the element `x`, sets the `current` pointer to its position, and returns true if found
d) It updates the element `x` at a specific position
**Correct Answer:** c) It searches for the element `x`, sets the `current` pointer to its position, and
returns true if found

---

**5. If the `find(x)` function does not locate the element `x` in the list, what does it return?**
a) 1 (true)
b) 0 (false)
c) -1
d) The index of the element
**Correct Answer:** b) 0 (false)

---

**6. When using the `remove()` method, which of the following operations is performed to maintain the
integrity of the list?**
a) Reallocate the list to a larger size
b) Shift elements on the right of the removed element one position to the right
c) Shift elements on the right of the removed element one position to the left
d) Insert a placeholder element at the removed position
**Correct Answer:** c) Shift elements on the right of the removed element one position to the left

---

**7. In the context of the `find(x)` function, what does the statement `if (j < size + 1)` check?**
a) It verifies if the element `x` is within the list boundaries
b) It checks if the index `j` is within the valid range of the list
c) It ensures that the element `x` was found and `j` is a valid position
d) It validates if `x` is the last element in the list
**Correct Answer:** c) It ensures that the element `x` was found and `j` is a valid position

---

**8. If the `current` pointer is at index 5 and you call `remove()`, what will be the new index of the
`current` pointer if element 7 is removed?**
a) It will point to index 6
b) It will point to index 4
c) It will point to index 5
d) It will be reset to the start of the list
**Correct Answer:** c) It will point to index 5
---

**9. What is the primary purpose of the `find(x)` function?**


a) To sort the list in ascending order
b) To locate an element and update the current position to that element
c) To delete the element `x` from the list
d) To insert the element `x` at a specified position
**Correct Answer:** b) To locate an element and update the current position to that element

---

**10. After the `find(x)` function is executed and the element `x` is found, what happens to the `current`
pointer?**
a) It is reset to the beginning of the list
b) It points to the position of the found element `x`
c) It moves to the next element after `x`
d) It remains unchanged
**Correct Answer:** b) It points to the position of the found element `x`

### Quiz: Array and Linked List Operations

**1. In the `find(x)` function, what does the `break` statement do when an element `x` is found?**
a) It terminates the function immediately
b) It exits the for loop
c) It sets the `current` pointer to the start of the list
d) It continues the loop to the next iteration
**Correct Answer:** b) It exits the for loop

---
**2. What value does `find(x)` return if the element `x` is found in the list?**
a) 0
b) -1
c) 1
d) The index of the element `x`
**Correct Answer:** c) 1

---

**3. What does the `get()` method do in a list implemented with an array?**
a) Adds a new element to the list
b) Retrieves the element at the current position
c) Removes the element at the current position
d) Updates the value at a specified position
**Correct Answer:** b) Retrieves the element at the current position

---

**4. What is the result of calling the `update(x)` method in a list?**


a) It adds `x` to the end of the list
b) It sets the value of the element at the current position to `x`
c) It removes the element `x` from the list
d) It shifts all elements to the right
**Correct Answer:** b) It sets the value of the element at the current position to `x`

---

**5. How does the `length()` method in a list function?**


a) It returns the size of the internal array
b) It returns the number of elements in the list
c) It returns the index of the last element
d) It returns the current position of the pointer
**Correct Answer:** b) It returns the number of elements in the list

---

**6. What does the `back()` method do in a list?**


a) Moves the `current` pointer one position forward
b) Moves the `current` pointer one position backward
c) Sets the `current` pointer to the start of the list
d) Sets the `current` pointer to the end of the list
**Correct Answer:** b) Moves the `current` pointer one position backward

---

**7. What is the purpose of the `start()` method in a list?**


a) Sets the `current` pointer to the last element
b) Sets the `current` pointer to the first element
c) Removes the first element from the list
d) Adds a new element to the start of the list
**Correct Answer:** b) Sets the `current` pointer to the first element

---

**8. How does the `end()` method affect the `current` pointer?**
a) It sets the `current` pointer to the beginning of the list
b) It moves the `current` pointer one position to the end of the list
c) It sets the `current` pointer to the last element
d) It sets the `current` pointer to a specified index
**Correct Answer:** c) It sets the `current` pointer to the last element

---

**9. What is the worst-case time complexity for the `add()` method when inserting an element at the start
of the list?**
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)
**Correct Answer:** c) O(n)

---

**10. In the context of the `remove()` method, what is the worst-case scenario for removing an
element?**
a) Removing an element from the end of the list
b) Removing an element from the middle of the list
c) Removing an element from the beginning of the list
d) Removing an element when the list is empty
**Correct Answer:** c) Removing an element from the beginning of the list

---

**11. When using a linked list, what does each node contain?**
a) The value of the element and the index of the next element
b) The value of the element and a pointer to the next node
c) The index of the element and the value of the next node
d) The value of the element and the size of the list
**Correct Answer:** b) The value of the element and a pointer to the next node
---

**12. How do you know if you have reached the end of a linked list?**
a) The `current` pointer points to NULL
b) The `head` pointer is NULL
c) The last node’s `next` pointer is NULL
d) The `current` pointer is equal to the size of the list
**Correct Answer:** c) The last node’s `next` pointer is NULL

---

**13. In a linked list, what role does the `head` pointer serve?**
a) Points to the last node of the list
b) Points to the current node being processed
c) Points to the first node of the list
d) Points to a specific element in the list
**Correct Answer:** c) Points to the first node of the list

---

**14. What happens when you remove an element from a linked list?**
a) The element is deleted, and the list is reindexed
b) The element is replaced with NULL
c) The nodes are rearranged, and the link to the next node is updated
d) The linked list is reset to its initial state
**Correct Answer:** c) The nodes are rearranged, and the link to the next node is updated

---

**15. What is the advantage of using a linked list over an array for dynamic data storage?**
a) Faster access to elements
b) Constant time complexity for element access
c) Dynamic size and no need for resizing
d) Simpler memory management
**Correct Answer:** c) Dynamic size and no need for resizing

---

**16. How do you traverse a linked list from the beginning to the end?**
a) Access elements by their index
b) Use a for loop with the index of each element
c) Follow the `next` pointers from the `head` node to the end
d) Reverse the list and access elements from the end
**Correct Answer:** c) Follow the `next` pointers from the `head` node to the end

---

**17. What does the `current` pointer represent in a linked list?**


a) The index of the current node
b) The address of the `head` node
c) The pointer to the current node in the list
d) The position of the last accessed node
**Correct Answer:** c) The pointer to the current node in the list

---

**18. In the context of a linked list, what does the `next` field in a node indicate?**
a) The position of the next node in the list
b) The memory address of the next node
c) The value of the next element in the list
d) The size of the linked list
**Correct Answer:** b) The memory address of the next node

---

**19. What is a major disadvantage of using a linked list compared to an array?**


a) Fixed size
b) Extra memory usage for pointers
c) Slower access time for elements
d) Complexity in implementation
**Correct Answer:** b) Extra memory usage for pointers

---

**20. How do you add a new node to the end of a linked list?**
a) Update the `head` pointer to the new node
b) Traverse the list to find the last node and update its `next` pointer to the new node
c) Insert the new node at the beginning and adjust the `head` pointer
d) Replace the `current` node with the new node
**Correct Answer:** b) Traverse the list to find the last node and update its `next` pointer to the new
node

Chapter#3
Here’s a comprehensive quiz based on array and linked list operations, complete with multiple-choice
questions and the correct answers:

---

### Quiz: Array and Linked List Operations


**1. In the `find(x)` function, what does the `break` statement do when an element `x` is found?**
a) It terminates the function immediately
b) It exits the for loop
c) It sets the `current` pointer to the start of the list
d) It continues the loop to the next iteration
**Correct Answer:** b) It exits the for loop

**2. What value does `find(x)` return if the element `x` is found in the list?**
a) 0
b) -1
c) 1
d) The index of the element `x`
**Correct Answer:** c) 1

**3. What does the `get()` method do in a list implemented with an array?**
a) Adds a new element to the list
b) Retrieves the element at the current position
c) Removes the element at the current position
d) Updates the value at a specified position
**Correct Answer:** b) Retrieves the element at the current position

**4. What is the result of calling the `update(x)` method in a list?**


a) It adds `x` to the end of the list
b) It sets the value of the element at the current position to `x`
c) It removes the element `x` from the list
d) It shifts all elements to the right
**Correct Answer:** b) It sets the value of the element at the current position to `x`

**5. How does the `length()` method in a list function?**


a) It returns the size of the internal array
b) It returns the number of elements in the list
c) It returns the index of the last element
d) It returns the current position of the pointer
**Correct Answer:** b) It returns the number of elements in the list

**6. What does the `back()` method do in a list?**


a) Moves the `current` pointer one position forward
b) Moves the `current` pointer one position backward
c) Sets the `current` pointer to the start of the list
d) Sets the `current` pointer to the end of the list
**Correct Answer:** b) Moves the `current` pointer one position backward

**7. What is the purpose of the `start()` method in a list?**


a) Sets the `current` pointer to the last element
b) Sets the `current` pointer to the first element
c) Removes the first element from the list
d) Adds a new element to the start of the list
**Correct Answer:** b) Sets the `current` pointer to the first element

**8. How does the `end()` method affect the `current` pointer?**
a) It sets the `current` pointer to the beginning of the list
b) It moves the `current` pointer one position to the end of the list
c) It sets the `current` pointer to the last element
d) It sets the `current` pointer to a specified index
**Correct Answer:** c) It sets the `current` pointer to the last element

**9. What is the worst-case time complexity for the `add()` method when inserting an element at the start
of the list?**
a) O(1)
b) O(log n)
c) O(n)
d) O(n^2)
**Correct Answer:** c) O(n)

**10. In the context of the `remove()` method, what is the worst-case scenario for removing an
element?**
a) Removing an element from the end of the list
b) Removing an element from the middle of the list
c) Removing an element from the beginning of the list
d) Removing an element when the list is empty
**Correct Answer:** c) Removing an element from the beginning of the list

**11. When using a linked list, what does each node contain?**
a) The value of the element and the index of the next element
b) The value of the element and a pointer to the next node
c) The index of the element and the value of the next node
d) The value of the element and the size of the list
**Correct Answer:** b) The value of the element and a pointer to the next node

**12. How do you know if you have reached the end of a linked list?**
a) The `current` pointer points to NULL
b) The `head` pointer is NULL
c) The last node’s `next` pointer is NULL
d) The `current` pointer is equal to the size of the list
**Correct Answer:** c) The last node’s `next` pointer is NULL

**13. In a linked list, what role does the `head` pointer serve?**
a) Points to the last node of the list
b) Points to the current node being processed
c) Points to the first node of the list
d) Points to a specific element in the list
**Correct Answer:** c) Points to the first node of the list

**14. What happens when you remove an element from a linked list?**
a) The element is deleted, and the list is reindexed
b) The element is replaced with NULL
c) The nodes are rearranged, and the link to the next node is updated
d) The linked list is reset to its initial state
**Correct Answer:** c) The nodes are rearranged, and the link to the next node is updated

**15. What is the advantage of using a linked list over an array for dynamic data storage?**
a) Faster access to elements
b) Constant time complexity for element access
c) Dynamic size and no need for resizing
d) Simpler memory management
**Correct Answer:** c) Dynamic size and no need for resizing

**16. How do you traverse a linked list from the beginning to the end?**
a) Access elements by their index
b) Use a for loop with the index of each element
c) Follow the `next` pointers from the `head` node to the end
d) Reverse the list and access elements from the end
**Correct Answer:** c) Follow the `next` pointers from the `head` node to the end

**17. What does the `current` pointer represent in a linked list?**


a) The index of the current node
b) The address of the `head` node
c) The pointer to the current node in the list
d) The position of the last accessed node
**Correct Answer:** c) The pointer to the current node in the list
**18. In the context of a linked list, what does the `next` field in a node indicate?**
a) The position of the next node in the list
b) The memory address of the next node
c) The value of the next element in the list
d) The size of the linked list
**Correct Answer:** b) The memory address of the next node

**19. What is a major disadvantage of using a linked list compared to an array?**


a) Fixed size
b) Extra memory usage for pointers
c) Slower access time for elements
d) Complexity in implementation
**Correct Answer:** b) Extra memory usage for pointers

**20. How do you add a new node to the end of a linked list?**
a) Update the `head` pointer to the new node
b) Traverse the list to find the last node and update its `next` pointer to the new node
c) Insert the new node at the beginning and adjust the `head` pointer
d) Replace the `current` node with the new node
**Correct Answer:** b) Traverse the list to find the last node and update its `next` pointer to the new
node

Here's a twenty-question quiz based on the information provided about linked lists and their
implementation in C++:

#### Part 1: Conceptual Understanding

1. **What does the "head pointer" of a linked list refer to?**


- A) The last node of the list
- B) The pointer to the first node of the list
- C) A pointer to the middle of the list
- D) A pointer that indicates the end of the list

**Correct Answer: B**

2. **In the linked list memory representation, what does the value `0` in the pointer part of a node
signify?**
- A) The node is the first in the list
- B) The node is the last in the list
- C) The node has no data
- D) The node is invalid

**Correct Answer: B**

3. **When a new node is added to a linked list, where is it typically inserted in relation to the current
node?**
- A) Before the current node
- B) After the current node
- C) At the beginning of the list
- D) At the end of the list

**Correct Answer: B**

4. **In the provided C++ code, what does the `new Node(9)` statement do?**
- A) Deletes a node with the value `9`
- B) Creates a new node with the value `9`
- C) Updates the existing node with the value `9`
- D) Finds a node with the value `9`

**Correct Answer: B**


5. **What is the purpose of the `set()` method in the `Node` class?**
- A) To retrieve the value of the node
- B) To update the value of the node
- C) To set the next pointer of the node
- D) To delete the node

**Correct Answer: B**

6. **How does the `getNext()` method in the `Node` class function?**


- A) It retrieves the data value of the node
- B) It sets the next pointer of the node
- C) It retrieves the pointer to the next node in the list
- D) It deletes the next node

**Correct Answer: C**

7. **Which part of the `add()` method in the `List` class ensures that the new node points to the next node
after it?**
- A) `newNode->setNext(currentNode->getNext());`
- B) `currentNode->setNext(newNode);`
- C) `currentNode = newNode;`
- D) `size++;`

**Correct Answer: A**

8. **What is the purpose of `lastCurrentNode` in the `add()` method?**


- A) To keep track of the previous node
- B) To point to the last node added
- C) To store the value of the last node
- D) To reset the current node
**Correct Answer: A**

9. **In the `add()` method, what does the `else` block handle?**
- A) Inserting a new node when the list is not empty
- B) Inserting a new node when the list is empty
- C) Removing a node from the list
- D) Retrieving data from the list

**Correct Answer: B**

10. **What does the `get()` method of the `List` class return?**
- A) The value of the last node
- B) The pointer to the current node
- C) The data value of the current node
- D) The total number of nodes in the list

**Correct Answer: C**

#### Part 2: C++ Implementation

11. **Which file typically contains the implementation of methods for a class in C++?**
- A) .h file
- B) .cpp file
- C) .txt file
- D) .cpp and .h file

**Correct Answer: B**

12. **In the `List` class, what is the purpose of `headNode`?**


- A) To store the last node
- B) To keep track of the current node
- C) To point to the first node of the list
- D) To count the number of nodes in the list

**Correct Answer: C**

13. **What does the `next()` method return if the `currentNode` is `NULL`?**
- A) `true`
- B) `false`
- C) `0`
- D) `1`

**Correct Answer: B**

14. **In the `List` class constructor, why is `headNode` set to a new `Node` with `setNext(NULL)`?**
- A) To initialize `headNode` as an empty node
- B) To prepare `headNode` for future node additions
- C) To delete existing nodes
- D) To create a node with data

**Correct Answer: A**

15. **What is the main function of the `traverse()` friend function in the `List` class?**
- A) To add nodes to the list
- B) To delete nodes from the list
- C) To display the elements of the list
- D) To retrieve the current node

**Correct Answer: C**


16. **How does the `addNodes()` function contribute to the `List` class?**
- A) It initializes a list
- B) It deletes nodes from the list
- C) It adds multiple nodes to a list
- D) It retrieves node values

**Correct Answer: C**

17. **What is the role of the `size` variable in the `List` class?**
- A) To keep track of the node values
- B) To store the memory address of nodes
- C) To count the total number of nodes in the list
- D) To store the next node's address

**Correct Answer: C**

18. **What will happen if `currentNode` is `NULL` when calling `next()`?**


- A) The method will return `true`
- B) The method will throw an error
- C) The method will return `false`
- D) The method will terminate

**Correct Answer: C**

19. **Which method is used to move the `currentNode` pointer to the next node in the `List` class?**
- A) `add()`
- B) `get()`
- C) `next()`
- D) `traverse()`
**Correct Answer: C**

20. **What is the main use of `Node *` pointers in the linked list implementation?**
- A) To store node data
- B) To keep track of node addresses
- C) To increment the size of the list
- D) To initialize the list

**Correct Answer: B

Chapter#4

Here’s a 20-question multiple-choice quiz based on the provided lecture on linked lists. Each question is
followed by the correct answer for reference.

---

**1. What does the `start()` method do in a linked list?**


A) Initializes the list with default values
B) Sets `lastCurrentNode` and `currentNode` to `headNode`
C) Deletes the head node
D) Moves `currentNode` to the last node
**Answer:** B) Sets `lastCurrentNode` and `currentNode` to `headNode`

**2. In the `remove()` method, which line of code updates the `next` pointer of the node before the node
to be removed?**
A) `delete currentNode;`
B) `currentNode = lastCurrentNode;`
C) `lastCurrentNode->setNext(currentNode->getNext());`
D) `size--;`
**Answer:** C) `lastCurrentNode->setNext(currentNode->getNext());`

**3. What does the statement `currentNode->getNext()` return?**


A) The value of the current node
B) The address of the node before the current node
C) The address of the node after the current node
D) NULL
**Answer:** C) The address of the node after the current node

**4. What is the purpose of the `delete currentNode;` statement in the `remove()` method?**
A) To reassign `currentNode` to the next node
B) To free the memory allocated for `currentNode`
C) To increment the size of the list
D) To move `currentNode` to `lastCurrentNode`
**Answer:** B) To free the memory allocated for `currentNode`

**5. After calling the `remove()` method, what does `currentNode = lastCurrentNode;` do?**
A) Updates the `currentNode` to point to the node that was before the removed node
B) Deletes the node pointed to by `lastCurrentNode`
C) Sets `currentNode` to NULL
D) Sets `lastCurrentNode` to NULL
**Answer:** A) Updates the `currentNode` to point to the node that was before the removed node

**6. What does the `length()` method return?**


A) The address of the first node
B) The number of nodes in the list
C) The last node in the list
D) The current node
**Answer:** B) The number of nodes in the list
**7. In the list implementation, what is the purpose of `Node *headNode`?**
A) To keep track of the last node
B) To point to the first node of the list
C) To store the size of the list
D) To keep track of the current node
**Answer:** B) To point to the first node of the list

**8. Which method would you use to traverse through the list after calling `start()`?**
A) `length()`
B) `remove()`
C) `next()`
D) `add()`
**Answer:** C) `next()`

**9. What will happen if the `remove()` method is called on the `headNode`?**
A) It will remove the `headNode` and update `headNode` to the next node
B) It will do nothing
C) It will set the `headNode` to NULL
D) It will only decrement the size of the list
**Answer:** A) It will remove the `headNode` and update `headNode` to the next node

**10. How does a doubly-linked list differ from a singly-linked list?**


A) It uses a single pointer per node
B) It has an additional `prevNode` pointer in each node
C) It does not use any pointers
D) It has a fixed size
**Answer:** B) It has an additional `prevNode` pointer in each node

**11. Which of the following is a new method added in the doubly-linked list node class?**
A) `getNext()`
B) `setNext()`
C) `getPrev()`
D) `setPrev()`
**Answer:** C) `getPrev()`

**12. In a doubly-linked list, what does the `setPrev(Node* prevNode)` method do?**
A) Sets the value of the node
B) Points to the next node in the list
C) Sets the `prevNode` pointer
D) Deletes the previous node
**Answer:** C) Sets the `prevNode` pointer

**13. What is a circularly-linked list?**


A) A list where each node points to NULL
B) A list where the last node points back to the first node
C) A list where nodes are connected in a tree structure
D) A list with no head node
**Answer:** B) A list where the last node points back to the first node

**14. What is the main advantage of using a circularly-linked list?**


A) It allows easy traversal in both directions
B) It prevents access to NULL pointers
C) It enables random access to elements
D) It simplifies the `add` operation
**Answer:** B) It prevents access to NULL pointers

**15. In the Josephus Problem, what does the `remove()` method do?**
A) Adds a node to the list
B) Removes the node at a specific position
C) Moves the `currentNode` to the next node
D) Updates the size of the list
**Answer:** B) Removes the node at a specific position

**16. When using the `add` method in a linked list, what operation is performed?**
A) A new node is inserted after the current node
B) The list is sorted
C) The head node is deleted
D) The list size is decreased
**Answer:** A) A new node is inserted after the current node

**17. In a doubly-linked list, how do you update the pointers to insert a new node between two existing
nodes?**
A) Update `nextNode` of the previous node and `prevNode` of the next node
B) Only update the `nextNode` of the new node
C) Only update the `prevNode` of the new node
D) Delete both adjacent nodes and add the new node
**Answer:** A) Update `nextNode` of the previous node and `prevNode` of the next node

**18. What happens when you call the `back()` method in a singly-linked list?**
A) It moves the `currentNode` one step back
B) It is not supported in singly-linked lists
C) It moves the `currentNode` to the start of the list
D) It deletes the previous node
**Answer:** B) It is not supported in singly-linked lists

**19. What is a key characteristic of a singly-linked list?**


A) It allows movement in both forward and backward directions
B) It has only one pointer per node, pointing to the next node
C) It allows direct access to any node
D) It requires the list to be sorted
**Answer:** B) It has only one pointer per node, pointing to the next node

**20. In the code provided for the Josephus Problem, what does the `while (list.length() > 1)` loop do?**
A) It counts the total number of nodes in the list
B) It continues removing nodes until only one node remains
C) It adds new nodes to the list
D) It prints all nodes in the list
**Answer:** B) It continues removing nodes until only one node remains

#### Question 1
What does the statement `list.next()` do in the given context?
- A) Moves the pointer to the previous node
- B) Moves the pointer forward by a specified number of nodes
- C) Removes the current node
- D) Displays the value of the current node

**Answer:** B) Moves the pointer forward by a specified number of nodes

#### Question 2
If the value of `M` is 3, how many times will `list.next()` be called before calling the `remove` method?
- A) 1
- B) 2
- C) 3
- D) 4

**Answer:** C) 3

#### Question 3
After removing a node, how does the position of the pointer change in the given problem?
- A) It stays at the same node
- B) It moves to the previous node
- C) It moves to the next node
- D) It moves to the start of the list

**Answer:** C) It moves to the next node

#### Question 4
In the while loop described, what happens when the length of the list becomes less than or equal to 1?
- A) The while loop continues indefinitely
- B) The while loop is terminated
- C) The pointer moves to the start of the list
- D) A new node is added to the list

**Answer:** B) The while loop is terminated

#### Question 5
How does the list behavior change after a node is removed?
- A) The list resets to the beginning
- B) The counting starts from the next node
- C) The list is sorted
- D) The pointer moves to the previous node

**Answer:** B) The counting starts from the next node

#### Question 6
What is the purpose of incrementing the value of `M` in different iterations?
- A) To make the list shorter
- B) To vary the step count for removing nodes
- C) To reset the list to its original state
- D) To double the number of nodes

**Answer:** B) To vary the step count for removing nodes

#### Question 7
What is the final result when the length of the list is one?
- A) The list is cleared
- B) The node is re-inserted at the start
- C) The single remaining node's value is displayed
- D) The list starts again from the beginning

**Answer:** C) The single remaining node's value is displayed

#### Question 8
If `M` is initially set to 3 and the list length is 10, which node will be removed first?
- A) 1st node
- B) 4th node
- C) 7th node
- D) 10th node

**Answer:** B) 4th node

#### Question 9
If the length of the list is 9 and `M` is 3, which node will be pointed to after three calls to `list.next()`
starting from the 4th node?
- A) 6th node
- B) 7th node
- C) 8th node
- D) 9th node
**Answer:** C) 8th node

#### Question 10
What is the significance of the Josephus problem in the context described?
- A) It determines the leader based on a fixed step count
- B) It calculates the total number of nodes
- C) It sorts the nodes in ascending order
- D) It resets the list position

**Answer:** A) It determines the leader based on a fixed step count

Chapter#5

Here's a twenty-question multiple-choice quiz based on the provided material on circular linked lists,
abstract data types, and stack implementations:

### 1. **What is the primary advantage of using a circular linked list in the Josephus problem?**
a) Faster insertion and deletion operations
b) Simplicity in removing elements in a circular manner
c) Easier to access elements randomly
d) Reduced memory usage
**Answer:** b) Simplicity in removing elements in a circular manner

### 2. **Which method in the `CList` class starts the traversal from the beginning of the list?**
a) `add()`
b) `start()`
c) `next()`
d) `remove()`
**Answer:** b) `start()`
### 3. **In the Josephus problem program, what does the `remove()` method do?**
a) Moves to the next element
b) Adds a new element to the list
c) Removes the current element from the list
d) Retrieves the current element
**Answer:** c) Removes the current element from the list

### 4. **What is the primary benefit of using encapsulation in data structures like `CList`?**
a) Faster execution of code
b) Hiding the internal implementation details from the user
c) Reducing memory usage
d) Allowing multiple inheritance
**Answer:** b) Hiding the internal implementation details from the user

### 5. **Which method of the stack data structure adds an element to the top?**
a) `pop()`
b) `top()`
c) `push()`
d) `isEmpty()`
**Answer:** c) `push()`

### 6. **What does the `top()` method of a stack return?**


a) The element at the bottom of the stack
b) The element at the top of the stack without removing it
c) The element at the middle of the stack
d) The element just below the top
**Answer:** b) The element at the top of the stack without removing it

### 7. **What does the `isEmpty()` method of a stack check for?**


a) If the stack is full
b) If the stack has more than one element
c) If the stack has no elements
d) If the stack has exactly one element
**Answer:** c) If the stack has no elements

### 8. **In the provided stack implementation, what should the user do before calling `pop()`?**
a) Call `isFull()`
b) Call `top()`
c) Call `isEmpty()`
d) Call `push()`
**Answer:** c) Call `isEmpty()`

### 9. **Which data structure is used to solve the Josephus problem in the provided program?**
a) Array
b) Singly Linked List
c) Doubly Linked List
d) Circular Linked List
**Answer:** d) Circular Linked List

### 10. **What does the `add()` method in the `CList` class do?**
a) Adds a new element to the list
b) Retrieves the current element
c) Removes the current element
d) Moves to the next element
**Answer:** a) Adds a new element to the list

### 11. **What is an abstract data type (ADT)?**


a) A specific implementation of a data structure
b) A collection of values and operations on those values
c) A type of programming language
d) A data structure with no methods
**Answer:** b) A collection of values and operations on those values

### 12. **Which method checks if the stack is full in the provided stack implementation?**
a) `isEmpty()`
b) `top()`
c) `isFull()`
d) `push()`
**Answer:** c) `isFull()`

### 13. **In a stack, what is the time complexity for both `push()` and `pop()` operations when
implemented with an array?**
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
**Answer:** a) O(1)

### 14. **What happens if you try to pop an element from an empty stack in the provided
implementation?**
a) The stack will be reset
b) An exception will be thrown
c) The stack will display an error message
d) The stack will crash
**Answer:** c) The stack will display an error message

### 15. **What is the main disadvantage of using an array to implement a stack?**
a) It is slow for insertion and deletion
b) It requires dynamic memory allocation
c) It has a fixed size and can become full
d) It does not support the `top()` method
**Answer:** c) It has a fixed size and can become full

### 16. **In the context of the stack implementation, what does the `push()` method do?**
a) Removes the top element
b) Checks if the stack is full
c) Adds a new element to the top
d) Retrieves the top element without removing it
**Answer:** c) Adds a new element to the top

### 17. **Which method in a circular linked list helps in moving to the next element?**
a) `start()`
b) `get()`
c) `remove()`
d) `next()`
**Answer:** d) `next()`

### 18. **What is the time complexity of the `length()` method in a circular linked list?**
a) O(1)
b) O(n)
c) O(log n)
d) O(n^2)
**Answer:** b) O(n)

### 19. **What does the `isEmpty()` method of a stack return if the stack has elements?**
a) True
b) False
c) Null
d) An exception
**Answer:** b) False
### 20. **What is a common real-life example of a stack?**
a) A list of books on a shelf
b) A circular queue
c) A stack of plates in a cafeteria
d) A doubly linked list
**Answer:** c) A stack of plates in a cafeteria

Chapter #6
Here’s a 30-question multiple-choice quiz based on the lecture on Stack data structures, including both
array-based and linked list implementations:

1. **What is the primary characteristic of a stack data structure?**


- A) First-In-First-Out (FIFO)
- B) Last-In-First-Out (LIFO)
- C) Random Access
- D) Sorted Order

**Answer:** B) Last-In-First-Out (LIFO)

2. **In a stack implemented using an array, where are elements typically pushed and popped from?**
- A) The beginning of the array
- B) The middle of the array
- C) The end of the array
- D) Random positions in the array

**Answer:** C) The end of the array

3. **Which method is used to check if a stack implemented with an array is full?**


- A) isEmpty()
- B) isFull()
- C) top()
- D) pop()

**Answer:** B) isFull()

4. **What is the time complexity of the `push()` operation in a stack implemented using a linked list?**
- A) O(1)
- B) O(n)
- C) O(log n)
- D) O(n^2)

**Answer:** A) O(1)

5. **In a stack implemented with a singly-linked list, where are new elements inserted?**
- A) At the end of the list
- B) At the beginning of the list
- C) In the middle of the list
- D) At random positions

**Answer:** B) At the beginning of the list

6. **Which method in a stack implemented with a linked list retrieves the top element without removing
it?**
- A) push()
- B) pop()
- C) top()
- D) isEmpty()

**Answer:** C) top()
7. **Which method is responsible for removing the top element from a stack implemented using a linked
list?**
- A) push()
- B) pop()
- C) top()
- D) isFull()

**Answer:** B) pop()

8. **What is the purpose of the `isEmpty()` method in a stack implemented using a linked list?**
- A) To check if the stack is full
- B) To check if the stack has no elements
- C) To get the top element
- D) To remove the top element

**Answer:** B) To check if the stack has no elements

9. **Why might a stack implemented with a linked list be preferred over one implemented with an
array?**
- A) It supports random access
- B) It has no fixed size limitation
- C) It uses less memory
- D) It is easier to implement

**Answer:** B) It has no fixed size limitation

10. **What is the time complexity of the `pop()` operation in a stack implemented using a linked list?**
- A) O(1)
- B) O(n)
- C) O(log n)
- D) O(n^2)

**Answer:** A) O(1)

11. **In the context of stacks, what does LIFO stand for?**
- A) Last-In-First-Out
- B) Least-In-First-Out
- C) Last-In-First-Ordered
- D) Largest-In-First-Out

**Answer:** A) Last-In-First-Out

12. **In a linked list implementation of a stack, what does the `head` pointer represent?**
- A) The last node in the list
- B) The first node in the list
- C) The middle node in the list
- D) A null value

**Answer:** B) The first node in the list

13. **When implementing a stack with a linked list, which pointer needs to be updated during the
`push()` operation?**
- A) The `next` pointer of the new node
- B) The `head` pointer
- C) The `previous` pointer of the current node
- D) The `last` pointer

**Answer:** B) The `head` pointer

14. **Which method should be called before performing a `pop()` operation to ensure that the stack is not
empty?**
- A) isFull()
- B) top()
- C) push()
- D) isEmpty()

**Answer:** D) isEmpty()

15. **What does the `top()` method return in a stack implemented with a linked list?**
- A) The value of the node at the end of the list
- B) The value of the node at the beginning of the list
- C) The value of the node that was just added
- D) The number of nodes in the stack

**Answer:** B) The value of the node at the beginning of the list

16. **Which of the following is NOT a reason to prefer a linked list implementation of a stack over an
array?**
- A) Dynamic memory allocation
- B) Avoidance of fixed size limitation
- C) Lower memory overhead for pointers
- D) Simplicity of implementation

**Answer:** C) Lower memory overhead for pointers

17. **What happens in a stack when the computer's address space becomes full?**
- A) The stack implementation itself fails
- B) The stack can continue to grow indefinitely
- C) The stack becomes empty
- D) The stack operations are unaffected
**Answer:** A) The stack implementation itself fails

18. **In postfix notation, how would you write the expression (A + B) * C?**
- A) A B + C *
- B) A + B C *
- C) (A B +) C *
- D) A + B * C

**Answer:** A) A B + C *

19. **How is operator precedence managed in postfix notation?**


- A) By using parentheses
- B) By changing the order of operands
- C) By reordering the operators
- D) By using the stack data structure

**Answer:** D) By using the stack data structure

20. **Which of the following is NOT a method of a stack implemented using a linked list?**
- A) push()
- B) pop()
- C) top()
- D) isFull()

**Answer:** D) isFull()

21. **What is the time complexity of checking if a stack is empty using a linked list implementation?**
- A) O(1)
- B) O(n)
- C) O(log n)
- D) O(n^2)

**Answer:** A) O(1)

22. **How does a stack's implementation affect its memory usage when using an array?**
- A) Memory is allocated dynamically as needed
- B) Memory is allocated all at once, potentially wasting space
- C) Memory is allocated in chunks of fixed size
- D) Memory is never wasted

**Answer:** B) Memory is allocated all at once, potentially wasting space

23. **In a singly-linked list stack, where does the `next` pointer of each node point?**
- A) To the previous node in the list
- B) To the next node in the list
- C) To a random node in the list
- D) To a null value

**Answer:** B) To the next node in the list

24. **Which of the following is a disadvantage of using a linked list to implement a stack?**
- A) Requires additional memory for pointers
- B) Cannot handle large amounts of data
- C) Does not support LIFO operations
- D) Requires fixed-size memory allocation

**Answer:** A) Requires additional memory for pointers

25. **What is the result of converting the infix expression A + B to postfix notation?**
- A) A B +
- B) A + B
- C) + A B
- D) A B

**Answer:** A) A B +

26. **What does the `isFull()` method check in a stack implemented with an array?**
- A) If the stack has reached its capacity
- B) If the stack has no elements
- C) If the stack has more than one element
- D) If the stack can accept more elements without resizing

**Answer:** A) If the stack has reached its capacity

27. **When using a stack for expression evaluation, what is the postfix form of the expression 12 + 60 -
23?**
- A) 12 60 + 23 -
- B) 12 60 - 23 +
- C) 12 + 60 - 23
- D) + 12 60 - 23

**Answer:** A) 12 60 + 23 -

28. **What is a key advantage of using a linked list over an array for stack implementation?**
- A) More complex pointer management
- B) Fixed memory allocation
- C) Dynamic size adjustment
- D) Faster memory access

**Answer:** C) Dynamic size adjustment


29. **In the

context of stack implementation, what does `push()` do?**


- A) Retrieves the top element
- B) Adds an element to the top of the stack
- C) Removes an element from the top of the stack
- D) Checks if the stack is empty

**Answer:** B) Adds an element to the top of the stack

30. **Which of the following operations is not constant time (O(1)) in a stack implemented with an
array?**
- A) push()
- B) pop()
- C) top()
- D) isFull()

**Answer:** D) isFull()

Chapter#7
Here’s a 30-question quiz based on your lecture notes about infix and postfix expressions, including their
conversion and evaluation. Each question has multiple choice answers, with the correct answers indicated.

---

**1. In infix notation, where are operators placed?**


- A) Before operands
- B) After operands
- C) Between operands
- D) Nowhere

**Answer:** C) Between operands

**2. What is the postfix notation of the infix expression `A + B`?**


- A) `AB+`
- B) `A+B`
- C) `+AB`
- D) `BA+`

**Answer:** A) `AB+`

**3. Which of the following is a valid postfix expression for the infix expression `(4 + 3) * 5`?**
- A) `43+5*`
- B) `4 3 + 5 *`
- C) `4 + 3 5 *`
- D) `4 3 5 * +`

**Answer:** A) `43+5*`

**4. How are parentheses used in postfix expressions?**


- A) They are used to group operands and operators.
- B) They are not used in postfix expressions.
- C) They determine the order of operations.
- D) They are used to indicate unary operations.

**Answer:** B) They are not used in postfix expressions.

**5. Which operation would you perform first in the postfix expression `4 3 2 * +`?**
- A) Addition
- B) Subtraction
- C) Multiplication
- D) Division

**Answer:** C) Multiplication

**6. In postfix evaluation, how do you handle an operator when encountered?**


- A) Push it onto the stack
- B) Pop two operands from the stack, apply the operator, and push the result
- C) Ignore it if there are not enough operands
- D) Directly output the result

**Answer:** B) Pop two operands from the stack, apply the operator, and push the result

**7. What does the `push()` operation do in the context of stack implementation?**
- A) Retrieves the top element
- B) Adds an element to the top of the stack
- C) Removes an element from the top of the stack
- D) Checks if the stack is empty

**Answer:** B) Adds an element to the top of the stack

**8. Which of the following operations is not constant time (O(1)) in a stack implemented with an
array?**
- A) push()
- B) pop()
- C) top()
- D) isFull()

**Answer:** D) isFull()
**9. What is the postfix notation of the infix expression `12 + 60 - 23`?**
- A) `12 60 23 - +`
- B) `12 60 + 23 -`
- C) `12 60 23 + -`
- D) `12 60 23 - +`

**Answer:** B) `12 60 + 23 -`

**10. For the infix expression `A * B + C`, which operation has the highest precedence?**
- A) Addition
- B) Multiplication
- C) Subtraction
- D) Division

**Answer:** B) Multiplication

**11. What is the postfix form of `A * B + C`?**


- A) `AB*C+`
- B) `A B C * +`
- C) `AB*C+`
- D) `A B * C +`

**Answer:** A) `AB*C+`

**12. How are operators with higher precedence handled in postfix notation?**
- A) They are placed before lower precedence operators.
- B) They are placed after lower precedence operators.
- C) They are ignored.
- D) Their precedence is determined by parentheses.
**Answer:** A) They are placed before lower precedence operators.

**13. In evaluating the postfix expression `6 2 3 + 5 *`, what is the first step?**
- A) Apply addition
- B) Apply multiplication
- C) Push the numbers onto the stack
- D) Pop the top two numbers from the stack

**Answer:** C) Push the numbers onto the stack

**14. What does the function `prcd(op1, op2)` do in the context of infix to postfix conversion?**
- A) Checks if `op1` has precedence over `op2`
- B) Determines if `op1` is an operand
- C) Compares `op1` and `op2` for equality
- D) Converts `op1` and `op2` to postfix

**Answer:** A) Checks if `op1` has precedence over `op2`

**15. What happens when encountering a closing parenthesis `)` in the infix to postfix conversion
algorithm?**
- A) Push it onto the stack
- B) Pop operators from the stack until encountering an opening parenthesis
- C) Discard it
- D) Add it to the postfix string

**Answer:** B) Pop operators from the stack until encountering an opening parenthesis

**16. Which algorithm step is responsible for converting the infix expression `A + B * C` to postfix?**
- A) Pushing all operands onto the stack
- B) Applying all operators immediately
- C) Pushing operators with lower precedence onto the stack
- D) Using parentheses to enforce operator precedence

**Answer:** C) Pushing operators with lower precedence onto the stack

**17. In the postfix expression `3 4 + 2 * 7 /`, what does `4 +` indicate?**


- A) Addition of `3` and `4`
- B) Multiplication of `2` and `7`
- C) Division of `7` by the result of `2 * 7`
- D) Addition of `2` and `7`

**Answer:** A) Addition of `3` and `4`

**18. What is the result of evaluating the postfix expression `7 2 3 + 1 - *`?**


- A) 8
- B) 5
- C) 9
- D) 14

**Answer:** D) 14

**19. When converting infix to postfix, what does encountering an operator `op` while the stack contains
operators with higher or equal precedence mean?**
- A) Push `op` onto the stack immediately
- B) Pop operators from the stack to the postfix string until an operator of lower precedence is
encountered
- C) Ignore the operator `op`
- D) Discard the top operator from the stack
**Answer:** B) Pop operators from the stack to the postfix string until an operator of lower
precedence is encountered

**20. How is a unary operator handled in postfix notation?**


- A) It is treated like a binary operator.
- B) It is not used in postfix notation.
- C) It does not require two operands.
- D) It is pushed onto the stack with its operands.

**Answer:** C) It does not require two operands.

**21. In the postfix expression `5 1 2 + 4 * + 3 -`, which operation is performed last?**


- A) Addition
- B) Multiplication
- C) Subtraction
- D) Division

**Answer:** C) Subtraction

**22. What does the `pop()` operation do in the context of stack implementation?**
- A) Adds an element to the stack
- B) Retrieves and removes the top element from the stack
- C) Checks if the stack is empty
- D) Peeks at the bottom element of the stack

**Answer:** B) Retrieves and removes the top element from the stack

**23. How do you determine the precedence of operators in infix expressions?**


- A) Based on the position of operators in the expression
- B) Using predefined rules of operator precedence
- C) By converting infix to postfix first
- D) Based on user input

**Answer:** B) Using predefined rules of operator precedence

**24. What is the result of the postfix expression `4 5 * 7 +`?**


- A) 39
- B) 23
- C) 12
- D) 35

**Answer:** A) 23

**25. Which operator has the highest precedence in most programming languages?**
- A) Addition
- B) Subtraction
- C) Multiplication
- D) Division

**Answer:** C) Multiplication

**26. In the infix expression `(A + B) * (C - D)`, how are the parentheses used?**
- A) To enforce precedence of operations
- B) To change the order of operands
- C) To separate operators
- D) To denote unary operations

**Answer:** A) To enforce precedence of operations

**27. What is the postfix notation of `A * (B + C) - D


`?**
- A) `ABC+*D-`
- B) `ABC+*D-`
- C) `A*BC+D-D`
- D) `AB+C*D-`

**Answer:** A) `ABC+*D-`

**28. When evaluating `3 4 5 * +`, what is the result of `4 * 5`?**


- A) 9
- B) 12
- C) 20
- D) 15

**Answer:** C) 20

**29. What is the postfix form of the infix expression `A / (B - C) + D`?**


- A) `A B C - / D +`
- B) `A B C - / D +`
- C) `AB-C/D+`
- D) `A B C - / D +`

**Answer:** A) `A B C - / D +`

**30. What is the final result of evaluating the postfix expression `7 8 + 3 2 + /`?**
- A) 2
- B) 5
- C) 6
- D) 4
**Answer:** C) 6

Chapter#8
Sure! Here’s a 30-question multiple-choice quiz on the conversion of infix expressions to postfix notation,
C++ templates, and stack usage:

---

### Quiz on Infix to Postfix Conversion, C++ Templates, and Stack Usage

**1. What is the purpose of parentheses in an infix expression?**


A) To separate operators
B) To change the order of evaluation
C) To increase the length of the expression
D) To add more operands

*Correct Answer: B) To change the order of evaluation*

**2. How is the expression `A + B * C` converted to postfix notation if addition has higher precedence
than multiplication?**
A) `AB+C*`
B) `A B C * +`
C) `(A B C * +)`
D) `AB C * +`

*Correct Answer: A) AB+C***

**3. In the conversion process from infix to postfix, what happens to opening parentheses?**
A) They are discarded
B) They are converted to closing parentheses
C) They are pushed onto the stack
D) They are placed in the postfix expression

*Correct Answer: C) They are pushed onto the stack*

**4. When encountering a closing parenthesis in infix to postfix conversion, what should be done?**
A) Discard the closing parenthesis
B) Push the closing parenthesis onto the stack
C) Pop operators from the stack until an opening parenthesis is encountered
D) Convert the closing parenthesis to a subtraction operator

*Correct Answer: C) Pop operators from the stack until an opening parenthesis is encountered*

**5. What is the postfix notation for the infix expression `(A + B) * C`?**
A) `AB+C*`
B) `A B + C *`
C) `A + B C *`
D) `A B C * +`

*Correct Answer: A) AB+C***

**6. In postfix notation, how are operands and operators arranged?**


A) Operands follow operators
B) Operators follow operands
C) Operands and operators are mixed randomly
D) Operands and operators are separated by parentheses

*Correct Answer: B) Operators follow operands*

**7. What data structure is commonly used to convert an infix expression to postfix notation?**
A) Queue
B) Stack
C) List
D) Array

*Correct Answer: B) Stack*

**8. In C++ templates, what does `template <class T>` signify?**


A) It specifies that `T` is a class type
B) It declares a template for a generic data type
C) It indicates a new data type named `T`
D) It defines a constant named `T`

*Correct Answer: B) It declares a template for a generic data type*

**9. Which of the following is NOT a member function of the Stack class template?**
A) `push()`
B) `pop()`
C) `peek()`
D) `sort()`

*Correct Answer: D) sort()*

**10. What does the `push()` function of the Stack class do?**
A) Removes the top element from the stack
B) Returns the top element of the stack
C) Adds an element to the top of the stack
D) Checks if the stack is empty

*Correct Answer: C) Adds an element to the top of the stack*


**11. What is the output of the following code? `Stack<int> intstack; intstack.push(5); cout <<
intstack.pop();`**
A) `5`
B) `0`
C) `Stack overflow`
D) `Stack underflow`

*Correct Answer: A) 5*

**12. What is the purpose of `#define MAXSTACKSIZE 50` in the Stack implementation?**
A) To define the maximum size of the stack
B) To create a constant named `MAXSTACKSIZE`
C) To allocate memory for the stack
D) To initialize the stack

*Correct Answer: A) To define the maximum size of the stack*

**13. What happens if you attempt to push an element onto a full stack?**
A) The element is added and the stack size is increased
B) The stack overflows and an error message is shown
C) The element is discarded
D) The stack is automatically resized

*Correct Answer: B) The stack overflows and an error message is shown*

**14. How is memory managed for the stack in the provided code?**
A) Static memory allocation
B) Dynamic memory allocation using `new` and `delete`
C) Automatic memory management
D) Memory is not allocated

*Correct Answer: B) Dynamic memory allocation using `new` and `delete`*

**15. What is the purpose of the `peek()` function in the Stack class?**
A) To add an element to the stack
B) To remove and return the top element of the stack
C) To return the top element without removing it
D) To check if the stack is full

*Correct Answer: C) To return the top element without removing it*

**16. In the context of function calls, what does the stack contain?**
A) Only the return address
B) Only the function arguments
C) Return address, function arguments, and local variables
D) Only the local variables

*Correct Answer: C) Return address, function arguments, and local variables*

**17. What does the `ret` instruction do in assembly language?**


A) It returns the result of a computation
B) It returns control to the calling function
C) It stores the result in a register
D) It increments the stack pointer

*Correct Answer: B) It returns control to the calling function*

**18. How are function arguments ordered on the stack?**


A) The first argument is on top
B) The last argument is on top
C) Arguments are in reverse order
D) Arguments are unordered

*Correct Answer: B) The last argument is on top*

**19. In the function call stack, where is the return address stored?**
A) At the bottom of the stack
B) At the top of the stack
C) In a register
D) In the function's local variables

*Correct Answer: B) At the top of the stack*

**20. Which of the following is NOT a typical use of a stack?**


A) Expression evaluation
B) Function call management
C) Dynamic memory allocation
D) Backtracking in algorithms

*Correct Answer: C) Dynamic memory allocation*

**21. What does the `pop()` function of the Stack class do?**
A) Adds an element to the stack
B) Removes and returns the top element of the stack
C) Returns the top element without removing it
D) Checks if the stack is full

*Correct Answer: B) Removes and returns the top element of the stack*
**22. How can you ensure that the Stack class template can be used with different data types?**
A) Use a different class for each data type
B) Write separate code for each data type
C) Use C++ templates to create a generic class
D) Use only one specific data type for the stack

*Correct Answer: C) Use C++ templates to create a generic class*

**23. What is the effect of the `delete nodes;` statement in the Stack destructor?**
A) Frees the memory allocated for the stack
B) Allocates more memory for the stack
C) Resets the stack size to zero
D) Reinitializes the stack

*Correct Answer: A) Frees the memory allocated for the stack*

**24. How does the stack handle function return values in assembly language?**
A) By storing the value in a global variable
B) By placing the return value on the stack
C) By storing the return value in a register
D) By discarding the return value

*Correct Answer: C) By storing the return value in a register*

**25. Which of the following statements about templates in C++ is true?**


A) Templates cannot be used for classes
B) Templates allow for code reuse with different data types
C) Templates require separate code for each data type
D) Templates are not supported in C++
*Correct Answer: B) Templates allow for code reuse with different data types*

**26. What is the role of `T* nodes;` in the Stack class definition?**
A) To store the size of the stack
B) To point to the array of stack elements
C) To hold the top index of the stack
D) To manage memory allocation for the stack

*Correct Answer: B) To point to the array of stack elements*

**27. How does the `empty()` function determine if the stack is empty?**
A) By checking if the stack size is zero
B) By checking if the top index is less than zero
C) By checking if the stack pointer is null
D) By checking if the stack array is full

*Correct Answer: B) By checking if the top index is less than zero*

**28. What is the initial value of the `top` variable in the Stack constructor?**
A) 0
B) 1
C) -1
D) MAXSTACKSIZE

*Correct Answer: C) -1*

**29. How is the postfix expression `AB+C*` evaluated?**


A) Addition is done first, then multiplication
B) Multiplication is done first, then addition
C) Both addition and multiplication are done simultaneously
D) The expression is evaluated from left to right

*Correct Answer: B) Multiplication is done first, then addition*

**30. What is the role of the `#include <iostream>` directive in C++?**


A) To define the maximum size of the stack
B) To include the standard input/output stream library
C) To manage memory allocation for the stack
D) To declare a template class

*Correct Answer: B) To include the standard input/output stream library*

Chapter # 9
Here is a 30-question multiple-choice quiz based on the concepts discussed in your lecture. Each question
includes the correct answer.

### Quiz on Stack and Queue Data Structures

**1. In the context of memory organization for processes, which section is used for function calls?**
A) Code
B) Static Data
C) Stack
D) Heap

*Correct Answer: C) Stack*

**2. What is the main role of the heap in memory organization?**


A) To store function call details
B) To store static data
C) To allocate memory dynamically
D) To manage local variables

*Correct Answer: C) To allocate memory dynamically*

**3. When a function is called, where are its parameters and local variables stored?**
A) In the code section
B) In the static data section
C) On the stack
D) In the heap

*Correct Answer: C) On the stack*

**4. What happens to the local variables of a function once it finishes execution?**
A) They are stored in the heap
B) They are moved to static data
C) They are removed from the stack
D) They are kept in the code section

*Correct Answer: C) They are removed from the stack*

**5. In C/C++ programming, where are static variables stored?**


A) On the stack
B) In the heap
C) In the static data section
D) In the code section

*Correct Answer: C) In the static data section*


**6. What is a queue's primary characteristic compared to a stack?**
A) LIFO (Last In First Out)
B) FIFO (First In First Out)
C) FILO (First In Last Out)
D) LILO (Last In Last Out)

*Correct Answer: B) FIFO (First In First Out)*

**7. Which operation adds an element to the rear of a queue?**


A) dequeue()
B) front()
C) isEmpty()
D) enqueue()

*Correct Answer: D) enqueue()*

**8. Which operation removes an element from the front of a queue?**


A) enqueue()
B) dequeue()
C) isEmpty()
D) front()

*Correct Answer: B) dequeue()*

**9. How does the `front()` function in a queue work?**


A) Removes and returns the front element
B) Returns the front element without removing it
C) Adds an element to the rear
D) Checks if the queue is empty
*Correct Answer: B) Returns the front element without removing it*

**10. In a queue implemented using a linked list, where are elements added?**
A) At the front
B) At the rear
C) In the middle
D) Randomly

*Correct Answer: B) At the rear*

**11. What does the `isEmpty()` function check in a queue?**


A) If the queue is full
B) If the queue has elements
C) If the queue is empty
D) If the queue is circular

*Correct Answer: C) If the queue is empty*

**12. In a circular array implementation of a queue, what does the `enqueue()` operation do?**
A) Adds an element at the front
B) Moves the rear pointer and adds an element
C) Removes an element from the rear
D) Checks if the queue is full

*Correct Answer: B) Moves the rear pointer and adds an element*

**13. When using a circular array for a queue, how is the `rear` pointer updated in `enqueue()`?**
A) It is incremented by 1 and wrapped around using modulo operation
B) It is decremented by 1
C) It is set to the front pointer
D) It is set to a fixed value

*Correct Answer: A) It is incremented by 1 and wrapped around using modulo operation*

**14. What does the `dequeue()` function do in a circular array implementation of a queue?**
A) Increments the front pointer
B) Decrements the rear pointer
C) Removes an element from the front and updates the front pointer
D) Adds an element to the rear

*Correct Answer: C) Removes an element from the front and updates the front pointer*

**15. Which data structure allows both insertion and deletion at one end?**
A) Queue
B) Stack
C) Linked List
D) Array

*Correct Answer: B) Stack*

**16. What is the primary use of a queue in simulations?**


A) To manage function calls
B) To model real-world processes
C) To store static data
D) To handle memory allocation

*Correct Answer: B) To model real-world processes*

**17. In the stack layout, what is the correct order of items stored when a function is called?**
A) Local variables, parameters, return address
B) Parameters, return address, local variables
C) Return address, parameters, local variables
D) Parameters, local variables, return address

*Correct Answer: D) Parameters, local variables, return address*

**18. Which of the following best describes a stack?**


A) FIFO
B) LIFO
C) FILO
D) Circular

*Correct Answer: B) LIFO*

**19. What is the purpose of the `isFull()` function in a queue implemented with an array?**
A) To check if there are elements in the queue
B) To determine if the array has reached its maximum capacity
C) To remove an element from the queue
D) To add an element to the queue

*Correct Answer: B) To determine if the array has reached its maximum capacity*

**20. Which data structure is better suited for scenarios where elements need to be processed in the order
they arrive?**
A) Stack
B) Queue
C) Linked List
D) Array

*Correct Answer: B) Queue*


**21. In a stack, which operation adds an element?**
A) push()
B) pop()
C) peek()
D) front()

*Correct Answer: A) push()*

**22. In a queue, which operation retrieves the element at the front without removing it?**
A) enqueue()
B) dequeue()
C) front()
D) isEmpty()

*Correct Answer: C) front()*

**23. What happens to the front pointer in a queue when `dequeue()` is called?**
A) It is incremented
B) It is decremented
C) It remains unchanged
D) It is reset to zero

*Correct Answer: A) It is incremented*

**24. How does a queue implemented using an array handle the wrap-around problem?**
A) By resizing the array
B) By shifting elements
C) By using a circular array
D) By using a linked list
*Correct Answer: C) By using a circular array*

**25. Which section of memory is used to store global variables and static data?**
A) Code section
B) Stack
C) Heap
D) Static data section

*Correct Answer: D) Static data section*

**26. What is the time complexity of the `enqueue()` and `dequeue()` operations in a queue implemented
using a linked list?**
A) O(1) for both operations
B) O(n) for both operations
C) O(n) for `enqueue()` and O(1) for `dequeue()`
D) O(1) for `enqueue()` and O(n) for `dequeue()`

*Correct Answer: A) O(1) for both operations*

**27. In a queue using an array, what does the `front` index represent?**
A) The position where new elements are added
B) The position of the last element
C) The position of the first element to be removed
D) The position of the middle element

*Correct Answer: C) The position of the first element to be removed*

**28. What is the primary purpose of the heap memory area?**


A) To manage function calls
B) To store local variables
C) To allocate memory dynamically
D) To handle static data

*Correct Answer: C) To allocate memory dynamically*

**29. In a stack, what operation retrieves but does not remove the top element?**
A) push()
B) pop()
C) peek()
D) front()

*Correct Answer: C) peek()*

**30. What feature differentiates a queue from a stack?**


A) A queue is LIFO while a stack is FIFO
B) A stack supports dynamic memory while a queue does not
C) A queue is FIFO while a stack is LIFO
D) A queue allows random access while a stack does not

*Correct Answer: C) A queue is FIFO while a stack is LIFO*

Chapter#10
Here's a quiz based on the content provided about queues, simulation models, and priority queues in the
context of a banking simulation:

### Quiz on Queues and Simulation Models

#### 1. What is the primary purpose of using a queue in the bank simulation described?
A) To store transaction history
B) To manage the order of customer service
C) To record customer complaints
D) To calculate daily profit

**Correct Answer: B) To manage the order of customer service**

#### 2. In the provided bank simulation, what happens when a new customer arrives?
A) The customer immediately leaves the bank
B) The customer is inserted into the shortest queue
C) The customer is randomly assigned to any queue
D) The customer is served immediately without waiting

**Correct Answer: B) The customer is inserted into the shortest queue**

#### 3. Which simulation model uses a clock to track time?


A) Event-based simulation
B) Time-based simulation
C) Queue-based simulation
D) Priority-based simulation

**Correct Answer: B) Time-based simulation**

#### 4. How does the event-based simulation differ from the time-based simulation?
A) It uses a continuous clock to track events
B) It processes events based on their occurrence time rather than waiting for the clock to tick
C) It does not use queues
D) It ignores the arrival and departure times of customers

**Correct Answer: B) It processes events based on their occurrence time rather than waiting for the clock
to tick**
#### 5. What is a priority queue?
A) A queue where the first item is served first
B) A queue where items are processed based on their priority rather than their arrival time
C) A queue where items are processed randomly
D) A queue where items are processed based on their arrival time

**Correct Answer: B) A queue where items are processed based on their priority rather than their arrival
time**

#### 6. In the context of the bank simulation, what information is stored in the `customer.dat` file?
A) Bank account details
B) Customer arrival time and transaction duration
C) Teller shift timings
D) Daily bank transactions

**Correct Answer: B) Customer arrival time and transaction duration**

#### 7. How is the smallest queue determined in the simulation?


A) By comparing the transaction times of customers
B) By counting the number of customers in each queue
C) By randomly selecting a queue
D) By checking the number of transactions processed

**Correct Answer: B) By counting the number of customers in each queue**

#### 8. What happens when a customer completes their transaction at a teller?


A) They are immediately removed from the queue
B) A departure event is created and added to the priority queue
C) They are moved to a different queue
D) They receive a bonus

**Correct Answer: B) A departure event is created and added to the priority queue**

#### 9. What does the `processArrival()` function do?


A) It processes the departure of a customer
B) It calculates the total wait time for customers
C) It handles the arrival of a new customer and assigns them to the shortest queue
D) It reads the customer data from the file

**Correct Answer: C) It handles the arrival of a new customer and assigns them to the shortest queue**

#### 10. What is the role of the `processDeparture()` function?


A) To read the customer data
B) To calculate the time a customer spends in the queue
C) To process a customer's departure and manage the next customer in the queue
D) To initialize the priority queue

**Correct Answer: C) To process a customer's departure and manage the next customer in the queue**

#### 11. What kind of data structure is used to manage customer events in the simulation?
A) Stack
B) Queue
C) Priority Queue
D) Array

**Correct Answer: C) Priority Queue**

#### 12. In the given C++ code, what does the `while` loop in the `main` function do?
A) It processes customer transactions directly
B) It continuously runs the simulation until all events are processed
C) It initializes the simulation
D) It reads customer data from the file

**Correct Answer: B) It continuously runs the simulation until all events are processed**

#### 13. What does the `readNewCustomer()` function do?


A) Processes customer departure
B) Reads new customer data from the file and adds an arrival event to the priority queue
C) Updates the transaction time of a customer
D) Creates a new teller queue

**Correct Answer: B) Reads new customer data from the file and adds an arrival event to the priority
queue**

#### 14. What is the purpose of the `Event` class in the simulation?
A) To store customer details
B) To manage the order of customer service
C) To represent a specific point in time when an event occurs, such as arrival or departure
D) To handle queue operations

**Correct Answer: C) To represent a specific point in time when an event occurs, such as arrival or
departure**

#### 15. Why might a priority queue be used in simulations?


A) To process items in a random order
B) To ensure that items are processed in the order of their priority
C) To eliminate the need for a queue
D) To speed up the simulation process

**Correct Answer: B) To ensure that items are processed in the order of their priority**
#### 16. What happens if the queue for a teller is empty when a customer arrives?
A) The customer waits in the queue
B) The customer leaves the bank
C) The customer is served immediately at the teller
D) The customer is assigned to a different teller

**Correct Answer: C) The customer is served immediately at the teller**

#### 17. How is the total wait time for all customers calculated?
A) By summing the time each customer spends at the teller
B) By calculating the time difference between arrival and departure for each customer
C) By counting the number of customers served
D) By measuring the total simulation time

**Correct Answer: B) By calculating the time difference between arrival and departure for each
customer**

#### 18. What is the output of the simulation program?


A) The total number of transactions
B) The total time spent by all customers and the average time spent per customer
C) The total number of customers who visited the bank
D) The total amount of money deposited or withdrawn

**Correct Answer: B) The total time spent by all customers and the average time spent per customer**

#### 19. What does the `totalTime` variable represent in the simulation?
A) The total number of customers served
B) The cumulative time all customers have spent in the bank
C) The total time the bank is open
D) The time taken to process each transaction

**Correct Answer: B) The cumulative time all customers have spent in the bank**

#### 20. What is the role of the `Customer` class in the simulation?
A) To manage the tellers
B) To represent a customer and their details, such as arrival time and transaction duration
C) To handle the priority queue operations
D) To maintain the simulation clock

**Correct Answer: B) To represent a customer and their details, such as arrival time and transaction
duration**

#### 21. What does the `enqueue()` method do in the queue?


A) It removes a customer from the queue
B) It adds a customer to the queue
C) It checks the queue length
D) It retrieves the next customer in line

**Correct Answer: B) It adds a customer to the queue**

#### 22. What is the purpose of incrementing the clock variable in the time-based simulation?
A) To move to the next customer in the queue
B) To simulate the passage of time and process events accordingly
C) To read new customer data
D) To update the queue lengths

**Correct Answer: B) To simulate the passage of time and process events accordingly**

#### 23. What does the `dequeue()` method do in the queue?


A) It adds a customer to the queue
B) It checks the status of the queue
C) It removes and returns the customer at the front of the queue
D) It initializes the queue

**Correct Answer: C) It removes and returns the customer at the front of the queue**

#### 24. How are departure events handled in the simulation?


A) They are ignored until the end of the simulation
B) They are created and added to the priority queue after a customer completes their transaction
C) They are processed immediately without adding to the priority queue
D) They are scheduled based on a random time

**Correct Answer: B) They are created and added to the priority queue after a customer completes their
transaction**

#### 25. What determines the priority of an event in the priority queue?
A) The type of event
B) The arrival time of the customer
C) The event's occurrence time
D) The customer's transaction duration

**Correct Answer: C) The event's occurrence time**

#### 26. What happens when a departure event is processed?


A) The customer is added to the queue
B) The customer is removed from the queue, and the next customer in the queue is marked for departure
C) The customer leaves the bank immediately
D) The customer's transaction duration is updated
**Correct Answer: B) The customer is removed from the queue, and the next customer in the queue is
marked for departure**

#### 27. In the bank simulation, what is the role of the `while` loop in the `main` function?
A) To read new customer data from the file
B) To continuously process events until the priority queue is

empty
C) To initialize the simulation parameters
D) To print the results of the simulation

**Correct Answer: B) To continuously process events until the priority queue is empty**

#### 28. How is customer service managed in the simulation?


A) Customers are served based on their arrival time
B) Customers are served in the order they appear in the queue
C) Customers are served based on the length of the queue they are assigned to
D) Customers are served immediately upon arrival without waiting

**Correct Answer: C) Customers are served based on the length of the queue they are assigned to**

#### 29. What is the key advantage of using a priority queue in the simulation?
A) It processes events in the order they are added
B) It ensures that events are processed based on their priority, allowing efficient handling of customer
service
C) It simplifies the simulation code
D) It reduces the time complexity of the simulation

**Correct Answer: B) It ensures that events are processed based on their priority, allowing efficient
handling of customer service**
#### 30. How does the simulation ensure that the time is accurately tracked?
A) By using a fixed time increment
B) By using a continuous clock and updating the time with each event
C) By randomly adjusting the time based on customer arrivals
D) By manually setting the time for each event

**Correct Answer: B) By using a continuous clock and updating the time with each event**

Chapter# 11
Here's a 30-question multiple-choice quiz based on the content from your lecture on priority queues and
binary trees. Each question is followed by the correct answer.

### Priority Queue and Binary Tree Quiz

**1. What is the primary characteristic of a priority queue compared to a regular queue?**
- A. FIFO order
- B. LIFO order
- C. Elements are retrieved based on priority
- D. Elements are sorted alphabetically

*Correct Answer: C. Elements are retrieved based on priority*

**2. In the provided C++ code for the `PriorityQueue`, what does the `full()` method check?**
- A. If the queue is empty
- B. If the queue size is greater than 0
- C. If the queue size is equal to `PQMAX`
- D. If the queue is not initialized

*Correct Answer: C. If the queue size is equal to `PQMAX`*


**3. What happens in the `remove()` method when the queue size becomes 0?**
- A. The rear is set to 0
- B. The rear is set to -1
- C. The queue is reset to default
- D. An error message is displayed

*Correct Answer: B. The rear is set to -1*

**4. What is the time complexity of removing an element from the beginning of an array in the priority
queue implementation?**
- A. O(1)
- B. O(n)
- C. O(log n)
- D. O(n^2)

*Correct Answer: B. O(n)*

**5. Which function is responsible for sorting elements in the `PriorityQueue`?**


- A. `remove()`
- B. `insert()`
- C. `full()`
- D. `sortElements()`

*Correct Answer: D. `sortElements()`*

**6. What is the purpose of the `insert()` method in the `PriorityQueue` class?**
- A. To check if the queue is full
- B. To remove an element from the queue
- C. To add an element to the queue and sort it
- D. To clear the queue
*Correct Answer: C. To add an element to the queue and sort it*

**7. How does the `PriorityQueue` implementation handle the situation when the queue is full?**
- A. It throws an exception
- B. It returns a NULL pointer
- C. It displays an error message and returns 0
- D. It automatically expands the queue

*Correct Answer: C. It displays an error message and returns 0*

**8. In a binary tree, what is the term for the node at the top of the tree?**
- A. Child
- B. Leaf
- C. Root
- D. Subtree

*Correct Answer: C. Root*

**9. How many children can a node in a binary tree have?**


- A. None
- B. One
- C. Two
- D. Three or more

*Correct Answer: C. Two*

**10. What is a strictly binary tree?**


- A. A binary tree where each node has at most two children
- B. A binary tree where each non-leaf node has exactly two children
- C. A tree where nodes can have multiple children
- D. A binary tree with all nodes having a single child

*Correct Answer: B. A binary tree where each non-leaf node has exactly two children*

**11. In the provided binary tree example, what is the level of the root node?**
- A. 1
- B. 2
- C. 0
- D. 3

*Correct Answer: C. 0*

**12. How is the level of a node in a binary tree determined?**


- A. It is based on the node's position in the array
- B. It is the number of children the node has
- C. It is one more than the level of its parent
- D. It is based on the node's data value

*Correct Answer: C. It is one more than the level of its parent*

**13. What defines a complete binary tree?**


- A. All nodes have two children
- B. All nodes are at the same level
- C. All leaf nodes are at the same level
- D. All nodes are connected in a circular manner

*Correct Answer: C. All leaf nodes are at the same level*

**14. In a binary tree, what are the children of a node called?**


- A. Siblings
- B. Descendants
- C. Leaf nodes
- D. Parents

*Correct Answer: B. Descendants*

**15. What does the `length()` method of the `PriorityQueue` class return?**
- A. The maximum size of the queue
- B. The number of elements in the queue
- C. The index of the last element
- D. The priority of the first element

*Correct Answer: B. The number of elements in the queue*

**16. Which of the following is NOT a characteristic of a binary tree?**


- A. Each node has at most two children
- B. Nodes are arranged in a linear sequence
- C. There is a root node
- D. The tree structure is hierarchical

*Correct Answer: B. Nodes are arranged in a linear sequence*

**17. What is the time complexity of sorting elements in the `PriorityQueue` after an insertion?**
- A. O(1)
- B. O(n)
- C. O(log n)
- D. O(n^2)

*Correct Answer: B. O(n)*


**18. What is the depth of a binary tree?**
- A. The number of nodes in the tree
- B. The maximum level of any leaf node
- C. The number of children of the root
- D. The total number of levels

*Correct Answer: B. The maximum level of any leaf node*

**19. What happens when you try to insert an element into a full priority queue?**
- A. The queue expands automatically
- B. The element is added but not sorted
- C. An error message is displayed, and the operation fails
- D. The oldest element is removed to make space

*Correct Answer: C. An error message is displayed, and the operation fails*

**20. Which data structure was discussed as an alternative to arrays for implementing priority queues?**
- A. Linked list
- B. Stack
- C. Graph
- D. Hash table

*Correct Answer: A. Linked list*

**21. What is the main advantage of using a tree over a linear data structure?**
- A. It allows faster searching and hierarchical data representation
- B. It uses less memory
- C. It has a simpler implementation
- D. It guarantees sorted data
*Correct Answer: A. It allows faster searching and hierarchical data representation*

**22. What does the `remove()` method return if the queue is empty?**
- A. An integer value indicating failure
- B. A NULL pointer
- C. The last inserted element
- D. A default event object

*Correct Answer: B. A NULL pointer*

**23. In the binary tree example, what is the depth of the tree shown?**
- A. 1
- B. 2
- C. 3
- D. 4

*Correct Answer: C. 3*

**24. What is the main difference between a binary tree and a strictly binary tree?**
- A. The number of nodes
- B. The level of nodes
- C. The requirement for each non-leaf node to have exactly two children
- D. The use of sorting

*Correct Answer: C. The requirement for each non-leaf node to have exactly two children*

**25. In the binary tree, what is the term for nodes that have no children?**
- A. Internal nodes
- B. Parent nodes
- C. Leaf nodes
- D. Root nodes

*Correct Answer: C. Leaf nodes*

**26. How are nodes in a binary tree connected?**


- A. Using pointers or references
- B. Using arrays
- C. Using a circular list
- D. Using hash tables

*Correct Answer: A. Using pointers or references*

**27. What term describes the process of organizing nodes in a binary tree by priority?**
- A. Sorting
- B. Balancing
- C. Hierarchical structuring
- D. Indexing

*Correct Answer: C. Hierarchical structuring*

**28. What is a key advantage of using a priority queue in simulations, such as banking systems?**
- A. Efficient handling of events based on priority
- B. Automatically sorting data
- C. Limiting the number of elements
- D. Preventing duplication of data

*Correct Answer: A. Efficient handling of events based on priority*

**29. In a complete binary tree, which of the following is true?**


- A. All levels, except possibly the last, are completely filled
- B. All nodes have exactly two children
- C. The tree is not balanced
- D. Nodes are sorted in ascending order

*Correct Answer: A. All levels, except possibly the last, are completely filled*

**30. Which traversal method is commonly used for binary trees to visit nodes in a specific order?**
- A. Pre-order, in-order, and post-order
- B. Linear search
- C. Depth-first search
- D. Breadth-first search

*Correct Answer: A. Pre-order, in-order, and post

Chapter # 12
Sure! Here's a 30-question multiple-choice quiz based on the information from your lecture notes on
binary trees. The correct answers are indicated in parentheses.

---

**1. What does the `left(p)` method return in a binary tree?**


a) The right sub-tree of node `p`
b) The parent of node `p`
c) The left sub-tree of node `p` (Correct)
d) The value stored in node `p`

**2. What does the `right(p)` method return?**


a) The left sub-tree of node `p`
b) The right sub-tree of node `p` (Correct)
c) The parent of node `p`
d) The value stored in node `p`

**3. What is the function of `parent(p)`?**


a) Returns the right sub-tree of node `p`
b) Returns the left sub-tree of node `p`
c) Returns the parent node of `p` (Correct)
d) Returns the value stored in node `p`

**4. How does the `brother(p)` method work in a binary tree?**


a) It returns the sibling node of `p` (Correct)
b) It returns the left child of node `p`
c) It returns the right child of node `p`
d) It returns the parent of node `p`

**5. What does `info(p)` return?**


a) The left sub-tree of node `p`
b) The right sub-tree of node `p`
c) The parent of node `p`
d) The value stored in node `p` (Correct)

**6. What does the `setLeft(p, x)` method do?**


a) Sets the value `x` in the left child of node `p` (Correct)
b) Sets the value `x` in the right child of node `p`
c) Sets `x` as the parent of node `p`
d) Deletes the left child of node `p`

**7. What does `setRight(p, x)` do?**


a) Sets the value `x` in the right child of node `p` (Correct)
b) Sets the value `x` in the left child of node `p`
c) Sets `x` as the parent of node `p`
d) Deletes the right child of node `p`

**8. In a binary tree, which operation is efficient for searching duplicates?**


a) Linear search in a list
b) Using a linked list
c) Binary tree search (Correct)
d) Using an array

**9. What is the time complexity of finding duplicates in a list using a binary tree?**
a) O(n)
b) O(log n)
c) O(n log n) (Correct)
d) O(n^2)

**10. What is the primary advantage of using a binary tree over a linked list for searching duplicates?**
a) Binary trees use less memory
b) Binary trees are easier to implement
c) Binary trees reduce the number of comparisons (Correct)
d) Linked lists are faster for searching

**11. What is the initial value of the left and right pointers in a newly created TreeNode object in C++?**
a) NULL (Correct)
b) 0
c) -1
d) Undefined

**12. What does the `isLeaf()` method check in a TreeNode?**


a) Whether the node has both left and right children
b) Whether the node is a leaf node (Correct)
c) Whether the node has a left child
d) Whether the node has a right child

**13. What is the constructor in the `TreeNode` class used for?**


a) Initializing tree nodes with default values
b) Deleting tree nodes
c) Creating and initializing a new TreeNode object (Correct)
d) Setting node values

**14. What does the `getLeft()` method return in the `TreeNode` class?**
a) The value stored in the left child
b) The left sub-tree pointer (Correct)
c) The parent node pointer
d) The right sub-tree pointer

**15. What does the `setLeft()` method do?**


a) Sets the left sub-tree pointer to the new TreeNode (Correct)
b) Sets the value of the left child
c) Deletes the left child node
d) Returns the left sub-tree pointer

**16. What is the purpose of the `insert()` function in the provided C++ code?**
a) To delete a node from the tree
b) To add a new node to the tree (Correct)
c) To print the tree
d) To search for a node

**17. How does the `insert()` function handle duplicate values?**


a) It ignores them
b) It replaces the existing node
c) It prints a message and deletes the new node (Correct)
d) It appends them to the list

**18. What condition terminates the while loop in the `insert()` function?**
a) When the new node is smaller than the current node
b) When the new node is greater than the current node
c) When a duplicate value is found
d) When `q` becomes NULL (Correct)

**19. What is the role of the `p` pointer in the `insert()` function?**
a) It points to the new node
b) It traverses the tree to find the correct position (Correct)
c) It initializes the tree
d) It sets the value of the node

**20. How is the `info` of a node accessed in the `TreeNode` class?**


a) Using the `setInfo()` method
b) Using the `getLeft()` method
c) Using the `getInfo()` method (Correct)
d) Using the `setLeft()` method

**21. What is the primary function of the `TreeNode` class?**


a) To perform tree operations
b) To manage the binary tree structure
c) To create and store data in nodes of the binary tree (Correct)
d) To sort elements in a tree

**22. What happens when the `info()` method is called?**


a) It deletes the node
b) It returns the value stored in the node (Correct)
c) It returns the left child node
d) It sets a new value in the node

**23. What type of data is the `object` member in the `TreeNode` class?**
a) Integer
b) String
c) Object pointer (Correct)
d) Boolean

**24. How is a new node added as the right child in the `insert()` function?**
a) `p->setRight(node);` (Correct)
b) `p->setLeft(node);`
c) `q->setRight(node);`
d) `q->setLeft(node);`

**25. What does the line `p = q;` do in the `insert()` function?**


a) It sets `p` to point to the left sub-tree
b) It sets `p` to point to the right sub-tree
c) It updates `p` to the current node `q` is pointing to (Correct)
d) It creates a new node

**26. In the `TreeNode` class, what does the `setInfo()` method do?**
a) It sets the value of the left child
b) It sets the value of the right child
c) It sets the value stored in the node (Correct)
d) It sets the parent node

**27. What does the `setRight()` method do?**


a) Sets the right sub-tree pointer (Correct)
b) Sets the left sub-tree pointer
c) Sets the value of the right child
d) Deletes the right child node

**28. What type of object does the `TreeNode` class template handle?**
a) Integer
b) String
c) Any type specified by the template parameter (Correct)
d) Float

**29. What is the delimiter used to indicate the end of the list in the C++ code?**
a) 0
b) -1 (Correct)
c) 1
d) NULL

**30. What is the expected output when attempting to insert a duplicate value using the `insert()`
function?**
a) The duplicate value is added to the tree
b) The tree is restructured
c) A message is printed and the new node is deleted (Correct)
d) The existing node value is updated

Chapter # 13
Here’s a thirty-question quiz based on the lecture content you provided. The correct answers are
indicated.

### Quiz

1. **What is the primary advantage of using a binary tree over a linked list for searching operations?**
- A) Linked lists are always faster.
- B) Binary trees require more memory.
- C) Binary trees allow for faster search operations.
- D) Linked lists are easier to implement.

**Answer: C) Binary trees allow for faster search operations.**

2. **In a binary tree, what is the maximum number of comparisons required to find a number in a tree of
depth \( d \)?**
- A) \( d \)
- B) \( d \times 2 \)
- C) \( 2^d \)
- D) \( d^2 \)

**Answer: A) \( d \)**

3. **What is the depth \( d \) of a complete binary tree with \( n \) nodes?**


- A) \( \log_2(n) \)
- B) \( \log_2(n + 1) - 1 \)
- C) \( \log_2(n - 1) \)
- D) \( \sqrt{n} \)

**Answer: B) \( \log_2(n + 1) - 1 \)**

4. **In a binary search tree (BST), where are the nodes with values less than the root node located?**
- A) Right sub-tree
- B) Left sub-tree
- C) Root node
- D) Not in the tree

**Answer: B) Left sub-tree**


5. **What traversal method prints nodes in the order: root, left subtree, right subtree?**
- A) Preorder
- B) Inorder
- C) Postorder
- D) Level order

**Answer: A) Preorder**

6. **Which traversal method prints nodes in the order: left subtree, root, right subtree?**
- A) Preorder
- B) Inorder
- C) Postorder
- D) Level order

**Answer: B) Inorder**

7. **What traversal method prints nodes in the order: left subtree, right subtree, root?**
- A) Preorder
- B) Inorder
- C) Postorder
- D) Level order

**Answer: C) Postorder**

8. **Which of the following is not a property of a binary search tree (BST)?**


- A) Left subtree nodes are smaller than the root.
- B) Right subtree nodes are larger than the root.
- C) All nodes in the left subtree are greater than the root.
- D) All nodes in the right subtree are smaller than the root.
**Answer: C) All nodes in the left subtree are greater than the root.**

9. **How does a binary tree generally compare in terms of search time to a linked list with the same
number of nodes?**
- A) Binary trees are slower.
- B) Binary trees are faster.
- C) They have the same search time.
- D) Linked lists are faster.

**Answer: B) Binary trees are faster.**

10. **What does the function `preorder(TreeNode<int>* treeNode)` do first?**


- A) Traverse the right subtree
- B) Traverse the left subtree
- C) Print the node value
- D) Check if the node is NULL

**Answer: C) Print the node value**

11. **In the `inorder` traversal of a binary tree, when is the root node printed?**
- A) Before traversing its subtrees
- B) After traversing the left subtree but before the right subtree
- C) After traversing both subtrees
- D) Only if it is the only node in the tree

**Answer: B) After traversing the left subtree but before the right subtree**

12. **In the `postorder` traversal, what is the last step?**


- A) Print the root node
- B) Traverse the left subtree
- C) Traverse the right subtree
- D) Traverse the right subtree and then the left subtree

**Answer: A) Print the root node**

13. **Which of the following is an example of recursion in C++?**


- A) A function calling another function
- B) A function calling itself
- C) A loop within a function
- D) A function returning a value

**Answer: B) A function calling itself**

14. **What is the output of the `inorder` traversal method for a BST if the tree nodes are in ascending
order?**
- A) Sorted order of nodes
- B) Reverse sorted order of nodes
- C) Random order of nodes
- D) All nodes in the left subtree followed by the right subtree

**Answer: A) Sorted order of nodes**

15. **Which traversal method does not produce a sorted list of nodes in a BST?**
- A) Preorder
- B) Inorder
- C) Postorder
- D) Level order

**Answer: C) Postorder**
16. **What is the depth of a binary tree with 100,000 nodes?**
- A) 14
- B) 15
- C) 20
- D) 25

**Answer: C) 20**

17. **Which of the following is true about the `find` method in a binary tree?**
- A) It inserts a new node if the number is not found.
- B) It returns true if the number is not found.
- C) It traverses the tree to determine if a number is present.
- D) It only prints the number if found.

**Answer: C) It traverses the tree to determine if a number is present.**

18. **What is the role of the `getLeft()` method in a binary tree?**


- A) Return the right child node
- B) Return the left child node
- C) Print the value of the node
- D) Check if the node is NULL

**Answer: B) Return the left child node**

19. **What will the `postorder` traversal method print first in a given binary tree?**
- A) The root node
- B) The left subtree
- C) The right subtree
- D) None of the above
**Answer: B) The left subtree**

20. **What is the result of traversing a BST with preorder method on the tree shown in the example?**
- A) 14 4 3 9 7 5 15 18 16 17 20
- B) 3 4 5 7 9 14 15 16 17 18 20
- C) 14 15 16 17 18 20 4 3 9 7 5
- D) 20 18 17 16 15 14 9 7 5 4 3

**Answer: A) 14 4 3 9 7 5 15 18 16 17 20**

21. **What is the maximum number of levels you need to traverse in a binary tree with 1 billion
nodes?**
- A) 20
- B) 25
- C) 30
- D) 40

**Answer: D) 40**

22. **In a binary search tree (BST), where are the nodes with values greater than the root node located?**
- A) Left sub-tree
- B) Right sub-tree
- C) Root node
- D) Not in the tree

**Answer: B) Right sub-tree**

23. **Which function would you use to print nodes in a binary tree in the order: left subtree, root, right
subtree?**
- A) Preorder
- B) Inorder
- C) Postorder
- D) Level order

**Answer: B) Inorder**

24. **What is the complexity of finding a number in a binary search tree with \( n \) nodes in the worst
case?**
- A) \( O(1) \)
- B) \( O(n) \)
- C) \( O(\log n) \)
- D) \( O(n^2) \)

**Answer: B) \( O(n) \)**

25. **Which traversal method ensures that nodes are printed in ascending order for a binary search
tree?**
- A) Preorder
- B) Inorder
- C) Postorder
- D) Level order

**Answer: B) Inorder**

26. **What is the output order for a `preorder` traversal on the following tree with root 10, left child 5,
and right child 15?**
- A) 10 5 15
- B) 5 10 15
- C) 15 10 5
- D) 5 15 10

**Answer: A) 10 5 15**
27. **Which traversal method is useful for evaluating expressions stored in a binary

tree?**
- A) Preorder
- B) Inorder
- C) Postorder
- D) Level order

**Answer: C) Postorder**

28. **In a `preorder` traversal of a binary tree, which node is visited last?**
- A) Leftmost node
- B) Rightmost node
- C) Root node
- D) All nodes are visited simultaneously

**Answer: B) Rightmost node**

29. **What is the depth of a binary tree with a maximum of 1,000 nodes if it is a perfect binary tree?**
- A) 8
- B) 9
- C) 10
- D) 11

**Answer: B) 9**

30. **What does the `getRight()` method return in a binary tree?**


- A) The left child node
- B) The right child node
- C) The parent node
- D) The root node

**Answer: B) The right child node**

Chapter # 14
Here’s a twenty-question quiz based on the information provided about tree traversal techniques
(preorder, inorder, and non-recursive traversal). The correct answers are indicated as well.

### Tree Traversal Quiz

1. **In preorder traversal, which of the following is printed first?**


- A) The left subtree
- B) The right subtree
- C) The root node
- D) The left and right subtrees
- **Correct Answer: C) The root node**

2. **In inorder traversal, which node is printed after visiting the left subtree?**
- A) The root node
- B) The right subtree
- C) The left subtree
- D) The right subtree before the root node
- **Correct Answer: A) The root node**

3. **Given the tree structure with root 14, which node comes immediately after node 4 in inorder
traversal?**
- A) Node 15
- B) Node 9
- C) Node 7
- D) Node 3
- **Correct Answer: B) Node 9**

4. **In a binary tree, what does the inorder traversal sequence for the tree with nodes [3, 4, 5, 7, 9, 14, 15,
16, 17, 18, 20] signify?**
- A) The order of nodes visited in postorder traversal
- B) The order of nodes visited in preorder traversal
- C) The order of nodes visited in inorder traversal
- D) The order of nodes visited in level-order traversal
- **Correct Answer: C) The order of nodes visited in inorder traversal**

5. **In a non-recursive inorder traversal using a stack, when does the stack become empty?**
- A) After all nodes are pushed onto the stack
- B) After the root node is processed
- C) After all nodes are popped from the stack
- D) After the left subtree is processed
- **Correct Answer: C) After all nodes are popped from the stack**

6. **In preorder traversal, which node is processed last in the tree with root node 14?**
- A) Node 14
- B) Node 20
- C) Node 17
- D) Node 5
- **Correct Answer: B) Node 20**

7. **For a binary tree, the inorder traversal visits nodes in which sequence?**
- A) Left subtree, root node, right subtree
- B) Root node, left subtree, right subtree
- C) Right subtree, root node, left subtree
- D) Root node, right subtree, left subtree
- **Correct Answer: A) Left subtree, root node, right subtree**

8. **Which of the following is true about postorder traversal?**


- A) The root node is printed last.
- B) The root node is printed first.
- C) The left subtree is printed before the right subtree.
- D) The right subtree is printed before the left subtree.
- **Correct Answer: A) The root node is printed last.**

9. **In the non-recursive inorder traversal of a binary tree, what happens when a node’s left subtree is
NULL?**
- A) The node is skipped.
- B) The node is pushed onto the stack.
- C) The node’s right subtree is immediately processed.
- D) The stack is emptied.
- **Correct Answer: C) The node’s right subtree is immediately processed.**

10. **Which traversal method requires an explicit stack for non-recursive implementation?**
- A) Postorder traversal
- B) Inorder traversal
- C) Preorder traversal
- D) Level-order traversal
- **Correct Answer: B) Inorder traversal**

11. **Which traversal method processes nodes in the order of left subtree, right subtree, and root node?**
- A) Preorder traversal
- B) Inorder traversal
- C) Postorder traversal
- D) Level-order traversal
- **Correct Answer: C) Postorder traversal**
12. **In the given tree with root 14, what is the sequence of nodes printed in preorder traversal?**
- A) 14, 4, 3, 9, 7, 5, 15, 18, 16, 17, 20
- B) 14, 4, 9, 3, 7, 5, 15, 18, 20, 16, 17
- C) 14, 15, 4, 9, 3, 7, 5, 18, 16, 20, 17
- D) 14, 4, 3, 9, 7, 5, 15, 18, 20, 16, 17
- **Correct Answer: A) 14, 4, 3, 9, 7, 5, 15, 18, 16, 17, 20**

13. **What is the first step in the inorder traversal of a binary tree using recursion?**
- A) Print the root node
- B) Traverse the right subtree
- C) Traverse the left subtree
- D) Check if the node is NULL
- **Correct Answer: C) Traverse the left subtree**

14. **What is the result of the level-order traversal of a binary tree with nodes [14, 4, 15, 3, 9, 18, 7, 16,
20, 5, 17]?**
- A) 14 4 15 3 9 18 7 16 20 5 17
- B) 14 15 4 18 3 9 7 16 20 5 17
- C) 14 4 15 9 3 18 7 16 20 5 17
- D) 14 4 15 7 9 3 18 16 20 5 17
- **Correct Answer: A) 14 4 15 3 9 18 7 16 20 5 17**

15. **In the non-recursive preorder traversal using a stack, what is the order of processing nodes starting
from the root node?**
- A) Right subtree first, then left subtree
- B) Left subtree first, then right subtree
- C) Root node first, then left subtree, then right subtree
- D) Left subtree first, then root node, then right subtree
- **Correct Answer: C) Root node first, then left subtree, then right subtree**
16. **Which traversal method visits nodes in the order: left subtree, right subtree, root node?**
- A) Level-order traversal
- B) Preorder traversal
- C) Inorder traversal
- D) Postorder traversal
- **Correct Answer: D) Postorder traversal**

17. **In a recursive inorder traversal, what action follows the visit to the left subtree?**
- A) Print the root node
- B) Visit the right subtree
- C) Return to the parent node
- D) Visit the left subtree again
- **Correct Answer: A) Print the root node**

18. **What is a characteristic of recursive tree traversal compared to non-recursive traversal?**


- A) Recursive traversal requires manual stack management.
- B) Non-recursive traversal typically uses less memory.
- C) Non-recursive traversal is always faster.
- D) Recursive traversal is less error-prone.
- **Correct Answer: B) Non-recursive traversal typically uses less memory.**

19. **In a binary tree, what is the key difference between preorder and inorder traversal?**
- A) Preorder visits the root node first, while inorder visits it after the left subtree.
- B) Inorder visits the root node first, while preorder visits it after the left subtree.
- C) Preorder and inorder traversals visit nodes in the same order.
- D) Preorder and inorder traversals use different methods to visit nodes.
- **Correct Answer: A) Preorder visits the root node first, while inorder visits it after the left subtree.**

20. **In the context of tree traversal, what does level-order traversal primarily focus on?**
- A) Visiting nodes in a depth-first manner
- B) Visiting nodes by level from top to bottom
- C) Visiting nodes in a left-to-right manner within each level
- D) Both B and C
- **Correct Answer: D) Both B and C**

Chapter# 15
Sure! Here's a 30-question multiple-choice quiz based on the concepts discussed in the lecture about tree
traversal and binary search trees (BST). The correct answers are indicated.

### Quiz Questions

1. **What traversal method prints the root node first in a binary tree?**
- A) Inorder
- B) Postorder
- C) Preorder *(Correct Answer)*
- D) Level-order

2. **Which data structure is used in level-order traversal of a binary tree?**


- A) Stack
- B) Queue *(Correct Answer)*
- C) List
- D) Array

3. **In level-order traversal, which nodes are visited first?**


- A) Leftmost nodes
- B) Rightmost nodes
- C) Nodes at the root level
- D) Nodes from top to bottom, left to right *(Correct Answer)*

4. **In the given code, what operation is performed by `q.dequeue()`?**


- A) Insert a node into the queue
- B) Remove and return the front node of the queue *(Correct Answer)*
- C) Print the node at the front of the queue
- D) Check if the queue is empty

5. **In the function `levelorder`, what happens if `treeNode` is NULL?**


- A) The function prints an error message
- B) The function returns immediately *(Correct Answer)*
- C) The function continues with an empty queue
- D) The function initiates a new queue

6. **What is the time complexity of level-order traversal in terms of the number of nodes, `n`?**
- A) O(log n)
- B) O(n) *(Correct Answer)*
- C) O(n^2)
- D) O(1)

7. **In a binary search tree (BST), where are values less than the current node's value located?**
- A) On the right subtree
- B) On the left subtree *(Correct Answer)*
- C) At the root node
- D) Randomly in the tree

8. **What type of data does the `wordTree` function in the provided code handle?**
- A) Integers
- B) Floats
- C) Characters *(Correct Answer)*
- D) Booleans

9. **How does the `insert` function in the code handle duplicate values?**
- A) It ignores the duplicate
- B) It overwrites the existing value
- C) It prints an error message and deletes the new node *(Correct Answer)*
- D) It merges the duplicate values

10. **Which traversal method would you use to print the elements of a BST in sorted order?**
- A) Preorder
- B) Postorder
- C) Inorder *(Correct Answer)*
- D) Level-order

11. **In the `insert` function, what does `strcmp(info, p->getInfo())` compare?**
- A) Two integers
- B) Two floating-point numbers
- C) Two strings *(Correct Answer)*
- D) Two boolean values

12. **When deleting a node with two children in a BST, which node typically replaces the deleted
node?**
- A) The right child
- B) The left child
- C) The smallest node in the right subtree *(Correct Answer)*
- D) The largest node in the left subtree

13. **What does the `inorder` function do in the provided code for a BST?**
- A) Deletes nodes
- B) Inserts nodes
- C) Traverses and prints nodes in sorted order *(Correct Answer)*
- D) Searches for nodes
14. **In a queue used for level-order traversal, which end is used for insertion?**
- A) The front end
- B) The rear end *(Correct Answer)*
- C) The middle
- D) The top end

15. **What will be the output of a level-order traversal for the tree in Figure 15.1?**
- A) 14 4 15 3 9 18 7 16 20 5 17 *(Correct Answer)*
- B) 14 15 4 3 9 18 7 20 16 17 5
- C) 14 4 3 9 15 18 7 16 20 5 17
- D) 14 15 4 18 9 3 7 20 16 5 17

16. **In the level-order traversal algorithm, what is checked before adding a node's children to the
queue?**
- A) If the node has siblings
- B) If the node has a parent
- C) If the node has left and right children *(Correct Answer)*
- D) If the node is a leaf

17. **Which function is used to insert elements into a queue in the level-order traversal code?**
- A) dequeue()
- B) push()
- C) add()
- D) enqueue() *(Correct Answer)*

18. **What will the queue contain after the first iteration in the level-order traversal function?**
- A) Only the root node
- B) Root node and its children *(Correct Answer)*
- C) All nodes in the tree
- D) Only the leftmost child
19. **What happens if a node has no children in the level-order traversal?**
- A) The node is skipped
- B) The node is printed and nothing is added to the queue *(Correct Answer)*
- C) The node's parent is added to the queue
- D) The node causes an error

20. **How are elements in a binary search tree (BST) typically arranged?**
- A) Randomly
- B) Sorted in increasing order by their values *(Correct Answer)*
- C) Sorted in decreasing order
- D) In a circular manner

21. **Which function is responsible for maintaining the binary search tree properties during insertion?**
- A) delete()
- B) insert() *(Correct Answer)*
- C) levelorder()
- D) inorder()

22. **In the `insert` function, what happens if `info` is equal to the current node's data?**
- A) The node is inserted as a duplicate
- B) The insertion operation is stopped
- C) An error message is displayed and the new node is deleted *(Correct Answer)*
- D) The new node is merged with the existing node

23. **What is the primary advantage of using a queue over a stack for level-order traversal?**
- A) Stack provides faster access
- B) Queue maintains the order of nodes from top to bottom *(Correct Answer)*
- C) Stack uses less memory
- D) Queue is simpler to implement
24. **In level-order traversal, what does `cout << *(treeNode->getInfo()) << " ";` do?**
- A) Enqueues the node's value
- B) Dequeues the node
- C) Prints the value of the node *(Correct Answer)*
- D) Deletes the node

25. **Which traversal method is used to visit nodes in the order of left subtree, root, and then right
subtree?**
- A) Preorder
- B) Postorder
- C) Inorder *(Correct Answer)*
- D) Level-order

26. **What does the `levelorder` function print as it traverses the tree?**
- A) The values of nodes in a preorder manner
- B) The values of nodes in a postorder manner
- C) The values of nodes level by level *(Correct Answer)*
- D) The values of nodes in an inorder manner

27. **In the code provided, how are the nodes added to the queue?**
- A) By pushing
- B) By enqueuing *(Correct Answer)*
- C) By appending
- D) By inserting

28. **Which traversal method is best suited for processing nodes level by level in a binary tree?**
- A) Preorder
- B) Postorder
- C) Inorder
- D) Level-order *(Correct Answer)*

29. **What must be true for a node to be inserted into the right subtree of a given node in a BST?**
- A) The new node's value must be smaller
- B) The new node's value must be equal
- C) The new node's value must be larger *(Correct Answer)*
- D) The new node's value must be the same

30. **What is the purpose of `treeNode->getLeft()` in the level-order traversal function?**


- A) To check if the node is a leaf
- B) To add the right subtree to the queue
- C) To enqueue the left child of the current node *(Correct Answer)*
- D) To print the left child's value

Chapter # 16
Here's a 30-question quiz based on the content from your lecture notes about binary trees and their
traversals:

### Binary Tree Quiz

**1. What is the primary data structure used for level-order traversal of a binary tree?**
- A) Stack
- B) Queue
- C) Array
- D) Linked List

**Correct Answer: B) Queue**

**2. Which of the following is true about level-order traversal?**


- A) It uses a Last In First Out (LIFO) principle.
- B) It uses a First In First Out (FIFO) principle.
- C) It requires recursion.
- D) It traverses the tree in depth-first manner.

**Correct Answer: B) It uses a First In First Out (FIFO) principle.**

**3. In the level-order traversal algorithm, what does the `dequeue()` function do?**
- A) Adds a node to the queue.
- B) Removes a node from the front of the queue.
- C) Inserts a node at the end of the queue.
- D) Clears all nodes from the queue.

**Correct Answer: B) Removes a node from the front of the queue.**

**4. In the provided `levelorder()` function, what happens if the input `treeNode` is NULL?**
- A) The function prints an error message.
- B) The function does nothing and returns immediately.
- C) The function inserts a dummy node into the queue.
- D) The function continues execution with the next node.

**Correct Answer: B) The function does nothing and returns immediately.**

**5. During a level-order traversal, which node is processed first?**


- A) The leftmost node at the deepest level.
- B) The rightmost node at the deepest level.
- C) The root node.
- D) The node with the smallest value.

**Correct Answer: C) The root node.**


**6. Which method of traversal uses a queue data structure for implementation?**
- A) Preorder Traversal
- B) Inorder Traversal
- C) Postorder Traversal
- D) Level-order Traversal

**Correct Answer: D) Level-order Traversal**

**7. In the given `levelorder()` function, what is the role of the `if` statement checking `treeNode-
>getLeft() != NULL`?**
- A) To enqueue the left subtree if it exists.
- B) To print the left subtree node.
- C) To dequeue the left subtree node.
- D) To terminate the traversal if the left subtree is NULL.

**Correct Answer: A) To enqueue the left subtree if it exists.**

**8. Which of the following traversals would visit the nodes in the order: left subtree, root, right
subtree?**
- A) Preorder Traversal
- B) Inorder Traversal
- C) Postorder Traversal
- D) Level-order Traversal

**Correct Answer: B) Inorder Traversal**

**9. What is the complexity of level-order traversal of a binary tree in terms of time?**
- A) O(log n)
- B) O(n)
- C) O(n log n)
- D) O(n^2)
**Correct Answer: B) O(n)**

**10. Which tree traversal method would be most suitable for printing a binary tree from top to bottom,
level by level?**
- A) Preorder
- B) Inorder
- C) Postorder
- D) Level-order

**Correct Answer: D) Level-order**

**11. If the root node of a binary tree contains the value 14, what will be the first element printed by the
`levelorder()` function?**
- A) 14
- B) 4
- C) 15
- D) 3

**Correct Answer: A) 14**

**12. In the provided code, which function is responsible for inserting nodes into the queue?**
- A) `dequeue()`
- B) `enqueue()`
- C) `getInfo()`
- D) `printTree()`

**Correct Answer: B) `enqueue()`**

**13. What is the output of the `levelorder()` function for the tree with root 14 and the following levels:
[4, 15], [3, 9, 18], [7, 16, 20], [5, 17]?**
- A) 14 4 15 3 9 18 7 16 20 5 17
- B) 14 3 9 15 7 18 16 20 5 17
- C) 14 4 15 9 3 18 7 20 16 5 17
- D) 14 4 15 7 9 3 18 16 20 5 17

**Correct Answer: A) 14 4 15 3 9 18 7 16 20 5 17**

**14. When performing level-order traversal, which of the following operations is performed when the
queue is empty?**
- A) The traversal continues.
- B) The function terminates.
- C) The queue is refilled.
- D) The root node is reinserted.

**Correct Answer: B) The function terminates.**

**15. In the provided code for binary search trees, what is the purpose of the `strcmp` function?**
- A) To compare two integer values.
- B) To compare two string values lexicographically.
- C) To sort nodes in the tree.
- D) To convert strings to integers.

**Correct Answer: B) To compare two string values lexicographically.**

**16. What will be the result of deleting a leaf node from a binary search tree?**
- A) The tree will be rebalanced.
- B) The node is removed and its parent's pointer is updated.
- C) The node is simply marked as deleted.
- D) The node is moved to the root.
**Correct Answer: B) The node is removed and its parent's pointer is updated.**

**17. When deleting a node with one child from a binary search tree, what happens?**
- A) The node is replaced by its child.
- B) The child is inserted into a new node.
- C) The node is moved to the root.
- D) The child is removed from the tree.

**Correct Answer: A) The node is replaced by its child.**

**18. In the given code for inserting nodes into a binary search tree, what does the `insert()` function do if
a duplicate value is encountered?**
- A) It inserts the duplicate value anyway.
- B) It deletes the existing node with the same value.
- C) It displays an error message and does not insert the duplicate.
- D) It replaces the existing node with the new value.

**Correct Answer: C) It displays an error message and does not insert the duplicate.**

**19. Which traversal method would visit the nodes in the order: left subtree, right subtree, root?**
- A) Preorder Traversal
- B) Inorder Traversal
- C) Postorder Traversal
- D) Level-order Traversal

**Correct Answer: C) Postorder Traversal**

**20. What does the `remove()` function do in the binary search tree context?**
- A) It adds a new node to the tree.
- B) It deletes a node from the tree.
- C) It prints the nodes of the tree.
- D) It balances the tree.

**Correct Answer: B) It deletes a node from the tree.**

**21. If a node to be deleted in a binary search tree has two children, which strategy is used to delete
it?**
- A) Replace it with its right child.
- B) Replace it with its left child.
- C) Replace it with the smallest node in its right subtree.
- D) Replace it with the largest node in its left subtree.

**Correct Answer: C) Replace it with the smallest node in its right subtree.**

**22. What type of binary tree traversal will produce a sorted sequence of elements?**
- A) Preorder Traversal
- B) Inorder Traversal
- C) Postorder Traversal
- D) Level-order Traversal

**Correct Answer: B) Inorder Traversal**

**23. Which function is used to print the values of nodes in the binary search tree in the provided
code?**
- A) `insert()`
- B) `remove()`
- C) `printTree()`
- D) `levelorder()`

**Correct Answer: C) `printTree()`**


**24. What value does the `levelorder()` function return after completing the traversal?**
- A) The height of the tree.
- B) The number of nodes in the tree.
- C) The nodes printed in level-order.
- D) Nothing (it only prints the values).

**Correct Answer: D) Nothing (it only prints the values).**

**25. In the `wordTree()` function, what data type is used for

the binary search tree?**


- A) Integer
- B) Float
- C) Character
- D) Boolean

**Correct Answer: C) Character**

**26. What is the purpose of the `getInfo()` function in the binary search tree context?**
- A) To insert a new node.
- B) To retrieve the value of the node.
- C) To remove a node from the tree.
- D) To print the value of the node.

**Correct Answer: B) To retrieve the value of the node.**

**27. In the `levelorder()` function, what is done if a node has no children?**


- A) The node is skipped.
- B) The node is added to the queue.
- C) The node's parent is reinserted into the queue.
- D) The node is printed but no children are enqueued.

**Correct Answer: D) The node is printed but no children are enqueued.**

**28. How is the binary search tree balanced after deletion of a node?**
- A) The tree is automatically balanced by the `remove()` function.
- B) The tree is manually balanced by the user.
- C) The tree requires no balancing as it is always balanced.
- D) The `remove()` function does not balance the tree.

**Correct Answer: D) The `remove()` function does not balance the tree.**

**29. What will be the output of the `printTree()` function after removing all even numbers from a tree
containing numbers 0 to 30?**
- A) All even numbers are printed.
- B) Only odd numbers from 1 to 29 are printed.
- C) Only even numbers from 0 to 30 are printed.
- D) No numbers are printed.

**Correct Answer: B) Only odd numbers from 1 to 29 are printed.**

**30. What is the significance of the constant `ITEM_NOT_FOUND` in the `BinarySearchTree` class?**
- A) It represents the default value for new nodes.
- B) It indicates that a search operation did not find a result.
- C) It is used to initialize the tree.
- D) It is a placeholder for node values.

**Correct Answer: B) It indicates that a search operation did not find a result.**

Chapter # 17
Certainly! Here's a 30-question quiz on reference variables and their use in C++ programming,
particularly with binary search trees and function arguments.

### Quiz on Reference Variables in C++

#### Multiple Choice Questions

1. **What does the `&` symbol represent when used in a function parameter list?**
- A) Address of the variable
- B) Reference to the variable
- C) Dereference the variable
- D) Logical AND operator
**Answer: B) Reference to the variable**

2. **In the function `void insert(const EType& x);`, what does `const EType& x` signify?**
- A) `x` is a constant pointer to `EType`
- B) `x` is a constant reference to `EType`
- C) `x` is a mutable reference to `EType`
- D) `x` is a pointer to a constant `EType`
**Answer: B) `x` is a constant reference to `EType`**

3. **Which operator is used to obtain the address of a variable in C++?**


- A) `*`
- B) `&`
- C) `->`
- D) `::`
**Answer: B) `&`**

4. **What is the correct syntax to declare a pointer to an integer in C++?**


- A) `int* ptr;`
- B) `ptr int*;`
- C) `int ptr*;`
- D) `*int ptr;`
**Answer: A) `int* ptr;`**

5. **In the function `intMinus1(int oldVal)`, how is the argument `oldVal` passed?**
- A) By reference
- B) By pointer
- C) By value
- D) By address
**Answer: C) By value**

6. **What does the `*` operator do in the context of a pointer variable?**


- A) Declares a pointer
- B) Dereferences the pointer
- C) Takes the address of a variable
- D) Performs multiplication
**Answer: B) Dereferences the pointer**

7. **Which function signature demonstrates passing an argument by pointer?**


- A) `int intMinus1(int oldVal);`
- B) `int intMinus2(int* oldVal);`
- C) `int intMinus3(int& oldVal);`
- D) `int* intMinus4(int oldVal);`
**Answer: B) `int intMinus2(int* oldVal);`**

8. **How does passing an argument by reference differ from passing by value?**


- A) It creates a copy of the argument.
- B) It directly accesses the argument in the caller's memory.
- C) It changes the argument's type.
- D) It adds an extra layer of indirection.
**Answer: B) It directly accesses the argument in the caller's memory.**

9. **In the function `int intMinus3(int& oldVal)`, what does `oldVal` refer to?**
- A) A copy of the argument
- B) The address of the argument
- C) The argument itself by reference
- D) A new variable with the same name
**Answer: C) The argument itself by reference**

10. **When calling `intMinus2(&myInt)`, what does `&myInt` represent?**


- A) The value of `myInt`
- B) A pointer to `myInt`
- C) The address of `myInt`
- D) A reference to `myInt`
**Answer: C) The address of `myInt`**

11. **What is the output of `cout << intMinus1(myInt);` where `myInt` is initialized to 31?**
- A) 30
- B) 31
- C) 32
- D) Error
**Answer: A) 30**

12. **What effect does `intMinus2(&myInt);` have on `myInt` if `myInt` is 31 and `intMinus2`
decrements its argument by 2?**
- A) `myInt` becomes 29
- B) `myInt` becomes 30
- C) `myInt` remains 31
- D) `myInt` becomes 32
**Answer: A) `myInt` becomes 29**

13. **In the `intMinus3` function, if `myInt` is passed by reference and is 31, what will `myInt` be after
`intMinus3` is called and decrements it by 3?**
- A) 31
- B) 28
- C) 30
- D) 27
**Answer: B) 28**

14. **Which memory area is used for storing local variables during function execution?**
- A) Heap
- B) Static Data
- C) Code
- D) Stack
**Answer: D) Stack**

15. **What is the main advantage of using reference variables over pointers for function arguments?**
- A) They require less memory.
- B) They are simpler and avoid pointer syntax.
- C) They are faster in execution.
- D) They prevent modifications to the argument.
**Answer: B) They are simpler and avoid pointer syntax.**

16. **In a function that uses call by reference, what happens to the original argument in the caller
function?**
- A) It remains unchanged.
- B) It is duplicated.
- C) It is modified.
- D) It is hidden from the called function.
**Answer: C) It is modified.**
17. **What does `*oldVal` in `intMinus2(int* oldVal)` represent?**
- A) The address of `oldVal`
- B) The value at the address pointed to by `oldVal`
- C) The value of `oldVal`
- D) The pointer itself
**Answer: B) The value at the address pointed to by `oldVal`**

18. **What is the purpose of the `const` keyword when used with reference variables, such as `const int&
x`?**
- A) To allow modification of the referenced value
- B) To prevent modification of the referenced value
- C) To change the data type of the reference
- D) To pass the reference by pointer
**Answer: B) To prevent modification of the referenced value**

19. **In the context of call stacks, where are function arguments and local variables stored?**
- A) Heap
- B) Static Data
- C) Stack
- D) Code
**Answer: C) Stack**

20. **Which function call would not modify the value of `myInt`?**
- A) `intMinus1(myInt)`
- B) `intMinus2(&myInt)`
- C) `intMinus3(myInt)`
- D) None of the above
**Answer: A) `intMinus1(myInt)`**
21. **When using `intMinus3(int& oldVal)`, how does the caller function's variable `myInt` relate to
`oldVal` in `intMinus3`?**
- A) They are independent variables.
- B) `oldVal` is a copy of `myInt`.
- C) `oldVal` is a reference to `myInt`.
- D) `oldVal` is an address of `myInt`.
**Answer: C) `oldVal` is a reference to `myInt`.**

22. **If `intMinus2` is called with `&myInt` and `myInt` is 31, what will the function return?**
- A) 31
- B) 29
- C) 30
- D) 28
**Answer: B) 29**

23. **What happens to the `retVal` variable in the caller function after calling `intMinus1`?**
- A) It will be the result of `intMinus1`, but `myInt` remains unchanged.
- B) It will be unchanged.
- C) It will be the same as `myInt`.
- D) It will cause a compilation error.
**Answer: A) It will be the result of `intMinus1`, but `myInt` remains unchanged.**

24. **In `intMinus3`, why is there no need to use `&` inside the function body?**
- A) Because `oldVal` is a pointer.
- B) Because `oldVal` is already a reference.
- C) Because `oldVal` is a copy of the value.
- D) Because `oldVal` is constant.
**Answer: B) Because `oldVal` is already a reference.**

25. **Which part of memory is used for dynamically allocated variables?**


- A) Code
- B) Static Data
- C) Stack
- D) Heap
**Answer: D) Heap**

26. **When `intMinus1` is called with `30 +

1`, what is the value passed to `intMinus1`?**


- A) 30
- B) 31
- C) 32
- D) 29
**Answer: B) 31**

27. **What will be the result if `intMinus2` is called with a pointer to a variable `myInt` which is initially
5, and the function decrements the value by 5?**
- A) `myInt` remains 5
- B) `myInt` becomes 0
- C) `myInt` becomes -5
- D) Compilation error
**Answer: C) `myInt` becomes -5**

28. **What does the `const` keyword do when used in `const int& x`?**
- A) Allows modification of `x`
- B) Disables modification of `x`
- C) Changes `x` to a pointer type
- D) Changes `x` to a reference type
**Answer: B) Disables modification of `x`**
29. **Which type of parameter passing would be most efficient for large objects in C++?**
- A) Pass by value
- B) Pass by pointer
- C) Pass by reference
- D) Pass by address
**Answer: C) Pass by reference**

30. **In C++, if `intMinus2` is defined as `void intMinus2(int* ptr)` and you want to pass `myInt` by
reference, what is the correct call?**
- A) `intMinus2(myInt);`
- B) `intMinus2(&myInt);`
- C) `intMinus2(*myInt);`
- D) `intMinus2(ptr(myInt));`
**Answer: B) `intMinus2(&myInt);`**

Chapter # 18
Here’s a 30-question quiz based on the lecture notes you provided, with multiple-choice answers and the
correct answers indicated:

1. **What is the primary purpose of the stack in function calls?**


- A) To store global variables
- B) To manage memory for local variables and function call parameters
- C) To store objects in heap memory
- D) To handle file operations
- **Correct Answer: B**

2. **In which memory area are local variables created when a function is called?**
- A) Heap
- B) Code segment
- C) Stack
- D) Static data
- **Correct Answer: C**

3. **Which of the following languages uses call by reference for all parameters?**
- A) C++
- B) Java
- C) FORTRAN
- D) PASCAL
- **Correct Answer: C**

4. **What is the main difference between call by value and call by reference?**
- A) Call by value uses pointers, call by reference does not.
- B) Call by reference does not copy the actual value, while call by value does.
- C) Call by value passes a reference, call by reference passes a copy of the value.
- D) Call by value stores variables on the heap, call by reference stores them on the stack.
- **Correct Answer: B**

5. **In Java, how are native data types like int and float passed?**
- A) By reference
- B) By value
- C) By pointer
- D) By name
- **Correct Answer: B**

6. **What happens to local variables when a function returns in C++?**


- A) They are saved to heap memory.
- B) They are retained until the program ends.
- C) They are destroyed.
- D) They are copied to global memory.
- **Correct Answer: C**
7. **Which of the following is true about objects created with `new` in C++?**
- A) They are automatically deallocated when the function returns.
- B) They are stored on the stack.
- C) They must be explicitly deallocated using `delete`.
- D) They are stored in static data memory.
- **Correct Answer: C**

8. **What is a dangling pointer?**


- A) A pointer that points to a valid memory location.
- B) A pointer that points to a memory location that has been deallocated.
- C) A pointer that has not been initialized.
- D) A pointer that is used for heap memory allocation.
- **Correct Answer: B**

9. **In the `loadCustomer()` function, what is the purpose of the `enqueue()` method?**
- A) To add objects to the heap.
- B) To remove objects from the queue.
- C) To add objects to the queue.
- D) To initialize the customer objects.
- **Correct Answer: C**

10. **When using reference variables in C++, which of the following is true?**
- A) They are used to directly access memory addresses.
- B) They must be initialized when declared.
- C) They can be reassigned to point to different variables.
- D) They can be null.
- **Correct Answer: B**

11. **What does the `const` keyword do when used with a function parameter?**
- A) It allows the parameter to be modified.
- B) It ensures the parameter cannot be modified within the function.
- C) It makes the parameter a global variable.
- D) It converts the parameter to a reference type.
- **Correct Answer: B**

12. **Why is dynamic memory allocation used in C++?**


- A) To allocate memory for local variables.
- B) To create objects that need to persist beyond the function call.
- C) To store global variables.
- D) To handle file operations.
- **Correct Answer: B**

13. **What is the main reason for using pointers to manage objects on the heap?**
- A) To avoid stack overflow.
- B) To manage memory dynamically.
- C) To automatically handle memory deallocation.
- D) To simplify object creation.
- **Correct Answer: B**

14. **How do pointers and references differ in terms of arithmetic operations?**


- A) Both support arithmetic operations equally.
- B) References do not support arithmetic operations, while pointers do.
- C) Pointers do not support arithmetic operations, while references do.
- D) Both do not support arithmetic operations.
- **Correct Answer: B**

15. **Which of the following statements is true about the heap and stack memory layout?**
- A) The stack grows upwards and the heap grows downwards.
- B) The stack grows downwards and the heap grows upwards.
- C) Both the stack and heap grow in the same direction.
- D) The stack and heap do not affect each other.
- **Correct Answer: B**

16. **In the `serviceCustomer()` function, what does the `delete` keyword do?**
- A) It deallocates memory for a pointer.
- B) It removes an object from the queue.
- C) It initializes a new object.
- D) It adds an object to the heap.
- **Correct Answer: A**

17. **Which keyword is used in C++ to define a constant value that cannot be modified?**
- A) static
- B) final
- C) const
- D) immutable
- **Correct Answer: C**

18. **What is an activation record?**


- A) A record of global variables.
- B) The portion of memory that holds function call parameters, return address, and local variables.
- C) A data structure used for heap memory management.
- D) A type of object in C++.
- **Correct Answer: B**

19. **What is the primary disadvantage of using references to transient objects?**


- A) They require more memory.
- B) They cannot be used with pointers.
- C) The transient objects are destroyed when the function exits.
- D) They cannot be used with heap memory.
- **Correct Answer: C**
20. **In the `loadCustomer()` function, what happens to the `c1` and `c2` pointers after the function
returns?**
- A) They are retained in the queue.
- B) They are destroyed, but the objects they point to remain on the heap.
- C) They are automatically deallocated.
- D) They cause a stack overflow.
- **Correct Answer: B**

21. **Which of the following best describes a transient object?**


- A) An object that is created dynamically and persists beyond the function call.
- B) An object that is stored in the heap and remains there until explicitly deleted.
- C) An object that is created on the stack and destroyed when the function returns.
- D) An object that is stored in global memory.
- **Correct Answer: C**

22. **When using dynamic memory allocation, which operator is used to allocate memory?**
- A) `malloc`
- B) `free`
- C) `new`
- D) `delete`
- **Correct Answer: C**

23. **What happens if you access a memory location after the object has been deleted?**
- A) The object is reinitialized.
- B) The program may crash or produce undefined behavior.
- C) The object’s memory is automatically reclaimed.
- D) The pointer is automatically reset to null.
- **Correct Answer: B**
24. **What is the purpose of the `getName()` method in the `Customer` class?**
- A) To set the name of the customer.
- B) To retrieve and return the name of the customer.
- C) To delete the customer object.
- D) To add the customer to a queue.
- **Correct Answer: B**

25. **Which of the following is a correct statement about pointers?**


- A) Pointers cannot be used to manage heap memory.
- B) Pointers are used to access memory addresses.
- C) Pointers automatically manage memory deallocation.
- D) Pointers are equivalent to reference variables.
- **Correct Answer: B**

26. **In C++, why should you avoid returning references to local variables from functions?**
- A) They cannot be assigned to global variables.
- B) The reference may become a dangling reference when the function exits.
- C) Local variables cannot be passed to other functions.
- D) They increase the function execution time.
- **Correct Answer: B**

27. **What is the role of the `&` sign when passing parameters in C++?**
- A) To indicate call by value.
- B) To indicate call by reference.
- C) To indicate call by pointer.
- D) To indicate a constant parameter.
- **Correct Answer: B**

28. **How can you prevent a dangling pointer in C++?**


- A) By not using pointers in your program.
- B) By initializing pointers to null after deallocation.
- C) By using global variables for dynamic memory allocation.
- D) By avoiding dynamic memory allocation entirely.
- **

Chapter #19
Here's a ten-question quiz based on the concepts covered in the lecture about the `const` keyword,
reference variables, and AVL trees:

### Quiz

**1. What does the `const` keyword do when used with a reference parameter in a function?**
- A) Allows the function to modify the referenced object.
- B) Prevents the function from modifying the referenced object.
- C) Creates a copy of the referenced object.
- D) Ensures the function can only read from the referenced object but not modify it.

**Correct Answer: B**

**2. When `const` is used at the end of a member function signature, what does it signify?**
- A) The function can modify the class's member variables.
- B) The function cannot modify the class's member variables.
- C) The function is private to the class.
- D) The function is a static member of the class.

**Correct Answer: B**

**3. What is a correct use of `const` in the return type of a function?**


- A) `const EType& findMin() const;`
- B) `EType& const findMin() const;`
- C) `const EType findMin() const;`
- D) `EType& findMin() const;`

**Correct Answer: A**

**4. Why should a function not return a reference to a local variable?**


- A) Local variables are static and their values persist after the function ends.
- B) Local variables are destroyed when the function ends, making their references invalid.
- C) Local variables are not visible outside the function.
- D) Local variables cannot be referenced within the function.

**Correct Answer: B**

**5. In an AVL tree, what is the maximum allowed difference in height between the left and right subtrees
of any node?**
- A) 2
- B) 1
- C) 0
- D) 3

**Correct Answer: B**

**6. What is a defining characteristic of an AVL tree?**


- A) All nodes have exactly two children.
- B) The height of the left and right subtrees at any node differs by no more than 2.
- C) The height of the left and right subtrees at any node differs by no more than 1.
- D) The tree is always complete and balanced.

**Correct Answer: C**


**7. What happens if you insert data into a binary search tree (BST) in sorted order?**
- A) The BST will remain balanced and efficient.
- B) The BST will resemble a linked list, becoming unbalanced.
- C) The BST will automatically convert into an AVL tree.
- D) The BST will have all nodes with two children.

**Correct Answer: B**

**8. How does returning by reference rather than by value benefit function performance?**
- A) It creates a new copy of the object each time.
- B) It avoids the overhead of copying large objects, improving performance.
- C) It ensures the object cannot be modified.
- D) It simplifies the function’s implementation.

**Correct Answer: B**

**9. When is it advisable to use a `const` reference parameter in a function?**


- A) When you want to modify the passed object within the function.
- B) When you want to avoid making a copy of the object and ensure it is not modified.
- C) When you want the function to create a copy of the object for its use.
- D) When the object passed is of a primitive data type.

**Correct Answer: B**

**10. In the context of AVL trees, what does the term "balance factor" refer to?**
- A) The number of nodes in the left and right subtrees.
- B) The difference in height between the left and right subtrees of a node.
- C) The total number of levels in the tree.
- D) The depth of the tree from the root to the deepest leaf.
**Correct Answer: B**

Chapter # 20
Here's a ten-question quiz based on the lecture content, including multiple-choice answers and the correct
answers indicated:

### Quiz on AVL Trees and the `const` Keyword

1. **What is the primary benefit of using the `const` keyword with reference parameters in C++
functions?**
- A) It allows the function to modify the parameter.
- B) It ensures that the parameter is read-only within the function.
- C) It eliminates the need for function overloading.
- D) It increases the speed of the function.

**Correct Answer:** B) It ensures that the parameter is read-only within the function.

2. **What does the `const` keyword signify when used at the end of a member function's signature?**
- A) The function is allowed to modify member variables.
- B) The function does not modify member variables.
- C) The function is a static member.
- D) The function has no return type.

**Correct Answer:** B) The function does not modify member variables.

3. **When returning an object by reference with `const` in C++, what is the effect?**
- A) The object can be modified by the caller.
- B) The object is returned as a copy.
- C) The caller cannot modify the object.
- D) The reference is always null.
**Correct Answer:** C) The caller cannot modify the object.

4. **In AVL trees, what is the maximum allowed difference in height between the left and right subtrees
of any node?**
- A) 0
- B) 1
- C) 2
- D) 3

**Correct Answer:** B) 1

5. **What is the main purpose of rotations in AVL trees?**


- A) To increase the number of nodes in the tree.
- B) To balance the tree and maintain the AVL property.
- C) To convert the AVL tree into a binary search tree.
- D) To change the tree's data to integers.

**Correct Answer:** B) To balance the tree and maintain the AVL property.

6. **What is the result of applying a left rotation to an AVL tree?**


- A) The right child of the rotated node becomes the new root of the subtree.
- B) The left child of the rotated node becomes the new root of the subtree.
- C) The rotated node becomes the new root, and the right child moves down.
- D) The entire tree is reversed.

**Correct Answer:** A) The right child of the rotated node becomes the new root of the subtree.

7. **In an AVL tree, which of the following statements is true about the inorder traversal of the tree?**
- A) The inorder traversal always results in a balanced tree.
- B) The inorder traversal results in a sorted sequence of values.
- C) The inorder traversal can be used to detect AVL violations.
- D) The inorder traversal always returns the same result regardless of tree balance.

8. **What happens if a function in C++ returns a reference to a local variable?**


- A) The reference will be valid as long as the function executes.
- B) The local variable will be preserved in memory.
- C) The reference becomes invalid once the function exits, leading to undefined behavior.
- D) The local variable is copied to the heap.
9. **In a binary search tree (BST), what is the primary advantage over a linked list when searching for an
element?**
- A) BSTs always have fewer nodes than linked lists.
- B) BSTs are always balanced and require fewer comparisons on average.
- C) BSTs allow faster searches due to their hierarchical structure, reducing the average number of
comparisons.
- D) Linked lists have the same search time complexity as BSTs.

10. **Which of the following is NOT a characteristic of an AVL tree?**


- A) It is a type of binary search tree.
- B) The height of the left and right subtrees of any node differs by at most 1.
- C) It always maintains a perfect balance with equal number of nodes on both sides.
- D) Rotations are used to maintain its balance..

Chapter # 21
Based on the content from your lecture, here’s a ten-question quiz with multiple-choice answers and the
correct answers indicated:

1. **What is the balance factor of a node in an AVL tree?**


- A) The difference in height between the left and right subtrees of the node.
- B) The sum of heights of the left and right subtrees of the node.
- C) The height of the left subtree only.
- D) The height of the right subtree only.

2. **After inserting node 4 into the AVL tree shown in Fig 21.3, what is the balance factor of node 2?**
- A) 0
- B) -1
- C) 1
- D) -2

3. **In Fig 21.4, after inserting node 5, what is the balance factor of node 3?**
- A) 0
- B) -1
- C) -2
- D) 1

4. **Which type of rotation is needed if the balance factor of a node is -2 and the insertion was in the
right subtree of the right child of that node?**
- A) Single left rotation
- B) Single right rotation
- C) Double left-right rotation
- D) Double right-left rotation

5. **In the AVL tree of Fig 21.5, which node became the new root after performing the rotation?**
- A) Node 2
- B) Node 3
- C) Node 4
- D) Node 5

6. **What is the result of performing an inorder traversal on the AVL tree shown in Fig 21.7?**
- A) 1 2 3 4 5 6
- B) 1 2 3 4 5 6 7
- C) 1 2 3 4 5 6 7 16
- D) 1 2 3 4 5 6 7 15 16

7. **In Fig 21.10, after inserting node 16, what is the balance factor of node 7?**
- A) 0
- B) 1
- C) -1
- D) -2

8. **What is the balance factor of node 7 after inserting node 15 in Fig 21.11?**
- A) 0
- B) -1
- C) 1
- D) -2

9. **Which type of rotation is required if the balance factor of a node is -2 and the insertion was in the
left subtree of the right child of that node?**
- A) Single left rotation
- B) Single right rotation
- C) Double left-right rotation
- D) Double right-left rotation

10. **In Fig 21.12, after rotating node 7, what is the new position of node 7?**
- A) It becomes the root of the tree.
- B) It becomes the left child of node 16.
- C) It becomes the right child of node 16.
- D) It remains in the same position.
Chapter # 22

1. **What is the main purpose of performing rotations in an AVL tree?**


- A) To increase the height of the tree.
- B) To balance the tree and maintain the AVL property.
- C) To decrease the number of nodes in the tree.
- D) To sort the nodes in ascending order.

2. **In which case does a single rotation successfully balance the AVL tree?**
- A) When a new node is inserted into the right subtree of the left child.
- B) When a new node is inserted into the left subtree of the right child.
- C) When a new node is inserted into the left subtree of the left child.
- D) When a new node is inserted into the right subtree of the right child.

3. **Which scenario requires a double rotation to fix the AVL tree?**


- A) When the new node is inserted into the right subtree of the right child.
- B) When the new node is inserted into the left subtree of the right child.
- C) When the new node is inserted into the right subtree of the left child.
- D) When the new node is inserted into the left subtree of the left child.

4. **What type of double rotation is performed when a new node is inserted into the left subtree of the
right child of the AVL tree?**
- A) Left-right rotation.
- B) Right-left rotation.
- C) Right-right rotation.
- D) Left-left rotation.
5. **What does the height difference between the left and right subtrees of a node indicate in an AVL
tree?**
- A) The node’s balance factor.
- B) The node’s level in the tree.
- C) The total number of nodes in the tree.
- D) The height of the entire tree.

6. **When a new node is inserted in the right subtree of the left child of an AVL tree, which rotation is
performed first?**
- A) Right rotation.
- B) Left rotation.
- C) Left-right rotation.
- D) Right-left rotation.

7. **In the AVL tree balancing process, what is the result of performing a right rotation followed by a left
rotation?**
- A) Right-left double rotation.
- B) Left-right double rotation.
- C) Single right rotation.
- D) Single left rotation.

8. **Which of the following is NOT a case where single rotation can fix the AVL tree imbalance?**
- A) Insertion in the left subtree of the left child.
- B) Insertion in the right subtree of the right child.
- C) Insertion in the left subtree of the right child.
- D) Insertion in the right subtree of the left child.
9. **What is the key difference between single and double rotations in AVL trees?**
- A) Single rotations involve two nodes, while double rotations involve more.
- B) Double rotations consist of two single rotations performed in a specific order.
- C) Single rotations are only performed on leaf nodes.
- D) Double rotations are used to remove nodes from the tree.

10. **What is the AVL tree’s property related to its balance factor?**
- A) The balance factor of any node must be 0.
- B) The balance factor of any node must be between -1 and 1.
- C) The balance factor of any node must be greater than 1.
- D) The balance factor of any node must be less than -1.

Chapter # 23
Nothig important in this chapter for mcq.

You might also like