GATE / CS ARCHIVE

GATE CSE 2004 / QUESTION 40

Set operations on unsorted linked lists

Data Structures · Arrays & Linked Lists · Full GATE CSE 2004 paper

GATE 2004, Q40 2 marks · MCQ
Report issue

Arrays & Linked Lists

Question 40, GATE 2004: Each set is an unsorted linked list. Under direct list algorithms, which operations among union, intersection, membership and cardinality are slowest?
Options:
(A) Union only
(B) Intersection and membership
(C) Membership and cardinality
(D) Union and intersection
Tap to enlarge
Your answer
Answer & solution

Answer: D for direct list algorithms (no official key was published)

1. Membership scans a list in O(n), and cardinality is O(n) by traversal (or O(1) if stored). For union/intersection of two unsorted lists of comparable size, direct algorithms test each element against the other list, taking Θ(n²) worst case while avoiding duplicates in the union.

2. Thus union and intersection, D. Auxiliary hashing or sorting can improve these operations; the comparison assumes direct operations on the stated unsorted-list representation without such an index.

3. Teaching check: For two length-n lists, compare each candidate against up to n elements of the other list. That nested search costs Θ(n²), unlike a single membership or counting scan. Union must eliminate duplicates rather than merely concatenate the lists.

Original paper, page 6