cyberops Posted February 23, 2008 at 02:36 AM Report Share #168489 Posted February 23, 2008 at 02:36 AM Boas, tenho aqui este codigo e estou com algumas duvidas em achas a complexidade disto Código: for(int i=0; i<sequencia.length; i++){ for(int j=i; j<sequencia.length; j++){ soma=0; for(int z=i; z<j; z++) soma=soma+sequencia[z]; if(soma==valor) return qq coisa } } ora ainda consigo achar parte: 1 (atribuicaoa do i) + 2n (duas atribuicoes do i++ e j=i n vezes) + (3((n)+(n-1)+(n-2)... (j++, soma=0 e z=i. isto tem q se transformar num somatorio mas n estou a ver como) etc etc) depois aquele terceiro ciclo for também está a complicar. alguem me consegue ajudar pff? Link to comment Share on other sites More sharing options...
djthyrax Posted February 23, 2008 at 02:54 AM Report Share #168491 Posted February 23, 2008 at 02:54 AM Pegando na tua análise, Para a parte do n + n-1 + n-2: http://www.jimloy.com/algebra/gauss.htm 3(n+(n*(n-1)/2)) = 3((n/2)*(n+1)) = 3(n/2) * 3(n+1) = 3n/2 + 3n+3 Substituindo ali em cima (no teu post), 1 + 2n + 3n/2+3n+3 = 4+3n/2+5n = 4 + (3/2)n+5n = (13/2)n + 4 Mas não te fies naquilo que eu digo. 🙂 Não peças ajuda por PM! A tua dúvida vai ter menos atenção do que se for postada na secção correcta do fórum! Link to comment Share on other sites More sharing options...
MX+ Posted February 23, 2008 at 04:34 AM Report Share #168493 Posted February 23, 2008 at 04:34 AM Isso é simples: n^2 (primeira e segunda iteração + n (n + 1) / 2 Mas linearmente é: n^3 Link to comment Share on other sites More sharing options...
Warrior Posted February 23, 2008 at 11:56 AM Report Share #168511 Posted February 23, 2008 at 11:56 AM Provavelmente querias colocar um * no início da segunda linha MX+ Link to comment Share on other sites More sharing options...
MX+ Posted February 23, 2008 at 05:12 PM Report Share #168600 Posted February 23, 2008 at 05:12 PM Provavelmente querias colocar um * no início da segunda linha MX+ Certissimo. Obrigado 🙂 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now