Algorithm Analysis Framework

Source: Internet
Author: User

An algorithm should know how to measure the time efficiency and space efficiency. However, more research measures the time efficiency, and the rapid development of hardware is not so important. How to measure the time efficiency is the number of basic operations. The number of basic operations. For example, to calculate the maximum value in a one-dimensional array:

 

[Java]
Public class ArrayTester2 {
/**
* @ Param args
*/
Public static void main (String [] args ){
Int [] array = {10, 20, 30, 40, 50, 60 };
Int max = array [0];
For (int I = 1; I <array. length; I ++ ){
If (array [I]> max ){
Max = array [I];
}

}
System. out. printf (max );
}
}

Public class ArrayTester2 {
/**
* @ Param args
*/
Public static void main (String [] args ){
Int [] array = {10, 20, 30, 40, 50, 60 };
Int max = array [0];
For (int I = 1; I <array. length; I ++ ){
If (array [I]> max ){
Max = array [I];
}

}
System. out. printf (max );
}
}
In the above example, the number of basic operations is the comparison of the if statement: array [I]> max, because this operation is executed in each loop, while max = array [I], it is executed only when the if statement is set up. It can be summarized as a rule, that is, the number of basic operations is the most time-consuming operation in the algorithm's most memory loop.

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.