The complexity analysis set and cycle set of the two tables

Source: Internet
Author: User

The complexity analysis set and cycle set of the two tables

 

Question: There are two tables with the same field. Now, we need to select the records with the same two fields. What can be done besides using two repeated loops? (Some questions)

 

There are actually many unclear points about this question, but as far as the question itself is concerned, it is obvious that the current complexity is O (n2). If you cannot answer this question, there is no optimization at all. Assume that the complexity of a record is O (1 ).

 

What are your solutions? You can consider various implementations and share your thoughts...


The two linked lists combine a linked list. The time complexity is?

If it is a circular linked list, the time complexity is 1, because a pointer to the circular linked list can directly know its front and back nodes, you only need to disconnect the pointer pointing to the respective node of the two cyclic linked lists and then link them.
If it is a single-chain table, the time complexity is n, because two single-chain tables can only be the first and last links, so the pointer of a chain table needs to be cyclically n times to find its tail pointer, then it is connected to another pointer.

How to calculate the time complexity of a for loop statement?

If there is no relationship between the number of cycles between internal and external loops, the product of the number of internal and external loops can be regarded as the complexity. If there is a relationship, the number of basic operations of the internal loop can be considered to analyze the complexity.

Related Article

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.