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)
Answer:B
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)
Explanation: To count the number of elements, you have to traverse through the entire list, hence complexity is O(n).