wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

PRE TEST_DSA_MIDTERMS

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

What does "Last-In, First-Out" (LIFO) mean in the context of stacks?

a)

The first element added is the first one to be removed

b)

The last element added is the first one to be removed

c)

Elements can be accessed in any order

d)

Elements are sorted as they are added

2.

Which method is used to add an item to the top of a stack in Python?

a)

add()

b)

push()

c)

append()

d)

insert()

3.

What does the pop() method do?

a)

Looks at the top item without removing it

b)

Removes the item from the top of the stack

c)

Checks if the stack is empty

d)

Adds an item to the stack

4.

In the expression 6 4 + 9 3 - *, what is the result after evaluating the expression?

a)

24

b)

60

c)

10

d)

18

5.

What is the purpose of the peek operation in stack?

a)

To remove the top item from the stack

b)

To check if the stack is empty

c)

To view the top item without removing it

d)

To add a new item to the stack

6.

Which of the following is a common application of stacks?

a)

Sorting data

b)

Storing parameters and return points during program execution

c)

Managing database connections

d)

Compressing files

7.

When converting from infix to postfix, what should be done when encountering a right parenthesis?

a)

Push it onto the stack

b)

Append it to the postfix expression

c)

Pop elements from the stack until a left parenthesis is encountered

d)

Ignore it completely

8.

What is the first step in evaluating a postfix expression?

a)

Classify the token as operand or operator

b)

Push the first operand onto the stack

c)

Perform the operation immediately

d)

Check if the stack is empty

9.

In Java, which method is used to check if a stack is empty?

a)

isEmpty()

b)

empty()

c)

checkEmpty()

d)

size()

10.

Which of the following strings is a palindrome?

a)

apple

b)

level

c)

banana

d)

cherry

11.

What does "First-In, First-Out" (FIFO) mean in the context of queues?

a)

The last element added is the first one to be removed

b)

The first element added is the first one to be removed

c)

Elements can be accessed in any order

d)

Elements are sorted as they are added

12.

Which of the following is the method used to remove the head of a queue in Python?

a)

dequeue()

b)

pop()

c)

popleft()

d)

remove()

13.

In a queue, what is the term for the first element?

a)

Tail

b)

Head

c)

Front

d)

End

14.

Which operation adds an item to the queue?

a)

Dequeue

b)

Enqueue

c)

Peek

d)

Poll

15.

What method is used in Java to add an item to a queue?

a)

add()

b)

offer()

c)

push()

d)

insert()

16.

Which data structure is commonly used to implement a queue in Java?

a)

ArrayList

b)

LinkedList

c)

HashMap

d)

TreeSet

17.

How do you check if a queue is empty in Java?

a)

if queue.empty()

b)

if queue.isEmpty()

c)

if queue.size() == 0

d)

if queue.length() == 0

18.

What is the purpose of the peek operation in a queue?

a)

To remove the head of the queue

b)

To check if the queue is empty

c)

To retrieve the head of the queue without removing it

d)

To add a new item to the queue

19.

What method is used in Python to retrieve the head of a queue?

a)

get()

b)

first()

c)

queue_name[0]

d)

head()

20.

Which method would you use to clear all elements from a queue in Java?

a)

clear()

b)

removeAll()

c)

delete()

d)

reset()

21.

What does a tree represent in a graphical form?

a)

A linear structure

b)

A hierarchical structure

c)

A circular structure

d)

A flat structure

22.

In a tree, what is the topmost node called?

a)

Leaf

b)

Child

c)

Root

d)

Branch

23.

What is a binary tree?

a)

A tree with no children

b)

A tree where all nodes have at least one child

c)

A tree where each node has at most two children

d)

A tree that has only leaf nodes

24.

Nodes that have the same parent are referred to as what?

a)

Cousins

b)

Siblings

c)

Ancestors

d)

Descendants

25.

What type of traversal visits nodes by level?

a)

Inorder

b)

Preorder

c)

Postorder

d)

Breadth-First

26.

In a postorder traversal, which node is visited last?

a)

Left child

b)

Right child

c)

Root node

d)

Any child node

27.

Which Java component is used to display hierarchical data as an outline?

a)

JList

b)

JTree

c)

JTable

d)

JPanel

28.

Which class is used in Java to represent a general-purpose node in a tree?

a)

TreeNode

b)

DefaultMutableTreeNode

c)

Node

d)

GenericNode

29.

What method would you use to add a child node to a parent node in Java?

a)

attach()

b)

add()

c)

insert()

d)

push()

30.

What is the result of traversing a tree in preorder?

a)

Left, Right, Root

b)

Root, Left, Right

c)

Left, Root, Right

d)

Root, Right, Left