Jump to content

Análise de Complexidade de programas


jonhhy

Recommended Posts

def triangletype(s1,s2,s3):
  if s1 == s2 and s2 == s3:  # Equilátero 2 ops Best case |  Isosceles 1op Best Case  2 ops Worst Case | Scalene 1 op
    print('Equilateral')
  elif s1 == s2 or s1 == s3 or s2 == s3: # Isosceles Best Case: 1op , 3op Worst Case | Escaleno 3ops
    print('Isosceles') # 3 ops BestC  | 4ops WorstC  ... combinando as condições poderá até dar em 2ops mas tlv piorá-se noutros casos  
  else:
    print('Scalene') # 4ops + print
# entre 2 e 4 ops à partida
def triangletype2(s1,s2,s3):
  if s1 == s2: # 1op
    if s1 == s3: 
      print('Equilateral') # 2ops
    else: print('Isosceles') #  2 ops 
  elif s1 == s3 or s2 == s3: # 1+[1,2]=[2,3] ops resulta de 
    print('Isosceles')
  else: print('Scalene') # 3 ops + print

Bom dia a todos,

 

gostaria de saber mais informações sobre a análise de complexidade de programas e algoritmos, de modo, por exemplo qual destes programas é o mais eficiente.

Edited by jonhhy
Link to comment
Share on other sites

Obtive esta resposta no dia de ontem:

"Hey! I slightly prefer the flat variant. Also, I guess, the cyclomatic complexity of the first variant will be lower

https://en.wikipedia.org/wiki/Cyclomatic_complexity

In Python, you can measure it with https://pypi.org/project/radon/ or https://pypi.org/project/mccabe/"

 

 

Enquanto isso estou a analisar o conteúdo desta unidade curricular: dcc.fc.up.pt/~pribeiro/aulasdaa2021

Edited by jonhhy
Link to comment
Share on other sites

Estará correto (parêntesis)?

interpretado a partir do slide 21 https://www.dcc.fc.up.pt/~pribeiro/aulas/daa2021/slides/1_analiseassintotica_05102020.pdf


https://ibb.co/B6LjSNZ

 

P.s: aqui ganhou significa ser mais complexo ou seja menos eficiente

 

EDITE: Meu raciocínio estava errado aqui, estava a pensar em ciclos

Edited by jonhhy
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.