initial commit

This commit is contained in:
Gabriel Franco 2026-09-10 10:06:01 -03:00
commit 52887f47de
33 changed files with 683 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
**/venv/
**/__pycache__

5
README.md Normal file
View file

@ -0,0 +1,5 @@
# Trabalho 1 de ALEST I
Este repositório contém a minha versão de entrega do T1 de Algoritmos e Estruturas de Dados I (ALEST I), juntamente com os códigos utilizados e a descrição do trabalho.

Binary file not shown.

12
code/algoritmo1.py Normal file
View file

@ -0,0 +1,12 @@
def f(n):
res = 0
cont_op = 0
for i in range(1, n*n+1):
for j in range(1, i+1, 2):
for k in range(n+1, 2*i+1, i*j):
res = res + k+1
cont_op += 1
return cont_op

13
code/algoritmo2.py Normal file
View file

@ -0,0 +1,13 @@
def f(n):
res = 0
cont_op = 0
i = n
while i <= n:
for j in range(i//2, i*i+1, i+1):
for k in range(n, 2*n+1, i+1):
res += n
cont_op += 1
i += i//2+1
return cont_op

12
code/algoritmo3.py Normal file
View file

@ -0,0 +1,12 @@
def f(n):
res = 0
cont_op = 0
for i in range(1, n*n+1, 2):
for j in range(i//2, 2*i+1, i//2+1):
k = j+1
while k <= n+j:
res += abs(j - i)
cont_op += 1
k += k//2+1
return cont_op

9
code/algoritmo4.py Normal file
View file

@ -0,0 +1,9 @@
def f(n):
res = 0
cont_op = 0
for i in range(1, n*n+1, 2):
for j in range(2, n+2, i+1):
for k in range(j//2, i+2, j//2+1):
res += j+1
cont_op += 1
return cont_op

9
code/algoritmo5.py Normal file
View file

@ -0,0 +1,9 @@
def f(n):
res = 0
cont_op = 0
for i in range(n//2, n+1, 3):
for j in range(i, i*i+1, 2):
for k in range(i, 2*j+1, 1):
res += n+j
cont_op += 1
return cont_op

60
code/core.py Normal file
View file

@ -0,0 +1,60 @@
import sys
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
matplotlib.use("TkAgg")
def plot(x, y, filename=None):
fig, ax = plt.subplots()
ax.plot(x, y, 'r+')
ax.set(xlabel="N (input)")
ax.set(ylabel="f(N) (Contagem de Operações)")
if filename is not None:
fig.savefig(filename)
return
fig.show()
plt.show()
def plot_log(x, y, filename=None):
fig, ax = plt.subplots()
ax.plot(x, np.log(y), 'g+')
ax.set(xlabel="N (input)")
ax.set(ylabel="f(N) (Contagem de Operações)")
ax.set_yscale('log')
if filename is not None:
fig.savefig(filename)
return
fig.show()
plt.show()
def plot_exp(x, y, filename=None):
fig, ax = plt.subplots()
ax.plot(x, np.exp(np.clip(y, sys.float_info.min, sys.float_info.max)), 'b+')
ax.set(xlabel="N (input)")
ax.set(ylabel="f(N) (Contagem de Operações)")
ax.set_yscale('log')
if filename is not None:
fig.savefig(filename)
return
fig.show()
plt.show()
def function_result(f, n=100):
x = []
y = []
for i in range(n):
result = f(i)
cont_op = 1 if result == 0 else result
x.append(i)
y.append(cont_op)
return x, y

36
code/main.py Normal file
View file

@ -0,0 +1,36 @@
import algoritmo1, algoritmo2, algoritmo3, algoritmo4, algoritmo5
# algoritmo1
content = ""
for i in range(100):
content += f"{i} {algoritmo1.f(i)}\n"
with open("../plots/alg1.txt", "w") as file:
file.write(content)
# algoritmo2
content = ""
for i in range(100):
content += f"{i} {algoritmo2.f(i)}\n"
with open("../plots/alg2.txt", "w") as file:
file.write(content)
# algortimo3
content = ""
for i in range(100):
content += f"{i} {algoritmo3.f(i)}\n"
with open("../plots/alg3.txt", "w") as file:
file.write(content)
# algoritmo4
content = ""
for i in range(100):
content += f"{i} {algoritmo4.f(i)}\n"
with open("../plots/alg4.txt", "w") as file:
file.write(content)
# algoritmo5
content = ""
for i in range(100):
content += f"{i} {algoritmo5.f(i)}\n"
with open("../plots/alg5.txt", "w") as file:
file.write(content)

2
code/requirements.txt Normal file
View file

@ -0,0 +1,2 @@
matplotlib
numpy

BIN
descricao_trabalho.pdf Normal file

Binary file not shown.

BIN
plots/alg1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

100
plots/alg1.txt Normal file
View file

@ -0,0 +1,100 @@
0 0
1 1
2 7
3 30
4 82
5 187
6 368
7 663
8 1106
9 1747
10 2631
11 3822
12 5376
13 7369
14 9868
15 12963
16 16732
17 21277
18 26687
19 33078
20 40550
21 49231
22 59232
23 70695
24 83742
25 98527
26 115183
27 133878
28 154756
29 177997
30 203756
31 232227
32 263576
33 298009
34 335703
35 376878
36 421722
37 470467
38 523312
39 580503
40 642250
41 708811
42 780407
43 857310
44 939752
45 1028017
46 1122348
47 1223043
48 1330356
49 1444597
50 1566031
51 1694982
52 1831726
53 1976599
54 2129888
55 2291943
56 2463062
57 2643607
58 2833887
59 3034278
60 3245100
61 3466741
62 3699532
63 3943875
64 4200112
65 4468657
66 4749863
67 5044158
68 5351906
69 5673547
70 6009456
71 6360087
72 6725826
73 7107139
74 7504423
75 7918158
76 8348752
77 8796697
78 9262412
79 9746403
80 10249100
81 10771021
82 11312607
83 11874390
84 12456822
85 13060447
86 13685728
87 14333223
88 15003406
89 15696847
90 16414031
91 17155542
92 17921876
93 18713629
94 19531308
95 20375523
96 21246792
97 22145737
98 23072887
99 24028878

BIN
plots/alg1_log.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
plots/alg1_loglog.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
plots/alg2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

100
plots/alg2.txt Normal file
View file

@ -0,0 +1,100 @@
0 1
1 1
2 2
3 3
4 3
5 4
6 5
7 6
8 7
9 8
10 9
11 10
12 11
13 12
14 13
15 14
16 15
17 16
18 17
19 18
20 19
21 20
22 21
23 22
24 23
25 24
26 25
27 26
28 27
29 28
30 29
31 30
32 31
33 32
34 33
35 34
36 35
37 36
38 37
39 38
40 39
41 40
42 41
43 42
44 43
45 44
46 45
47 46
48 47
49 48
50 49
51 50
52 51
53 52
54 53
55 54
56 55
57 56
58 57
59 58
60 59
61 60
62 61
63 62
64 63
65 64
66 65
67 66
68 67
69 68
70 69
71 70
72 71
73 72
74 73
75 74
76 75
77 76
78 77
79 78
80 79
81 80
82 81
83 82
84 83
85 84
86 85
87 86
88 87
89 88
90 89
91 90
92 91
93 92
94 93
95 94
96 95
97 96
98 97
99 98

BIN
plots/alg2_log.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

BIN
plots/alg2_loglog.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

BIN
plots/alg3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

100
plots/alg3.txt Normal file
View file

@ -0,0 +1,100 @@
0 0
1 3
2 7
3 20
4 33
5 52
6 75
7 100
8 127
9 159
10 191
11 235
12 272
13 316
14 363
15 412
16 466
17 522
18 582
19 643
20 708
21 779
22 845
23 922
24 998
25 1078
26 1164
27 1250
28 1336
29 1433
30 1525
31 1624
32 1721
33 1833
34 1937
35 2047
36 2160
37 2276
38 2393
39 2521
40 2644
41 2775
42 2902
43 3039
44 3176
45 3318
46 3459
47 3604
48 3755
49 3909
50 4060
51 4222
52 4380
53 4548
54 4714
55 4883
56 5059
57 5234
58 5415
59 5599
60 5782
61 5972
62 6162
63 6358
64 6554
65 6753
66 6960
67 7167
68 7376
69 7590
70 7800
71 8025
72 8242
73 8469
74 8694
75 8923
76 9155
77 9394
78 9632
79 9875
80 10116
81 10372
82 10619
83 10880
84 11134
85 11392
86 11658
87 11924
88 12192
89 12467
90 12744
91 13025
92 13306
93 13592
94 13875
95 14165
96 14462
97 14756
98 15055
99 15358

BIN
plots/alg3_log.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

BIN
plots/alg3_loglog.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

BIN
plots/alg4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

100
plots/alg4.txt Normal file
View file

@ -0,0 +1,100 @@
0 0
1 1
2 3
3 16
4 37
5 93
6 173
7 328
8 531
9 865
10 1279
11 1896
12 2633
13 3661
14 4857
15 6448
16 8263
17 10593
18 13211
19 16480
20 20109
21 24541
22 29413
23 35256
24 41627
25 49153
26 57303
27 66808
28 77041
29 88845
30 101489
31 115936
32 131343
33 148801
34 167347
35 188208
36 210293
37 234973
38 261021
39 289960
40 320419
41 354081
42 389423
43 428296
44 469017
45 513613
46 560233
47 611088
48 664151
49 721825
50 781899
51 846976
52 914653
53 987741
54 1063637
55 1145368
56 1230123
57 1321153
58 1415431
59 1516440
60 1620929
61 1732621
62 1848033
63 1971136
64 2098207
65 2233473
66 2372963
67 2521168
68 2673861
69 2835805
70 3002509
71 3179016
72 3360563
73 3552481
74 3749727
75 3957928
76 4171753
77 4397133
78 4628441
79 4871920
80 5121639
81 5384161
82 5653243
83 5935776
84 6225197
85 6528733
86 6839493
87 7165048
88 7498171
89 7846785
90 8203319
91 8576056
92 8957073
93 9355021
94 9761617
95 10185888
96 10619183
97 11070913
98 11532051
99 12012400

BIN
plots/alg4_log.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

BIN
plots/alg4_loglog.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

BIN
plots/alg5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

100
plots/alg5.txt Normal file
View file

@ -0,0 +1,100 @@
0 1
1 1
2 2
3 2
4 10
5 296
6 632
7 632
8 1219
9 1219
10 2171
11 9003
12 13341
13 13341
14 19176
15 19176
16 26841
17 66571
18 86755
19 86755
20 111437
21 111437
22 141277
23 275897
24 336812
25 336812
26 407737
27 407737
28 489767
29 832461
30 976893
31 976893
32 1140114
33 1140114
34 1323762
35 2054458
36 2347954
37 2347954
38 2673041
39 2673041
40 3032008
41 4412930
42 4948658
43 4948658
44 5533558
45 5533558
46 6170678
47 8561898
48 9465507
49 9465507
50 10441404
51 10441404
52 11493504
53 15368494
54 16802974
55 16802974
56 18339149
57 18339149
58 19981909
59 25943093
60 28113635
61 28113635
62 30422326
63 30422326
64 32875139
65 41669445
66 44828301
67 44828301
68 48169563
69 48169563
70 51700395
71 64234807
72 68686150
73 68686150
74 73372715
75 73372715
76 78302965
77 95660075
78 101764859
79 101764859
80 108166996
81 108166996
82 114876356
83 138329916
84 146510736
85 146510736
86 155061111
87 155061111
88 163992426
89 195022900
90 205768852
91 205768852
92 216967388
93 216967388
94 228631516
95 268941632
96 282813173
97 282813173
98 297231910
99 297231910

BIN
plots/alg5_log.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

BIN
plots/alg5_loglog.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

22
plots/plots.gp Normal file
View file

@ -0,0 +1,22 @@
set grid
do for [i=1:5] {
set term pngcairo size 800,600
unset logscale
set output sprintf("alg%d.png", i)
plot sprintf("alg%d.txt", i) with linespoints title sprintf("Algoritmo %d", i)
unset output
set logscale y
set output sprintf("alg%d_log.png", i)
plot sprintf("alg%d.txt", i) with linespoints title sprintf("Algoritmo %d", i)
unset output
set logscale x
set logscale y
set output sprintf("alg%d_loglog.png", i)
plot sprintf("alg%d.txt", i) with linespoints title sprintf("Algoritmo %d", i)
unset output
unset logscale
}