Nepal's open education portal

EduNepal

Data Structures and Algorithms — Complete Course Notes (BCA 3rd Sem)

Comprehensive lecture notes on asymptotic analysis, stacks, queues, linked lists, trees, graphs, and sorting algorithms for TU BCA.

Data Structures and Algorithms · CACS201 · Semester 3

BCA Curriculum 2079

Course Code: CACS201 | Tribhuvan University BCA 3rd Semester Curriculum.


1. Algorithm Analysis & Asymptotic Notations

The efficiency of an algorithm is measured in terms of Time Complexity (CPU execution time) and Space Complexity (memory storage consumed) as a function of input size n.

Asymptotic Notations:

  1. Big O (O): Upper bound. Represents worst-case running time: f(n) ≤ c · g(n) for all n ≥ n0.
  2. Big Omega (Ω): Lower bound. Represents best-case running time: f(n) ≥ c · g(n).
  3. Big Theta (\Theta): Tight bound. Represents average-case when upper and lower bounds coincide.

2. Linear Data Structures: Stack ADT

A stack is a Last-In, First-Out (LIFO) abstract data structure where insertions and deletions happen only at one end called the top.

Primary Operations:

  • push(item): Add an element to the top. Checks for Stack Overflow.
  • pop(): Remove the element from the top. Checks for Stack Underflow.
  • peek(): Inspect the current top element without removing it.

```c #define MAX 100 int stack[MAX]; int top = -1;

void push(int item) { if (top == MAX - 1) { printf("Stack Overflow!\n"); return; } stack[++top] = item; }

int pop() { if (top == -1) { printf("Stack Underflow!\n"); return -1; } return stack[top--]; } ```


3. Non-Linear Structures: Binary Search Tree (BST)

A Binary Search Tree is a binary tree where:

  • For every node N, values in the left subtree are strictly less than N.key.
  • Values in the right subtree are strictly greater than N.key.
  • Inorder traversal of a BST always yields sorted keys!

```c struct Node { int key; struct Node left, right; };

struct Node* search(struct Node* root, int key) { if (root NULL || root->key key) return root; if (key < root->key) return search(root->left, key); return search(root->right, key); } ```


4. Sorting Algorithms Comparison

AlgorithmBest CaseAverage CaseWorst CaseSpace ComplexityStable?
Bubble SortO(n)O(n2)O(n2)O(1)Yes
Insertion SortO(n)O(n2)O(n2)O(1)Yes
Merge SortO(n \log n)O(n \log n)O(n \log n)O(n)Yes
Quick SortO(n \log n)O(n \log n)O(n2)O(\log n)No
Heap SortO(n \log n)O(n \log n)O(n \log n)O(1)No

Related video lessons

View all →

Practice questions

View all →
  • What is the worst-case time complexity of Quick Sort algorithm? (a) O(n) (b) O(n log n) (c) O(n^2) (d) O(log n)objective · 1 marks
  • Differentiate between Linear Queue and Circular Queue. Explain how modulo arithmetic prevents false overflow.short · 5 marks

View all questions for this subject →

← Back to all notes