From 97725167ee306fcd032ae6efb36e2785fa333239 Mon Sep 17 00:00:00 2001 From: V Pratheek Date: Sun, 27 Oct 2024 15:44:40 +0530 Subject: [PATCH] Added the DSA Learning Track and Roadmap --- .env.sample | 15 - src/app/(pages)/Resources/[id]/page.jsx | 437 ++++++++------------- src/lib/dsa-content.js | 490 ++++++++++++++++++++++++ src/lib/dsa-track-content.js | 159 ++++++++ 4 files changed, 807 insertions(+), 294 deletions(-) delete mode 100644 .env.sample create mode 100644 src/lib/dsa-content.js create mode 100644 src/lib/dsa-track-content.js diff --git a/.env.sample b/.env.sample deleted file mode 100644 index 3359434..0000000 --- a/.env.sample +++ /dev/null @@ -1,15 +0,0 @@ -GMAIL_USER=your-email@gmail.com -GMAIL_PASS=your-email-password - -SMTP_EMAIL= -SMTP_PASSWORD= - -GEMINI_API_KEY='Add your Gemini API Key' - -NEXT_PUBLIC_SUPABASE_URL=your-supabase-url -NEXT_PUBLIC_SUPABASE_ANON_KEY=your-supabase-anon-key -NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME=your-cloudinary-name -NEXT_PUBLIC_CLOUDINARY_API_KEY=your-cloudinary-api-key - - -# Also rename this file as .env \ No newline at end of file diff --git a/src/app/(pages)/Resources/[id]/page.jsx b/src/app/(pages)/Resources/[id]/page.jsx index af1c9e0..e475151 100644 --- a/src/app/(pages)/Resources/[id]/page.jsx +++ b/src/app/(pages)/Resources/[id]/page.jsx @@ -2,14 +2,82 @@ import { useEffect } from 'react'; import { useRouter, useParams } from 'next/navigation'; -import resources from '../resources'; +import resources from '../resources'; import { cppContent } from '@/lib/cpp-content'; +import { dsaContent } from '@/lib/dsa-content'; import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { Card, CardHeader, CardTitle, CardContent } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog"; +// Solution Dialog Component +const SolutionDialog = ({ solution }) => { + if (!solution) return null; + + return ( + + + + + + + Solution + +
+
+
+                            {solution.code}
+                        
+
+
+

Explanation:

+

{solution.explanation}

+
+
+
+
+ ); +}; + +// Exercise Card Component +const ExerciseCard = ({ exercise }) => ( +
+
+

+ {exercise.title} +

+ + {exercise.difficulty} + +
+

{exercise.description}

+
+
+

Hints:

+
    + {exercise.hints.map((hint, hintIndex) => ( +
  • + {hint} +
  • + ))} +
+
+ +
+
+); + function ResourceDetail() { const router = useRouter(); const params = useParams(); @@ -27,74 +95,19 @@ function ResourceDetail() { return null; } + // Define learning track types const isCppTrack = resource.id === 4; + const isDSATrack = resource.id === 5; + const isLearningTrack = isCppTrack || isDSATrack; - // Solution Dialog Component - const SolutionDialog = ({ solution }) => { - if (!solution) return null; - - return ( - - - - - - - Solution - -
-
-
-                                {solution.code}
-                            
-
-
-

Explanation:

-

{solution.explanation}

-
-
-
-
- ); + // Get appropriate content based on track type + const getTrackContent = () => { + if (isCppTrack) return cppContent; + if (isDSATrack) return dsaContent; + return null; }; - // Exercise Card Component - const ExerciseCard = ({ exercise }) => ( -
-
-

- {exercise.title} -

- - {exercise.difficulty} - -
-

{exercise.description}

-
-
-

Hints:

-
    - {exercise.hints.map((hint, hintIndex) => ( -
  • - {hint} -
  • - ))} -
-
- -
-
- ); + const content = getTrackContent(); return (
@@ -108,7 +121,7 @@ function ResourceDetail() { {/* Content Section */}
- {isCppTrack ? ( + {isLearningTrack && content ? ( Introduction @@ -122,7 +135,7 @@ function ResourceDetail() { - Introduction to C++ + {resource.title}

@@ -139,7 +152,7 @@ function ResourceDetail() { Code Examples - {cppContent.examples.map((example, index) => ( + {content.examples.map((example, index) => (

{example.title}

@@ -152,197 +165,84 @@ function ResourceDetail() {
                             
                         
 
-{/* Roadmap Tab */}
-
-    
- {cppContent.roadmap.map((section, index) => ( - - - - {section.title} - - - -

{section.description}

-
- {section.topics.map((topic, topicIndex) => ( -
- - {topicIndex + 1} - - {topic} -
- ))} -
-
-
- ))} -
-
- -{/* Resources Tab */} - -
- {/* Documentation Section */} - - - - Documentation & References - - - -
- {cppContent.resources.documentation.map((doc, index) => ( -
-
-

- {doc.title} -

- {doc.type} -
-

{doc.description}

- - Visit Resource → - -
- ))} -
-
-
- - {/* Tutorials Section */} - - - - Online Tutorials & Courses - - - -
- {cppContent.resources.tutorials.map((tutorial, index) => ( -
-
-

- {tutorial.title} -

- {tutorial.type} -
-

{tutorial.description}

- - Start Learning → - -
- ))} -
-
-
- - {/* Video Resources */} - - - - Video Tutorials - - - -
- {cppContent.resources.videos.map((video, index) => ( -
-
-

- {video.title} -

- {video.platform} + {/* Roadmap Tab */} + +
+ {content.roadmap.map((section, index) => ( + + + + {section.title} + + + +

{section.description}

+
+ {section.topics.map((topic, topicIndex) => ( +
+ + {topicIndex + 1} + + {topic} +
+ ))} +
+
+
+ ))}
-

{video.description}

- - Watch Now → - -
- ))} -
- - + - {/* Books Section */} - - - - Recommended Books - - - -
- {cppContent.resources.books.map((book, index) => ( -
-
-

- {book.title} -

- {book.level} + {/* Resources Tab */} + +
+ {Object.entries(content.resources).map(([category, items]) => ( + + + + {category.charAt(0).toUpperCase() + category.slice(1)} + + + +
+ {items.map((item, index) => ( +
+
+

+ {item.title} +

+ + {item.type || item.platform || item.level} + +
+

+ {item.description} +

+ {item.url && ( + + Visit Resource → + + )} +
+ ))} +
+
+
+ ))}
-

By {book.author}

-

{book.description}

-
- ))} -
- - + - {/* Practice Platforms */} - - - - Practice Platforms - - - -
- {cppContent.resources.practice.map((platform, index) => ( -
-
-

- {platform.title} -

- {platform.type} -
-

{platform.description}

- - Start Practicing → - -
- ))} -
-
-
-
- {/* Practice Tab */}
@@ -358,7 +258,7 @@ function ResourceDetail() {
- {cppContent.practice.beginnerExercises.map((exercise, index) => ( + {content.practice.beginnerExercises.map((exercise, index) => ( ))}
@@ -377,7 +277,7 @@ function ResourceDetail() {
- {cppContent.practice.intermediateExercises.map((exercise, index) => ( + {content.practice.intermediateExercises.map((exercise, index) => ( ))}
@@ -396,26 +296,7 @@ function ResourceDetail() {
- {cppContent.practice.advancedExercises.map((exercise, index) => ( - - ))} -
-
- - - {/* Challenge Problems */} - - - - Challenge Problems - - Expert - - - - -
- {cppContent.practice.challengeProblems.map((exercise, index) => ( + {content.practice.advancedExercises.map((exercise, index) => ( ))}
@@ -423,8 +304,6 @@ function ResourceDetail() {
- - {/* ... Other tabs content ... */} ) : ( diff --git a/src/lib/dsa-content.js b/src/lib/dsa-content.js new file mode 100644 index 0000000..48888bf --- /dev/null +++ b/src/lib/dsa-content.js @@ -0,0 +1,490 @@ +export const dsaContent = { + examples: [ + { + title: "Array Operations", + code: `// Example of basic array operations +int arr[] = {1, 2, 3, 4, 5}; +int n = sizeof(arr) / sizeof(arr[0]); + +// Accessing elements +cout << "First element: " << arr[0] << endl; + +// Linear search +for(int i = 0; i < n; i++) { + if(arr[i] == 3) { + cout << "Found 3 at index " << i << endl; + break; + } +}`, + explanation: "Basic array operations including initialization, accessing elements, and linear search implementation." + }, + { + title: "Linked List Implementation", + code: `struct Node { + int data; + Node* next; + Node(int val) : data(val), next(nullptr) {} +}; + +class LinkedList { + Node* head; +public: + LinkedList() : head(nullptr) {} + + void insert(int val) { + Node* newNode = new Node(val); + if(!head) { + head = newNode; + return; + } + newNode->next = head; + head = newNode; + } +};`, + explanation: "Implementation of a basic singly linked list with insertion operation." + }, + { + title: "Stack Implementation", + code: `template +class Stack { + vector items; + +public: + void push(T item) { + items.push_back(item); + } + + T pop() { + if (isEmpty()) { + throw runtime_error("Stack is empty"); + } + T item = items.back(); + items.pop_back(); + return item; + } + + T peek() const { + if (isEmpty()) { + throw runtime_error("Stack is empty"); + } + return items.back(); + } + + bool isEmpty() const { + return items.empty(); + } + + size_t size() const { + return items.size(); + } +}; + +// Example usage: +int main() { + Stack stack; + + // Push elements + stack.push(1); + stack.push(2); + stack.push(3); + + // Pop and print elements + while (!stack.isEmpty()) { + cout << stack.pop() << " "; // Outputs: 3 2 1 + } + + return 0; +}`, + explanation: "This example demonstrates a generic stack implementation using a vector. It includes all basic stack operations: push, pop, peek, isEmpty, and size. The stack follows LIFO (Last-In-First-Out) principle and includes proper error handling for empty stack operations." + }, + { + title: "Binary Search Implementation", + code: `// Iterative Binary Search +int binarySearch(vector& arr, int target) { + int left = 0; + int right = arr.size() - 1; + + while (left <= right) { + int mid = left + (right - left) / 2; // Prevents integer overflow + + if (arr[mid] == target) { + return mid; // Found the target + } + + if (arr[mid] < target) { + left = mid + 1; // Target is in the right half + } else { + right = mid - 1; // Target is in the left half + } + } + + return -1; // Target not found +} + +// Recursive Binary Search +int binarySearchRecursive(vector& arr, int target, int left, int right) { + if (left > right) { + return -1; // Base case: target not found + } + + int mid = left + (right - left) / 2; + + if (arr[mid] == target) { + return mid; // Found the target + } + + if (arr[mid] < target) { + // Search right half + return binarySearchRecursive(arr, target, mid + 1, right); + } else { + // Search left half + return binarySearchRecursive(arr, target, left, mid - 1); + } +} + +// Example usage: +int main() { + vector arr = {1, 3, 5, 7, 9, 11, 13, 15}; + int target = 7; + + // Using iterative method + int iterativeResult = binarySearch(arr, target); + cout << "Iterative Result: " << iterativeResult << endl; + + // Using recursive method + int recursiveResult = binarySearchRecursive(arr, target, 0, arr.size() - 1); + cout << "Recursive Result: " << recursiveResult << endl; + + return 0; +}`, + explanation: "This example shows both iterative and recursive implementations of binary search. Binary search is an efficient algorithm for finding an element in a sorted array with O(log n) time complexity. The code includes detailed comments explaining each step and demonstrates proper handling of array bounds and target comparison." + }, + { + title: "Graph Representation and BFS Traversal", + code: `#include +#include +#include + +class Graph { + unordered_map> adjacencyList; + +public: + // Add an edge to the graph + void addEdge(int from, int to) { + adjacencyList[from].push_back(to); + adjacencyList[to].push_back(from); // For undirected graph + } + + // Breadth-First Search traversal + void BFS(int startVertex) { + // Keep track of visited vertices + unordered_map visited; + + // Create a queue for BFS + queue q; + + // Mark the start vertex as visited and enqueue it + visited[startVertex] = true; + q.push(startVertex); + + cout << "BFS starting from vertex " << startVertex << ": "; + + while (!q.empty()) { + // Dequeue a vertex and print it + int vertex = q.front(); + cout << vertex << " "; + q.pop(); + + // Get all adjacent vertices + // If an adjacent hasn't been visited, mark it visited + // and enqueue it + for (int adjacent : adjacencyList[vertex]) { + if (!visited[adjacent]) { + visited[adjacent] = true; + q.push(adjacent); + } + } + } + cout << endl; + } + + // Print the graph structure + void printGraph() { + for (const auto& pair : adjacencyList) { + cout << "Vertex " << pair.first << " -> "; + for (int adjacent : pair.second) { + cout << adjacent << " "; + } + cout << endl; + } + } +}; + +int main() { + Graph g; + + // Add edges to create a sample graph + g.addEdge(0, 1); + g.addEdge(0, 2); + g.addEdge(1, 2); + g.addEdge(2, 3); + g.addEdge(3, 4); + g.addEdge(4, 0); + + cout << "Graph structure:" << endl; + g.printGraph(); + + cout << "\nPerforming BFS traversal:" << endl; + g.BFS(0); + + return 0; +}`, + explanation: "This example demonstrates graph representation using an adjacency list and implements Breadth-First Search (BFS) traversal. The code shows how to create an undirected graph, add edges, and traverse it using BFS. The implementation uses STL containers (unordered_map, vector, queue) for efficient operations. BFS is crucial for shortest path algorithms in unweighted graphs and level-order traversals." + } + ], + roadmap: [ + { + title: "1. Basic Data Structures", + description: "Master fundamental data structures and their operations", + topics: [ + "Arrays and Dynamic Arrays", + "Linked Lists (Singly & Doubly)", + "Stacks and their applications", + "Queues and Priority Queues", + "Hash Tables and Collision Resolution", + "Trees (Binary & BST)", + "Heaps" + ] + }, + { + title: "2. Basic Algorithms", + description: "Learn essential algorithmic techniques and analysis", + topics: [ + "Time & Space Complexity", + "Searching Algorithms", + "Sorting Algorithms", + "Recursion Fundamentals", + "Two Pointer Technique", + "Sliding Window", + "Basic Problem Solving" + ] + }, + { + title: "3. Advanced Data Structures", + description: "Explore complex data structures and their use cases", + topics: [ + "AVL Trees", + "Red-Black Trees", + "B-Trees", + "Graphs Representation", + "Disjoint Sets", + "Trie", + "Segment Trees" + ] + }, + { + title: "4. Advanced Algorithms", + description: "Master advanced algorithmic paradigms", + topics: [ + "Dynamic Programming", + "Greedy Algorithms", + "Graph Algorithms", + "Backtracking", + "String Algorithms", + "Bit Manipulation", + "Advanced Problem Solving" + ] + } + ], + resources: { + documentation: [ + { + title: "GeeksforGeeks DSA", + url: "https://www.geeksforgeeks.org/data-structures/", + description: "Comprehensive DSA tutorial and practice platform", + type: "Tutorial Platform" + }, + { + title: "CP Algorithms", + url: "https://cp-algorithms.com/", + description: "Advanced algorithms and data structures", + type: "Reference" + } + ], + tutorials: [ + { + title: "Introduction to Algorithms", + url: "https://ocw.mit.edu/courses/6-006-introduction-to-algorithms-spring-2020/", + description: "MIT OpenCourseWare's algorithm course", + type: "Course" + }, + { + title: "Data Structures Easy to Advanced", + url: "https://www.youtube.com/watch?v=RBSGKlAvoiM", + description: "Comprehensive DSA course by William Fiset", + type: "Video Course" + } + ], + videos: [ + { + title: "Abdul Bari Algorithms", + url: "https://www.youtube.com/watch?v=0IAPZzGSbME&list=PLDN4rrl48XKpZkf03iYFl-O29szjTrs_O", + description: "In-depth algorithms course", + platform: "YouTube" + }, + { + title: "mycodeschool DSA", + url: "https://www.youtube.com/user/mycodeschool", + description: "Data structures and algorithms explained", + platform: "YouTube" + } + ], + books: [ + { + title: "Introduction to Algorithms (CLRS)", + author: "Cormen, Leiserson, Rivest, Stein", + description: "The most comprehensive algorithms book", + level: "Advanced" + }, + { + title: "Competitive Programming 3", + author: "Steven Halim", + description: "Essential for competitive programming", + level: "Intermediate" + } + ], + practice: [ + { + title: "LeetCode", + url: "https://leetcode.com/", + description: "Platform for practicing DSA problems", + type: "Practice Platform" + }, + { + title: "Codeforces", + url: "https://codeforces.com/", + description: "Competitive programming platform", + type: "Competition Platform" + } + ] + }, + practice: { + beginnerExercises: [ + { + title: "Array Reversal", + difficulty: "Easy", + description: "Write a function to reverse an array in-place.", + hints: [ + "Use two pointers approach", + "Think about swapping elements", + "Consider array length (odd vs even)" + ], + solution: { + code: `void reverseArray(int arr[], int n) { + int start = 0, end = n - 1; + while (start < end) { + // Swap elements + int temp = arr[start]; + arr[start] = arr[end]; + arr[end] = temp; + start++; + end--; + } +}`, + explanation: "This solution uses the two-pointer technique. We maintain two pointers, one at the start and one at the end of the array. We swap the elements at these positions and move the pointers towards the center until they meet." + } + } + ], + intermediateExercises: [ + { + title: "Binary Search Tree Implementation", + difficulty: "Medium", + description: "Implement a binary search tree with insert and search operations.", + hints: [ + "Define a Node structure first", + "Handle the empty tree case", + "Remember BST properties", + "Use recursion for insertion" + ], + solution: { + code: `struct Node { + int data; + Node *left, *right; + Node(int val) : data(val), left(nullptr), right(nullptr) {} +}; + +class BST { + Node* root; + + Node* insertRec(Node* root, int val) { + if (!root) return new Node(val); + + if (val < root->data) + root->left = insertRec(root->left, val); + else if (val > root->data) + root->right = insertRec(root->right, val); + + return root; + } + +public: + BST() : root(nullptr) {} + + void insert(int val) { + root = insertRec(root, val); + } +};`, + explanation: "This implementation includes a Node structure and a BST class. The insert operation maintains the BST property where left child is smaller and right child is larger than the parent." + } + } + ], + advancedExercises: [ + { + title: "Graph DFS Implementation", + difficulty: "Hard", + description: "Implement Depth First Search for a graph represented as an adjacency list.", + hints: [ + "Use recursion for DFS", + "Keep track of visited nodes", + "Consider disconnected components", + "Think about base cases" + ], + solution: { + code: `class Graph { + int V; + vector> adj; + + void DFSUtil(int v, vector& visited) { + visited[v] = true; + cout << v << " "; + + for(int u : adj[v]) { + if(!visited[u]) + DFSUtil(u, visited); + } + } + +public: + Graph(int v) : V(v) { + adj.resize(V); + } + + void addEdge(int v, int u) { + adj[v].push_back(u); + adj[u].push_back(v); + } + + void DFS() { + vector visited(V, false); + for(int v = 0; v < V; v++) { + if(!visited[v]) + DFSUtil(v, visited); + } + } +};`, + explanation: "This implementation uses adjacency list representation and recursion to perform DFS. It handles disconnected components and uses a visited array to prevent cycles." + } + } + ] + } +}; \ No newline at end of file diff --git a/src/lib/dsa-track-content.js b/src/lib/dsa-track-content.js new file mode 100644 index 0000000..6e59036 --- /dev/null +++ b/src/lib/dsa-track-content.js @@ -0,0 +1,159 @@ +export const trackContent = { + examples: [ + { + title: "Basic Example 1", + code: `// Your code example here`, + explanation: "Explanation of the basic concept..." + }, + { + title: "Intermediate Example", + code: `// Your code example here`, + explanation: "More complex concept explanation..." + } + ], + + roadmap: [ + { + title: "1. Foundation", + description: "Master the fundamental concepts and basic principles.", + topics: [ + "Core concept 1", + "Core concept 2", + "Basic principles", + "Fundamental operations", + "Key terminology", + "Basic tools setup", + "Getting started guide" + ] + }, + { + title: "2. Intermediate Concepts", + description: "Build upon the basics with more advanced topics.", + topics: [ + "Advanced concept 1", + "Advanced concept 2", + "Best practices", + "Common patterns", + "Tool mastery", + "Performance considerations", + "Testing strategies" + ] + }, + { + title: "3. Advanced Topics", + description: "Dive deep into complex and specialized areas.", + topics: [ + "Expert topic 1", + "Expert topic 2", + "Advanced patterns", + "Optimization techniques", + "Architecture patterns", + "Advanced tools", + "Industry standards" + ] + } + ], + + resources: { + documentation: [ + { + title: "Official Documentation", + url: "https://example.com/docs", + description: "Complete reference and guides", + type: "Documentation" + }, + { + title: "API Reference", + url: "https://example.com/api", + description: "Comprehensive API documentation", + type: "Reference" + } + ], + tutorials: [ + { + title: "Beginner's Guide", + url: "https://example.com/tutorial", + description: "Step-by-step tutorial for beginners", + type: "Tutorial Series" + }, + { + title: "Interactive Course", + url: "https://example.com/course", + description: "Hands-on learning platform", + type: "Course Platform" + } + ], + videos: [ + { + title: "Video Course Series", + url: "https://example.com/videos", + description: "Comprehensive video tutorials", + platform: "YouTube" + } + ], + books: [ + { + title: "Definitive Guide", + author: "Author Name", + description: "Complete guide for all skill levels", + level: "All Levels" + } + ], + practice: [ + { + title: "Practice Platform", + url: "https://example.com/practice", + description: "Interactive exercises and challenges", + type: "Practice Platform" + } + ] + }, + + practice: { + beginnerExercises: [ + { + title: "First Steps", + difficulty: "Easy", + description: "Basic exercise for beginners", + hints: [ + "Start with the basics", + "Follow the pattern" + ], + solution: { + code: `// Solution code here`, + explanation: "Step-by-step explanation of the solution" + } + } + ], + intermediateExercises: [ + { + title: "Building Skills", + difficulty: "Medium", + description: "More challenging exercise", + hints: [ + "Consider edge cases", + "Think about efficiency" + ], + solution: { + code: `// Solution code here`, + explanation: "Detailed explanation of the approach" + } + } + ], + advancedExercises: [ + { + title: "Expert Challenge", + difficulty: "Hard", + description: "Complex problem-solving exercise", + hints: [ + "Think about optimization", + "Consider multiple approaches" + ], + solution: { + code: `// Solution code here`, + explanation: "In-depth analysis of the solution" + } + } + ] + } +}; \ No newline at end of file