Open In App

Data Structures | Linked List | Question 10

Like Article
Like
Save
Share
Report

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)

(A)

union 

(B)

 membership

(C)

cardinality

(D)

 union, intersection


Answer: (D)

Explanation:

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


Last Updated : 28 Jun, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads