2. Large o representation of data structures and algorithms

Source: Internet
Author: User

I. Large O notation

Large o notation is not an algorithm. It is used to indicate how quickly an algorithm solves a problem. In general, we describe how quickly a thing is done in terms of time, for example, how many minutes I have completed a computational problem. But the algorithm is difficult to use accurate time to describe, so we use the algorithm to solve the problem of a total number of steps to represent the speed of the algorithm.

Using the first two search methods for example, simple find we want to use each element of the list to compare one by one, if there are n elements, then the simple lookup requires up to n steps to find the data (data at the end of the list). While two-point lookup uses only the median to compare, when looking for an array with n elements, it is necessary to log2n the number of times.

The speed of the two algorithms is represented by the large O notation: O (n), O (log2n).

Note: 1. Large o notation reflects the worst case scenario of the algorithm; 2. The large O notation indicates that the algorithm solves the problem by changing the number of operands as the data increases.

Other common large O-notation:

O (N)--Simple search

O (LOG2N)--Two points find

O (n!)--Travel business issues

Second, the problem of traveling business

If a traveler wants to route 5 cities, he plans the shortest route connecting the 5 cities, then he will calculate (5x4x3x2x1=) 120 times to find the shortest route. Similarly, if you want to route n cities, you have to go through n! calculation to find the shortest route. This is the problem of traveling business.

2. Large o representation of data structures and algorithms

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.