This repository contains the solutions for the fourth practical work of Algorithms and Data Structures 2, implementing various tree and hash table structures in Java and C, tested with a Pokémon dataset and verified for correctness and memory leaks using Verde and Valgrind.
  • Java 64.6%
  • C 33.3%
  • Makefile 1.8%
  • Shell 0.3%
Find a file
2024-12-03 16:27:42 -03:00
01. Árvore Binária Adiciona questão 01 2024-12-02 14:42:43 -03:00
02. Árvore Binária de Árvore Binárias 02: corrige formatação 2024-12-02 16:12:31 -03:00
03. Árvore AVL 03: corrige dramático erro de ortografia num comentário 2024-12-03 16:27:42 -03:00
04. Árvore Alvinegra 04: re-reimplementa alvinegra a partir do material dado 2024-12-02 18:18:30 -03:00
05. Tabela Hash Direta com Reserva .clang-format: aumenta tamanho máximo de linha para 100 2024-12-03 12:50:40 -03:00
06. Tabela Hash Direta com Rehash .clang-format: aumenta tamanho máximo de linha para 100 2024-12-03 12:50:40 -03:00
07. Tabela Hash Indireta com Lista Simples 07: libera lista corretamente 2024-12-03 13:52:02 -03:00
util Adiciona script auxiliares de teste com Valgrind 2024-12-03 16:17:27 -03:00
.clang-format .clang-format: aumenta tamanho máximo de linha para 100 2024-12-03 12:50:40 -03:00
.gitignore Esboça questão 03 2024-12-03 15:17:40 -03:00
config.mk Adiciona script auxiliares de teste com Valgrind 2024-12-03 16:17:27 -03:00
Makefile Adiciona script auxiliares de teste com Valgrind 2024-12-03 16:17:27 -03:00
pokemon.csv Adiciona questão 01 2024-12-02 14:42:43 -03:00
README.md README.md: indica que o trabalho já está terminado 2024-12-03 16:18:41 -03:00

Trabalho Prático 4

Aqui se encontrará o quarto trabalho prático de Algoritmos e Estruturas de Dados 2 (1610100) de 2024/2.

Resultados

Todos os exercícios resultaram em corretude de 100% segundo o Verde e, segundo o Valgrind, nenhum vazamento de memória é possível em nenhuma das questões escritas em C.

Como testar

Como testar a corretude

É possível executar todos os testes, verificando se a saída do programa corresponde com as saídas esperadas pelo Verde, tendo instalado e configurado um compilador de C, um kit de desenvolvimento Java, GNU Make, e o Valgrind. Basta clonar esse repositório e, na raiz, executar o comando abaixo:

make

Dependendo do seu sistema, pode ser nececssário instalar GNU Diffutils e, opcionalmente, colordiff.

Para cada teste que tiver sucesso, você verá uma linha semelhante a essa:

Files pub.out and teste.out are identical

Se todos os testes tiverem sucesso, você verá algo assim:

Testando 01. Árvore Binária:
	javac -Xlint -Xdiags:verbose -g ArvoreBinaria.java
	java ArvoreBinaria ../pokemon.csv < pub.in > teste.out
	Files pub.out and teste.out are identical

Testando 02. Árvore Binária de Árvore Binárias:
	javac -Xlint -Xdiags:verbose -g ArvoreArvore.java
	java ArvoreArvore ../pokemon.csv < pub.in > teste.out
	Files pub.out and teste.out are identical

Testando 03. Árvore AVL:
	clang -Werror -Wall -Wextra -pedantic -O3 -g --debug --std=c99  -lm  avl.c   -o avl
	valgrind --leak-check=full --log-file=valgrind_report.txt ./avl ../pokemon.csv < pub.in > teste.out
	Files pub.out and teste.out are identical

Testando 04. Árvore Alvinegra:
	javac -Xlint -Xdiags:verbose -g Alvinegra.java
	java Alvinegra ../pokemon.csv < pub.in > teste.out
	Files pub.out and teste.out are identical

Testando 05. Tabela Hash Direta com Reserva:
	javac -Xlint -Xdiags:verbose -g HashDiretaReserva.java
	java HashDiretaReserva ../pokemon.csv < pub.in > teste.out
	Files pub.out and teste.out are identical

Testando 06. Tabela Hash Direta com Rehash:
	javac -Xlint -Xdiags:verbose -g HashDiretaRehash.java
	java HashDiretaRehash ../pokemon.csv < pub.in > teste.out
	Files pub.out and teste.out are identical

Testando 07. Tabela Hash Indireta com Lista Simples:
	clang -Werror -Wall -Wextra -pedantic -O3 -g --debug --std=c99  -lm  hash_indireta.c   -o hash_indireta
	valgrind --leak-check=full --log-file=valgrind_report.txt ./hash_indireta ../pokemon.csv < pub.in > teste.out
	Files pub.out and teste.out are identical

Se algum teste falhar, a execução terminará imediatamente com a seguinte linha (ou semelhante):

make: *** [../config.mk:37: testjava] Error 1

Como verificar vazamentos de memória

Basta executar, na raiz:

make report

Para cada questão escrita em C, você deverá ver linhas como essas:

Command: ./hash_indireta ../pokemon.csv
All heap blocks were freed -- no leaks are possible

Eis um exemplo de saída possível, se todos os testes tiverem sucesso:

==3303628== Memcheck, a memory error detector
==3303628== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==3303628== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info
==3303628== Command: ./avl ../pokemon.csv
==3303628== Parent PID: 3303627
==3303628==
==3303628==
==3303628== HEAP SUMMARY:
==3303628==     in use at exit: 0 bytes in 0 blocks
==3303628==   total heap usage: 5,586 allocs, 5,586 frees, 134,320 bytes allocated
==3303628==
==3303628== All heap blocks were freed -- no leaks are possible
==3303628==
==3303628== For lists of detected and suppressed errors, rerun with: -s
==3303628== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
==3303768== Memcheck, a memory error detector
==3303768== Copyright (C) 2002-2024, and GNU GPL'd, by Julian Seward et al.
==3303768== Using Valgrind-3.24.0 and LibVEX; rerun with -h for copyright info
==3303768== Command: ./hash_indireta ../pokemon.csv
==3303768== Parent PID: 3303767
==3303768==
==3303768==
==3303768== HEAP SUMMARY:
==3303768==     in use at exit: 0 bytes in 0 blocks
==3303768==   total heap usage: 5,630 allocs, 5,630 frees, 134,360 bytes allocated
==3303768==
==3303768== All heap blocks were freed -- no leaks are possible
==3303768==
==3303768== For lists of detected and suppressed errors, rerun with: -s
==3303768== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)