Getting Started with DSA in C++
February 15, 2024
C++ / DSA
8 min read
Data Structures and Algorithms (DSA) form the backbone of computer science and are essential for acing technical interviews. In this guide, I'll walk you through my proven approach to mastering DSA using C++.
1. Choose the Right Resources
Start with a good book like "Introduction to Algorithms" (CLRS) or online courses. I personally recommend:
- Books: "Cracking the Coding Interview" for practice, "The Algorithm Design Manual" for deeper understanding.
- Online platforms: GeeksforGeeks, LeetCode, and HackerRank for hands-on practice.
- YouTube channels: takeUforward, CodeHelp by Babbar, and freeCodeCamp.
2. Master the Fundamentals First
Don't jump into complex problems. Build a solid foundation:
- Arrays & Strings: Understand time complexity, two-pointer techniques.
- Linked Lists: Practice reversal, cycle detection.
- Stacks & Queues: Implement using arrays and linked lists.
- Trees: Binary trees, BST, traversals (inorder, preorder, postorder).
3. Code Daily in C++
Here's a simple template for competitive programming in C++:
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// Your code here
return 0;
}
4. Practice Problem-Solving Patterns
Recognize common patterns like sliding window, binary search on answer, dynamic programming memoization. I maintain a personal repository (gfg-POTD) where I document daily solutions.
Pro Tip: Solve at least one problem daily, even if it's easy. Consistency beats intensity.
5. Analyze and Optimize
After solving a problem, always check the editorial. Learn about time/space complexity trade-offs. Ask yourself: Can I do better? This habit separates good programmers from great ones.
Remember, DSA is a marathon, not a sprint. Stay patient and keep coding!
← Back to all blogs
Building a Secure E-Commerce Site with PHP
January 20, 2024
PHP / MySQL
10 min read
E-commerce platforms are complex beasts. In this post, I'll share my experience building a fully functional e-commerce website using PHP, MySQL, and integrating Razorpay for payments.
Architecture Overview
My project (GitHub repo) follows the MVC pattern loosely:
- Frontend: HTML5, CSS3, JavaScript (vanilla) – responsive design with Bootstrap.
- Backend: PHP 8 for server-side logic, MySQL for database.
- Authentication: Google OAuth 2.0 for seamless login.
- Payments: Razorpay API integration.
Database Design (Simplified)
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
email VARCHAR(255) UNIQUE,
name VARCHAR(100),
google_id VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE products (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(255),
description TEXT,
price DECIMAL(10,2),
stock INT,
image_url VARCHAR(500)
);
CREATE TABLE orders (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT,
total DECIMAL(10,2),
status ENUM('pending','paid','shipped'),
razorpay_order_id VARCHAR(100),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id)
);
Security Best Practices Implemented
- Prepared statements: Prevents SQL injection.
- Password hashing: Using `password_hash()` and `password_verify()`.
- CSRF tokens: On all forms.
- HTTPS enforcement: Redirects all HTTP traffic.
- Input validation: Both client-side and server-side.
Razorpay Integration
Key steps:
- Create an order on your server using Razorpay PHP SDK.
- Send order details to frontend.
- Use Razorpay checkout JS to capture payment.
- Verify payment signature on server before updating order status.
// Server-side order creation
$api = new Razorpay\Api\Api("YOUR_KEY", "YOUR_SECRET");
$orderData = [
'receipt' => 'rcpt_'.time(),
'amount' => $total * 100, // in paise
'currency' => 'INR'
];
$razorpayOrder = $api->order->create($orderData);
Challenges Faced
The biggest challenge was handling asynchronous payment callbacks. I implemented a webhook endpoint to update order status even if the user closes the browser. Always test with Razorpay test mode first!
← Back to all blogs
My Journey into AI Research
March 1, 2024
Research / AI
6 min read
Transitioning from software development to AI research was both exciting and daunting. Here's my story and the resources that helped me.
The Beginning
It all started during my third year of computer science. I took an elective on machine learning and was instantly hooked. The idea that computers could learn patterns from data felt like magic. I began with Andrew Ng's famous Coursera course.
Building Mathematical Foundation
AI research requires solid math. I revisited:
- Linear Algebra: Strang's book and 3Blue1Brown videos.
- Calculus: Understanding gradients and backpropagation.
- Probability & Statistics: For understanding distributions and Bayesian thinking.
First Research Project: Optimizing Database Queries with ML
My first attempt was applying reinforcement learning to choose optimal indexes in MySQL. It was a failure initially – the model took forever to train. But I learned valuable lessons about problem framing and dataset creation.
Resources That Helped
- Books: "Pattern Recognition and Machine Learning" by Bishop, "Deep Learning" by Goodfellow.
- Courses: fast.ai, CS231n (Stanford), and Hugging Face's NLP course.
- Papers: I started with survey papers on arXiv before diving into specific architectures.
Advice for beginners: Don't get overwhelmed. Start with one subfield (CV, NLP, RL) and build projects. Kaggle competitions are great for hands-on practice.
Current Work
I'm now exploring few-shot learning and its applications in low-resource languages. The journey is long, but every small discovery makes it worthwhile.
← Back to all blogs