Skip to content
Related Articles
Open in App
Not now

Related Articles

Data Structures | Linked List | Question 10

Improve Article
Save Article
  • Difficulty Level : Hard
  • Last Updated : 28 Jun, 2021
Improve Article
Save Article

Suppose each set is represented as a linked list with elements in arbitrary order. Which of the operations among union, intersection, membership, cardinality will be the slowest? (GATE CS 2004)








 union, intersection

Answer: (D)


Cardinality and membership are definitely not the slowest one. For cardinality, just count the number of nodes in a list. For membership, just traverse the list and look for a match
For getting intersection of L1 and L2, search for each element of L1 in L2 and print the elements we find in L2. 
There can be many ways for getting union of L1 and L2. One of them is as follows 
a) Print all the nodes of L1 and print only those which are not present in L2. 
b) Print nodes of L2.

Quiz of this Question
Please comment below if you find anything wrong in the above post

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!