Linked list operation time

radha gogia

radha gogia

@radha-BTDzli Oct 19, 2024
Please help me out with the following question,I am unable to actually make out the right option,I am able to make out only the correct option as intersection ,and that too not sure with it so what should be the approach followed for solving this question.

gate

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Ankita Katdare

    Ankita Katdare

    @abrakadabra Dec 7, 2014

    So, this is the question:

    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?

    a) union only
    b) intersection, membership
    c) membership, cardinality
    d) union, intersection

    I think the answer should be D.

    For intersection n*n comparisons are required.
    For union n*n comparisons are required. (As after merging of two lists, we again have to find out the common elements)
    A combination of both above will be the slowest.
    Also, For Membership & Cardinality both - only n comparisons are needed.

    Let's however wait for more answers.
  • radha gogia

    radha gogia

    @radha-BTDzli Dec 8, 2014

    Ankita Katdare
    So, this is the question:

    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?

    a) union only
    b) intersection, membership
    c) membership, cardinality
    d) union, intersection

    I think the answer should be D.

    For intersection n*n comparisons are required.
    For union n*n comparisons are required. (As after merging of two lists, we again have to find out the common elements)
    A combination of both above will be the slowest.
    Also, For Membership & Cardinality both - only n comparisons are needed.

    Let's however wait for more answers.
    Mam,please can you explain why cardinality would take n comparisons when in each set we will have to check for duplicate elements also,since cardinality is number of distinct elements,therefore,it would too work like union operation checking for duplicate elements,so it must also take nearly the same time as union operation.