Whether the unidirectional list has intersections and finds intersections

Source: Internet
Author: User

How can I tell if there is an intersection?

Two one-way lists, if there are intersections, then their last node must be the same node. We can find the last node of the list, and compare whether they are the same node.

If two linked lists have intersections, how do you determine the position of the intersection?

Each node in a list is compared to each node in another list, and if the same is found, then the same is the intersection point. However, the time complexity of this algorithm is O (MN).

If two linked lists Intersect, then the position of the intersection must be the same as the end of the list (the same linked list is followed). We can align the two lists with the tail end as the starting position. After aligning, compare each node in turn, so that the algorithm complexity is O (m+n).


Whether the unidirectional list has intersections and finds intersections

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.