253 views

3 Answers

2 votes
2 votes
I am not sure in compiler but lets go option by option.

1. Traveling the list till null,if null kis encountered then there is no Loop.So this seems to be true.But what will happen in case there is a loop.Then we will use option 2.

2.If same address is encountered again while traversing list, then we know there is a loop.

3.The multiple nodes can have same value,which means there can be no loop but still multiple nodes can have same valie ,so it cant be find the loop.

4.Both 1 and 2 are true,.

So i think d is the answer here as combination of 1 and 2 will help to find the loop.It is not possible with only 1 or ony 2 as if only 1 is true then it can't find loop if exists and if only 2 is true it dont know when to stop.I will say D is the answer
1 votes
1 votes
Loop: In programming, it does not have a termination. Null means it is an end to the current traverse. hence while traversing if we found NULL, it means the list has got an end. Hence loop does not exist.

In Linked list, a collection of nodes which are distributed over memory(Non-contiguous). So nodes can be present anywhere in the memory at different addresses. To check for the presence of a loop, we need to check whether any node is pointing to already traversed node.  Just comparing the addresses of Node is not sufficient for the loop detection.

Even comparing value stored in a node with other value stored in node does not detect the loop.

Hence Option A is correct.

Correct me if I am wrong.
1 votes
1 votes
1.It is the case where list has no loop :

if null is encountered while traveling that definitely means no loop and it says too about the end of list .

2.when list has loop :

when list has loop then null wont be present there in any of the node.and any one of the visited node address will  repeat surely.

we can check it by taking one visited_flag for each node .we will make it one after visiting .so if any node appears whose visited_flag value is 1 already that means loop is present there in the list.and that will only occur when the same address will come again.

so checking any condition their must be two part :

 i> termination part

 ii> detection part

termination part will be the presence of null and detection part is address repeatation . so "D" is the correct answer

Related questions

0 votes
0 votes
1 answer
1
deepak_8404 asked Oct 1, 2023
280 views
Consider a lower triangular matrix stored in row major order as p[-25 - - + 749][-25 - - - + 749] with base address = 6800, size of each element = 6 byte. Find the value ...
0 votes
0 votes
1 answer
2
jugnu1337 asked May 16, 2023
803 views
The total number of binary trees possible with height n - 2 having n nodes are?(2n - 5)^ 2n - 3 (2n - 7)^2n - 3(n - 3) ^2n - 2(2n - 7)^ 2n - 2
–4 votes
–4 votes
2 answers
4
Souvik33 asked Oct 27, 2022
607 views
*MSQ*The following figure depicts a a. A tree and only treeb. A tree with 3 nodesc. A graph (Since every tree is a graph)d. A graph and only graph