Question Bank › Technical › Data Structures › MCQ
In general, what is the index of the first element of an array?
What is the output of the following Java code?
public class Demo {
public static void main(String args[]) {
int[] nums = {7, 8, 9, 10, 11};
System.out.println(nums[2]);
System.out.println(nums[4]);
}
}What is the output of the following Java code?
public class Demo {
public static void main(String args[]) {
int[] marks = {10, 20, 30, 40, 50};
System.out.println(marks[5]);
}
}In C, what is the index of the very first element of an array?
In C, if you declare int marks[8]; what is the last valid index you can use?
In C, which operator is used to access individual elements of an array?
In a student record system, Rohan stores roll numbers in one array and marks in another array, where the element at index i in each array belongs to the same student. What are such arrays called?
Which type of array is used internally to implement the list data type in Python?
Dynamic arrays overcome the fixed-size limitation of static arrays.
In data structures, what is a bit array?
In the context of bit arrays, what does the term 'population count' (also called Hamming weight) refer to?
In a bit array, which operation reports the position of the earliest bit that is set to 1?
Which of the following is NOT an application of bit arrays?
Which of the following is NOT an advantage of a bit array?
Which of the following is NOT a disadvantage of bit arrays?
Which bitwise operation should be used to force a chosen bit of a number to 1?
Which bitwise operation is used to toggle a specific bit?
Which bitwise operator would you use to invert every bit in a bit array?
Consider the following Java method for a circular linked list where each node has a getNext() method and an getItem() method returning an integer. What does the method do?
public void check(int value) {
int flag = 0;
if (head != null) {
Node temp = head.getNext();
while ((temp != head) && (temp.getItem() != value)) {
temp = temp.getNext();
flag = 1;
break;
}
}
if (flag == 1)
System.out.println("success");
else
System.out.println("fail");
}Consider a circular linked list where 'head' points to the first node and each node has getNext() and getItem(). What does the following method do?
public int mystery()
{
if(head == null)
return Integer.MIN_VALUE;
int val;
Node temp = head;
while(temp.getNext() != head)
temp = temp.getNext();
if(temp == head)
{
val = head.getItem();
head = null;
return val;
}
temp.setNext(head.getNext());
val = head.getItem();
head = head.getNext();
return val;
}Consider a circular linked list where 'head' points to the first node and each node has getNext() and getItem(). What does the following method do?
public int mystery()
{
if(head == null)
return Integer.MIN_VALUE;
int val;
Node temp = head;
Node prev;
while(temp.getNext() != head)
{
prev = temp;
temp = temp.getNext();
}
if(temp == head)
{
val = head.getItem();
head = null;
return val;
}
val = temp.getItem();
prev.setNext(head);
return val;
}A circular queue is also commonly known by which name?
In a circular queue of capacity CAPACITY stored in an array, how is the rear index advanced to the next position?
Why is a circular queue needed?
Consider a doubly linked deque with sentinel nodes 'head' and 'trail'. Study this method:
public void function(Object item)
{
Node temp = new Node(item, trail);
if(isEmpty())
{
head.setNext(temp);
temp.setNext(trail);
}
else
{
Node cur = head.getNext();
while(cur.getNext() != trail)
{
cur = cur.getNext();
}
cur.setNext(temp);
}
size++;
}
What does this method do?A double-ended queue (deque) allows insertion and deletion at both ends. Suppose you are required to implement a deque using only stacks, which support only push and pop operations. Let the stack size be 's' and the number of elements in the deque be 'd'. What is the time complexity of performing addFront and addRear respectively?
Which of the following correctly deletes an element from the front of a doubly-ended queue implemented with a dummy head node (head.getNext() is the front element)?
a)
public Object deleteFront() throws emptyDEQException
{
if(isEmpty())
throw new emptyDEQException("Empty");
else
{
Node temp = head.getNext();
Node cur = temp;
Object e = temp.getEle();
head.setNext(cur);
size--;
return e;
}
}
b)
public Object deleteFront() throws emptyDEQException
{
if(isEmpty())
throw new emptyDEQException("Empty");
else
{
Node temp = head.getNext();
Node cur = temp.getNext();
Object e = temp.getEle();
head.setNext(cur);
size--;
return e;
}
}
c)
public Object deleteFront() throws emptyDEQException
{
if(isEmpty())
throw new emptyDEQException("Empty");
else
{
Node temp = head.getNext();
Node cur = temp.getNext();
Object e = temp.getEle();
head.setNext(temp);
size--;
return e;
}
}
d)
public Object deleteFront() throws emptyDEQException
{
if(isEmpty())
throw new emptyDEQException("Empty");
else
{
Node temp = head.getNext();
Node cur = temp.getNext();
Object e = temp.getEle();
temp.setNext(cur);
size--;
return e;
}
}Priya needs a list in which she can keep adding or removing items while the program runs. What is such a dynamic array?
What does the physical size of a dynamic array refer to?
In a dynamic array, the count of elements currently stored in it is known as its:
Which of the following is a disadvantage of dynamic arrays?
In a dynamic array (like a growable list), what is the time complexity of appending an element at the end?
In a dynamic array implementation, the array's allocated size is shrunk (deallocated) when the number of stored elements falls below what percentage of the backend physical capacity?
In the special (best) case, the time complexity of inserting or deleting an element at the end of a dynamic array is:
In a bounded-size dynamic array implementation, the array is divided into two parts. What is the purpose of these two parts?
While converting an infix expression to prefix notation, which data structure is primarily used?
The postfix form of the infix expression P*Q+R/S is:
What is the prefix (Polish) notation for the infix expression: p+q-r/s&t|u ? (Operators: | has lowest precedence, then &, then + and -, then / and *; all left-associative.)
How many stacks are required to evaluate a prefix expression?
How many stacks are required to evaluate an infix expression directly (without first converting it)?
Using the infix evaluation algorithm, evaluate: 6*3+4-8/4
Evaluate the infix expression x^y+z where ^ denotes exponentiation, with x=3, y=2, z=4.
Evaluate the expression a/b + c*d where a=8, b=4, c=3, d=2. Choose the correct answer.
Evaluate the following prefix expression: - + 8 / 12 4 6
What is another name for a postfix expression?
Which of the following is an example of a postfix expression?
Which of the following is an infix expression?
In a postfix (Reverse Polish) expression, each operator is written after its operands. Is this statement correct?
What is the prefix notation for the expression P+(Q*R)?
When evaluating an infix expression using the standard two-stack algorithm, how many times is the input expression scanned?
The system throws an error if parentheses are encountered in an infix expression evaluation algorithm.
Evaluate the infix expression a+b*c-d/e^f where a=2, b=3, c=4, d=8, e=2, f=2.
Using the standard infix evaluation rules (precedence and left-to-right associativity), evaluate: 4 + 3 * 2 - 5
While evaluating an infix expression, the order in which operators are applied is decided by their precedence (and associativity when precedences are equal).
While evaluating an infix expression using two stacks (operand stack and operator stack), which of the following statements is INCORRECT?
In the conversion of an infix expression to postfix, parentheses are simply ignored.
Which data structure is used to convert an infix expression to a postfix expression?
What is the postfix expression for the infix expression x-y-z?
Convert the infix expression a+(b*c-(d/e^f)*g)*h to postfix using the stack algorithm. Which of the following is correct?
What is the correct postfix expression for the following infix expression? p+q*(r^s-t)^(u+v*w)-z
While converting an infix expression to a postfix expression, what is done when an operand (a number or variable) is read?
Which statement is INCORRECT regarding the infix-to-postfix conversion algorithm?
While converting an infix expression to postfix using a stack, what should be done when a left parenthesis '(' is encountered?Ravi converts an infix expression containing N tokens into postfix form using a stack. What is the time complexity of this infix-to-postfix conversion algorithm?
What is the postfix expression for the infix expression p*(q+r)/s?
Convert the infix expression a+b*c+(d*e) into its postfix form.
What is the postfix expression for the infix expression x/y^z-w?
Which of the following code snippets correctly counts the number of elements in a singly linked list?
What does the following Java method do?
public Object removeNode()
{
if(count == 0)
{
System.out.println("List is empty");
System.exit(0);
}
else
{
Node cur = head.getNext();
Node dup = cur.getNext();
Object e = cur.getEle();
head.setNext(dup);
count--;
return e;
}
}Consider an unsorted singly linked list represented with only a head pointer. Which of the following operations can be done in O(1) time? i) Insertion at the front of the list ii) Insertion at the end of the list iii) Deletion of the front node iv) Deletion of the last node
The following C function takes a singly-linked list as input and moves the last node to the front of the list, returning the modified head. Part of the code is left blank. Choose the correct replacement for 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;
}Consider a singly linked list with a head reference. What does the following method do?
public int function(int data)
{
Node temp = head;
int var = 0;
while(temp != null)
{
if(temp.getData() == data)
{
return var;
}
var = var + 1;
temp = temp.getNext();
}
return Integer.MIN_VALUE;
}Consider a singly linked list class where 'head' points to the first node and 'count' stores the number of nodes. What does the following method do?
public void show()
{
if(count == 0)
System.out.println("empty list");
else
{
Node temp = head;
while(temp != null)
{
System.out.println(temp.getData());
temp = temp.getNext();
}
}
}The C function below takes a singly linked list of integers and rearranges its elements. It is called on a list containing the integers 11, 22, 33, 44, 55, 66, 77 in that order. What will the list contain after the function finishes?
struct node {
int value;
struct node *next;
};
void rearrange(struct node *list) {
struct node *p, *q;
int temp;
if ((!list) || !list->next) return;
p = list;
q = list->next;
while (q) {
temp = p->value;
p->value = q->value;
q->value = temp;
p = q->next;
q = p ? p->next : 0;
}
}A singly linked list node has fields 'index', 'val' and 'next'. The list object itself is the head node. Which method correctly fetches the value at a given index by traversing the list and returning null if not found?
Which of the following is a valid parallel array implementation?
Which of the following is a disadvantage of parallel arrays compared to traditional arrays of records?
Ravi is designing a system where one array stores student roll numbers and another array stores their marks, accessed in the same order. Which of the following is an advantage of using such parallel arrays?
Evaluate the postfix expression ab c * + where a=2, b=3, c=4.
What is the result of the postfix expression mn*op*+ where m=3, n=4, o=2, p=5?
Evaluate the postfix expression ab+cd/- where a=7, b=5, c=8, d=4.
What is the time complexity of the algorithm that evaluates a postfix expression containing N tokens?
A computer can evaluate a postfix expression more easily than the equivalent infix expression.
While evaluating a postfix expression using a stack, when an operator is encountered, what is the correct operation to be performed?
Evaluate the postfix expression: xy*z+uv*w+t*+ where x=2, y=3, z=4, u=5, v=6, w=2, t=3.
Evaluate the postfix expression: 6, 3, 5, +, *, 2, 8, 4, /, +, *
While evaluating a prefix expression, in which direction is the expression string read?
While evaluating a prefix expression using a character stack, pushing the newline character '\n' causes an error.
Evaluate the prefix expression: / / / 24 6 2 2
Evaluate the following prefix expression: + 3 - 3 1 / - 6 2 + - 4 2 1
Using the evaluation of prefix algorithm, evaluate the prefix expression +-8 3 5.
Which data structure is most efficient for implementing a priority queue?
Which of the following is NOT an advantage of a priority queue?
In a priority queue implemented as an unsorted linked list, what is the worst-case time complexity to insert a new element with a given priority?
If the elements "P", "Q", "R" and "S" are inserted into a queue one by one and then deleted one at a time, in what order will they be removed?
What is the time complexity of the enqueue operation in a standard queue implemented using a linked list?
What does the following Java method do for an array-based queue with front index and array q?
public Object peekFront()
{
if(isEmpty())
return -999;
else
{
Object high;
high = q[front];
return high;
}
}In a linked-list based queue used to manage orders at a sweet shop, which condition must be checked before performing an insertion (enqueue) operation?
In a linked-list based queue used at a bank token counter, which condition must be checked before performing a deletion (dequeue) operation?
When inserting a node into a linked queue, the node is taken from which free-node list?
INTMAT EDTECH (OPC) PRIVATE LIMITED
No - 16, Javaraiahna Doddi, Mysore Road,
Bengaluru Urban, BENGALURU,
Karnataka 560098, India
contact@intmatedtech.com