Solution Review: Union and Intersection of Linked Lists
Discover how to implement union and intersection operations on linked lists in C#. Learn to traverse, link, and remove duplicates, and explore the time complexity involved in these algorithms. This lesson guides you through a solution review and highlights areas for potential optimization.
We'll cover the following...
Solution: Union #
There is nothing too tricky going on here. Traverse to the tail of the first list, and link it to the first node of the second list on line 125 - 131 in LinkedList.cs. Now, remove duplicates from the combined list.
Time complexity
If you did not have the care of duplicates, the runtime complexity of this algorithm would be O(m) where m is the size of the first list. However, because of duplicates, you need to traverse the whole union list. This increases the time complexity to ...