This shows you the differences between two versions of the page.
sd-ca:laboratoare:lab-11 [2022/05/17 16:15] mihai.pirvulet [Ștergere] |
sd-ca:laboratoare:lab-11 [2025/05/12 13:52] (current) andreea.peiu [Laborator 9 - Arbori generici. Trie] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Laborator 11 - Arbori generci. Trie ====== | + | ====== Laborator 9 - Arbori generici. Trie ====== |
Responsabili | Responsabili | ||
- | * [[mailto:mitapirvuet@gmail.com|Mihai Pirvulet]] | + | * [[mailto:andreeapeiu2005@gmail.com|Peiu Andreea]] |
- | * [[mailto:radustefanminea@gmail.com|Radu Minea]] | + | * [[mailto:marina@oprea.eu|Oprea Marina]] |
===== Obiective ===== | ===== Obiective ===== | ||
Line 167: | Line 167: | ||
if nextNode does not exist | if nextNode does not exist | ||
create nextNode | create nextNode | ||
- | n_children++ | + | node->n_children++ |
+ | nNodes++ | ||
insert(nextNode, key without first letter, value) | insert(nextNode, key without first letter, value) | ||
Line 178: | Line 179: | ||
{{ :sd-ca:8c18e786-6c8a-4a10-ac5f-10ce3716795a.jpeg?nolink&750 |}} | {{ :sd-ca:8c18e786-6c8a-4a10-ac5f-10ce3716795a.jpeg?nolink&750 |}} | ||
+ | |||
+ | În desenul de mai sus, nodurile roșii reprezintă nodurile cu end_of_word = true (cuvinte integrale, de sine stătătoare, adică dacă inserăm ”Mihai” in Trie, doar nodul cu ”Mihai” va avea end_of_word = true, în vreme ce ”M”, ”Mi”, ”Mih”, ”Miha” vor avea end_of_word = false). | ||
+ | |||
+ | Să facem o scurtă trecere prin cele 3 operații din desen: | ||
+ | - "aa": ”aa” reprezintă un cuvânt (are end_of_word = true), însă are copii (”aa”->n_children > 0), adică reprezintă un prefix pentru alte cuvinte inserate anterior in Trie. Astfel, pur și simplu flag-ul de end_of_word de pe nodul ”aa” este trecut la false. | ||
+ | - "aacx": ”aacx” reprezintă un cuvânt, și nu are copii, deci se vor șterge nodurile recursiv, de jos în sus - de la ”x” până la primul nod întâlnit (iarăși, de jos în sus, întrucât revenim din recursivitate) ce are copii (cel de-al doilea ”a” din ”aacx”) sau are end_of_word = true. | ||
+ | - "aab": similar ca mai sus. | ||
=== Pseudocod === | === Pseudocod === | ||
Line 193: | Line 201: | ||
| | ||
// remove was called on a key that doesn't exist | // remove was called on a key that doesn't exist | ||
- | return 0 | + | return false |
| | ||
nextNode = child corresponding to the first letter of the key | nextNode = child corresponding to the first letter of the key | ||
Line 199: | Line 207: | ||
if nextNode exists and remove(nextNode, key without first letter) == true | if nextNode exists and remove(nextNode, key without first letter) == true | ||
delete nextNode | delete nextNode | ||
- | n_children-- | + | node->n_children-- |
+ | nNodes-- | ||
| | ||
if node->n_children == 0 and node->end_of_word == false | if node->n_children == 0 and node->end_of_word == false | ||
Line 211: | Line 220: | ||
<note important>Observati ca functiile primesc ca si parametru o structura de tip **trie_node_t**, nu **trie_t**. Deci, pseudocodul de mai sus va trebui implementat in niste functii helper. Motivul pentru care acestea nu sunt incluse in schelet este acela ca puteti implementa **iterativ** daca doriti, fara sa mai fie nevoie de helpere.</note> | <note important>Observati ca functiile primesc ca si parametru o structura de tip **trie_node_t**, nu **trie_t**. Deci, pseudocodul de mai sus va trebui implementat in niste functii helper. Motivul pentru care acestea nu sunt incluse in schelet este acela ca puteti implementa **iterativ** daca doriti, fara sa mai fie nevoie de helpere.</note> | ||
- | ===== Schelet ===== | ||
- | {{:sd-ca:laboratoare:lab11_2022_v2.zip|Scheletul de laborator}} | ||
===== Exerciții ===== | ===== Exerciții ===== | ||
<note> | <note> | ||
- | Trebuie să vă creați cont de [[https://lambdachecker.io | Lambda Checker]], dacă nu v-ați creat deja, pe care îl veți folosi la SD pe toată durata semestrului. Aveti grija sa selectati contestul corect la submit, si anume **[[https://lambdachecker.io/contest/42 |SD-CA-LAB-11-Trie]]** | + | Trebuie să vă creați cont de [[https://code.devmind.ro | Devmind]], dacă nu v-ați creat deja, pe care îl veți folosi la SD pe toată durata semestrului. |
</note> | </note> | ||