Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7799175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:13:26+00:00 2026-06-02T00:13:26+00:00

We have to check if two given linked lists contain the same data. Order

  • 0

We have to check if two given linked lists contain the same data. Order in this case does not matter, meaning that {1,3,2} and {2,1,3}are same. I think that we should introduce a new variable counter=0 and perform the following procedure:

while(node1->next!=NULL)
{
    int value=node1->value;
    if(contains(node2,value)){
        counter++;
    }

    node1=node1->next;

    if(counter== number of elements in node 1) 
        return true; 
    else return false;
}

Another method is to sort both lists and compare node by node. Which one is optimal? In the first case it takes O(n^2) operations, while in the second case like Nlog(N)+O(N), (if we use merge sort). Am I right in my thinking? Or is there another optimal method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:13:27+00:00Added an answer on June 2, 2026 at 12:13 am

    Out of the two methods you posted, 2nd is better. But I would suggest you to hashing.

    Hash the 1st linked list first.

    Check the 2nd list while hashing it.

    This way, it can be done in O(n) time in total.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two objects of the same class (Model) type. I want to check
I want to check the gap between two or more words, i have given
I have two versions of the same question : 1-Given a list of number
I'm needing to check the differences between two XMLs but not blindly, Given that
How do I check if two words have a common char? ex. : word
Is it possible to check if two frames have a collision or check if
I have two tests to check the expected exception throw. I am using Junit
If I have two different arrays and all I can do is check whether
I have two arrays: $array1 = array(1=>1,10=>1,12=>0,13=>13); $array2 = array(1=>Hello,10=>Test,12=>check,13=>error); Here $array1 has keys
We are using ankhsvn to check in our .net code, however I have two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.