Home » Data Structure & Algorithms » Frequency of a Number in LinkedList

Frequency of a Number in LinkedList

 

Question :

WAP to find the length of a linkedlist in O(n) time complexity.

Algorithm :

Iterative Solution :

Step 1: If head is null return 0

Step 2 : Traverse each node and compare each element with the given value.If there is an equality found, then increment the counter.The final value of counter is occurrence of the given value in the LinkedList.

Program :

 

OutPut :

 
 


Leave a comment

Your email address will not be published. Required fields are marked *

4 + thirteen =