In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
What is an algorithm?
Algorithm (Algorithm) refers to the accurate and complete description of the problem-solving solution, is a series of clear commands to solve the problem, and the algorithm represents the strategy mechanism to describe the problem-solving in a systematic way. In other words, for a certain standard input, the required output can be obtained in a limited time. If an algorithm is flawed or is not suitable for a problem, executing the algorithm will not solve the problem. Different algorithms may use different time, space or efficiency to accomplish the same task. The advantages and disadvantages of an algorithm can be measured by space complexity and time complexity.
These two pieces of code can be called algorithms because they can solve the problem of adding two numbers and adding from 1 to n, respectively. The algorithm does not have to be very complex, as small as one line of code, up to tens of thousands of lines of code, as long as it can solve a specific problem, it is the algorithm.
How to evaluate the quality of the algorithm
Using different algorithms to solve the same problem, the efficiency may be very different.
Two existing algorithms for calculating Fibonacci number (fibonacci number)
Fibonacci series: 1 1 2 3 5 8. )
Here
Public static int fib1 (int n) {if (no (1))
$2n+6 $> > O (n)
$n ^ 2 + 2n+6 $> > O ($n ^ 2 $)
$4N ^ 3 + 3n ^ 2 + 22n+100 $> > O ($n ^ 3 $)
(2.2) the base of logarithmic order is generally omitted
$log_2n=log_29+log_9n$ (logarithms of any base can be converted to each other by multiplying a constant)
so $log_2n$ and $log_9n$ are collectively referred to as $logn$
Note: the large O representation is only a rough analytical model and an estimate, which can help us to understand the execution efficiency of an algorithm in a short time.
Calculate the time complexity of the following code
Public static void test1 (int n) {/ / 1 (perform a judgment operation) if (n > 10) {System.out.println ("n > 10");} else if (n > 5) {/ / 2 System.out.println ("n > 5");} else {System.out.println ("n")
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.