10/16/2025
Data Structures
Algorithms
Assignment 1
M Sameer Malik
NASTP INSTITUTE OF INFORMATION AND TECHNOLOGY
Data Structures Algorithms | Sameer Malik
Contents
Question 1 ..................................................................................................................................2
Question 2: ...................................................................................................................................3
Output: ....................................................................................................................................3
Source code: ...........................................................................................................................3
pg. 1
Data Structures Algorithms | Sameer Malik
Question 1
Q1) Distinguish between any two data structures through explaining difference in their
applicability in cybersecurity-related computer systems, and support your comparison with at
least
two relevant examples. [CLO-1, C2, PLO2]
Data Structures:
1)Stack
2)Queue
Working Principle:
Stack works on LIFO, which implies last in first out.
Queue works on FIFO, which implies first in first out.
Accessibility:
In stack-based structures only the top element is accessible.
In Queue based structures only the last inserted item is first removed.
Stack in Cyber Security:
Buffer Overflow
Threat Actors abuse stack by exploiting stack overflow vulnerabilities.
By manipulating the stack frames, they redirect the program to malicious code.
Queue in Cyber Security:
Network Packet handling
The incoming network packets are stored in a queue.
They are processed in the order they come FIFO.
Conclusion
Stack is ideal when tracking execution order in reverse, handling function calls or
memory exploits.
Queue is ideal when handling network traffic or tasks in order, ensuring fairness and
performance.
pg. 2
Data Structures Algorithms | Sameer Malik
Question 2:
Comprehend your object-oriented concepts providing solution for any management
system of your choice. You can design any system (e.g., Library Management System, Student
Management System, or Inventory Management System) using Object-Oriented Programming
(OOP) principles. Your implementation should include:
• At least two classes with relevant attributes and methods.
• Object creation to represent real-world entities.
• Arrays to store data
• Functionality to perform key operations such as add, update, delete, and display records.
Output:
Source code:
#include <iostream>
pg. 3
Data Structures Algorithms | Sameer Malik
using namespace std;
class Student {
public:
int roll;
string name;
float marks;
void show() {
cout << "Roll: " << roll << " Name: " << name << " Marks:" << marks << endl;
}
};
class Manager {
public:
Student arr[50];
int count = 0;
void add(int r, string n, float m) {
arr[count].roll = r;
arr[count].name = n;
arr[count].marks = m;
count++;
}
void update(int r, float m) {
for(int i=0;i<count;i++){
if(arr[i].roll==r){
arr[i].marks = m;
cout<<"Marks updated ok"<<endl;
pg. 4
Data Structures Algorithms | Sameer Malik
return;
}
}
cout<<"roll not found"<<endl;
}
void removeStu(int r) {
for(int i=0;i<count;i++){
if(arr[i].roll==r){
arr[i] = arr[count-1];
count--;
cout<<"student removed"<<endl;
return;
}
}
cout<<"cant delete, no roll"<<endl;
}
void display(){
if(count==0){
cout<<"no data to show"<<endl;
return;
}
for(int i=0;i<count;i++){
arr[i].show();
}
}
};
int main(){
pg. 5
Data Structures Algorithms | Sameer Malik
Manager m;
int ch, r;
string n;
float mk;
while(true){
cout<<"1 Add"<<endl<<"2 Update"<<endl<<"3 Delete"<<endl<<"4 Show"<<endl<<"5
Exit"<<endl;
cin>>ch;
if(ch==1){
cout<<"Roll:"<<endl; cin>>r;
cout<<"Name:"<<endl; cin>>n;
cout<<"Marks:"<<endl; cin>>mk;
[Link](r,n,mk);
}
else if(ch==2){
cout<<"roll to update:"<<endl;
cin>>r;
cout<<"new marks:"<<endl;
cin>>mk;
[Link](r,mk);
}
else if(ch==3){
cout<<"roll delete:"<<endl;
cin>>r;
[Link](r);
}
else if(ch==4){
[Link]();
pg. 6
Data Structures Algorithms | Sameer Malik
}
else if(ch==5){
cout<<"bye"<<endl;
break;
}
else{
cout<<"wrong choice"<<endl;
}
}
}
pg. 7