NEW
Font size
WorksheetsPRE TEST_DSA_MIDTERMS
Total questions: 30
Worksheet time: 15mins
What does "Last-In, First-Out" (LIFO) mean in the context of stacks?
The first element added is the first one to be removed
The last element added is the first one to be removed
Elements can be accessed in any order
Elements are sorted as they are added
Which method is used to add an item to the top of a stack in Python?
add()
push()
append()
insert()
What does the pop() method do?
Looks at the top item without removing it
Removes the item from the top of the stack
Checks if the stack is empty
Adds an item to the stack
In the expression 6 4 + 9 3 - *, what is the result after evaluating the expression?
24
60
10
18
What is the purpose of the peek operation in stack?
To remove the top item from the stack
To check if the stack is empty
To view the top item without removing it
To add a new item to the stack
Which of the following is a common application of stacks?
Sorting data
Storing parameters and return points during program execution
Managing database connections
Compressing files
When converting from infix to postfix, what should be done when encountering a right parenthesis?
Push it onto the stack
Append it to the postfix expression
Pop elements from the stack until a left parenthesis is encountered
Ignore it completely
What is the first step in evaluating a postfix expression?
Classify the token as operand or operator
Push the first operand onto the stack
Perform the operation immediately
Check if the stack is empty
In Java, which method is used to check if a stack is empty?
isEmpty()
empty()
checkEmpty()
size()
Which of the following strings is a palindrome?
apple
level
banana
cherry
What does "First-In, First-Out" (FIFO) mean in the context of queues?
The last element added is the first one to be removed
The first element added is the first one to be removed
Elements can be accessed in any order
Elements are sorted as they are added
Which of the following is the method used to remove the head of a queue in Python?
dequeue()
pop()
popleft()
remove()
In a queue, what is the term for the first element?
Tail
Head
Front
End
Which operation adds an item to the queue?
Dequeue
Enqueue
Peek
Poll
What method is used in Java to add an item to a queue?
add()
offer()
push()
insert()
Which data structure is commonly used to implement a queue in Java?
ArrayList
LinkedList
HashMap
TreeSet
How do you check if a queue is empty in Java?
if queue.empty()
if queue.isEmpty()
if queue.size() == 0
if queue.length() == 0
What is the purpose of the peek operation in a queue?
To remove the head of the queue
To check if the queue is empty
To retrieve the head of the queue without removing it
To add a new item to the queue
What method is used in Python to retrieve the head of a queue?
get()
first()
queue_name[0]
head()
Which method would you use to clear all elements from a queue in Java?
clear()
removeAll()
delete()
reset()
What does a tree represent in a graphical form?
A linear structure
A hierarchical structure
A circular structure
A flat structure
In a tree, what is the topmost node called?
Leaf
Child
Root
Branch
What is a binary tree?
A tree with no children
A tree where all nodes have at least one child
A tree where each node has at most two children
A tree that has only leaf nodes
Nodes that have the same parent are referred to as what?
Cousins
Siblings
Ancestors
Descendants
What type of traversal visits nodes by level?
Inorder
Preorder
Postorder
Breadth-First
In a postorder traversal, which node is visited last?
Left child
Right child
Root node
Any child node
Which Java component is used to display hierarchical data as an outline?
JList
JTree
JTable
JPanel
Which class is used in Java to represent a general-purpose node in a tree?
TreeNode
DefaultMutableTreeNode
Node
GenericNode
What method would you use to add a child node to a parent node in Java?
attach()
add()
insert()
push()
What is the result of traversing a tree in preorder?
Left, Right, Root
Root, Left, Right
Left, Root, Right
Root, Right, Left
