diff --git a/app/components/subjects.tsx b/app/components/subjects.tsx index 489c3b3..ce00fa7 100644 --- a/app/components/subjects.tsx +++ b/app/components/subjects.tsx @@ -123,7 +123,7 @@ const subjectCodes: Record = { }; // Available subjects -const available = ["ep", "c", "em1", "em2", "oops","os", "ml"]; +const available = ["ep", "c", "em1", "em2", "oops", "dsc", "os", "ml"]; export default function SubjectsSection() { return ( diff --git a/app/sem2/dsc/[chapter]/page.tsx b/app/sem2/dsc/[chapter]/page.tsx new file mode 100644 index 0000000..0e6c2b9 --- /dev/null +++ b/app/sem2/dsc/[chapter]/page.tsx @@ -0,0 +1,109 @@ +import Link from "next/link"; +import { Righteous } from "next/font/google"; + +import { Ch0Content } from "../content/chapter0"; +import { Ch1Content } from "../content/chapter1"; + +import { ArrowBigLeft, ArrowBigRight } from "lucide-react"; + +const righteous = Righteous({ + subsets: ["latin"], + weight: "400", + variable: "--font-righteous", +}); + +const chapters = [ + { id: "ch0", title: "Course Outline", component: Ch0Content }, + { id: "ch1", title: "Arrays", component: Ch1Content }, +]; + +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 ( +
+ +
+

+ Data Structures using C +

+ +

+ {chapter.title} +

+ + {/* Navigation */} +
+ {prevChapter ? ( + + Previous + + ) : ( +
+ )} + + {nextChapter ? ( + + Next + + ) : ( +
+ )} +
+ +
+ +
+ + {/* Bottom Navigation */} +
+ {prevChapter ? ( + + {prevChapter.title} + + ) : ( +
+ )} + + {nextChapter ? ( + + {nextChapter.title}{" "} + + + ) : ( +
+ )} +
+
+ ); +} diff --git a/app/sem2/dsc/components/sidebar.tsx b/app/sem2/dsc/components/sidebar.tsx new file mode 100644 index 0000000..1122746 --- /dev/null +++ b/app/sem2/dsc/components/sidebar.tsx @@ -0,0 +1,112 @@ +"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: "Arrays" }, + ]; + + const quizSlugMap: Record = { + c: "c-programming", + em1: "em1", + ep: "ep", + em2: "em2", + oops: "oops", + }; + + const subjectKey = pathname.split("/")[2] ?? ""; + const quizSlug = quizSlugMap[subjectKey]; + const quizHref = quizSlug ? `/quiz/${quizSlug}` : "/quiz"; + const quizActive = pathname.startsWith("/quiz"); + + return ( +
+ + {/* Sidebar */} + + + + +
+ ); +} diff --git a/app/sem2/dsc/content/chapter0.tsx b/app/sem2/dsc/content/chapter0.tsx new file mode 100644 index 0000000..32086e7 --- /dev/null +++ b/app/sem2/dsc/content/chapter0.tsx @@ -0,0 +1,87 @@ +export const Ch0Content = () => { + return ( +
+ +

+ Welcome to Data Structures using C. + This course introduces the concepts of organizing and storing data efficiently + using C programming. It covers fundamental data structures and algorithms + such as arrays, linked lists, stacks, queues, trees, graphs, searching, + and sorting techniques. +

+ +
+

Module I: Arrays

+
    +
  • Introduction to arrays
  • +
  • Declaration and initialization
  • +
  • Common array operations (accessing, traversal, searching, insertion, deletion, updating)
  • +
  • Applications, advantages and limitations
  • +
+
+ +
+

Module II: Linked Lists

+
    +
  • Singly linked lists
  • +
  • Doubly linked lists
  • +
  • Circular linked lists
  • +
+
+ +
+

Module III: Stacks

+
    +
  • Stack operations
  • +
  • Array implementation
  • +
  • Applications of stacks
  • +
+
+ +
+

Module IV: Queues

+
    +
  • Queue operations
  • +
  • Types of queues
  • +
  • Applications of queues
  • +
+
+ +
+

Module V: Trees

+
    +
  • Binary trees
  • +
  • Tree traversal techniques
  • +
  • Binary search trees
  • +
+
+ +
+

Module VI: Graphs

+
    +
  • Graph representation
  • +
  • Breadth First Search
  • +
  • Depth First Search
  • +
+
+ +
+

Module VII: Searching

+
    +
  • Linear Search
  • +
  • Binary Search
  • +
+
+ +
+

Module VIII: Sorting

+
    +
  • Bubble Sort
  • +
  • Selection Sort
  • +
  • Insertion Sort
  • +
+
+ +
+ ); +}; \ No newline at end of file diff --git a/app/sem2/dsc/content/chapter1.tsx b/app/sem2/dsc/content/chapter1.tsx new file mode 100644 index 0000000..e37a8da --- /dev/null +++ b/app/sem2/dsc/content/chapter1.tsx @@ -0,0 +1,293 @@ +export const Ch1Content = () => { + return ( +
+ +

+ Module I: Arrays. + Arrays are one of the most fundamental data structures in C. + They are used to store multiple elements of the same data type + in contiguous memory locations and provide efficient access + through indexes. +

+ +
+ + {/* Introduction */} +
+

+ Introduction to Arrays +

+ +

+ An array stores a collection of similar elements under a + single variable name. Each element is accessed using an index, + and indexing starts from 0 in C. +

+ +
    +
  • Stores multiple values using one variable
  • +
  • Elements occupy contiguous memory locations
  • +
  • Allows direct access through indexes
  • +
+
+ +
+ + {/* Declaration */} +
+

+ Declaration and Initialization +

+ +

+ Arrays are declared using a data type, array name and size. +

+ +
+ +
+ Code Example +
+ +
+{`int numbers[5];
+
+int values[5] = {10,20,30,40,50};`}
+          
+ +
+
+ +
+ + {/* Common Operations */} +
+

+ Common Array Operations +

+ +

+ Arrays support several common operations used to manipulate + and process elements. +

+ +
+ +
+ + {/* Accessing */} +
+

+ Accessing Elements +

+ +

+ Individual elements are accessed using indexes. +

+ +
+
+{`int arr[5]={10,20,30,40,50};
+
+printf("%d",arr[2]);`}
+          
+
+ +

+ Time Complexity: O(1) +

+
+ +
+ + {/* Traversal */} +
+

+ Traversal +

+ +

+ Traversal means visiting each element of the array one by one. +

+ +
+ +
+{`for(int i=0;i<5;i++){
+   printf("%d ",arr[i]);
+}`}
+          
+ +
+ +

+ Time Complexity: O(n) +

+ +
+ +
+ + {/* Searching */} +
+

+ Searching +

+ +

+ Searching is used to find a specific element in an array. +

+ +
+ +
+{`int key=30;
+
+for(int i=0;i<5;i++){
+   if(arr[i]==key)
+      printf("Found");
+}`}
+          
+ +
+ +

+ Time Complexity: O(n) +

+ +
+ +
+ + {/* Insertion */} +
+

+ Insertion +

+ +

+ Insertion adds a new element at a specific position by shifting + elements. +

+ +
+ +
+{`for(int i=n;i>pos;i--){
+   arr[i]=arr[i-1];
+}
+
+arr[pos]=value;`}
+          
+ +
+ +

+ Time Complexity: O(n) +

+ +
+ +
+ + {/* Deletion */} +
+

+ Deletion +

+ +

+ Deletion removes an element and shifts remaining elements. +

+ +
+ +
+{`for(int i=pos;i
+
+        
+ +

+ Time Complexity: O(n) +

+ +
+ +
+ + {/* Updating */} +
+

+ Updating Elements +

+ +

+ Updating changes an existing value using its index. +

+ +
+ +
+{`arr[1]=100;`}
+          
+ +
+ +

+ Time Complexity: O(1) +

+ +
+ +
+ + {/* Applications */} +
+

+ Applications of Arrays +

+ +
    +
  • Searching algorithms
  • +
  • Sorting algorithms
  • +
  • Matrix representation
  • +
  • Implementation of stacks and queues
  • +
+
+ +
+ + {/* Advantages */} +
+

+ Advantages of Arrays +

+ +
    +
  • Fast access using indexes
  • +
  • Easy traversal of elements
  • +
  • Efficient memory usage for fixed-size data
  • +
+
+ +
+ + {/* Limitations */} +
+

+ Limitations of Arrays +

+ +
    +
  • Fixed size once declared
  • +
  • Insertion and deletion operations are costly
  • +
  • Stores only same data type elements
  • +
+
+ +
+ ); +}; \ No newline at end of file diff --git a/app/sem2/dsc/layout.tsx b/app/sem2/dsc/layout.tsx new file mode 100644 index 0000000..b81e990 --- /dev/null +++ b/app/sem2/dsc/layout.tsx @@ -0,0 +1,24 @@ +// app/sem1/ep/layout.tsx +import Navbar from "../../components/navbar"; +import Sidebar from "./components/sidebar"; + +export const metadata = { + title: "Data Structures using C | openCSE", + description: "Data Structures using C notes and tutorials for openCSE", +}; + +export default function Sem1EpLayout({ children }: { children: React.ReactNode }) { + return ( +
+ + +
+ + +
+
{children}
+
+
+
+ ); +} diff --git a/app/sem2/dsc/page.tsx b/app/sem2/dsc/page.tsx new file mode 100644 index 0000000..2b771af --- /dev/null +++ b/app/sem2/dsc/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.

+
+ ); +} diff --git a/notes/dsa/arrays/README.md b/notes/dsa/arrays/README.md new file mode 100644 index 0000000..e7c627b --- /dev/null +++ b/notes/dsa/arrays/README.md @@ -0,0 +1,174 @@ +# Arrays in C + +## Introduction + +An array is a collection of elements of the same data type stored in contiguous memory locations. + +Arrays allow multiple values to be stored using a single variable name, making programs easier to manage and organize. + +Example: + +Instead of writing: + +```c +int a = 10; +int b = 20; +int c = 30; +``` + +We can use an array: + +```c +int numbers[3] = {10, 20, 30}; +``` + +--- + +## Syntax of Arrays + +```c +datatype array_name[size]; +``` + +Example: + +```c +int marks[5]; +``` + +This creates an integer array capable of storing 5 elements. + +--- + +## Declaration and Initialization + +```c +int numbers[5] = {1, 2, 3, 4, 5}; +``` + +--- + +## Accessing Array Elements + +Array elements are accessed using index values. + +Indexing starts from `0`. + +```c +#include + +int main() { + int numbers[3] = {10, 20, 30}; + + printf("%d\n", numbers[0]); + printf("%d\n", numbers[1]); + printf("%d\n", numbers[2]); + + return 0; +} +``` + +### Output + +```text +10 +20 +30 +``` + +--- + +## Taking Input in Arrays + +```c +#include + +int main() { + int numbers[5]; + + for(int i = 0; i < 5; i++) { + scanf("%d", &numbers[i]); + } + + printf("Array elements are:\n"); + + for(int i = 0; i < 5; i++) { + printf("%d ", numbers[i]); + } + + return 0; +} +``` + +--- + +## Advantages of Arrays + +- Easy storage of multiple values +- Fast access using index +- Simplifies code +- Useful in implementing other data structures + +--- + +## Disadvantages of Arrays + +- Fixed size +- Insertion and deletion operations can be costly +- Can only store same data type elements + +--- + +## Time Complexity + +| Operation | Time Complexity | +|------------|----------------| +| Access | O(1) | +| Search | O(n) | +| Insertion | O(n) | +| Deletion | O(n) | + +--- + +## Applications of Arrays + +- Storing marks of students +- Matrix representation +- Searching algorithms +- Sorting algorithms +- Implementing stacks and queues + +--- + +## Basic Interview Questions + +### 1. What is an array? + +An array is a collection of elements of the same data type stored in contiguous memory locations. + +### 2. What is the index of the first element in an array? + +The first element is stored at index `0`. + +### 3. What is the main limitation of arrays? + +Arrays have a fixed size. + +### 4. Can arrays store different data types together? + +No, arrays can only store elements of the same data type. + +--- + +## Practice Problems + +1. Find the largest element in an array +2. Reverse an array +3. Find the sum of all array elements +4. Search for an element in an array + +--- + +## Conclusion + +Arrays are one of the most fundamental data structures in C programming. They provide an efficient way to store and access multiple values and are widely used in programming and problem solving. \ No newline at end of file