WorksheetsFinal Examination ITESDT
Total questions: 34
Worksheet time: 17mins
in Java, a ______________is a data structure that follows the Last-
In-First-Out (LIFO) principle. This means that the last
element added to the stack is the first one to be removed
Stacks
Linked List
QUEUE
Tree
Which of the following is NOT a method of the Java Stack class?
push()
pop()
peek()
remove()
What is a stack data structure?
A data structure that allows elements to be added or removed from both ends
A data structure that allows elements to be added or removed from the front end only
A data structure that allows elements to be added or removed from the back end only
A data structure that stores elements in a random order
Which of the following is true about the peek() method in the Java Stack class?
It removes and returns the top element of the stack.
It returns the top element of the stack without removing it.
It returns the bottom element of the stack.
It removes and returns the bottom element of the stack.
In which order are elements removed from a stack data structure?
First-in, last-out (FILO)
Last-in, first-out (LIFO)
Random order
None of the above
What happens when you try to pop an element from an empty stack?
An exception is thrown
The stack remains unchanged
The stack is automatically resized to accommodate the missing element
The stack is deleted
Which of the following data structures is similar to a stack, but allows elements to be added or removed from both ends?
Queue
Deque
Linked List
Binary Tree
Which of the following is the correct order of steps to implement a stack using an array?
Declare an array, initialize the top variable to -1, implement push() and pop() methods.
Declare an array, initialize the top variable to 0, implement push() and pop() methods.
Declare an array, initialize the top variable to 1, implement push() and pop() methods.
Declare an array, don't initialize the top variable, implement push() and pop() methods.
Which of the following classes can be used to implement queue and deque data structures using arrays in Java?
ArraySet
ArrayQueue
ArrayDeque
ArrayList
Which package must be imported to use the ArrayDeque class in Java?
java.util.ArrayList
java.util.LinkedList
java.util.PriorityQueue
java.util.ArrayDeque
What is the syntax for creating an ArrayDeque in Java?
ArrayDeque<Type> deque = new ArrayDeque<>();
ArrayDeque deque = new ArrayDeque<Type>();
ArrayDeque deque = new ArrayDeque();
ArrayDeque<Type> deque = new ArrayDeque<Type>();
Which method is used to insert an element at the end of an ArrayDeque?
addFirst()
addLast()
add()
offerLast()
Which method is used to check if an ArrayDeque is empty?
isEmpty()
isFull()
isNull()
isNotEmpty()
Which method is used to remove and return the first element of an ArrayDeque without throwing an exception if the deque is empty?
remove()
removeFirst()
removeLast()
poll()
Which method is used to remove and return the first occurrence of a specified element from an ArrayDeque?
remove()
removeFirst()
removeLast()
remove(element)
Which method is used to add an element to the end of an ArrayDeque?
addFirst()
addLast()
add()
offerLast()
Which method is used to access the last element of an ArrayDeque without removing it?
getLast()
getFirst()
peekLast()
peekFirst()
Which method is used to remove and return the last element of an ArrayDeque?
removeFirst()
removeLast()
remove()
pollLast()
Which method is used to access the first element of an ArrayDeque?
getFirst()
getLast()
peekFirst()
peekLast()
Which method is used to remove and return the first element of an ArrayDeque?
removeFirst()
removeLast()
remove()
pollFirst()
What is the output of the following code?
ArrayDeque: [Dog, Cat, Cow, Horse]
Removed Element: Dog
New ArrayDeque: [Cat, Cow, Horse]
Removed First Element: Cat
Removed Last Element: Horse
ArrayDeque: [Dog, Cat, Cow, Horse]
Removed Element: Cat
New ArrayDeque: [Dog, Cow, Horse]
Removed First Element: Dog
Removed Last Element: Horse
ArrayDeque: [Dog, Cat, Cow, Horse]
Removed Element: Dog
New ArrayDeque: [Cat, Cow, Horse]
Removed First Element: Cow
Removed Last Element: Cat
ArrayDeque: [Dog, Cat, Cow, Horse]
Removed Element: Horse
New ArrayDeque: [Dog, Cat, Cow]
Removed First Element: Dog
Removed Last Element: Cow
What is the purpose of the ArrayDeque class in this code?
To implement a stack data structure
To implement a queue data structure
To implement a deque data structure
To implement a linked list data structure
Which method is used to add an element to the beginning of the ArrayDeque?
add()
addFirst()
addLast()
insert()
Which class does the Stack class extend in Java?
Set
List
Vector
Map
Which package must be imported to use the Stack class in Java?
java.util.Set
java.util.List
java.util.Vector
java.util.Stack
What is the syntax for creating a stack of integers in Java using the Stack class?
Stack<Integer> stacks = new Stack<>();
Stack stacks = new Stack<Integer>();
Stack<Integer> stacks = new Stack<Integer>();
Stack stacks = new Stack();
Which method is used to add an element to the top of the stack in Java?
add()
push()
insert()
append()
Which method is used to remove and return an element from the top of the stack in Java?
remove()
pop()
delete()
extract()
Which method is used to access an element from the top of the stack without removing it in Java?
get()
peek()
access()
retrieve()
Which method is used to search for an element in the stack in Java?
find()
locate()
search()
seek()
How does the search() method in the Stack class return the position of an element in the stack in Java?
It returns the index of the element in the stack.
It returns the position of the element from the bottom of the stack.
It returns the position of the element from the top of the stack.
It returns the depth of the element in the stack.
Why is it recommended to use the ArrayDeque class instead of the Stack class to implement the stack data structure in Java?
Because the Stack class is deprecated.
Because the ArrayDeque class is more efficient than the Stack class.
Because the ArrayDeque class provides more functionality than the Stack class.
Because the Stack class is not part of the Java collections framework.
What is a tree data structure?
A linear data structure that stores data sequentially
A nonlinear hierarchical data structure that consists of nodes connected by edges
A data structure that consists of key-value pairs
What is a leaf node in a tree?
The topmost node of a tree
A node that contains a key or value and pointers to its child nodes
The last node of each path that does not contain a link/pointer to child nodes
