0% found this document useful (0 votes)
5 views19 pages

Cs301 Mcqs File Self

cs601 mcqs file

Uploaded by

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

Cs301 Mcqs File Self

cs601 mcqs file

Uploaded by

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

Cs301 mcqs

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

3. What is an Abstract Data Type (ADT)?


o A) A data structure implemented directly in memory
o B) A data type defined by its behavior rather than its implementation
o C) A data type built specifically for circular lists
o D) A type of data structure only used in C++

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 statement outputs the final leader in the Josephus problem?

 A) cout << "remove: " << list.get() << endl;


 B) cout << "leader is: " << list.get() << endl;
 C) list.start();
 D) list.remove();

In the circular list, the next() method is used to:

 A) Start the list from the beginning


 B) Move to the next element in the list
 C) Remove the next element in the list
 D) Get the length of the list

Which line in the code defines the circular list object?

 A) int i, N=10, M=3;


 B) CList list;
 C) list.add(i);
 D) list.next();

Which method is used to retrieve the current element in the circular list?

 A) add()
 B) start()
 C) next()
 D) get()

The program stops running when:

 A) All elements have been removed


 B) Only one element remains in the list
 C) The variable M becomes zero
 D) The variable N reaches zero

 What is a primary benefit of using a circular list in the Josephus problem?


o A) It reduces memory usage.
o B) It simplifies the solution by allowing continuous iteration without additional
checks.
o C) It automatically selects a leader.
o D) It requires fewer programming skills.

 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.

 Why is there no NULL in a circular linked list with elements?


oA) Because it is always a singly linked list
oB) Because the last node links back to the first node
oC) Because it can only contain a single element
o D) Because all nodes link to the same data

 In which situation would next in a singly linked list return false?


o A) When there is only one node in the list
o B) When the list contains no elements
o C) When it reaches the last node, which has its next set to NULL
o D) When there are more than 10 elements in the list
o
 How does using a class like CList in C++ promote code reusability?
o A) It creates new data structures for every program.
o B) It avoids using methods entirely.
o C) The class and its methods can be used in multiple programs.
o D) It eliminates the need for methods in other programs.

 What is encapsulation in the context of the CList class?


oA) Storing only data without any methods
oB) Hiding the data and methods inside the class
oC) Making all methods public for easy access
oD) Restricting the class to only one object

 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.

 What is the key feature of an abstract data type (ADT)?


o A) It is implemented only with arrays.
o B) It defines values and operations abstractly, without specific implementation details.
o C) It is only available in C++.
o D) It has a fixed size.

 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.

 In C++, which programming construct is commonly used to implement abstract data


types (ADTs)?
o A) Functions
o B) Arrays
o C) Classes
o D) Pointers

 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.

 Which of the following is a benefit of using an appropriate data structure in algorithms?


o A) It makes the algorithm slower but more reliable.
o B) It makes the algorithm easier and more efficient.
o C) It complicates the algorithm but increases memory usage.
o D) It reduces the need for any algorithms.

 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 is an Abstract Data Type (ADT)?


o A) A specific implementation of a data structure.
o B) A concept defining a data type through values and operations, independent of
implementation.
o C) A method of storing data that is unique to C++.
o D) A software-specific data structure.

 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.

 Why is a singly linked list challenging to navigate backward?


o A) It uses only a single pointer per node.
o B) It has too many NULL pointers.
C) It lacks efficient dynamic memory allocation.
o
D) It doesn’t store any data at the head node..
o
 Which pointers are used in a doubly linked list to enable bidirectional navigation?
o A) head and tail
o B) prev and next
o C) start and end
o D) left and right

 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.

 What is a possible indication of a poorly implemented ADT?


oA. It has an easily understandable interface.
oB. It consumes too much time for operations.
oC. It uses standard libraries for implementation.
oD. It provides clear documentation.

 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 a stack, where are new items added?


o A. At the bottom
o B. In the middle
o C. At the top
o D. In a random position

 What happens when an element is removed from a stack?


oA. The element is removed from the bottom.
oB. The element is removed from the top.
oC. The element is removed from a random position.
oD. All elements are removed.

 Which of the following is an example of a real-life stack?


oA. A line of people waiting for a ticket
oB. A stack of books
oC. A tree with branches
oD. A circular racetrack

 If a method in an ADT is too time-consuming, what is a recommended approach?


o A. Ignore it, as the ADT's internal implementation cannot be changed.
o B. Manually rewrite the ADT.
o C. Request the ADT developer to optimize the internal implementation.
o D. Replace the ADT with another completely different data structure.

 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) The cassette at the bottom will be easily accessible.


 b) All cassettes will fall down.
 c) Only the top cassette will fall.
 d) None of the above.

2. In a stack data structure, which element is removed first?

 a) The bottom element


 b) The middle element
 c) The top element
 d) Any element can be removed

3. Which data structure does the stack resemble in real life?

 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

4. In a stack, which operation is used to insert a new item at the top?

 a) add()
 b) push()
 c) insert()
 d) set()

5. What does the pop() method do in a stack?

 a) Inserts an element at the bottom


 b) Returns the top element without removing it
 c) Removes and returns the top element
 d) Removes an element from the middle

6. What is the purpose of the top() method in a stack?

 a) It removes the top element.


 b) It returns the top element without removing it.
 c) It returns the bottom element.
 d) It removes the bottom element.
7. In a stack, where can new items be added or removed?

 a) At the top only


 b) At the bottom only
 c) In the middle
 d) At any position

8. Which term best describes a stack's structure?

 a) First In, First Out (FIFO)


 b) First In, Last Out (FILO)
 c) Last In, First Out (LIFO)
 d) Random Access

9. When choosing method names for a stack, why might terms like push, pop, and
top be preferred?

 a) They are easier to remember.


 b) They convey the operations clearly.
 c) They are shorter names.
 d) All of the above

10. Which of the following is NOT an appropriate action in a stack?

 a) Adding an element at the top


 b) Removing an element from the middle
 c) Returning the top element without removing it
 d) Removing the top element

1. What is the initial state of the stack?

 A) It has one element.


 B) It has two elements.
 C) It is empty.
 D) It has three elements.

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?

 A) The first element pushed


 B) The element at the bottom
 C) The element at the middle
 D) The element at the top

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

7. What is the data structure property of a stack?

 A) FIFO (First In First Out)


 B) LIFO (Last In First Out)
 C) FILO (First In Last Out)
 D) FILA (First In Last Added)

8. Which function checks if a stack is empty?

 A) isFull()
 B) isNull()
 C) isEmpty()
 D) isStack()
9. If a pop operation is called on an empty stack, what might happen?

 A) The operation will complete without error.


 B) The stack will add a default element.
 C) It throws an exception.
 D) The last element will be popped again.

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 is the role of the isEmpty() method in the stack implementation?


o A) To allow exceptions to be thrown.
o B) To prevent exceptions by ensuring pop is only called on a non-empty stack.
o C) To check if the stack can handle more elements.
o D) To reset the stack.

 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.

 Which data structure principle does a stack follow?


o A) FIFO (First-In-First-Out)
o B) LIFO (Last-In-First-Out)
o C) FILO (First-In-Last-Out)
o D) None of the above

 In an array-based stack implementation, where is the "top" of the stack located?


o A) At the start of the array
o B) At the middle of the array
o C) At the end of the array
o D) Randomly positioned

 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.

 Which of the following describes the pop operation in an array-based stack?


o A) Inserts an element at the end of the array.
o B) Removes the last element without shifting others.
o C) Removes the first element and shifts remaining elements to the left.
o D) Clears the entire stack.

 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.

1. What does the isFull() method return?


o A) True if the stack is empty
o B) True if the stack is full
o C) The size of the stack
o D) The top element of the stack
2. Before calling the push(x) method, which method should be called to check if
the stack can accept more elements?
o A) isEmpty()
o B) isFull()
o C) top()
o D) pop()

3. What does the pop() method do in the stack?


o A) Adds an element to the stack
o B) Returns the top element without removing it
o C) Removes and returns the top element of the stack
o D) Checks if the stack is empty

4. What is the purpose of the top() method?


o A) To check if the stack is full
o B) To return the top element of the stack without modifying it
o C) To remove the top element from the stack
o D) To initialize the stack

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

6. What does the isEmpty() method check?


o A) If the stack is full
o B) If there are no elements in the stack
o C) If the stack has at least one element
o D) The current size of the stack

7. In the push(int x) method, what does the expression A[++current] = x; do?


o A) Decreases the value of current by 1
o B) Increments current by 1 and assigns x to the new position
o C) Assigns x to the current index without changing it
o D) Checks if current exceeds the size of the array

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

1. What does the isFull() method check in a stack?


o A) If the stack is empty
o B) If the stack is full
o C) The number of elements in the stack
o D) The maximum size of the stack

2. What is the initial value of current in the stack constructor?


o A) 0
o B) 1
o C) -1
o D) 10

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

5. What does the top() method return?


o A) The size of the stack
o B) The last element pushed onto the stack
o C) The first element in the stack
o D) The number of elements in the stack

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

8. What does the isEmpty() method return?


o A) 1 when the stack is empty
o B) 0 when the stack is empty
o C) The number of elements in the stack
o D) A boolean value indicating if the stack has elements

9. What data structure does the stack use in this implementation?


o A) Linked List
o B) Array
o C) Queue
o D) Tree

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

11. Which variable indicates the current position of the stack?


o A) size
o B) object
o C) current
o D) A
Answer: C) current

Additional Conceptual MCQs

13. What is a limitation of using an array to implement a stack?


o A) Easy to implement
o B) Fixed size
o C) Fast operations
o D) Simple memory management

14. How can the limitation of a fixed size stack be avoided?


o A) Increase the size of the array dynamically
o B) Use a linked list
o C) Decrease the size of the stack
o D) Ignore the limitation

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()

You might also like