Cs301 Mcqs File Self
Cs301 Mcqs File Self
Lecture no 5:
1. What is one of the benefits of using a circular list in programming?
o A) It provides random access to elements.
o B) It allows efficient navigation through elements in a loop.
o C) It reduces the number of elements in the list.
o D) It automatically sorts elements in ascending order.
2. Which data structure was used in the Josephus problem program to select a leader?
o A) Stack
o B) Queue
o C) Circular List
o D) Linked List
4. In the Josephus problem program, what does the list.length() function check?
o A) The total number of people initially in the list
o B) The current number of elements in the list
o C) The number of times an element has been removed
o D) The maximum capacity of the list
o
5. Which method is used to initialize the starting point in the circular list?
o A) add()
o B) start()
o C) length()
o D) remove()
o
6. What is a stack in data structures?
o A) A collection of items where the last item added is the first to be removed
o B) A collection of items where the first item added is the first to be removed
o C) A structure that organizes items in a circular manner
oD) A type of array that holds data in sorted order
7. Which data structure property is associated with stacks?
o A) FIFO (First In, First Out)
o B) LIFO (Last In, First Out)
o C) Random Access
o D) Sequential Access
8. What does the get() method in the circular list program do?
o A) Adds an element to the list
o B) Returns the current element in the list
o C) Deletes the current element from the list
o D) Moves to the next element in the list
o
9. What does the remove() method do in the circular list implementation?
o A) Removes the last element of the list
o B) Removes the first element of the list
o C) Removes the current element from the list
o D) Resets the list
o
10. How would you implement a stack using arrays?
o A) By pushing elements at the beginning of the array
o B) By pushing and popping elements at the same end of the array
o C) By using circular indexing
o D) By storing each element in a linked list
What will list.length() return when only one person is left in the Josephus problem?
A) 10
B) 3
C) 1
D) 0
Which method is used to retrieve the current element in the circular list?
A) add()
B) start()
C) next()
D) get()
What advantage does using the CList class provide to the programmer?
oA) The programmer does not need to know the internal structure of the list.
oB) It restricts the list to only ten elements.
oC) It only allows traversal from start to end.
oD) It requires that the list be implemented as an array.
If a programmer solves the Josephus problem using an array instead of CList, they
must:
o A) Write additional code to navigate and modify the array elements in order.
o B) Use built-in methods from the array to solve the problem.
o C) Call methods like add and remove directly on the array.
o D) Set each element of the array to NULL when it is removed.
Which methods make up the interface of the CList class for the Josephus problem?
oA) add, remove, next, back, and get
oB) insert, delete, search, and sort
oC) push, pop, and peek
oD) add, sort, and search
What does the term "factory" mean in the context of the CList class?
oA) It means creating a single instance of the list.
B) It refers to a class that can create multiple objects of the same type.
o
C) It refers to an object that can only be used once.
o
D) It means only one object can exist at a time.
o
What is the main advantage of using a class to define a list data type in a program?
o A) It uses less memory.
o B) It simplifies the program code.
o C) It is easier to debug.
o D) It allows the use of only arrays.
Why is the implementation of abstract data types (ADT) not a concern in programs using
them?
o A) They are implemented as arrays by default.
o B) The interface remains the same regardless of internal implementation.
o C) Only arrays are used to implement ADTs.
o D) ADTs do not need any methods for usage.
Which pointer types are used in a doubly linked list to facilitate forward and backward
navigation?
o A) prev and forward
o B) left and right
o C) next and prev
o D) start and end
What problem does a circular linked list solve in comparison to other linked lists?
o A) Handling of NULL pointers at the beginning and end.
o B) Providing a quicker method to add elements.
o C) Increasing the speed of data retrieval.
o D) Allowing only forward navigation.
Which operation is NOT necessarily provided by a list ADT according to the text?
o A) add
o B) get
o C) start
o D) delete_last
If the requirements change, why can the internal implementation of a list ADT be
modified without affecting the program?
o A) The interface for accessing the ADT remains the same.
o B) List ADTs cannot be modified.
o C) All ADTs are implemented with arrays.
o D) List ADTs use dynamic memory allocation.
How does encapsulation benefit the use of data structures like lists in programming?
o A) It limits the use of arrays.
o B) It prevents changes in code.
o C) It hides the internal implementation details from the user.
o D) It restricts the use of certain methods.
What problem does a singly linked list encounter that a doubly linked list resolves?
oA) Inability to dynamically allocate memory.
oB) Complexity in traversing backward.
oC) Inability to connect nodes.
oD) Limited storage capacity.
Why can't the code using an array in the main program be reused in other problems?
o A) Arrays are always static.
o B) It is specifically tied to a main program and not flexible for other use cases.
o C) Arrays are incompatible with the CList data structure.
o D) Arrays require constant memory allocation.
What is the main purpose of using a data structure class, like CList, in a program?
o A) To reduce the overall memory usage.
o B) To allow flexibility in the program's use of data types.
o C) To simplify and organize the program's code.
o D) To ensure that arrays are the primary data structure used.
How does encapsulation in a data structure class benefit its usage in programming?
o A) It restricts certain operations from being performed.
o B) It allows flexibility in internal implementation without affecting usage.
o C) It requires the use of arrays for data handling.
o D) It makes the data structure code accessible in other programs.
What problem does using an array to implement a list data structure often lead to?
o A) Difficulty in increasing the size.
o B) Incompatibility with C++.
o C) Restricted pointer usage.
o D) Reduced efficiency in operations.
What problem does the circular linked list solve compared to other types of linked lists?
oA) It prevents NULL pointers by connecting the first and last nodes.
oB) It simplifies the process of adding new nodes.
oC) It only allows forward navigation.
oD) It eliminates the need for pointers.
How does encapsulation benefit the use of list data structures in C++?
o A) It allows lists to be implemented only with arrays.
o B) It restricts the addition of new methods to the list.
o C) It enables consistent method use regardless of internal list implementation.
o D) It increases memory usage efficiency.
What action can a programmer take if a list implemented with arrays does not meet
program requirements?
o A) Switch to using a singly linked list or doubly linked list.
o B) Reduce the list size.
o C) Replace the list with an array.
o D) Remove the class and redefine the program.
What methods are typically part of the interface for a List ADT?
o A) start, size, and clear
o B) add, get, remove
o C) initialize, reset, finalize
o D) begin, end, middle
What is the main advantage of using ADTs (Abstract Data Types) in programming?
o A. ADTs allow programmers to understand the internal implementation.
o B. ADTs provide a fixed implementation that cannot be changed.
oC. ADTs allow changing implementation without affecting users.
oD. ADTs ensure faster code performance in all cases.
Why might a programmer need to check the performance of an ADT during
program development?
o A. To understand the ADT's interface thoroughly.
o B. To ensure the ADT's internal implementation is visible.
o C. To verify if the ADT is solving the problem effectively.
o D. To change the ADT’s internal code manually.
When using a factory class, how are users affected by changes to the factory's
internal implementation?
o A. Users are directly affected by changes in the factory's internals.
o B. Users are not affected if the interface remains the same.
o C. Users must update their code every time the factory changes.
o D. Users have to recompile the code whenever the factory changes.
In which form are library classes provided to programmers if the source code is not
accessible?
o A. Text format
o B. Binary (object) format
o C. XML format
o D. HTML format
Where can a programmer find the interface methods of an ADT if the source code is
unavailable?
o A. In the .cpp file.
o B. In the .txt file.
o C. In the .h (header) file.
o D. In the README file.
.
Which of the following statements best describes a stack?
o A. A stack is a collection of elements arranged in a circular order.
o B. A stack is a collection of elements arranged in a linear order.
o C. A stack is a collection where any element can be accessed directly.
o D. A stack is a collection of elements arranged in a random order.
In which scenario does the user of an ADT need to be concerned with its internal
details?
o A. When the ADT is functioning as expected.
o B. When the ADT's performance impacts the program negatively.
o C. When using the ADT’s interface only.
o D. When the ADT is implemented in a standard library.
1. If you try to access the bottom cassette in a stack of fifty cassettes, what will
happen?
a) A queue of people
b) A row of books on a shelf
c) Plates stacked in a cylinder with a spring
d) None of the above
a) add()
b) push()
c) insert()
d) set()
9. When choosing method names for a stack, why might terms like push, pop, and
top be preferred?
2. After pushing the numbers 2, 5, and 7 into the stack, what will the stack look
like from bottom to top?
A) 7, 5, 2
B) 5, 2, 7
C) 2, 5, 7
D) 2, 7, 5
3. In a stack, which element is removed first in a pop operation?
4. What is the order of elements from top to bottom after pushing the numbers 2,
5, 7, and 1?
A) 1, 7, 5, 2
B) 2, 1, 5, 7
C) 2, 5, 1, 7
D) 7, 1, 5, 2
5. After popping one element from a stack with elements 1, 7, 5, and 2, which
number will be at the top?
A) 1
B)7
C) 5
D) 2
A) isFull()
B) isNull()
C) isEmpty()
D) isStack()
9. If a pop operation is called on an empty stack, what might happen?
10. What type of error might occur if you try to divide a number by zero in C++?
A) Stack Overflow
B) Null Pointer Exception
C) Division by Zero Exception
D) Null Exception
What will happen if isEmpty() is not called before pop on an empty stack?
o A) The program will proceed normally.
o B) The stack will automatically reset.
o C) There will be a problem as pop will attempt to remove a non-existent element.
o D) A new element will be added instead.
When using an array for stack implementation, which methods are part of the stack
interface?
o A) push and pop
o B) insert and delete
o C) isEmpty and isFull
o D) shift and unshift
What is the worst-case scenario for insertion and deletion in an array-based stack
implementation?
o A) Inserting and deleting from the middle of the array
o B) Inserting and deleting from the end of the array
o C) Inserting and deleting from the beginning of the array
o D) Inserting and deleting elements of equal size
In the array-based stack, why is it best to insert and remove elements from the end
of the array?
o A) To keep the array sorted.
o B) To avoid shifting elements.
o C) To fill the array faster.
o D) To utilize all array positions.
If the array used for stack implementation is full, what should the user do?
o A) Continue adding elements, as the array will resize automatically.
o B) Clear the array and start over.
o C) Stop adding elements as no more elements can be pushed.
o D) Shift all elements to the left to make space.
Why doesn't the user need to know the internal implementation of the stack?
o A) It complicates the usage of the stack.
o B) It helps separate the interface from the implementation.
o C) It makes debugging difficult.
o D) The internal implementation is irrelevant.
5. What value does current have when the stack is initially created?
o A) 0
o B) 1
o C) -1
o D) The size of the stack
8. What is the significance of not including if statements in the push and pop
methods?
o A) It simplifies the code
o B) It is the user's responsibility to manage the stack correctly
o C) The methods do not need to check conditions
o D) The stack implementation is guaranteed to always succeed
Answer: B
9. Which of the following is NOT part of the stack interface mentioned in the text?
o A) isEmpty()
o B) isFull()
o C) pop()
o D) getSize()
10. What is the expected behavior of the top() method when called on an empty
stack?
o A) It will return 0
o B) It will throw an error or undefined behavior
o C) It will return -1
o D) It will return the last element inserted
3. Which method is responsible for removing the top element from the stack?
o A) push(int x)
o B) pop()
o C) top()
o D) isFull()
4. What will happen if you try to push an element into a full stack?
o A) The element will be added to the stack
o B) An error will occur
o C) The last element will be removed
o D) A message will be printed saying the stack is full
6. What will be the output when trying to pop elements from an empty stack?
o A) The last element will be returned
o B) A message will be printed indicating the stack is empty
o C) An error will occur
o D) The program will terminate
7. Which of the following operations takes constant time in the stack implementation?
o A) push()
o B) pop()
o C) top()
o D) All of the above
10. If you push 12 elements onto the stack, what will be the output?
o A) All elements will be pushed successfully
o B) Stack is full, can't insert new element
o C) The program will crash
o D) The first 10 elements will be stored, and the rest ignored
15. Which of the following operations will not result in a change to the stack's state?
o A) push()
o B) pop()
o C) top()
o D) isEmpty()