CrazyEngineers
  • Linked list operation time

    radha gogia

    radha gogia

    @radha-BTDzli
    Updated: Oct 19, 2024
    Views: 1.1K
    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
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • Ankita Katdare

    AdministratorDec 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.
    Are you sure? This action cannot be undone.
    Cancel
  • radha gogia

    MemberDec 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.
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register