Build a system that efficiently suggests the top K most frequent words matching a given prefix, similar to how search engines or mobile keyboards suggest completions as you type.
This section explains how to manually build and run the project using g++
on Windows (with MSYS2 or MinGW installed) and Visual Studio Code.
auto-suggest-trie/
│
├── include/
│ └── Trie.hpp
│
├── src/
│ └── Trie.cpp
│
├── main.cpp
├── words.csv
├── main.exe (output after build)
└── .vscode/
└── tasks.json
Replace the content with this to use g++
and correctly include the source/header files:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\msys64\\ucrt64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}/main.cpp",
"${workspaceFolder}/src/Trie.cpp",
"-I",
"${workspaceFolder}/include",
"-o",
"${workspaceFolder}/main.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Build task using g++"
}
]
}
Open VS Code Terminal and press:
Ctrl + Shift + B
or
g++ -g filename with directory\main.cpp -I filename with directory\include -o filename with directory\main.exe filename with directory\Trie.cpp
This will compile main.cpp
and Trie.cpp
, and create main.exe
in the project root folder.
✅ If successful, you’ll see main.exe
appear in your folder.
From the terminal, run the built file:
./main.exe
Or, on Windows:
main.exe
This will execute your program and show suggestions based on the logic inside main.cpp
.
words.csv
must exist in the project root and contain a list of words (one per line).- You can edit
main.cpp
to customize the suggestion logic or change input prompts. main.exe
will be overwritten every time you build.
- If
main.exe
is not created, check the build terminal for errors. - Ensure
g++
path intasks.json
matches your MSYS2 or MinGW installation. - Restart VS Code if changes don’t reflect.