Submitted in partial fulfillment of the requirements for the course
Computer Concepts (CC) / Data Structures
Submitted By
Student Name :Ankush
Roll Number :________________
Branch :Computer Science & Engineering
Semester :________________
Subject :Computer Concepts (CC)
Guided By
Faculty Name :________________
Designation :Assistant Professor / Professor
Academic Year: 2025 ā 2026
Certificate
This is to certify that the Mini Project entitled “Data Structures in C++ ā Arrays, Stack, Sorting, and Graph Traversal” has been submitted by Ankush, Roll No. ________________, in partial fulfillment of the requirements for the course Computer Concepts (CC), Department of Computer Science & Engineering.
The work presented in this report is genuine and has been carried out by the student under the guidance of the faculty. This project is an original work and has not been submitted elsewhere for any other degree or diploma.
Student’s Signature Ankush
Faculty Signature ________________
Place: ________________ Date: ________________
Table of Contents
1. Introduction4
2. Objectives4
3. Tools & Technologies Used4
4. Array Operations5
4.1 Theory5
4.2 Algorithm5
4.3 Code5
5. Stack Operations6
5.1 Theory6
5.2 Algorithm6
5.3 Code6
6. Sorting Algorithms7
6.1 Bubble Sort7
6.2 Selection Sort7
6.3 Comparison Table7
7. Graph Traversal ā BFS & DFS8
7.1 BFS Theory & Algorithm8
7.2 DFS Theory & Algorithm8
7.3 Code9
8. Sample Output10
9. Conclusion11
10. References11
1. Introduction
Data structures are the backbone of efficient computer programming. This mini project is developed in C++ to demonstrate the implementation and working of fundamental data structures and algorithms. The project covers Arrays, Stacks, Sorting Algorithms (Bubble Sort and Selection Sort), and Graph Traversal Techniques (BFS and DFS) ā all managed through a user-friendly, menu-driven console interface.
Understanding these concepts is essential for every Computer Science student, as they form the foundation of advanced algorithms, operating systems, databases, and many real-world applications.
2. Objectives
To understand and implement basic data structures in C++ using arrays.
To implement a Stack data structure with Push, Pop, Peek, and Display operations.
To apply and compare Bubble Sort and Selection Sort algorithms.
To implement BFS (Breadth First Search) and DFS (Depth First Search) graph traversal techniques.
To perform Linear Search and compute basic statistics (Sum, Average, Min, Max) on arrays.
To develop a clean and interactive menu-driven C++ program.
3. Tools & Technologies Used
Tool / Technology
Description
C++ (C++17)
Core programming language used for implementation
GCC / G++ Compiler
Compiler used to build and run the program
VS Code / Dev-C++
IDE used for writing and testing the code
STL <queue>
Standard C++ queue used for BFS traversal
Windows OS
Operating system environment
4. Array Operations
4.1 Theory
An Array is a linear data structure that stores elements of the same data type in contiguous memory locations. Each element in an array is accessed using its index. Arrays provide O(1) access time. In this project, arrays are used to store integers inputted by the user, upon which various operations are performed.
Operations Implemented:
Sum ā Calculates the total sum of all elements.
Average ā Computes the arithmetic mean.
Maximum ā Finds the largest element.
Minimum ā Finds the smallest element.
Linear Search ā Searches for an element sequentially from index 0.
4.2 Algorithm ā Linear Search
Start from index 0.
Compare each element with the target key.
If match found, return the index and print “FOUND”.
If end of array is reached without match, print “NOT FOUND”.
Time Complexity: Best Case ā O(1) | Worst Case ā O(n) | Average ā O(n/2)
4.3 Code Snippet
void arrayOps() {
int n, arr[100], sum = 0;
cout << “Enter number of elements: “;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
sum += arr[i];
}
int maxVal = arr[0], minVal = arr[0];
for (int i = 1; i < n; i++) {
if (arr[i] > maxVal) maxVal = arr[i];
if (arr[i] < minVal) minVal = arr[i];
}
cout << “Sum: ” << sum << ” Average: ” << (float)sum/n;
cout << ” Max: ” << maxVal << ” Min: ” << minVal;
}
5. Stack Operations
5.1 Theory
A Stack is a linear data structure that follows the LIFO (Last In First Out) principle ā the element inserted last is the first one to be removed. Think of it like a stack of plates: you add and remove from the top.
Operations Implemented:
Push ā Insert an element on top of the stack.
Pop ā Remove the top element from the stack.
Peek ā View the top element without removing it.
Display ā Show all elements from top to bottom.
Overflow Check ā Prevent push when stack is full.
Underflow Check ā Prevent pop when stack is empty.
Stack is implemented using a plain array with a top pointer variable. Time Complexity: Push ā O(1), Pop ā O(1), Peek ā O(1).
5.2 Algorithm
PUSH: If top == SIZE-1, print Overflow. Else, increment top and insert element at stackArr[top].
POP: If top == -1, print Underflow. Else, print stackArr[top] and decrement top.
PEEK: If top == -1, stack is empty. Else, return stackArr[top] without modifying top.
DISPLAY: Traverse from index top down to 0 and print each element.
Bubble Sort is a simple comparison-based sorting algorithm. It works by repeatedly swapping adjacent elements if they are in the wrong order. The largest element “bubbles up” to its correct position in each pass.
Algorithm:
Repeat for i = 0 to n-2:
For j = 0 to n-i-2:
If arr[j] > arr[j+1], swap them.
If no swap occurred in a pass, array is sorted ā break early.
void bubbleSort(int arr[], int n) {
for (int i = 0; i < n-1; i++) {
bool swapped = false;
for (int j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
swap(arr[j], arr[j+1]);
swapped = true;
}
}
if (!swapped) break; // Already sorted
}
}
6.2 Selection Sort
Selection Sort works by selecting the minimum element from the unsorted portion and placing it at the beginning. It performs fewer swaps compared to Bubble Sort.
Algorithm:
Repeat for i = 0 to n-2:
Find the index of minimum element in arr[i..n-1].
Swap arr[i] with arr[minIdx].
void selectionSort(int arr[], int n) {
for (int i = 0; i < n-1; i++) {
int minIdx = i;
for (int j = i+1; j < n; j++)
if (arr[j] < arr[minIdx]) minIdx = j;
swap(arr[i], arr[minIdx]);
}
}
6.3 Comparison Table
Parameter
Bubble Sort
Selection Sort
Best Case
O(n) (with optimization)
O(n²)
Worst Case
O(n²)
O(n²)
Average Case
O(n²)
O(n²)
Space Complexity
O(1)
O(1)
Swaps
Many
At most n-1
Stable
Yes
No
7. Graph Traversal ā BFS & DFS
7.1 BFS ā Breadth First Search
BFS traverses a graph level by level, starting from a source node (node 0). It uses a Queue (FIFO) to keep track of nodes to visit. BFS is used in shortest path finding, web crawlers, and network broadcasting.
Algorithm:
Mark source node as visited, enqueue it.
While queue is not empty: Dequeue a node, print it.
For each unvisited neighbor of the node: mark visited, enqueue it.
Repeat until queue is empty.
Data Structure Used: Queue |
Time Complexity: O(V + E) |
Space Complexity: O(V)
7.2 DFS ā Depth First Search
DFS traverses a graph by going as deep as possible from a node before backtracking. It uses Recursion (Call Stack) internally. DFS is used in topological sorting, cycle detection, and maze solving.
Algorithm (Recursive):
Mark the starting node as visited and print it.
For each neighbor of the current node:
If not visited, recursively call DFS on that neighbor.
Data Structure Used: Recursion (Stack) |
Time Complexity: O(V + E) |
Space Complexity: O(V)
7.3 BFS & DFS Comparison
Parameter
BFS
DFS
Data Structure
Queue (FIFO)
Stack / Recursion
Traversal
Level by Level
Depth First
Time Complexity
O(V + E)
O(V + E)
Memory Usage
More (stores all nodes at level)
Less (path only)
Best For
Shortest Path
Cycle Detection, Topological Sort
7.4 Code Snippet
// BFS using queue
void bfs() {
queue<int> q;
for (int i = 0; i < n; i++) visited[i] = 0;
q.push(0); visited[0] = 1;
while (!q.empty()) {
int node = q.front(); q.pop();
cout << node << ” “;
for (int i = 0; i < n; i++)
if (adj[node][i]==1 && visited[i]==0)
{ q.push(i); visited[i] = 1; }
}
}
// DFS using recursion
void dfsHelper(int node) {
visited[node] = 1;
cout << node << ” “;
for (int i = 0; i < n; i++)
if (adj[node][i]==1 && visited[i]==0)
dfsHelper(i);
}
8. Sample Output
Main Menu
============================================
CC MINI PROJECT – DATA STRUCTURES
============================================
===== MAIN MENU =====
1. Array Operations (Sum, Max, Min, Search)
2. Stack Operations (Push, Pop, Peek, Display)
3. Sorting (Bubble Sort + Selection Sort)
4. Graph Traversal (BFS + DFS)
5. Exit
———————
Enter your choice: 1
Array Operations Output
Enter number of elements (max 100): 5
Enter 5 elements:
10 45 23 7 89
—– Array Results —–
Elements : 10 45 23 7 89
Sum : 174
Average : 34.8
Maximum : 89
Minimum : 7
Enter element to search (Linear Search): 23
[FOUND] Element 23 found at index 2.
Stack Operations Output
— Stack Menu —
1. Push 2. Pop 3. Peek 4. Display 5. Back
Enter choice: 1
Enter value to push: 50
[SUCCESS] 50 pushed onto stack.
Enter choice: 4
Stack (Top –> Bottom): 50
Sorting Output
Enter number of elements (max 100): 5
Enter 5 elements:
64 34 25 12 22
Original Array : 64 34 25 12 22
Bubble Sort : 12 22 25 34 64
Selection Sort : 12 22 25 34 64
Graph BFS & DFS Output
Enter number of nodes: 4
Enter adjacency matrix:
0 1 1 0
1 0 0 1
1 0 0 1
0 1 1 0
BFS Traversal: 0 1 2 3
DFS Traversal: 0 1 3 2
9. Conclusion
This mini project successfully demonstrates the implementation of fundamental data structures and algorithms in C++. Through this project, the following key learnings were achieved:
Arrays provide a simple and efficient way to store and manipulate sequential data.
The Stack (LIFO) data structure is fundamental in recursion, expression evaluation, and undo operations.
Bubble Sort and Selection Sort are foundational comparison-based sorting algorithms, each with specific advantages.
BFS and DFS provide complementary strategies for graph traversal with distinct use-cases.
A menu-driven program improves usability and makes the implementation interactive and practical.
This project helped in building a strong conceptual foundation in data structures, which is essential for pursuing advanced topics like Tree traversal, Dynamic Programming, and Graph Algorithms.
10. References
Book: “Data Structures and Algorithms in C++” by Michael T. Goodrich, Roberto Tamassia, David M. Mount.
Book: “Introduction to Algorithms” by Thomas H. Cormen (CLRS) ā MIT Press.
Book: “Let Us C++” by Yashavant Kanetkar ā BPB Publications.