A powerful graph-based recommendation engine built in C++ that leverages social connections and user interactions to provide intelligent recommendations. Perfect for e-commerce, social networks, and content platforms!
- Graph-Based Recommendations: Uses adjacency lists for efficient relationship mapping
- Multiple Algorithms:
- Collaborative Filtering
- Popularity-Based Recommendations
- BFS-Based Recommendations
- Social Network Analysis: Leverages user connections for better suggestions
- File-based Storage: Persistent data storage with easy file management
- Modern C++17 with clean OOP design
- Modular Architecture for easy extension
- Automatic Build System with Makefile
- Cross-Platform (Windows/Linux/Mac support)
- Efficient Graph Operations with adjacency list representation
GRAPHBASE_RECOMMENDATION_SYSTEM/
βββ π src/
β βββ π Algorithms/ # Recommendation algorithms
β β βββ CollaborativeFiltering.cpp
β β βββ Popularity.cpp
β β βββ Recommendation.cpp
β βββ π Graph/ # Graph data structure
β β βββ graph.cpp
β β βββ graph.h
β βββ π Models/ # Data models
β β βββ items.cpp
β β βββ users.cpp
β βββ π Storage/ # File handling
β β βββ FileManager.cpp
β β βββ FileManager.h
β βββ main.cpp # Entry point
βββ π tests/ # Test cases
βββ π data/ # Sample data files
β βββ interactions.txt
β βββ users.txt
βββ π Utils/ # Utility functions
βββ π makefile # Build automation
βββ π README.md # This file
- C++ Compiler (g++/clang++/MSVC)
- Make (for build automation)
- Git (for version control)
- Clone the repository
git clone https://github.com/deeplukhi/GRAPHBASE_RECOMMENDATION_SYSTEM.git
cd GRAPHBASE_RECOMMENDATION_SYSTEM- Build the project
make- Run the application
make run| Command | Description |
|---|---|
make |
Build the project |
make run |
Build and run the application |
make test |
Run test cases |
make clean |
Clean build files |
make help |
Show available commands |
Users β Graph Nodes
Interactions β Graph Edges
Items β Recommendation Targets
graph TD
A[Load Data] --> B[Build Graph]
B --> C{Select Algorithm}
C --> D[Collaborative Filtering]
C --> E[Popularity Based]
C --> F[BFS Based]
D --> G[Generate Recommendations]
E --> G
F --> G
G --> H[Output Results]
// Load data
graph socialGraph;
FileManager::loadUsers("data/users.txt", socialGraph);
FileManager::loadInteractions("data/interactions.txt", socialGraph);
// Get recommendations for user 1
vector<int> recommendations = CollaborativeRecommendation::recommend(socialGraph, 1);
// Display results
cout << "Recommended items: ";
for (int item : recommendations) {
cout << item << " ";
}Finds users with similar preferences and recommends items they liked.
Formula:
similarity(u,v) = (common items) / sqrt(total items of u * total items of v)
Recommends trending items based on overall popularity.
Features:
- Most viewed items
- Most purchased items
- Trending this week
Uses Breadth-First Search to explore social connections and find relevant items.
Advantages:
- Considers social influence
- Discovers hidden connections
- Excellent for social networks
UserID:1 Name:Alice
UserID:2 Name:Bob
UserID:3 Name:Charlie
UserID:1 ItemID:101 Interaction:view
UserID:1 ItemID:102 Interaction:purchase
UserID:2 ItemID:101 Interaction:view
UserID:3 ItemID:103 Interaction:purchase
Run comprehensive tests:
make testAdd your own test cases in the tests/ directory. The build system automatically detects new test files!
Here's a real example of the recommendation system in action:
PS C:\Users\HP\OneDrive\Desktop\DSA PROJECTS\GRAPHBASE_RECOMMENDATION_SYSTEM --UPDATE> make run
---
MOVIE RECOMMENDATION SYSTEM
---
[β] Loading previous user interactions...
[β] Data loaded successfully!
Enter your name: deepv12
Welcome, deepv12 π±
Your User ID: 82
β How many favorite movies would you like to add? 2
π¬ Enter movie names (use ' _' instead of space):
βdark
[Added] dark
βnarcos
[Added] narcos
π Generating personalized recommendations...
π Recommended Movies For You
---
chernoBy1
alice_in_borderland
squid_game
stranger_thingsKey Features Demonstrated:
- β User registration and ID assignment
- β Favorite movie collection
- β Personalized recommendation generation
- β Clean, user-friendly interface
- Create new files in
src/Algorithms/:
// NewAlgorithm.h
#pragma once
#include "../Graph/graph.h"
class NewAlgorithm {
public:
static vector<int> recommend(graph& g, int userId);
};
// NewAlgorithm.cpp
#include "NewAlgorithm.h"
vector<int> NewAlgorithm::recommend(graph& g, int userId) {
// Your implementation
}- The Makefile automatically includes your new files!
Modify the models in src/Models/ and update the FileManager for data persistence.
| Operation | Time Complexity | Space Complexity |
|---|---|---|
| Graph Building | O(E) | O(V + E) |
| Collaborative Filtering | O(VΒ²) | O(V) |
| Popularity Ranking | O(V log V) | O(V) |
| BFS Recommendations | O(V + E) | O(V) |
V = Number of vertices (users)
E = Number of edges (interactions)
We welcome contributions! Here's how:
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature- Commit changes
git commit -m 'Add amazing feature'- Push to branch
git push origin feature/amazing-feature- Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Found a bug? Have a feature request?
Open an Issue