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
Unit 3•Unit 3 of 5
Unit 3: 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--]; } ```
Data Structures and Algorithms Complete Course (freeCodeCamp)
Open lesson pageLesson videos
Related video lessons
Practice questions
- 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
