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 only
(B) intersection, membership
(C) membership, cardinality
(D) union, intersection
Explanation: 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.
All of these methods will require more operations than intersection as we have to process intersection node plus other nodes.
Quiz of this Question
- Data Structures | Linked List | Question 11
- Data Structures | Linked List | Question 14
- Data Structures | Linked List | Question 12
- Data Structures | Linked List | Question 9
- Data Structures | Misc | Question 4
- Advantages of vector over array in C++
- Data Structures and Algorithms | Set 37
- Data Structures and Algorithms | Set 36
- Data Structures | Heap | Question 12
- Data Structures | Linked List | Question 17