Académique Documents
Professionnel Documents
Culture Documents
I. 5- Select *
From ( Select (1-(tailleC*1.0)/(tailleF*1.0))*100 Taux
From Fichier F, Compression C
Where F.numeroF = C.numeroF
Order by Taux Desc
Limit 3 )
Order by Taux
I. 6-
import sqlite3
f = input("Donner le format de compression : ")
con = sqlite3.connect("C:/BDcompressions.sql")
cur = con.cursor()
r = "Select format From Algorithme Where format = ?"
cur.execute(r,(f,))
L=cur.fetchall()
if L==[]: print("Le format n'existe pas dans la BD")
else:
r = "Select avg((1-(tailleC*1.0)/(tailleF*1.0))*100) From Fichier F,
Compression C Where F.numeroF = C.numeroF And format = ?"
cur.execute(r,(f,))
t = cur.fetchone()
print(t[0])
con.close()
Page 1 sur 6
Partie II : La compression de HUFFMAN
II. 1- L’espace mémoire occupé par un entier naturel
Le plus grand nombre entier positif, avec signe, qu’on peut coder sur
12 bits est : 011111111111(2) = 211 -1 = 2047
def entier(B):
S,n=0,len(B)
for i in range(n-1, -1, -1):
S=2*S + int(B[i])
return S
def fusion(P,Q):
if P==[] or Q==[]: return P+Q
elif P[0][1] < Q[0][1]: return [P[0]]+fusion(P[1:],Q)
else: return [Q[0]]+fusion(P,Q[1:])
Page 2 sur 6
def tri(F):
n=len(F)
if n<=1: return F
else : return fusion(tri(F[:n//2]),tri(F[n//2:]))
def insere(F,t):
i=len(F)-1
while i>=0 and F[i][1]>t[1]:
i=i-1
F=F[:i+1]+[t]+F[i+1 :] # ou F.insert(i+1,t)
def arbre_Huffman(F):
F=tri(F)
while len(F)>1:
X,Y=F.pop(0),F.pop(0)
if type(X[0])!=list and type(Y[0])!=list :
pere=([X[1]+Y[1],[X[0],[],[]],[Y[0],[],[]]], X[1]+Y[1])
elif type(X[0])==list and type(Y[0])==list:
pere=([X[1]+Y[1],X[0],Y[0]],X[1]+Y[1])
elif type(X[0])!=list and type(Y[0])==list:
pere=([X[1]+Y[1],[X[0],[],[]],Y[0]],X[1]+Y[1])
elif type(X[0])==list and type(Y[0])!=list:
pere=([X[1]+Y[1],X[0],[Y[0],[],[]]],X[1]+Y[1])
insere(F,pere)
return F[0][0]
Page 3 sur 6
S=S+code[k]
return S
ou :
def identite(n):
return np.eye(n)
III. 3- Transvection :
def transvection(M,p,q,r):
M[p]+= r*M[q]
Page 4 sur 6
III. 5- Rechercher la ligne du pivot
def ligne_pivot(M,c):
p=c
for i in range(c):
if abs(M[i,c])>abs(M[p,c]): p=i
return p
Page 5 sur 6
for i in range(len(M)):
M[i]=M[i].split()
M=np.array(M,float)
if inversible(M) : return(inverse(M))
print("Matrice non inversible")
Page 6 sur 6