aboutsummaryrefslogtreecommitdiff
Implementation of a dictionary based on hash tables and red-black trees

Implementation of a dictionary based on hash tables and red-black trees

1. Task1

  1. Implement a data structure – a hash table, which is characterized by the following operations: insertion, deletion, and search. Based on it, implement an application – a dictionary. As a hash function, you can choose an arbitrary function, for example, taking the first letter of the word. Add The function for completely clearing the dictionary and loading/updating the dictionary from a text file.
  2. For the selected text in Russian, build a dictionary based on red‑black trees. Implement functions for adding, deleting, and searching for a word. (use of ready‑made data structures is PROHIBITED!!!). Add a function for completely clearing the dictionary and loading/updating the dictionary from a text file.

The additional implementation also includes the possibility of optimizing the dictionary (for example, searching for potential cognates in different forms; the simplest criterion is 2/3 of the word length). The choice of words to be kept in the dictionary is up to the user. It is not allowed to use ready‑made solutions from the STL library.

2. Documentation

The exported report can be found at this link.

3. Showcase

Start of the program and the menu:

HASH-TABLE:......FILE LOADED (159 ENTRIES)
RED-BLACK-TREE:..FILE LOADED (159 ENTRIES)

SELECT:
 [00] GENERAL:.........EXIT
 [01] HASH-TABLE:......PRINT
 [02] HASH-TABLE:......INSERT
 [03] HASH-TABLE:......DELETE
 [04] HASH-TABLE:......SEARCH
 [05] HASH-TABLE:......CLEAR
 [06] HASH-TABLE:......LOAD_FROM_FILE
 [07] RED-BLACK-TREE:..PRINT
 [08] RED-BLACK-TREE:..INSERT
 [09] RED-BLACK-TREE:..DELETE
 [10] RED-BLACK-TREE:..SEARCH
 [11] RED-BLACK-TREE:..CLEAR
 [12] RED-BLACK-TREE:..LOAD_FROM_FILE
>

Example output of the PRINT menu items:

example-hash-table.png

Figure 1: Hash table

example-red-black-tree.png

Figure 2: Red-black tree

Example session: (menu replaced with # comments)

> asdf
> -1
> 13
>
> 04 # (HASH-TABLE) SEARCH
WORD: словарь
ENTRY FOUND
> 10 # (RED-BLACK-TREE) SEARCH
WORD: словарь
ENTRY FOUND
>
> 04 # (HASH-TABLE) SEARCH
WORD: тест
ENTRY NOT FOUND
> 10 # (RED-BLACK-TREE) SEARCH
WORD: тест
ENTRY NOT FOUND
> 06 # (HASH-TABLE) LOAD_FROM_FILE
FILENAME: text
FILE LOADED (30 ENTRIES)
> 12 # (RED-BLACK-TREE) LOAD_FROM_FILE
FILENAME: text
FILE LOADED (30 ENTRIES)
> 04 # (HASH-TABLE) SEARCH
WORD: тест
ENTRY FOUND
> 10 # (RED-BLACK-TREE) SEARCH
WORD: тест
ENTRY FOUND
>
> 02 # (HASH-TABLE) INSERT
WORD: слово
ENTRY INSERTED
> 04 # (HASH-TABLE) SEARCH
WORD: слово
ENTRY FOUND
> 03 # (HASH-TABLE) DELETE
WORD: слово
ENTRY DELETED
> 04 # (HASH-TABLE) SEARCH
WORD: слово
ENTRY NOT FOUND
> 05 # (HASH-TABLE) CLEAR
HASH TABLE CLEARED
> 04 # (HASH-TABLE) SEARCH
WORD: тест
ENTRY NOT FOUND
>
> 08 # (RED-BLACK-TREE) INSERT
WORD: слово
ENTRY INSERTED
> 10 # (RED-BLACK-TREE) SEARCH
WORD: слово
ENTRY FOUND
> 09 # (RED-BLACK-TREE) DELETE
WORD: слово
ENTRY DELETED
> 10 # (RED-BLACK-TREE) SEARCH
WORD: слово
ENTRY NOT FOUND
> 11 # (RED-BLACK-TREE) CLEAR
HASH TABLE CLEARED
> 10 # (RED-BLACK-TREE) SEARCH
WORD: тест
ENTRY NOT FOUND
> 00 # (GENERAL) EXIT

4. Unlicense

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to https://unlicense.org/

Footnotes:

1

Original text:

  1. Реализовать структуру данных – хеш-таблицу, для которой характерны операции: добавления, удаления и поиска. На ее основе реализовать приложение – словарь. В качестве хеш-функции, можно выбрать произвольную функцию, например, брать первую букву слова. Добавить функцию полной очистки словаря и загрузки/дополнения словаря из текстового файла.
  2. Для выбранного текста на русском языке построить словарь на основе красно-черных деревьев. Реализовать функции добавления, удаления и поиска слова. (НЕЛЬЗЯ использовать готовые структуры данных!!!). Добавить функцию полной очистки словаря и загрузки/дополнения словаря из текстового файла.

Дополнительная реализация также включает возможность оптимизации словаря (например, поиск потенциальных однокоренных слов в разных формах; самый простой критерий – 2/3 длины слова). Выбор слов, которые следует оставить в словаре – за пользователем. Использовать готовые решения из библиотеки STL не разрешается.

Created: 2026-11-07 Sat 07:54