Data Structures Questions asked in HCL

Question 1

Time: 00:00:00
What do first and last nodes of a xor linked lists contain? (let address of first and last be A and B)

NULL xor A and B xor NULL

NULL xor A and B xor NULL

NULL and NULL

NULL and NULL

A and B

A and B

NULL xor A and B

NULL xor A and B

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 2

Time: 00:00:00
Given 10,8,6,7,9
swap the above numbers such that finally, you got 6,7,8,9,10
so now reverse 10
9,7,6,8,10
now reverse 9
8,6,7,9,10
7,6,8,9,10
6,7,8,9,10
at this point 6 is ahead so no more reversing can be done so stop.
To implement above algorithm which data structure is better and why?

linked list. because we can swap elements easily

linked list. because we can swap elements easily

arrays. because we can swap elements easily

arrays. because we can swap elements easily

xor linked list. because there is no overhead of pointers and so memory is saved

xor linked list. because there is no overhead of pointers and so memory is saved

doubly linked list. because you can traverse back and forth

doubly linked list. because you can traverse back and forth

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 3

Time: 00:00:00
Consider insert at beginning into xor linked list logic


void xor-linked-list insert(struct node **head_ref, int value)
{
node *new_node = new (struct node);
new_node->value = value;
new_node->nodepointerxored = xor (*head_ref, NULL);
if (*head_pointer == NULL)
{
printf("invalid");
}
else
{
let b,c,d are nodes and a is to be inserted at the beginning, an address field must contain NULL xor b and b
address filed must be a xor c.
}
*head_pointer = new_node;
}


how would you convert the English sentences in above to code

node* next = XOR ((*head_ref)->npx, NULL); (*head_ref)->npx = XOR (new_node, next);

node* next = XOR ((*head_ref)->npx, NULL); (*head_ref)->npx = XOR (new_node, next);

node* next = XOR ((*head_ref)->npx, NULL); (*head_ref) = XOR (new_node, next);

node* next = XOR ((*head_ref)->npx, NULL); (*head_ref) = XOR (new_node, next);

that cannot be achieved

that cannot be achieved

both a and b are correct

both a and b are correct

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 4

Time: 00:00:00
Level order traversal of a tree is formed with the help of

breadth first search

breadth first search

depth-first search

depth-first search

dijkstra’s algorithm

dijkstra’s algorithm

prims algorithm

prims algorithm

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 5

Time: 00:00:00
The following lines talk about deleting a node in a binary tree.(the tree property must not be violated after deletion)
i) from root search for the node to be deleted
ii)
iii) delete the node at
what must be statement ii) and fill up statement iii)

i)-find random node, replace with the node to be deleted. iii)- delete the node

i)-find random node, replace with the node to be deleted. iii)- delete the node

ii)-find node to be deleted. iii)- delete the node at the found location

ii)-find node to be deleted. iii)- delete the node at the found location

ii)-find deepest node, replace with the node to be deleted. iii)- delete a node

ii)-find deepest node, replace with the node to be deleted. iii)- delete a node

ii)-find deepest node, replace with the node to be deleted. iii)- the deepest node

ii)-find deepest node, replace with the node to be deleted. iii)- the deepest node

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 6

Time: 00:00:00
What is the code below trying to print?

void print(tree *root,tree *node)
{
if(root ==null) return 0
if(root-->left==node || root-->right==node || print(root->left,node)||printf(root->right,node)
{
print(root->data)
}
}

just printing all nodes

just printing all nodes

not a valid logic to do any task

not a valid logic to do any task

printing ancestors of a node passed as the argument

printing ancestors of a node passed as the argument

printing nodes from the leaf node to a node passed as the argument

printing nodes from the leaf node to a node passed as the argument

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 7

Time: 00:00:00
Advantages of linked list representation of binary trees over arrays?

dynamic size

dynamic size

ease of insertion/deletion

ease of insertion/deletion

ease in randomly accessing a node

ease in randomly accessing a node

both dynamic size and ease of insertion/deletion

both dynamic size and ease of insertion/deletion

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 8

Time: 00:00:00
Given the code, choose the correct option that is consistent with the code

build(A,i)
left-> 2*i
right->2*i +1
temp- > i
if(left<= heap_length[A] ans A[left] >A[temp])
temp -> left
if (right = heap_length[A] and A[right] > A[temp])
temp->right
if temp!= i
swap(A[i],A[temp])
build(A,temp)

Here A is the heap

It is the build function of the max heap.

It is the build function of the max heap.

It is the build function of min heap.

It is the build function of min heap.

It is general build function of any heap.

It is general build function of any heap.

None of the mentioned

None of the mentioned

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 9

Time: 00:00:00
Given an array of element 5,7,9,1,3,10,8,4. Tick all the correct sequences of elements after inserting all the elements in a min-heap.

1,3,4,7,8,9,10

1,3,4,7,8,9,10

1,4,3,8,9,5,7,10

1,4,3,8,9,5,7,10

1,3,4,5,8,7,9,10

1,3,4,5,8,7,9,10

None of these

None of these

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

Question 10

Time: 00:00:00
For the construction of a binary heap with the property that parent node has value less than child node.In reference to that which line is incorrect. Line indexed from 1.

add(int k)
{
heap_size++;
int i = heap_size - 1;
harr[i] = k;
while (i != 0 && harr[parent(i)] < harr[i])
{
swap(&harr[i], &harr[parent(i)]);
i = parent(i);
}
}

Line -3

Line -3

Line – 5

Line – 5

Line – 6

Line – 6

Line -7

Line -7

Once you attempt the question then PrepInsta explanation will be displayed.

Please login to submit your explanation

Start

["0","40","60","80","100"]
["Need more practice! \r\n","Keep trying! \r\n","Not bad! \r\n","Good work! \r\n","Perfect! \r\n"]

Hey ! Follow us on G+