Introduction To Data Structures - Study Mode
[#166] What is the time complexity of pop() operation when the stack is implemented using an array?
Correct Answer
(A) O(1)
[#167] What is the time complexity of deleting from the rear end of the dequeue implemented with a singly linked list?
Correct Answer
(C) O(n)
[#168] The data structure required for Breadth First Traversal on a graph is?
Correct Answer
(C) Queue
[#169] Which of the following piece of code has the functionality of counting the number of elements in the list?
Correct Answer
(A) public int length(Node head)
{
int size = 0
Node cur = head
while(cur!=null)
{
size++
cur = cur.getNext()
}
return size
}
[#170] Given the Node class implementation, select one of the following that correctly inserts a node at the tail of the list. public class Node
{
protected int data
protected Node prev
protected Node next
public Node(int data)
{
this.data = data
prev = null
next = null
}
public Node(int data, Node prev, Node next)
{
this.data = data
this.prev = prev
this.next = next
}
public int getData()
{
return data
}
public void setData(int data)
{
this.data = data
}
public Node getPrev()
{
return prev
}
public void setPrev(Node prev)
{
this.prev = prev
}
public Node getNext
{
return next
}
public void setNext(Node next)
{
this.next = next
}
}
public class DLL
{
protected Node head
protected Node tail
int length
public DLL()
{
head = new Node(Integer.MIN_VALUE,null,null)
tail = new Node(Integer.MIN_VALUE,null,null)
head.setNext(tail)
length = 0
}
}
Correct Answer
(A) public void insertRear(int data)
{
Node node = new Node(data,tail.getPrev(),tail)
node.getPrev().setNext(node)
tail.setPrev(node)
length++
}