Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
cf4c6c1
setup file deleted
coderTanisha22 Nov 1, 2025
d92b1f8
tst.h file added
coderTanisha22 Nov 4, 2025
9775e18
tst.cpp file added
coderTanisha22 Nov 4, 2025
0b946dd
Update minheap.cpp
Anika438 Nov 10, 2025
fdb0414
Updated lru.cpp
AkshitaM1234 Nov 11, 2025
19f5c02
Updated lru.h
AkshitaM1234 Nov 11, 2025
54de5d8
Updated graph.h
maahi271005 Nov 11, 2025
f4ed409
Updated lru_test.cpp
AkshitaM1234 Nov 11, 2025
d59c28c
Implement CooccurrenceGraph class with methods for adding edges, calc…
maahi271005 Nov 11, 2025
231831c
Updated kmp.cpp
AkshitaM1234 Nov 11, 2025
5f03f55
Updated kmp.h
AkshitaM1234 Nov 11, 2025
a70b6f5
Update heap_test.cpp
Anika438 Nov 11, 2025
f5a79a0
Update minheap.cpp
Anika438 Nov 11, 2025
ec7bfb3
Merge branch 'stagingcpp' of https://github.com/maahi271005/Smart-Cod…
maahi271005 Nov 11, 2025
330b554
Update heap_test.cpp
Anika438 Nov 11, 2025
4567f7d
Merge branch 'stagingcpp' of https://github.com/maahi271005/Smart-Cod…
maahi271005 Nov 11, 2025
9f896e1
update stack.h
maahi271005 Nov 12, 2025
0116a57
update stack.cpp
maahi271005 Nov 12, 2025
7fd8ef3
updated freq store
maahi271005 Nov 12, 2025
323e1eb
update freq store cpp
maahi271005 Nov 12, 2025
2d6ee76
Update ranker.h
Anika438 Nov 12, 2025
c342b7d
Update ranker.h
Anika438 Nov 12, 2025
4635be3
Merge branch 'stagingcpp' of https://github.com/maahi271005/Smart-Cod…
maahi271005 Nov 12, 2025
2f95c7a
add minheap code
coderTanisha22 Nov 12, 2025
277e53d
add minheap code
coderTanisha22 Nov 12, 2025
f922dd0
added testing code for tst
coderTanisha22 Nov 12, 2025
5bd6a24
added main.cpp code
coderTanisha22 Nov 12, 2025
06a0c9a
added ranker.cpp code
coderTanisha22 Nov 12, 2025
583ff4d
code modification done
coderTanisha22 Nov 12, 2025
5ada1c6
some modifications done
coderTanisha22 Nov 12, 2025
c36b5e8
final running code
maahi271005 Nov 12, 2025
a6e4460
Readme.md written
coderTanisha22 Nov 12, 2025
0b5b60c
Readme.md written
coderTanisha22 Nov 12, 2025
08f9b2c
updated README.md
coderTanisha22 Nov 12, 2025
6f908af
added README.md file at correct place
coderTanisha22 Nov 12, 2025
ffa9985
Removed README.md from inside project folder
coderTanisha22 Nov 12, 2025
b3c59da
Updated README.md
AkshitaM1234 Nov 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 193 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
# Smart Code Autocomplete Engine (C++)

The Smart Code Autocomplete Engine is a C++ project designed to suggest intelligent code completions in real time — similar to how modern IDEs like VS Code or IntelliJ offer autocomplete suggestions.
It applies core Data Structures and Algorithms (DSA) concepts such as Tries, Heaps, and LRU (Least Recently Used) caching to efficiently predict the next most probable code tokens based on user input frequency and context.

## Idea
When a programmer starts typing part of a keyword or function name, the engine quickly:
Searches through a Trie (prefix tree) for all words starting with that prefix.
Uses a Heap to rank suggestions by frequency or relevance.
Employs an LRU Cache to prioritize recently used or selected completions, making the system adaptive over time.

This results in fast, memory-efficient, and intelligent autocomplete suggestions that simulate the logic behind real-world code editors — but built purely from scratch using fundamental DSA concepts.


## DSA Concepts used

### 1. Trie (Prefix Tree)

- Files: tst.h, tst.cpp, tst_test.cpp
- Used for storing and retrieving words efficiently based on their prefixes.
- Enables O(L) time complexity lookups (where L = length of prefix).
- Supports real-time suggestions as the user types each character.

🔹 Concepts used: String manipulation, recursion, tree traversal, prefix-based searching.

### 2. Min-Heap / Max-Heap

- Files: minheap.h, minheap.cpp, heap_test.cpp
- Maintains the top N most frequent or relevant words efficiently.
- Provides constant-time access to the best-ranked suggestion.
- Used during ranking and sorting of autocomplete results.

🔹 Concepts used: Binary heap operations, priority queue logic, partial sorting.

### 3. LRU (Least Recently Used) Cache
- Files: lru.h, lru.cpp, lru_test.cpp
- Stores recently used suggestions for quick access.
- Improves responsiveness by avoiding repetitive Trie lookups.
- Implemented using a combination of doubly linked list + hash map.

🔹 Concepts used: Linked lists, hashing, cache eviction policy.

### 4. KMP (Knuth–Morris–Pratt) Algorithm
- Files: kmp.h, kmp.cpp
- Used for efficient substring pattern matching between typed input and stored code tokens.
- Ensures fast lookup of partial matches even in large word lists.

🔹 Concepts used: Prefix table computation, linear-time pattern searching.

### 5. Graph Data Structure

- Files: graph.h, graph.cpp
- Represents relationships between tokens or code components.
- Can model transitions between function calls or variable dependencies for context-aware suggestions.

🔹 Concepts used: Adjacency list representation, graph traversal (BFS/DFS).

### 6. Stack

- Files: stack.h, stack.cpp
- Used internally for recursive operations, backtracking, or maintaining function call hierarchies.
- Simplifies control flow during traversal or undo operations in text editing logic.

🔹 Concepts used: LIFO operations, template-based generic stack implementation.

### 7. Ranking System
- Files: ranker.h, ranker.cpp
- Combines frequency and recency scores from Trie, Heap, and LRU cache to rank autocomplete suggestions.
- Implements a weighted scoring system for realistic, adaptive predictions.

🔹 Concepts used: Comparator functions, dynamic sorting, frequency-based ranking.

### 8. Frequency Storage
- Files: freq_store.h, freq_store.cpp, frequency.txt
- Keeps track of how often each word is used.
- Updates dynamically after every suggestion selection, making the model “learn” over time.

🔹 Concepts used: File handling, hash mapping, frequency analysis.

---

## Features
- Insert code keywords or phrases
- Autocomplete suggestions based on prefix
- Suggestions ranked by frequency
- Snippet support (e.g., `fori` → `for (int i = 0; i < n; i++)`)
- Practical demonstration of Trie + Hash Map + Heap working together

## Tech Stack Used

| Category | Technologies / Tools | Description |
|-----------|----------------------|--------------|
| **Language** | C++ (C++17 Standard) | Core implementation of all modules, data structures, and algorithms. |
| **Build System** | GNU Make (Makefile) | Used for compiling multiple source files and linking into a single executable. |
| **Compiler** | GCC / G++ | To compile and build the C++ source files efficiently. |
| **Version Control** | Git + GitHub | For code management, versioning, and collaboration among team members. |
| **Testing Framework** | Custom test files (`tests/`) | Unit testing for core modules like Trie, LRU, and Heap. |
| **Data Storage** | Text files (`data/words.txt`, `data/frequency.txt`) | Stores training words and their frequency for suggestion ranking. |
| **Editor / IDE** | VS Code | Primary development environment for coding, debugging, and project organization. |

---


## How It Works
1. User enters keywords (e.g., `print`, `printf`, `private`, etc.)
2. Trie stores all words for fast prefix lookup
3. Hash map tracks how often each word is used
4. Heap finds the most frequent matches for a prefix
5. Snippets expand small abbreviations into full code blocks

## Example Usage
- Type: `pri`
- Suggestions: `print`, `printf`, `private` (ranked)
- Type: `fori`
- Expanded snippet: `for (int i = 0; i < n; i++)`

## Setup Instructions
---
### 1. Clone the repository
- git clone https://github.com/maahi271005/Smart-Code-Autocomplete-Engine-DSA-Project
- cd smart_autocomplete

---


### 2. (Optional) Create and activate virtual environment

If your project uses Python utilities or scripts (e.g., preprocessing):

- python3 -m venv dsavenv
- source dsavenv/bin/activate

---

### 3. Install build tools (for Linux/Ubuntu)
- sudo apt update
- sudo apt install build-essential

---
### 4. Build the project

Use the provided Makefile:

- make clean
- make


This will generate the executable:

- ./smart_autocomplete

---
### 5. Run the program
./smart_autocomplete


If you encounter GLIBCXX_3.4.32 not found, simply rebuild the project on your machine (make clean && make) to link against your local C++ standard library.

---
## Running Tests

To verify components:

- g++ tests/heap_test.cpp -o heap_test && ./heap_test
- g++ tests/lru_test.cpp -o lru_test && ./lru_test
- g++ tests/tst_test.cpp -o tst_test && ./tst_test

---
## Applications
- Code Editors (VS Code, JetBrains)
- Search Engines
- Chatbots
- AI-assisted development tools

---


## Contributors
| Name | GitHub |
|------|---------|
| Tanisha Ray | [![GitHub](https://img.shields.io/badge/-@tanisharay-181717?logo=github&style=flat)](https://github.com/coderTanisha22) |
| Maahi Ratanpara | [![GitHub](https://img.shields.io/badge/-@maahiratanpara-181717?logo=github&style=flat)](https://github.com/maahi271005) |
| Anika Sharma | [![GitHub](https://img.shields.io/badge/-@anikasharma-181717?logo=github&style=flat)](https://github.com/Anika438) |
| Akshita Maheshwari | [![GitHub](https://img.shields.io/badge/-@akshitamaheshwari-181717?logo=github&style=flat)](https://github.com/AkshitaM1234) |


---
## Educational Purpose
This project demonstrates the application of DSA in a real-world scenario — showing how core structures like tries, heaps, and caches can combine to form an intelligent system used in everyday developer tools.
//test



40 changes: 0 additions & 40 deletions setup_cpp.sh

This file was deleted.

10 changes: 10 additions & 0 deletions smart_autocomplete/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#virtual environments
venv/
env/
dsavenv/

# Ignore object files and binaries
*.o
*.out
*.exe
smart_autocomplete
8 changes: 4 additions & 4 deletions smart_autocomplete/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ SRC = $(wildcard src/*.cpp)
OBJ = $(SRC:.cpp=.o)
TARGET = smart_autocomplete

all: \$(TARGET)
all: $(TARGET)

\$(TARGET): \$(OBJ)
\$(CXX) \$(CXXFLAGS) -o \$@ \$(OBJ)
$(TARGET): $(OBJ)
$(CXX) $(CXXFLAGS) -o $@ $(OBJ)

clean:
rm -f \$(OBJ) \$(TARGET)
rm -f $(OBJ) $(TARGET)
Empty file removed smart_autocomplete/README.md
Empty file.
4 changes: 4 additions & 0 deletions smart_autocomplete/data/frequency.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
for 1
const_cast 1
continue 1
delete 1
Empty file removed smart_autocomplete/data/seeds.txt
Empty file.
88 changes: 88 additions & 0 deletions smart_autocomplete/data/words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
for
while
if
else
switch
case
break
continue
return
int
float
double
char
bool
void
string
vector
map
set
list
queue
stack
auto
const
static
class
struct
namespace
public
private
protected
virtual
override
template
typename
include
iostream
std
cout
cin
endl
printf
scanf
main
new
delete
try
catch
throw
this
nullptr
true
false
array
deque
unordered_map
unordered_set
algorithm
sort
find
push_back
pop_back
size
empty
clear
begin
end
iterator
function
lambda
constexpr
inline
extern
typedef
using
enum
union
operator
friend
mutable
volatile
register
sizeof
typeid
dynamic_cast
static_cast
reinterpret_cast
const_cast
21 changes: 21 additions & 0 deletions smart_autocomplete/include/freq_store.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef FREQ_STORE_H
#define FREQ_STORE_H

#include <string>
#include <unordered_map>

class FreqStore {
private:
std::unordered_map<std::string, int> frequencies;
std::string filePath;

public:
FreqStore(const std::string& path);
void load();
void save();
int get(const std::string& token);
void bump(const std::string& token, int amount = 1);
void set(const std::string& token, int freq);
};

#endif
19 changes: 19 additions & 0 deletions smart_autocomplete/include/graph.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef GRAPH_H
#define GRAPH_H

#include <string>
#include <unordered_map>
#include <map>

class CooccurrenceGraph {
private:
std::unordered_map<std::string, std::map<std::string, int>> adjacencyList;

public:
void addEdge(const std::string& from, const std::string& to);
double getBoost(const std::string& from, const std::string& to);
void display();
int getEdgeWeight(const std::string& from, const std::string& to);
};

#endif
Loading