diff --git a/Cours/cours6.py b/Cours/cours6.py new file mode 100644 index 0000000..63e1e26 --- /dev/null +++ b/Cours/cours6.py @@ -0,0 +1,100 @@ +# Complexité + +import numpy as np + +def diviseurs1(n): + d = 0 + k = 1 + while k <= n: + if n % k == 0: + d += 1 + k += 1 + return d + + +def diviseurs2(n): + d = 0 + k = 1 + while k * k < n: + if n % k == 0: + d += 2 + k += 1 + if k * k == n: + d += 1 + return d + +#Instructions élémentaires + + +""" +Les opérations arithmétiques, +les comparaisons de données élémentaires () +les transferts de données +les instructions de contrôle +sont considérés de coût constant (1) + +En revanche, tester l'égalité de deux chaines de caractère n'est de coût +constant qu'en cas de tests un à un. + +Aussi, la recopie d'un tableau n'est pas de coût constant. + +Les coûts résonables : + logarithmique O(log(n)) + linéaire O(n) + semi-linéaire O(nlog(n)) + quadratique O(n²) +""" + +def f1(n): + x = 0 + for i in range(n): + for j in range(n): + x += 1 + return x +#O(n²) + +def f2(n): + pass + + +def f4(n): # O(logn) + x, i = 0, n + while i > 1: + x += 1 + i //= 2 + return x + + +def f5(n): # O(nlog(n)) + x, i = 0, n + while i > 1: + for j in range(n): + x += 1 + i //= 2 + return x + +def f6(n): + x, i = 0, n + while i > 1: + for j in range(i) : + x += 1 + i //= 2 + return x + +def cherche(x, l): + for y in l: + if y == x: + return True + return False + +def cherche_dicho(x, l): + i, j = 0, len(l) + while i < j: + k = (i + j) // 2 + if l[k] == x: + return True + elif l[k] > x: + j = k + else: + i = k + 1 + return False \ No newline at end of file diff --git a/maths/Applications/exo10.py b/maths/Applications/exo10.py new file mode 100755 index 0000000..bccfabb --- /dev/null +++ b/maths/Applications/exo10.py @@ -0,0 +1,7 @@ +#!/usr/bin/env python3 +def verifier(L, p, q): + return len(L)==p and min(L)>=0 and max(L) <= q - 1 +def composer(L1, L2): + return [L2[i] for i in L1] +def permutation(L): + diff --git a/maths/Q b/maths/Q new file mode 100644 index 0000000..ef7de2b --- /dev/null +++ b/maths/Q @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +""" +Created on Fri Nov 29 19:54:04 2019 + +@author: suwako +""" + +def f(n, k=14): + return ((n+k)/(n))**(1/2) +def test(n, k=14): + L=[] + for i in range(1, n+1): + a=f(i, k) + if a == int(a): + L.append(i) + return L \ No newline at end of file