diff --git a/app/components/subjects.tsx b/app/components/subjects.tsx index d586e86..fefcc0b 100644 --- a/app/components/subjects.tsx +++ b/app/components/subjects.tsx @@ -101,7 +101,7 @@ const subjectCodes: Record = { "Data Science using Python Libraries": "dsp", "Artificial Intelligence": "ai", - "Algorithm Design and Analysis": "ada", + "Algorithm Design and Analysis": "ada2", "Cloud Computing": "cc", "Economics for Engineers": "ee", "IoT (Internet of Things)": "iot", @@ -125,7 +125,7 @@ const subjectCodes: Record = { }; // Available subjects -const available = ["ep", "c", "em1", "em2", "oops", "dsc", "os", "ml", "dops"]; +const available = ["ep", "c", "em1", "em2", "oops", "dsc", "os", "ml", "dops", "ada2"]; export default function SubjectsSection() { return ( diff --git a/app/sem4/dbms/components/sidebar.tsx b/app/sem4/dbms/components/sidebar.tsx index e091292..d958623 100644 --- a/app/sem4/dbms/components/sidebar.tsx +++ b/app/sem4/dbms/components/sidebar.tsx @@ -2,7 +2,7 @@ import { Righteous } from "next/font/google"; import Link from "next/link"; import { usePathname } from "next/navigation"; -import { useState } from "react"; +import { useState, useEffect } from "react"; const righteous = Righteous({ subsets: ["latin"], @@ -12,13 +12,19 @@ const righteous = Righteous({ export default function Sidebar() { const pathname = usePathname(); - const [open, setOpen] = useState(true); + const [open, setOpen] = useState(false); + + useEffect(() => { + if (window.innerWidth >= 768) { + setOpen(true); + } + }, []); const chapters = [ { id: "ch0", title: "Course Outline" }, { id: "ch1", title: "Introduction to Databases" }, - { id: "ch2", title: "Entity-Relationship Model" }, - { id: "ch3", title: "Relational Model and SQL" }, + { id: "ch2", title: "Entity-Relationship Model" }, + { id: "ch3", title: "Relational Model and SQL" }, // { id: "ch4", title: "Normalization" }, // { id: "ch5", title: "Transactions and Concurrency Control" }, // { id: "ch6", title: "Indexing and Hashing" }, @@ -27,47 +33,59 @@ export default function Sidebar() { ]; return ( -
- +

+ Chapters +

+
    + {chapters.map((ch) => { + const active = pathname === `/sem4/dbms/${ch.id}`; + return ( +
  • + + {ch.title} + +
  • + ); + })} +
+ - -
+ + + ); -} \ No newline at end of file +} + diff --git a/app/sem5/ada2/[chapter]/page.tsx b/app/sem5/ada2/[chapter]/page.tsx new file mode 100644 index 0000000..d4241ed --- /dev/null +++ b/app/sem5/ada2/[chapter]/page.tsx @@ -0,0 +1,199 @@ +import Link from "next/link"; + +import { Ch0Content } from "../content/chapter0"; +import { Ch1Content } from "../content/chapter1"; +import { Ch2Content } from "../content/chapter2"; +import { Ch3Content } from "../content/chapter3"; +import { Ch4Content } from "../content/chapter4"; +import { Ch5Content } from "../content/chapter5"; +import { Ch6Content } from "../content/chapter6"; +import { Ch7Content } from "../content/chapter7"; +import { Ch8Content } from "../content/chapter8"; + +import { ArrowBigLeft, ArrowBigRight } from "lucide-react"; +import { Righteous } from "next/font/google"; + +const righteous = Righteous({ + subsets: ["latin"], + weight: "400", + variable: "--font-righteous", +}); + +const chapters = [ + { + id: "ch0", + title: "Course Outline", + component: Ch0Content, + }, + + { + id: "ch1", + title: "Introduction to Algorithms", + component: Ch1Content, + }, + + { + id: "ch2", + title: "Time and Space Complexity", + component: Ch2Content, + }, + + { + id: "ch3", + title: "Searching and Sorting Algorithms", + component: Ch3Content, + }, + + { + id: "ch4", + title: "Divide and Conquer Technique", + component: Ch4Content, + }, + + { + id: "ch5", + title: "Greedy Method", + component: Ch5Content, + }, + + { + id: "ch6", + title: "Dynamic Programming", + component: Ch6Content, + }, + + { + id: "ch7", + title: "Graph Algorithms", + component: Ch7Content, + }, + + { + id: "ch8", + title: "Backtracking and Branch & Bound", + component: Ch8Content, + }, +]; + +type ChapterProps = { + params: { chapter: string }; +}; + +export default function ChapterPage({ params }: ChapterProps) { + + const currentIndex = chapters.findIndex( + (c) => c.id === params.chapter + ); + + const chapter = chapters[currentIndex]; + + if (!chapter) { + return ( +

+ Chapter not found +

+ ); + } + + const ChapterComponent = chapter.component; + + const prevChapter = + currentIndex > 0 + ? chapters[currentIndex - 1] + : null; + + const nextChapter = + currentIndex < chapters.length - 1 + ? chapters[currentIndex + 1] + : null; + + return ( +
+ + {/* Main Content */} +
+ +

+ Algorithm Design and Analysis +

+ +

+ {chapter.title} +

+ + {/* Top Navigation */} +
+ + {prevChapter ? ( + + + Previous + + ) : ( +
+ )} + + {nextChapter ? ( + + Next + + + ) : ( +
+ )} + +
+ +
+ + + +
+ + {/* Bottom Navigation */} +
+ + {prevChapter ? ( + + + + {prevChapter.title} + + ) : ( +
+ )} + + {nextChapter ? ( + + {nextChapter.title} + + + ) : ( +
+ )} + +
+ +
+ ); +} \ No newline at end of file diff --git a/app/sem5/ada2/components/sidebar.tsx b/app/sem5/ada2/components/sidebar.tsx new file mode 100644 index 0000000..dc3b51d --- /dev/null +++ b/app/sem5/ada2/components/sidebar.tsx @@ -0,0 +1,129 @@ +"use client"; + +import { Righteous } from "next/font/google"; +import Link from "next/link"; +import { usePathname } from "next/navigation"; +import { useState } from "react"; + +const righteous = Righteous({ + subsets: ["latin"], + weight: "400", + variable: "--font-righteous", +}); + +export default function Sidebar() { + const pathname = usePathname(); + const [open, setOpen] = useState(true); + + const chapters = [ + { id: "ch0", title: "Course Outline" }, + + { + id: "ch1", + title: "Introduction to Algorithms", + }, + + { + id: "ch2", + title: "Time and Space Complexity", + }, + + { + id: "ch3", + title: "Searching and Sorting Algorithms", + }, + + { + id: "ch4", + title: "Divide and Conquer Technique", + }, + + { + id: "ch5", + title: "Greedy Method", + }, + + { + id: "ch6", + title: "Dynamic Programming", + }, + + { + id: "ch7", + title: "Graph Algorithms", + }, + + { + id: "ch8", + title: "Backtracking and Branch & Bound", + }, + ]; + + return ( +
+ + + + + +
+ ); +} \ No newline at end of file diff --git a/app/sem5/ada2/content/chapter0.tsx b/app/sem5/ada2/content/chapter0.tsx new file mode 100644 index 0000000..e694fba --- /dev/null +++ b/app/sem5/ada2/content/chapter0.tsx @@ -0,0 +1,186 @@ +export const Ch0Content = () => { + return ( +
+

+ Welcome to{" "} + + Algorithm Design and Analysis + {" "} + — a core subject that helps you learn how to solve problems efficiently + using step-by-step methods called algorithms. In this course, you will + understand how algorithms work, how to measure their performance, and + how to design optimized solutions for real-world problems. +

+ +
+ +
+

+ Module I:{" "} + + Introduction to Algorithms + +

+ +
    +
  • What is an algorithm and why it is important
  • +
  • Characteristics of a good algorithm
  • +
  • Difference between algorithm and program
  • +
  • How to write algorithms using pseudocode and flowcharts
  • +
  • Basics of problem solving techniques
  • +
  • Real-life examples of algorithms
  • +
+
+ +
+ +
+

+ Module II:{" "} + + Time and Space Complexity + +

+ +
    +
  • Why complexity analysis is needed
  • +
  • Understanding time complexity
  • +
  • Understanding space complexity
  • +
  • Best case, worst case, and average case analysis
  • +
  • Introduction to Big O, Omega, and Theta notation
  • +
  • Simple examples for complexity calculation
  • +
+
+ +
+ +
+

+ Module III:{" "} + + Searching and Sorting Algorithms + +

+ +
    +
  • Linear search and binary search
  • +
  • Bubble sort and selection sort
  • +
  • Insertion sort and merge sort
  • +
  • Quick sort and heap sort basics
  • +
  • Comparison between different sorting algorithms
  • +
  • Choosing the best algorithm for a problem
  • +
+
+ +
+ +
+

+ Module IV:{" "} + + Divide and Conquer Technique + +

+ +
    +
  • Concept of divide and conquer
  • +
  • Breaking a problem into smaller subproblems
  • +
  • Merge sort using divide and conquer
  • +
  • Quick sort working process
  • +
  • Binary search using divide and conquer
  • +
  • Advantages and limitations of this technique
  • +
+
+ +
+ +
+

+ Module V:{" "} + + Greedy Method + +

+ +
    +
  • Introduction to greedy algorithms
  • +
  • How greedy choice works
  • +
  • Activity selection problem
  • +
  • Fractional knapsack problem
  • +
  • Huffman coding basics
  • +
  • Advantages and disadvantages of greedy approach
  • +
+
+ +
+ +
+

+ Module VI:{" "} + + Dynamic Programming + +

+ +
    +
  • Introduction to dynamic programming
  • +
  • Difference between greedy and dynamic programming
  • +
  • Overlapping subproblems and optimal substructure
  • +
  • Fibonacci problem using DP
  • +
  • 0/1 Knapsack problem
  • +
  • Longest common subsequence basics
  • +
+
+ +
+ +
+

+ Module VII:{" "} + + Graph Algorithms + +

+ +
    +
  • Introduction to graphs and terminology
  • +
  • Breadth First Search (BFS)
  • +
  • Depth First Search (DFS)
  • +
  • Shortest path algorithms basics
  • +
  • Minimum spanning tree concepts
  • +
  • Applications of graph algorithms in real life
  • +
+
+ +
+ +
+

+ Module VIII:{" "} + + Backtracking and Branch & Bound + +

+ +
    +
  • Introduction to backtracking technique
  • +
  • N-Queens problem
  • +
  • Sum of subsets problem
  • +
  • Concept of Branch and Bound
  • +
  • Traveling Salesman Problem basics
  • +
  • Comparing backtracking with other techniques
  • +
+
+ +
+ +

+ By the end of this course, you will be able to analyze algorithms, + compare their efficiency, and design optimized solutions for coding + problems and real-world applications. This subject builds a strong + foundation for competitive programming, technical interviews, and + software development. +

+
+ ); +}; \ No newline at end of file diff --git a/app/sem5/ada2/content/chapter1.tsx b/app/sem5/ada2/content/chapter1.tsx new file mode 100644 index 0000000..3e03860 --- /dev/null +++ b/app/sem5/ada2/content/chapter1.tsx @@ -0,0 +1,259 @@ +export const Ch1Content = () => { + return ( +
+

+ This chapter introduces the basics of algorithms and problem solving. + You will learn what algorithms are, why they are important, and how + they help computers solve problems step by step in an efficient way. +

+ +
+ +
+

+ + What is an Algorithm? + +

+ +
    +
  • + An algorithm is a step-by-step procedure used to solve a problem. +
  • + +
  • + It takes some input, processes it, and produces the required output. +
  • + +
  • + Algorithms are used in daily life and computer programs. +
  • + +
  • + A good algorithm should be simple, correct, and efficient. +
  • +
+ +
+

Real-Life Example

+ +
{`Making Tea Algorithm
+
+Step 1 → Boil water
+Step 2 → Add tea leaves
+Step 3 → Add sugar and milk
+Step 4 → Stir properly
+Step 5 → Serve tea`}
+
+
+ +
+ +
+

+ + Characteristics of an Algorithm + +

+ +
    +
  • + Input: An algorithm can take + input values. +
  • + +
  • + Output: It must produce at + least one result. +
  • + +
  • + Definiteness: Steps should be + clear and unambiguous. +
  • + +
  • + Finiteness: It must end after + a limited number of steps. +
  • + +
  • + Efficiency: It should solve + the problem quickly using fewer resources. +
  • +
+ +
+

+ Exam Tip: Remember the five main characteristics — Input, Output, + Definiteness, Finiteness, and Efficiency. +

+
+
+ +
+ +
+

+ + Algorithm vs Program + +

+ +
    +
  • + An algorithm is the logic or method used to solve a problem. +
  • + +
  • + A program is the actual code written in a programming language. +
  • + +
  • + Algorithms are language independent. +
  • + +
  • + Programs depend on programming languages like Java, Python, or C++. +
  • +
+ +
+

Simple Difference

+ +
{`Algorithm → Steps to add two numbers
+Program   → Java/Python code that adds numbers`}
+
+
+ +
+ +
+

+ + Pseudocode and Flowcharts + +

+ +
    +
  • + Pseudocode: A simple, + human-readable way of writing algorithm steps. +
  • + +
  • + Flowchart: A graphical + representation of an algorithm using symbols. +
  • + +
  • + Both help in understanding the logic before coding. +
  • + +
  • + They make debugging and problem solving easier. +
  • +
+ +
+

Pseudocode Example

+ +
{`Algorithm to Find Sum
+
+START
+Input A, B
+SUM = A + B
+Print SUM
+END`}
+
+
+ +
+ +
+

+ + Types of Problem Solving Approaches + +

+ +
    +
  • + Brute Force: Try all possible + solutions. +
  • + +
  • + Divide and Conquer: Break a + problem into smaller parts. +
  • + +
  • + Greedy Method: Choose the + best option at each step. +
  • + +
  • + Dynamic Programming: Store + previous results to avoid repeated work. +
  • + +
  • + Backtracking: Try solutions + and backtrack if they fail. +
  • +
+ +
+

+ These techniques are the foundation of advanced algorithms and are + very important for coding interviews. +

+
+
+ +
+ +
+

+ + Importance of Algorithms + +

+ +
    +
  • + Algorithms help solve problems efficiently. +
  • + +
  • + They reduce execution time and memory usage. +
  • + +
  • + Good algorithms improve software performance. +
  • + +
  • + They are important in AI, web apps, games, banking systems, and + search engines. +
  • + +
  • + Strong algorithm knowledge is essential for placements and coding + interviews. +
  • +
+ +
+

Real-World Applications

+ +
{`Google Search   → Searching Algorithms
+Instagram Feed → Recommendation Algorithms
+Google Maps    → Shortest Path Algorithms
+Amazon         → Sorting and Recommendation Algorithms`}
+
+
+
+ ); +}; \ No newline at end of file diff --git a/app/sem5/ada2/content/chapter2.tsx b/app/sem5/ada2/content/chapter2.tsx new file mode 100644 index 0000000..e0c590c --- /dev/null +++ b/app/sem5/ada2/content/chapter2.tsx @@ -0,0 +1,279 @@ +export const Ch2Content = () => { + return ( +
+

+ This chapter explains how to measure the efficiency of algorithms using + time and space complexity. You will learn how fast an algorithm runs, + how much memory it uses, and how to compare different algorithms. +

+ +
+ +
+

+ + Why Complexity Analysis is Important + +

+ +
    +
  • + Complexity analysis helps us understand how efficient an algorithm + is. +
  • + +
  • + It helps compare multiple algorithms for the same problem. +
  • + +
  • + Faster algorithms save execution time and system resources. +
  • + +
  • + Efficient algorithms are important for large-scale applications. +
  • +
+ +
+

Simple Example

+ +
{`Algorithm A → Takes 2 seconds
+Algorithm B → Takes 20 seconds
+
+Algorithm A is more efficient.`}
+
+
+ +
+ +
+

+ + Time Complexity + +

+ +
    +
  • + Time complexity measures how much time an algorithm takes to run. +
  • + +
  • + It depends on the size of the input. +
  • + +
  • + We calculate time complexity by counting basic operations. +
  • + +
  • + It is usually represented using Big O notation. +
  • +
+ +
+

Example

+ +
{`for(int i = 0; i < n; i++) {
+   print(i);
+}
+
+Loop runs n times
+Time Complexity = O(n)`}
+
+
+ +
+ +
+

+ + Space Complexity + +

+ +
    +
  • + Space complexity measures the amount of memory used by an algorithm. +
  • + +
  • + Extra arrays, variables, and recursive calls increase space usage. +
  • + +
  • + Efficient algorithms try to use less memory. +
  • + +
  • + Both time and space are important for performance. +
  • +
+ +
+

Example

+ +
{`int arr[n];
+
+The array stores n elements
+Space Complexity = O(n)`}
+
+
+ +
+ +
+

+ + Best Case, Worst Case, and Average Case + +

+ +
    +
  • + Best Case: Minimum time taken + by an algorithm. +
  • + +
  • + Worst Case: Maximum time + taken by an algorithm. +
  • + +
  • + Average Case: Expected time + for normal inputs. +
  • + +
  • + Worst case analysis is most commonly used in exams and interviews. +
  • +
+ +
+

Linear Search Example

+ +
{`Best Case    → Element found at first position
+Worst Case   → Element found at last position
+Average Case → Element found somewhere in middle`}
+
+
+ +
+ +
+

+ + Big O Notation + +

+ +
    +
  • + Big O notation represents the upper bound of time complexity. +
  • + +
  • + It describes how runtime grows as input size increases. +
  • + +
  • + It ignores constants and smaller terms. +
  • + +
  • + Big O helps compare algorithms easily. +
  • +
+ +
+

Common Complexities

+ +
{`O(1)     → Constant Time
+O(log n) → Logarithmic Time
+O(n)     → Linear Time
+O(n²)    → Quadratic Time
+O(2^n)   → Exponential Time`}
+
+
+ +
+ +
+

+ + Omega and Theta Notation + +

+ +
    +
  • + Omega (Ω): Represents the + best-case lower bound. +
  • + +
  • + Theta (Θ): Represents the + exact growth rate. +
  • + +
  • + These notations are used in mathematical analysis of algorithms. +
  • + +
  • + Big O is more commonly used in practical programming. +
  • +
+ +
+

+ Easy Trick: O → Upper Bound, Ω → Lower Bound, Θ → Exact Bound. +

+
+
+ +
+ +
+

+ + Complexity Comparison of Common Algorithms + +

+ +
    +
  • + Linear Search → O(n) +
  • + +
  • + Binary Search → O(log n) +
  • + +
  • + Bubble Sort → O(n²) +
  • + +
  • + Merge Sort → O(n log n) +
  • + +
  • + Quick Sort Average Case → O(n log n) +
  • +
+ +
+

Important Observation

+ +
{`O(log n) is faster than O(n)
+O(n log n) is usually better than O(n²)
+
+Lower complexity = Better performance`}
+
+
+
+ ); +}; \ No newline at end of file diff --git a/app/sem5/ada2/content/chapter3.tsx b/app/sem5/ada2/content/chapter3.tsx new file mode 100644 index 0000000..7287939 --- /dev/null +++ b/app/sem5/ada2/content/chapter3.tsx @@ -0,0 +1,315 @@ +export const Ch3Content = () => { + return ( +
+

+ This chapter explains searching and sorting algorithms. Searching helps + find data efficiently, while sorting arranges data in a particular + order. These are some of the most important topics in Algorithm Design + and Analysis. +

+ +
+ +
+

+ + Introduction to Searching + +

+ +
    +
  • + Searching means finding a required element from a collection of + data. +
  • + +
  • + Efficient searching saves time in large applications. +
  • + +
  • + Two common searching techniques are Linear Search and Binary Search. +
  • + +
  • + Binary Search is faster but requires sorted data. +
  • +
+ +
+

Example

+ +
{`Find 25 in array:
+[10, 15, 20, 25, 30]
+
+Result → Element found at index 3`}
+
+
+ +
+ +
+

+ + Linear Search + +

+ +
    +
  • + Linear Search checks elements one by one. +
  • + +
  • + It works on both sorted and unsorted arrays. +
  • + +
  • + Easy to understand and implement. +
  • + +
  • + Time Complexity = O(n) +
  • +
+ +
+

Linear Search Logic

+ +
{`for each element in array
+   if element == target
+      return found`}
+
+
+ +
+ +
+

+ + Binary Search + +

+ +
    +
  • + Binary Search works only on sorted arrays. +
  • + +
  • + It repeatedly divides the array into two halves. +
  • + +
  • + Faster than Linear Search for large inputs. +
  • + +
  • + Time Complexity = O(log n) +
  • +
+ +
+

Binary Search Idea

+ +
{`Middle element checked first
+
+If target < middle → search left half
+If target > middle → search right half`}
+
+ +
+

+ Exam Tip: Binary Search is one of the most frequently asked + algorithms in coding interviews. +

+
+
+ +
+ +
+

+ + Introduction to Sorting + +

+ +
    +
  • + Sorting means arranging data in ascending or descending order. +
  • + +
  • + Sorting improves searching and data management efficiency. +
  • + +
  • + Different sorting algorithms have different speeds and approaches. +
  • + +
  • + Some algorithms are simple while others are highly optimized. +
  • +
+ +
+

Example

+ +
{`Unsorted → [5, 2, 8, 1]
+
+Sorted → [1, 2, 5, 8]`}
+
+
+ +
+ +
+

+ + Bubble Sort + +

+ +
    +
  • + Bubble Sort repeatedly swaps adjacent elements if they are in the + wrong order. +
  • + +
  • + Larger elements move toward the end after each pass. +
  • + +
  • + Very easy to understand but inefficient for large data. +
  • + +
  • + Time Complexity = O(n²) +
  • +
+ +
+

Bubble Sort Idea

+ +
{`Compare adjacent elements
+Swap if left > right
+Repeat until array becomes sorted`}
+
+
+ +
+ +
+

+ + Selection Sort + +

+ +
    +
  • + Selection Sort repeatedly selects the smallest element. +
  • + +
  • + The smallest element is placed at the correct position. +
  • + +
  • + Number of swaps is less compared to Bubble Sort. +
  • + +
  • + Time Complexity = O(n²) +
  • +
+ +
+

Selection Sort Process

+ +
{`Find smallest element
+Swap with first unsorted position
+Repeat for remaining array`}
+
+
+ +
+ +
+

+ + Insertion Sort + +

+ +
    +
  • + Insertion Sort places each element in its correct position. +
  • + +
  • + Works similar to arranging playing cards. +
  • + +
  • + Efficient for small or nearly sorted arrays. +
  • + +
  • + Time Complexity = O(n²) +
  • +
+ +
+

Insertion Sort Idea

+ +
{`Take one element at a time
+Insert it into the sorted portion
+Repeat until all elements are sorted`}
+
+
+ +
+ +
+

+ + Merge Sort and Quick Sort + +

+ +
    +
  • + Merge Sort uses Divide and Conquer technique. +
  • + +
  • + It divides the array into smaller parts and merges them in sorted + order. +
  • + +
  • + Quick Sort selects a pivot element and partitions the array. +
  • + +
  • + Both are faster than simple sorting algorithms for large inputs. +
  • + +
  • + Average Time Complexity = O(n log n) +
  • +
+ +
+

+ Merge Sort is stable and predictable, while Quick Sort is usually + faster in practice. +

+
+
+
+ ); +}; \ No newline at end of file diff --git a/app/sem5/ada2/content/chapter4.tsx b/app/sem5/ada2/content/chapter4.tsx new file mode 100644 index 0000000..27b8106 --- /dev/null +++ b/app/sem5/ada2/content/chapter4.tsx @@ -0,0 +1,243 @@ +export const Ch4Content = () => { + return ( +
+

+ This chapter explains the Divide and Conquer technique. It is a powerful + problem-solving method where a large problem is divided into smaller + subproblems, solved separately, and then combined to get the final + answer. +

+ +
+ +
+

+ + Introduction to Divide and Conquer + +

+ +
    +
  • + Divide and Conquer breaks a problem into smaller subproblems. +
  • + +
  • + Each subproblem is solved independently. +
  • + +
  • + The results are combined to form the final solution. +
  • + +
  • + It is widely used in efficient algorithms. +
  • +
+ +
+

Basic Steps

+ +
{`1. Divide the problem
+2. Solve smaller subproblems
+3. Combine the solutions`}
+
+
+ +
+ +
+

+ + Advantages of Divide and Conquer + +

+ +
    +
  • + Reduces problem complexity. +
  • + +
  • + Makes algorithms faster and more efficient. +
  • + +
  • + Works well for recursive solutions. +
  • + +
  • + Useful for large datasets and complex problems. +
  • +
+ +
+

+ Many advanced algorithms like Merge Sort and Quick Sort use Divide + and Conquer. +

+
+
+ +
+ +
+

+ + Binary Search using Divide and Conquer + +

+ +
    +
  • + Binary Search repeatedly divides the array into halves. +
  • + +
  • + It works only on sorted arrays. +
  • + +
  • + Search space becomes smaller after each step. +
  • + +
  • + Time Complexity = O(log n) +
  • +
+ +
+

Binary Search Process

+ +
{`Check middle element
+
+If target is smaller → go left
+If target is larger  → go right`}
+
+
+ +
+ +
+

+ + Merge Sort + +

+ +
    +
  • + Merge Sort divides the array into smaller halves. +
  • + +
  • + Each half is sorted recursively. +
  • + +
  • + Sorted halves are merged together. +
  • + +
  • + Time Complexity = O(n log n) +
  • + +
  • + Space Complexity = O(n) +
  • +
+ +
+

Merge Sort Example

+ +
{`[8, 4, 2, 6]
+
+Divide → [8,4] [2,6]
+Further Divide → [8] [4] [2] [6]
+
+Merge → [4,8] [2,6]
+Final Merge → [2,4,6,8]`}
+
+
+ +
+ +
+

+ + Quick Sort + +

+ +
    +
  • + Quick Sort selects a pivot element. +
  • + +
  • + Elements smaller than pivot move left. +
  • + +
  • + Elements larger than pivot move right. +
  • + +
  • + Process repeats recursively. +
  • + +
  • + Average Time Complexity = O(n log n) +
  • +
+ +
+

Quick Sort Example

+ +
{`Array → [5, 2, 7, 1]
+
+Pivot = 5
+
+Left Side  → [2,1]
+Right Side → [7]
+
+Sorted Array → [1,2,5,7]`}
+
+
+ +
+ +
+

+ + Divide and Conquer vs Brute Force + +

+ +
    +
  • + Brute Force tries every possible solution directly. +
  • + +
  • + Divide and Conquer solves smaller parts separately. +
  • + +
  • + Divide and Conquer is usually faster and more optimized. +
  • + +
  • + It is better for handling large problems efficiently. +
  • +
+ +
+

+ Easy Trick: Divide and Conquer = Divide → Solve → Combine. +

+
+
+
+ ); +}; \ No newline at end of file diff --git a/app/sem5/ada2/content/chapter5.tsx b/app/sem5/ada2/content/chapter5.tsx new file mode 100644 index 0000000..e3bd61a --- /dev/null +++ b/app/sem5/ada2/content/chapter5.tsx @@ -0,0 +1,237 @@ +export const Ch5Content = () => { + return ( +
+

+ The Greedy Method is a powerful algorithmic paradigm used to solve optimization problems. + It builds up a solution piece by piece, always choosing the next option that offers the + most obvious and immediate benefit (the "locally optimal" choice), with the hope that + these steps lead to the best overall solution (the "globally optimal" choice). +

+ +
+ +
+

+ + Introduction to Greedy Method + +

+ +
    +
  • + Makes the best choice available at the current moment without looking ahead. +
  • + +
  • + It is a "shortsighted" approach because it never reconsiders past decisions. +
  • + +
  • + Highly efficient and fast, making it ideal for large-scale data processing. +
  • + +
  • + Works perfectly for problems that exhibit the Greedy Choice Property and Optimal Substructure. +
  • +
+ +
+

Basic Core Strategy

+ +
{`1. Feasible: Check if the choice satisfies the constraints
+2. Locally Optimal: Pick the best candidate from the remaining pool
+3. Unalterable: Once added to the solution, a choice cannot be changed`}
+
+
+ +
+ +
+

+ + Advantages and Disadvantages + +

+ +
    +
  • + Advantage: Very simple to design, implement, and debug. +
  • + +
  • + Advantage: Executes significantly faster than Dynamic Programming or Brute Force. +
  • + +
  • + Disadvantage: It can get stuck in local optima and fail to find the global maximum or minimum. +
  • + +
  • + Disadvantage: Proving that a greedy approach actually works mathematically can be incredibly difficult. +
  • +
+ +
+

+ Always remember: Greedy choices do not always guarantee the mathematically correct absolute answer, but they frequently give a very close approximation in record time. +

+
+
+ +
+ +
+

+ + Fractional Knapsack Problem + +

+ +
    +
  • + Unlike the 0/1 Knapsack problem, items can be broken down into smaller fractions. +
  • + +
  • + We sort items by their value-to-weight ratio: Value / Weight. +
  • + +
  • + We take as much of the highest-density item as possible before moving to the next. +
  • + +
  • + Time Complexity = O(n log n) due to the initial sorting step. +
  • +
+ +
+

Fractional Knapsack Process

+ +
{`Capacity = 50kg
+Item A: Value $60, Weight 10kg (Ratio = 6)
+Item B: Value $100, Weight 20kg (Ratio = 5)
+Item C: Value $120, Weight 30kg (Ratio = 4)
+
+1. Take all of A (10kg, $60) → 40kg left
+2. Take all of B (20kg, $100) → 20kg left
+3. Take fraction of C (20kg out of 30kg, $80)
+
+Total Value = $60 + $100 + $80 = $240`}
+
+
+ +
+ +
+

+ + Minimum Spanning Trees (MST) + +

+ +
    +
  • + Connects all vertices in a weighted graph together with the minimum total edge weight. +
  • + +
  • + Kruskal's Algorithm: Sorts all edges by weight and greedily adds the smallest edge that doesn't create a loop. +
  • + +
  • + Prim's Algorithm: Starts at a single node and greedily expands to the cheapest connected neighbor vertex. +
  • + +
  • + Both algorithms rely purely on greedy choices at each iteration. +
  • +
+ +
+

Kruskal vs Prim Execution

+ +
{`Kruskal's Approach:
+1. Sort all edges: [A-B: 1, C-D: 2, B-C: 4, A-D: 7]
+2. Pick A-B (1) → Pick C-D (2) → Pick B-C (4)
+3. Skip A-D (7) because it closes a cycle!
+
+Prim's Approach:
+1. Start at Node A → Look at neighbors
+2. Pick cheapest connection to reach a fresh node
+3. Repeat until every vertex is locked in`}
+
+
+ +
+ +
+

+ + Huffman Coding & Shortest Paths + +

+ +
    +
  • + Huffman Coding: Used for lossless data compression. It greedily combines the two least frequent characters to build a tree. +
  • + +
  • + Characters used most often get shorter binary codes, saving storage space. +
  • + +
  • + Dijkstra's Algorithm: Finds the shortest path from a single source node to all other nodes in a graph. +
  • + +
  • + Greedily extracts the closest unvisited vertex from a priority queue to update paths. +
  • +
+ +
+

Greedy Applications Summary

+ +
{`Huffman: Frequent letters → shorter paths (fewer bits)
+Dijkstra: Always process the current closest node first
+Job Scheduling: Always pick the task with the earliest deadline`}
+
+
+ +
+ +
+

+ + Greedy Method vs Divide and Conquer + +

+ +
    +
  • + Divide and Conquer splits a problem down and combines solved parts later. +
  • + +
  • + Greedy builds a solution linearly by executing optimal paths straight through. +
  • + +
  • + Divide and Conquer utilizes explicit recursion to process sub-tasks. +
  • + +
  • + Greedy algorithms usually run inside a straightforward, single iterative loop. +
  • +
+ +
+

+ Quick Formula: Greedy Method = Evaluate Options → Pick Best Now → Move Forward Permanently. +

+
+
+
+ ); +}; \ No newline at end of file diff --git a/app/sem5/ada2/content/chapter6.tsx b/app/sem5/ada2/content/chapter6.tsx new file mode 100644 index 0000000..92d50d9 --- /dev/null +++ b/app/sem5/ada2/content/chapter6.tsx @@ -0,0 +1,204 @@ +export const Ch6Content = () => { + return ( +
+

+ Dynamic Programming (DP) is an advanced algorithmic technique used to solve complex optimization problems. + It works by breaking a problem down into simpler, overlapping subproblems, solving each subproblem exactly + once, and storing their solutions in a table so that you never have to recompute the same answer twice. +

+ +
+ +
+

+ + Core Prerequisites for Dynamic Programming + +

+ +
    +
  • + Overlapping Subproblems: The problem can be broken down into smaller subproblems which are reused multiple times. +
  • + +
  • + Optimal Substructure: The optimal solution to the main problem can be constructed directly from the optimal solutions of its subproblems. +
  • + +
  • + Data Storage: Uses a dedicated cache data structure (like an array or hash map) to hold answers. +
  • + +
  • + Time-Space Tradeoff: It consumes memory space in exchange for drastically reducing exponential time complexities down to polynomial time. +
  • +
+ +
+

The Problem with Naive Recursion

+ +
{`Standard Fibonacci Recursion Tree for F(5):
+                 F(5)
+               /      \\
+            F(4)       F(3)
+           /    \\     /    \\
+         F(3)  F(2)  F(2)  F(1)
+
+Notice how F(3) and F(2) are computed multiple times!
+Dynamic Programming fixes this by saving the first computed result.`}
+
+
+ +
+ +
+

+ + The Two Approaches: Memoization vs Tabulation + +

+ +
    +
  • + Top-Down (Memoization): You start with the main problem and solve it recursively. Before evaluating a subproblem, you check if its answer is already in your cache. +
  • + +
  • + Bottom-Up (Tabulation): Avoids recursion entirely. You start by solving the smallest possible subproblems first, filling up an iterative table from left to right. +
  • + +
  • + Memoization suffers from recursive call stack overhead, which can cause stack overflow errors on huge datasets. +
  • + +
  • + Tabulation is generally faster and cleaner because it utilizes straightforward, iterative array indexing loops. +
  • +
+ +
+

+ Mental Shortcut: Memoization is "Lazy" (computes values only when absolutely requested), while Tabulation is "Eager" (pre-computes all sub-states systematically from the ground up). +

+
+
+ +
+ +
+

+ + Classic Application: 0/1 Knapsack Problem + +

+ +
    +
  • + Unlike the Fractional Knapsack problem, items cannot be broken into smaller fractions. You must either take an item (1) or leave it completely (0). +
  • + +
  • + The Greedy approach completely fails here because choosing the local maximum value might lock out room for a better combined set. +
  • + +
  • + DP handles this by building a 2D grid tracking `dp[item_index][remaining_capacity]`. +
  • + +
  • + Time & Space Complexity: O(n * W), where n is the number of items and W is the total target weight capacity. +
  • +
+ +
+

0/1 Knapsack Decisions

+ +
{`For each item, we evaluate two distinct sub-states:
+
+Option 1: Exclude the item
+→ Max profit remains the same as the previous item's capacity state.
+
+Option 2: Include the item (if weight allows)
+→ Current item value + Max profit of the remaining weight capacity.
+
+DP State Equation: dp[i][w] = max(dp[i-1][w], val[i-1] + dp[i-1][w - wt[i-1]])`}
+
+
+ +
+ +
+

+ + Classic Application: Longest Common Subsequence (LCS) + +

+ +
    +
  • + LCS finds the longest subsequence present in two distinct strings in the exact same relative order (characters do not need to be consecutive). +
  • + +
  • + Essential for text diff tools, spell checkers, and bioinformatics gene sequence matching. +
  • + +
  • + If characters match, the current grid block increments the diagonal cell state value by 1. +
  • + +
  • + If characters mismatch, the grid cell pulls the maximum value from either its top or its left neighbor cell. +
  • +
+ +
+

LCS Grid Matching Logic

+ +
{`String 1 = "ABCD", String 2 = "ACBD"
+
+If String1[i] == String2[j]:
+    LCS[i][j] = 1 + LCS[i-1][j-1]
+Else:
+    LCS[i][j] = max(LCS[i-1][j], LCS[i][j-1])
+
+Final Output Value yields 3 (Subsequence: "ABD" or "ACD")`}
+
+
+ +
+ +
+

+ + Algorithmic Paradigm Matrix: DP vs Greedy vs Divide & Conquer + +

+ +
    +
  • + Divide & Conquer: Splits problems into independent subproblems (e.g., Merge Sort splits completely distinct array halves). +
  • + +
  • + Greedy Method: Makes a irreversible, localized selection at each step with no backtracking capability. +
  • + +
  • + Dynamic Programming: Extensively searches all dependent overlapping paths but tracks answers systematically to guarantee global optimality. +
  • + +
  • + DP is usually selected when a greedy strategy fails to prove mathematically stable or correct across varying test conditions. +
  • +
+ +
+

+ Summary Formula: Dynamic Programming = Smart Recursion + Storing Shared State Data Results. +

+
+
+
+ ); +}; \ No newline at end of file diff --git a/app/sem5/ada2/content/chapter7.tsx b/app/sem5/ada2/content/chapter7.tsx new file mode 100644 index 0000000..3b32caa --- /dev/null +++ b/app/sem5/ada2/content/chapter7.tsx @@ -0,0 +1,163 @@ +export const Ch7Content = () => { + return ( +
+

+ Graph algorithms are fundamental tools used to solve complex network problems. They power modern + systems behind routing engines like Google Maps, social media connection graphs, recommendation + systems, and network communication structures by evaluating objects and the relationships between them. +

+ +
+ +
+

+ Understanding Graph Anatomy +

+ +
    +
  • + Vertices (Nodes): Discrete objects or entities within the system (e.g., cities, users, or web pages). +
  • + +
  • + Edges (Connections): Linkages between nodes. They can be Directed (one-way relationship) or Undirected (mutual connection). +
  • + +
  • + Weighted vs. Unweighted: Edges can carry data attributes like distance, traffic capacity, or cost (Weighted), or simply denote a baseline link (Unweighted). +
  • + +
  • + Representation: Handled in code via an Adjacency Matrix (a 2D grid ideal for dense graphs) or an Adjacency List (an array of lists ideal for memory savings in sparse graphs). +
  • +
+ +
+

Graph Visual Representations

+ +
{`Visual Structure:
+  (A)---[5]---(B)       Vertices = {A, B, C, D}
+   |           |        Edges    = {(A,B,5), (A,C,2), (B,D,1), (C,D,8)}
+  [2]         [1]
+   |           |        Adjacency List Structure:
+  (C)---[8]---(D)       A → [B: 5, C: 2] | B → [A: 5, D: 1]`}
+
+
+ +
+ +
+

+ + Breadth-First Search (BFS) + +

+ +
    +
  • + Explores a graph level-by-level, visiting all immediate neighbors of a node before moving deeper down. +
  • + +
  • + Data Structure: Implemented using a First-In-First-Out (FIFO) Queue. +
  • + +
  • + Guarantees finding the absolute shortest path on unweighted or uniform-edge networks. +
  • + +
  • + Time Complexity: O(V + E) where V is vertices and E is edges. +
  • +
+ +
+

BFS Traversal Process

+ +
{`Queue State Tracing (Starting at Node A):
+1. Initialize: Push root node A to Queue → [A], Visit tracker: {A}
+2. Dequeue A: Look at A's neighbors (B, C). Push unvisited neighbors to Queue → [B, C]
+3. Dequeue B: Look at neighbors. Push unvisited to Queue → [C, D]
+4. Dequeue C: Neighbors already added. Queue remains → [D]
+
+Final Discovery Order: A → B → C → D (Radial Expansion)`}
+
+
+ +
+ +
+

+ + Depth-First Search (DFS) + +

+ +
    +
  • + Dives along a single path as deeply as possible before backtracking to check remaining side branches. +
  • + +
  • + Data Structure: Implemented using a Last-In-First-Out (LIFO) Stack or implicit functional recursion. +
  • + +
  • + Commonly applied in topological sorting, cycle detection, and resolving dependencies (e.g., build tool compilations). +
  • + +
  • + Space Complexity: O(V) in worst-case, reflecting maximum recursive call stack depths. +
  • +
+ +
+

DFS Traversal Process

+ +
{`Recursive Execution Path (Starting at Node A):
+1. Visit Node A → Mark visited.
+2. Step forward to first unvisited child (Node B).
+3. Step forward from B to its unvisited child (Node D).
+4. Hit Dead-End at D → Backtrack up to B → Backtrack up to A.
+5. Move to next unvisited branch from A → Visit Node C.
+
+Final Discovery Order: A → B → D → C (Linear Drilling)`}
+
+
+ +
+ +
+

+ + Shortest Path & Network Optimization + +

+ +
    +
  • + Dijkstra's Algorithm: Solves single-source shortest paths on weighted graphs using a greedy minimum priority queue. Cannot handle negative weights. +
  • + +
  • + Bellman-Ford Algorithm: Slower alternative to Dijkstra, but safely accommodates negative edge weights and flags dangerous infinite negative cycles. +
  • + +
  • + Minimum Spanning Trees (MST): Spans every vertex in a graph with the absolute lowest combined cumulative edge cost using Prim's or Kruskal's methodologies. +
  • + +
  • + Crucial for physical network routing, utility pipe installations, and minimizing electrical circuit trace connections. +
  • +
+ +
+

+ Core Traversal Rule: Use BFS if you want the shortest path on unweighted maps (like minimum steps in a puzzle). Use DFS if you need to systematically explore every single state node layout or map dead-ends. +

+
+
+
+ ); +}; \ No newline at end of file diff --git a/app/sem5/ada2/content/chapter8.tsx b/app/sem5/ada2/content/chapter8.tsx new file mode 100644 index 0000000..6d978ec --- /dev/null +++ b/app/sem5/ada2/content/chapter8.tsx @@ -0,0 +1,203 @@ +export const Ch8Content = () => { + return ( +
+

+ Backtracking and Branch & Bound are state-space search paradigms used to solve difficult + combinatorial problems where a brute-force calculation is completely impossible. Both methods + systematically explore a tree-like solution space, but they employ radically different strategies + for navigating, pruning, and optimizing the paths they traverse. +

+ +
+ +
+

+ + Understanding Backtracking (Depth-First Strategy) + +

+ +
    +
  • + Builds candidate solutions incrementally and abandons a path ("backtracks") as soon as it determines the path cannot lead to a valid solution. +
  • + +
  • + Traversal Order: Relies on a Depth-First Search (DFS) approach to explore a single potential outcome path to its absolute limit. +
  • + +
  • + Pruning: Uses bounding conditions or explicit constraint checks to drop an invalid path immediately, avoiding checking millions of sub-choices. +
  • + +
  • + Ideal for decision problems, constraint satisfaction problems, or finding all possible valid configurations (e.g., puzzles, mazes). +
  • +
+ +
+

Backtracking Algorithm Template

+ +
{`function solve(node):
+    if is_complete_solution(node):
+        return true / print_solution
+        
+    for each choice in get_available_choices(node):
+        if is_valid(choice):
+            make_choice(choice)      // Step forward
+            if solve(next_node): 
+                return true
+            undo_choice(choice)      // Backtrack (Step backward)
+            
+    return false`}
+
+
+ +
+ +
+

+ + Classic Backtracking Example: The N-Queens Problem + +

+ +
    +
  • + The goal is to place $N$ chess queens on an $N \times N$ chessboard such that no two queens attack each other. +
  • + +
  • + A naive brute-force search would examine billions of placement combinations for even moderate board configurations. +
  • + +
  • + Backtracking places queens row by row. If a queen cannot be safely set in the current row, the algorithm stops, backs up to the prior row, shifts that queen, and tries again. +
  • + +
  • + Constraint Checks: Validates row, column, and both diagonal lines before committing to a tile placement. +
  • +
+ +
+

4-Queens State Space Exploration

+ +
{`Row 1: Place Queen at (1,1)
+Row 2: Check (2,1) X, Check (2,2) X, Place Queen at (2,3)
+Row 3: Check (3,1) X, (3,2) X, (3,3) X, (3,4) X → Dead End!
+
+[Backtrack to Row 2] → Move Queen to (2,4)
+Row 3: Can now safely place Queen at (3,2)
+Row 4: Check choices... Continue process until entire matrix resolves.`}
+
+
+ +
+ +
+

+ + Understanding Branch & Bound (Breadth/Best-First Strategy) + +

+ +
    +
  • + Designed strictly for discrete optimization problems where you need to maximize profit or minimize an overall execution cost. +
  • + +
  • + Traversal Order: Typically avoids DFS, opting for Breadth-First Search (BFS) or a Best-First Search using a priority queue. +
  • + +
  • + Bounding Functions: Calculates a mathematical "bound" value at every single node to evaluate the best possible outcome that branch could produce. +
  • + +
  • + If a node's best-case bound is worse than a validated solution we already found, the entire branch is discarded instantly without exploration. +
  • +
+ +
+

Branch & Bound Pruning Logic

+ +
{`Goal: Minimize Travel Distance
+Current Best Complete Tour found = 450 miles
+
+Evaluating Node X (Partial Path):
+Calculated Lower Bound for Node X = 485 miles
+(Even in a perfect scenario, this path cannot beat 450 miles)
+
+Decision: Kill Node X and all of its sub-branches immediately.`}
+
+
+ +
+ +
+

+ + Classic Branch & Bound Application: Traveling Salesperson (TSP) + +

+ +
    +
  • + The objective is to find the absolute shortest possible route that visits every city exactly once and returns to the origin point. +
  • + +
  • + As nodes expand, a cost-reduction matrix calculates a guaranteed minimum lower bound for completing the remainder of the trip. +
  • + +
  • + Using a Least-Cost (LC) Branch & Bound approach, the algorithm always opens up the node possessing the lowest cost bound first. +
  • + +
  • + This allows it to ignore hundreds of thousands of high-cost paths, finishing dramatically faster than standard recursion. +
  • +
+ +
+

Comparison: Backtracking vs. Branch & Bound

+ +
{`Feature          | Backtracking             | Branch & Bound
+-------------------------------------------------------------------
+Search Tree      | Depth-First Search (DFS) | BFS or Best-First (PQ)
+Target Problems  | Decision / Constraint    | Pure Optimization
+Memory Demand    | Low (Call Stack only)    | High (Tracks Active Nodes)
+Goal             | Find any/all solutions   | Find single optimal solution`}
+
+
+ +
+ +
+

+ + Algorithmic Selection Rule + +

+ +
    +
  • + Use Backtracking if you need to generate all permutations, solve matching puzzles, or navigate physical maze paths where tracking the current stack is fast. +
  • + +
  • + Use Branch & Bound when managing business optimization problems with deep cost matrices like item scheduling, routing logistics, or the 0/1 Knapsack problem. +
  • +
+ +
+

+ Quick Blueprint: Backtracking explores blindly down a line until it hits an invalid wall. Branch & Bound looks across options and mathematically proves which branches are worth walking down. +

+
+
+
+ ); +}; \ No newline at end of file diff --git a/app/sem5/ada2/layout.tsx b/app/sem5/ada2/layout.tsx new file mode 100644 index 0000000..5f50607 --- /dev/null +++ b/app/sem5/ada2/layout.tsx @@ -0,0 +1,43 @@ +// app/sem4/ada/layout.tsx + +import Navbar from "../../components/navbar"; +import Sidebar from "./components/sidebar"; + +export const metadata = { + title: "Algorithm Design and Analysis | openCSE", + + description: + "Free and Open Documentations for Algorithm Design and Analysis", +}; + +export default function Sem4ADALayout({ + children, +}: { + children: React.ReactNode; +}) { + + return ( +
+ + {/* Navbar */} + + +
+ + {/* Sidebar */} + + + {/* Main Content */} +
+ +
+ {children} +
+ +
+ +
+ +
+ ); +} \ No newline at end of file diff --git a/app/sem5/ada2/page.tsx b/app/sem5/ada2/page.tsx new file mode 100644 index 0000000..2b771af --- /dev/null +++ b/app/sem5/ada2/page.tsx @@ -0,0 +1,9 @@ +// app/page.tsx +export default function Home() { + return ( +
+

Welcome to the Tutorial

+

Select a chapter from the sidebar to get started.

+
+ ); +}