What is the functionality of the following code? Choose the most appropriate answer.
public int function()
{
if(head == null)
return Integer.MIN_VALUE;
int var;
Node temp = head;
while(temp.getNext() != head)
temp = temp.getNext();
if(temp == head)
{
var = head.getItem();
head = null;
return var;
}
temp.setNext(head.getNext());
var = head.getItem();
head = head.getNext();
return var;
}A. Return data from the end of the list
B. Returns the data and deletes the node at the end of the list
C. Returns the data from the beginning of the list
D. Returns the data and deletes the node from the beginning of the list
Select an option to see the answer and solution.
What does 'stack overflow' refer to?
A. accessing item from an undefined stack
B. adding items to a full stack
C. removing items from an empty stack
D. index out of bounds exception
Select an option to see the answer and solution.
What is the functionality of the following piece of code?
public void fun(int x)
{
q1.offer(x);
}A. Perform push() with push as the costlier operation
B. Perform push() with pop as the costlier operation
C. Perform pop() with push as the costlier operation
D. Perform pop() with pop as the costlier operation
Select an option to see the answer and solution.
In a stack, if a user tries to remove an element from an empty stack it is called . . . . . . . .
A. Underflow
B. Empty collection
C. Overflow
D. Garbage Collection
Select an option to see the answer and solution.
A data structure in which elements can be inserted or deleted at/from both ends but not in the middle is?
A. Queue
B. Circular queue
C. Dequeue
D. Priority queue
Select an option to see the answer and solution.
What does the following function check for? (all necessary headers to be included and function is called from main)
#define MAX 10
typedef struct stack
{
int top;
int item[MAX];
}stack;
int function(stack *s)
{
if(s->top == -1)
return 1;
else return 0;
}A. full stack
B. invalid index
C. empty stack
D. infinite stack
Select an option to see the answer and solution.
What are the applications of dequeue?
A. A-Steal job scheduling algorithm
B. Can be used as both stack and queue
C. To find the maximum of all sub arrays of size k
D. All of the mentioned
Select an option to see the answer and solution.
A linear list of elements in which deletion can be done from one end (front) and insertion can take place only at the other end (rear) is known as . . . . . . . .
A. Queue
B. Stack
C. Tree
D. Linked list
Select an option to see the answer and solution.
With what data structure can a priority queue be implemented?
A. Array
B. List
C. Heap
D. Tree
Select an option to see the answer and solution.
When does the ArrayIndexOutOfBoundsException occur?
A. Compile-time
B. Run-time
C. Not an error
D. Not an exception at all
Select an option to see the answer and solution.
The following C function takes a simply-linked list as an input argument. It modifies the list by moving the last element to the front of the list and returns the modified list. Some part of the code is left blank. Choose the correct alternative to replace the blank line.
typedef struct node
{
int value;
struct node *next;
}Node;
Node *move_to_front(Node *head)
{
Node *p, *q;
if ((head == NULL: || (head->next == NULL))
return head;
q = NULL; p = head;
while (p-> next !=NULL)
{
q = p;
p = p->next;
}
_______________________________
return head;
}A. q = NULL; p->next = head; head = p;
B. q->next = NULL; head = p; p->next = head;
C. head = p; p->next = q; q->next = NULL;
D. q->next = NULL; p->next = head; head = p;
Select an option to see the answer and solution.
Which of the following concepts make extensive use of arrays?
A. Binary trees
B. Scheduling of processes
C. Caching
D. Spatial locality
Select an option to see the answer and solution.
Elements in an array are accessed . . . . . . . .
A. randomly
B. sequentially
C. exponentially
D. logarithmically
Select an option to see the answer and solution.
Consider an implementation of unsorted singly linked list. Suppose it has its representation with a head pointer only. Given the representation, which of the following operation can be implemented in O(1) time?
I. Insertion at the front of the linked list
II. Insertion at the end of the linked list
III. Deletion of the front node of the linked list
IV. Deletion of the last node of the linked list
A. I and II
B. I and III
C. I, II and III
D. I, II and IV
Select an option to see the answer and solution.
Which of the following array element will return the top-of-the-stack-element for a stack of size N elements(capacity of stack > N)?
A. S[N-1]
B. S[N]
C. S[N-2]
D. S[N+1]
Select an option to see the answer and solution.
What is the need for a circular queue?
A. effective usage of memory
B. easier computations
C. to delete elements based on priority
D. implement LIFO principle in queues
Select an option to see the answer and solution.
Which of these is not an application of a linked list?
A. To implement file systems
B. For separate chaining in hash-tables
C. To implement non-binary trees
D. Random Access of elements
Select an option to see the answer and solution.
Assuming int is of 4bytes, what is the size of int arr[15];?
Select an option to see the answer and solution.
How do you initialize an array in C?
A. int arr[3] = (1,2,3);
B. int arr(3) = {1,2,3};
C. int arr[3] = {1,2,3};
D. int arr(3) = (1,2,3);
Select an option to see the answer and solution.
Given pointer to a node X in a singly linked list. Only one pointer is given, pointer to head node is not given, can we delete the node X from given linked list?
A. Possible if X is not last node
B. Possible if size of linked list is even
C. Possible if size of linked list is odd
D. Possible if X is not first node
Select an option to see the answer and solution.