Data Struct Final
Data Struct Final
Data Struct Final
a) A data structure that shows a hierarchical behavior b) Container of objects of similar types
c) Container of objects of mixed types d) All of the mentioned
2. 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);
3. How do you instantiate an array in Java?
a) int arr[] = new int(3); b) int arr[]; c) int arr[] = new int[3]; d) int arr() = new int(3);
4. Which of the following is a correct way to declare a multidimensional array in Java?
a) int[][] arr; b) int arr[][]; c) int []arr[]; d) All of the mentioned
5. What is the output of the following piece of code?
public class array
{
public static void main(String args[])
{
int []arr = {1,2,3,4,5};
System.out.println(arr[2]);
System.out.println(arr[4]);
}
}
a) 3 and 5 b) 5 and 3 c) 2 and 4 d) 4 and 2
34. Convert the following Infix expression to Postfix form using a stack
x + y * z + (p * q + r) * s, Follow usual precedence rule and assume that the expression is legal.
a) xyz*+pq*r+s*+ b) xyz*+pq*r+s+*
c) xyz+*pq*r+s*+ d) None of the mentioned
35. Which of the following statement(s) about stack data structure is/are NOT correct?
a) Linked List are used for implementing Stacks
b) Top of the Stack always contain the new node
c) Stack is the FIFO data structure
d) Null link is present in the last node at the bottom of the stack
36. Consider the following operation performed on a stack of size 5.
Push(1);
Pop();
Push(2);
Push(3);
Pop();
Push(4);
Pop();
Pop();
Push(5);
After the completion of all operation, the number of elements present in stack are
a) 1 b) 2 c) 3 d) 4
37. Which of the following is not an inherent application of stack?
a) Reversing a string b) Evaluation of postfix expression
c) Implementation of recursion d) Job scheduling
38. The type of expression in which operator succeeds its operands is?
a) Infix Expression b) Prefix Expression
c) Postfix Expression d) None of the mentioned
39. Assume that the operators +,-, X are left associative and ^ is right associative.
The order of precedence (from highest to lowest) is ^, X, +, -. The postfix expression for the infix
expression a + b X c – d ^ e ^ f is
a) abc X+ def ^^ –
b) abc X+ de^f^ –
c) ab+c Xd – e ^f^
d) -+aXbc^ ^def
40. If the elements “A”, “B”, “C” and “D” are placed in a stack and are deleted one at a time, what is
the order of removal?
a) ABCD
b) DCBA
c) DCAB
d) ABDC
41. A linear collection of data elements where the linear node is given by means of pointer is called?
a) Linked list
b) Node list
c) Primitive list
d) None of the mentioned
42. 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
43. In linked list each node contain minimum of two fields. One field is data field to store the data
second field is?
a) Pointer to character
b) Pointer to integer
c) Pointer to node
d) Node
44. What would be the asymptotic time complexity to add a node at the end of singly linked list, if the
pointer is initially pointing to the head of the list?
a) O(1)
b) O(n)
c) θ(n)
d) θ(1)
45. What would be the asymptotic time complexity to add an element in the linked list?
a) O(1) b) O(n) c) O(n2) d) None of the mentioned
46. What would be the asymptotic time complexity to find an element in the linked list?
a) O(1) b) O(n) c) O(n2) d) None of the mentioned
47. What would be the asymptotic time complexity to insert an element at the second position in the
linked list?
a) O(1) b) O(n) c) O(n2) d) None of the mentioned
48. The concatenation of two list can performed in O(1) time. Which of the following variation of
linked list can be used?
a) Singly linked list b) Doubly linked list c) Circular doubly linked list
d) Array implementation of list
49. Consider the following definition in c programming language
struct node
{
int data;
struct node * next;
}
typedef struct node NODE;
NODE *ptr;
Which of the following c code is used to create new node?
a) ptr = (NODE*)malloc(sizeof(NODE));
b) ptr = (NODE*)malloc(NODE);
c) ptr = (NODE*)malloc(sizeof(NODE*));
d) ptr = (NODE)malloc(sizeof(NODE));
50. What kind of linked list is best to answer question like “What is the item at position n?”
a) Singly linked list b) Doubly linked list
c) Circular linked list d) Array implementation of linked list
51. Linked lists are not suitable to for the implementation of?
a) Insertion sort b) Radix sort
c) Polynomial manipulation d) Binary search
52. Linked list is considered as an example of ___________ type of memory allocation.
a) Dynamic b) Static
c) Compile time
d) None of the mentioned
53. In Linked List implementation, a node carries information regarding
a) Data
b) Link
c) Data and Link
d) None of the mentioned
54. Linked list data structure offers considerable saving in
a) Computational Time
b) Space Utilization
c) Space Utilization and Computational Time
d) None of the mentioned
55. Which of the following points is/are true about Linked List data structure when it is compared
with array
a) Arrays have better cache locality that can make them better in terms of performance
b) It is easy to insert and delete elements in Linked List
c) Random access is not allowed in a typical implementation of Linked Lists
d) All of the mentioned
56. What does the following function do for a given Linked List with first node as head?
1->2->3->4->5->6
void fun(struct node* start)
{
if(start == NULL)
return;
printf("%d ", start->data);
if(start->next != NULL )
fun(start->next->next);
printf("%d ", start->data);
}
a) 1 4 6 6 4 1 b) 1 3 5 1 3 5 c) 1 2 3 5 d) 1 3 5 5 3 1
59. The following C function takes a simply-linked list as 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.
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) 1, 2, 3, 4, 5, 6, 7
b) 2, 1, 4, 3, 6, 5, 7
c) 1, 3, 2, 5, 4, 7, 6
d) 2, 3, 4, 5, 6, 7, 1
61. In the worst case, the number of comparisons needed to search a singly linked list of length n for a
given element is
a) log 2 n b) n⁄2 c) log 2 n – 1 d) n
62. 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
63. You are given pointers to first and last nodes of a singly linked list, which of the following
operations are dependent on the length of the linked list?
a) Delete the first element b) Insert a new element as a first element
c) Delete the last element of the list d) Add a new element at the end of the list
64. In the worst case, the number of comparisons needed to search a singly linked list of length n for a
given element is
a) log2 n b) n⁄2 c) log2 n – 1 d) n
65. Which of the following is not a disadvantage to the usage of array?
a) Fixed size b) You know the size of the array prior to allocation
c) Insertion based on position d) Accessing elements at specified positions
66. What is the time complexity of inserting at the end in dynamic arrays?
a) O(1) b) O(n) c) O(logn) d) Either O(1) or O(n)
67. What is the time complexity to count the number of elements in the linked list?
a) O(1) b) O(n) c) O(logn) d) None of the mentioned
68. Which of the following performs deletion of the last element in the list? Given below is the Node
class.
class Node
{
protected Node next;
protected Object ele;
Node(Object e,Node n)
{
ele = e;
next = n;
}
public void setNext(Node n)
{
next = n;
}
public void setEle(Object e)
{
ele = e;
}
public Node getNext()
{
return next;
}
public Object getEle()
{
return ele;
}
}
class SLL
{
Node head;
int size;
SLL()
{
size = 0;
}
}
a)
{
if(size == 0)
return null;
Node cur;
Node temp;
cur = head;
while(cur.getNext() != null)
{
cur = cur.getNext();
temp = cur;
}
temp.setNext(null);
return cur;
}
{
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;
}
}
a)
b)
c)
d)
78. Which of the following piece of code removes the node from a given position?
a)
b)
c)
b)
c)
d)
a) head-0-1-2-3-4-5-6-tail
b) head-1-2-3-4-5-6-tail
c) head-6-1-2-3-4-5-0-tail
d) head-0-1-2-3-4-5-tail
View Answer
a) Return the element at the tail of the list but do not remove it
b) Return the element at the tail of the list and remove it from the list
c) Return the last but one element from the list but do not remove it
d) Return the last but one element at the tail of the list and remove it from the list
84. Consider the following doubly linked list: head-1-2-3-4-5-tail
What will be the list after performing the given sequence of operations?
a) head-6-1-2-3-4-5-tail
b) head-6-1-2-3-4-tail
c) head-1-2-3-4-5-6-tail
d) head-1-2-3-4-5-tail
85. What differentiates a circular linked list from a normal linked list?
a) You cannot have the ‘next’ pointer point to null in a circular linked list
b) It is faster to traverse the circular linked list
c) You may or may not have the ‘next’ pointer point to null in a circular linked list
d) All of the mentioned
86. How do you count the number of elements in the circular linked list?
a)
b)
c)
{
Node temp = new Node(data);
Node cur = head;
while(cur.getNext() != head)
cur = cur.getNext()
if(head == null)
{
head = temp;
head.setNext(head);
}
else
{
temp.setNext(head);
head = temp;
cur.setNext(temp);
}
size++;
}
b)
c)
d)
90. 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
91. 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;
Node cur;
while(temp.getNext() != head)
{
cur = temp;
temp = temp.getNext();
}
if(temp == head)
{
var = head.getItem();
head = null;
return var;
}
var = temp.getItem();
cur.setNext(head);
return var;
}
94. Which of the following real world scenarios would you associate with a stack data structure?
a) Piling up of chairs, one above the other
b) people standing in a line to be serviced at a counter
c) offer services based on the priority of the customer
d) all of the mentioned
95. What does the following function check for? (all necessary headers to be included and function is
called from main)
#define MAX 10