Segment You can never know the code of its running time

xiaoxiao2021-03-06  61

Today, the data structure class is given, the teacher gave us the following of this violent code. You can also take a look. You can analyze its lower limit of log2 (n) without obstacles, but the problem is that no one can prove that for any positive integer N, this program will not fall into a dead cycle. So, you can't analyze its upper limit. #include "iostream"

Bool isodd (int N) {

IF (n% 2 == 0) Return False; Else Return True;

}

Int main () {

INT N; std :: cin >> n; std :: cout << std :: end1;

While (n> 1) {

IF (isODD (N)) n = 3 * n 1; ELSE N / = 2; std :: cout << n << std :: endl;}

Return 0;

}

转载请注明原文地址:https://www.9cbs.com/read-85051.html

New Post(0)