Question
a)
public int length(Node head)
{
int size = 0;
Node cur = head;
while(cur!=null)
{
size++;
cur = cur.getNext();
}
return size;
}
b)
public int length(Node head)
{
int size = 0;
Node cur = head;
while(cur!=null)
{
cur = cur.getNext();
size++;
}
return size;
}
c)
public int length(Node head)
{
int size = 0;
Node cur = head;
while(cur!=null)
{
size++;
cur = cur.getNext();
}
}
d)
public int length(Node head)
{
int size = 0;
Node cur = head;
while(cur!=null)
{
size++;
cur = cur.getNext().getNext();
}
return size;
}
a.
a
b.
b
c.
c
d.
d
Posted under Linked Lists Data Structures and Algorithms
Engage with the Community - Add Your Comment
Confused About the Answer? Ask for Details Here.
Know the Explanation? Add it Here.
Q. Which of the following piece of code has the functionality of counting the number of elements in the list?
Similar Questions
Discover Related MCQs
Q. What differentiates a circular linked list from a normal linked list?
View solution
Q. What is the time complexity of searching for an element in a circular linked list?
View solution
Q. Which of the following application makes use of a circular linked list?
View solution
Q. Which of the following is false about a circular linked list?
View solution
Q. Consider a small circular linked list. How to detect the presence of cycles in this list effectively?
View solution
Q. What is a skip list?
View solution
Q. Skip lists are similar to which of the following datastructure?
View solution
Q. What is the time complexity improvement of skip lists from linked lists in insertion and deletion?
View solution
Q. To which datastructure are skip lists similar to in terms of time complexities in worst and best cases?
View solution
Q. The nodes in a skip list may have many forward references. their number is determined
View solution
Q. Are the below statements true about skiplists?
In a sorted set of elements skip lists can implement the below operations
i.given a element find closest element to the given value in the sorted set in O(logn)
ii.find the number of elements in the set whose values fall a given range in O(logn)
View solution
Q. How to maintain multi-level skip list properties when insertions and deletions are done?
View solution
Q. Is a skip list like balanced tree?
View solution
Q. What is indexed skip list?
View solution
Q. What is xor linked list ?
View solution
Q. What does a xor linked list have ?
View solution
Q. What does first and last nodes of a xor linked lists contain ? (let address of first and last be A and B)
View solution
Q. Disadvantages of xor lists
View solution
Q. What are the important properties of xor lists
View solution
Q. Which of the following statements are true ?
i) practical application of XOR linked lists are in environments with limited space requirements, such as embedded devices.
ii)xor lists are not suitable because most garbage collectors will fail to work properly with classes or structures that don’t contain literal pointers
iii)in order to calculate the address of the next node you need to remember the address of the previous node
iv)xor lists are much efficient than single, doubly linked lists and arrays
View solution
Suggested Topics
Are you eager to expand your knowledge beyond Data Structures and Algorithms? We've curated a selection of related categories that you might find intriguing.
Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!
![](/Images/allcat-Microprocessor.png)
Microprocessor
Understand the heart of your computer with our Microprocessor MCQs. Topics include...
![](/Images/allcat-Software Engineering.png)
Software Engineering
Learn about the systematic approach to developing software with our Software...