What is the time complexity to count the number of elements in the linked list?

Q & ACategory: Data StructureWhat is the time complexity to count the number of elements in the linked list?
Admin Staff asked 4 years ago

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) O(n2)

1 Answers
Admin Staff answered 4 years ago

b) O(n)