SlideShare a Scribd company logo
Basics Data Structure & Array Implementation
ADT
Data Structure Sec 06
Prepared by: Abdullah Emam
Fayoum international Technological University, Department of Information
Technology
Data Structures
Definition: A data structure is a way of organizing and
storing data so that it can be accessed and modified
efficiently.
Purpose: To process data logically and optimize
performance in programs.
Classification of Data Structures
 Primitive Data Structures
• Integer, Float, Character, Boolean
 Non-Primitive Data Structures
• Linear: Arrays, Linked Lists, Stacks, Queues
• Non-Linear
• Hash
Arrays
 Fixed-size, indexed collection of elements of the same type.
 Pros: Fast access using indices (O(1)).
 Cons: Static size, costly insert/delete.
 Example:
int arr[5] = {10, 20, 30, 40, 50};
Linked Lists
Dynamic data structure consisting of nodes pointing
to the next node.
Types: Singly, Doubly, Circular
Pros: Dynamic size, efficient insert/delete.
Cons: Slow access time (O(n)).
Example Node Structure:
class Node {
int data;
Node* next;
};
Stack (LIFO)
 Last-In, First-Out structure.
 Operations: push(), pop(), top(), isEmpty()
 Used in: Function calls, expression parsing.
stack<int> s;
s.push(10);
Queue (FIFO)
Student s1;
s1.name = "Alice";
s1.age = 20;
Practical Applications of Data Structures
➢ Real-World Examples:
• Trees: File system directories.
• Graphs: Social network connections.
• Hash Tables: Database indexing.
• Heaps: Task scheduling systems.
➢ Case Study:
❑ Implementing a Contact List:
• Array: Suitable for a fixed number of contacts with quick index-based access.
• Linked List: Suitable for a dynamic list where contacts are frequently added or
removed.
• Hash Table: Suitable for quick search operations based on contact names.
Introduction to ADT (Abstract Data Type)
ADT (Abstract Data Type)
• ADT is a logical description of how data is viewed
and the operations on it.
• Does not depend on implementation.
• Examples of ADTs: List, Stack, Queue, Tree
List ADT:
• A collection of ordered elements.
• Elements can be inserted or deleted at specific
positions.
• Types: Singly List, Doubly List, Circular List, Array-
based List
Array-Based List ADT Overview
• Uses a fixed-size array to store elements.
• Elements are contiguously stored in memory.
• Efficient random access, but costly
insertions/deletions in the middle.
Operations in Array List ADT
❖Create Structure of Array
❖Insert(pos, value): Add element at given
index
❖Remove(pos): Remove element at index
❖Search(value): Find index of element
❖Display(): Print all elements
❖isEmpty() / isFull(): Check list status
Structure of Array-Based List
class ArrayADT {
private:
int* arr;
int capacity;
int size;
arr: Pointer to dynamic array
capacity: Maximum number of
elements the list can store
size: Current number of elements
Constructor & Destructor
ArrayADT(int cap) {
capacity = cap;
size = 0;
arr = new int[capacity];
}
~ArrayADT() {
delete[] arr;
}
Explanation:
Allocates dynamic memory
using new.
Frees memory in destructor.
Check if the array is empty Or full
// Check if the array is empty
bool isEmpty() {
return size == 0;
}
// Check if the array is full
bool isFull() {
return capacity == size;
}
Insert Operation
void insert(int value, int pos) {
if (isFull()) {
cout << "Array is fulln";
return;
}
if (size >= capacity || pos < 0 || pos > size) {
cout << "Insert failed.n";
return;
}
for (int i = size - 1; i >= pos; i--)
{ arr[i + 1] = arr[i];}
arr[pos] = value;
size++;
}
Remove Operation
void remove(int pos) {
if (isEmpty()) {
cout << "Array is emptyn";
return;
}
if (pos < 0 || pos >= size) {
cout << "Delete failed.n";
return;
}
for (int i = pos; i < size - 1; i++)
arr[i] = arr[i + 1];
size--;
}
Search Operation
int search(int value) {
for (int i = 0; i < size; i++) {
if (arr[i] == value)
return i;
}
return -1;
} Explanation:
•Returns index of first occurrence or -1 if
not found.
Update Operation
void update(int pos, int value) {
if (pos < 0 || pos >= size) {
cout << "Update failed.n";
return;
}
arr[pos] = value;
}
Explanation:
•Directly updates value at given
index.
Get Operation
int get(int pos) {
if (pos < 0 || pos >= size) {
cout << "Invalid position.n";
return -1;
}
return arr[pos];
}
Explanation:
•Returns value at a given index.
Display Operation
void display() {
cout << "Array: ";
for (int i = 0; i < size; i++)
cout << arr[i] << " ";
cout << endl;
}
Explanation:
•Traverses and prints all elements.
Main Function Example
int main() {
ArrayADT a(10);
a.insert(10, 0);
a.insert(20, 1);
a.insert(15, 1);
a.display();
a.remove(1);
a.display();
int index = arr.Search(15);
if (index != -1) cout << "Element found at index " << index << "n";
else cout << "Element not foundn";
cout << (arr.isEmpty() ? "Array is emptyn" : "Array is not emptyn");
cout << (arr.isFull() ? "Array is fulln" : "Array is not fulln");
return 0;
}
Complete Code
class ArrayADT {
private:
int* arr;
int capacity;
int size;
public:
ArrayADT(int cap) {
capacity = cap;
size = 0;
arr = new int[capacity];
}
~ArrayADT() {
delete[] arr;
}
void insert(int value, int pos) {
if (size >= capacity || pos < 0 || pos > size)
{ cout << "Insert failed.n";
return; }
for (int i = size - 1; i >= pos; i--)
{ arr[i + 1] = arr[i];}
arr[pos] = value;
size++;}
void remove(int pos) {
if (pos < 0 || pos >= size) {
cout << "Delete failed.n";
return;
}
for (int i = pos; i < size - 1; i++)
arr[i] = arr[i + 1];
size--;
}
int search(int value) {
for (int i = 0; i < size; i++) {
if (arr[i] == value)
return i;
}
return -1;
}
void update(int pos, int value) {
if (pos < 0 || pos >= size) {
cout << "Update failed.n";
return;
}
arr[pos] = value;
}
int get(int pos) {
if (pos < 0 || pos >= size) {
cout << "Invalid position.n";
return -1;
}
return arr[pos];
}
void display() {
cout << "Array: ";
for (int i = 0; i < size; i++)
cout << arr[i] << " ";
cout << endl;
}
};
int main() {
ArrayADT a(10);
a.insert(10, 0);
a.insert(20, 1);
a.insert(15, 1);
a.display();
a.remove(1);
a.display();
cout << "Index of 20: " << a.search(20) <<
endl;
a.update(1, 99);
a.display();
cout << "Element at index 1: " << a.get(1)
<< endl;
cout << (arr.isEmpty() ? "Array is emptyn" :
"Array is not emptyn");
cout << (arr.isFull() ? "Array is fulln" :
"Array is not fulln");
return 0;
}
Sec 06 Basics Data Structure & Array Implementation .pdf

More Related Content

PPT
02 Arrays And Memory Mapping
PDF
Aj unit2 notesjavadatastructures
PDF
Array (data structure using c++).PPT presentation
PPTX
Basic of array and data structure, data structure basics, array, address calc...
PDF
PPTX
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
PPTX
array lecture engineeringinformatin_technology.pptx
PPTX
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
02 Arrays And Memory Mapping
Aj unit2 notesjavadatastructures
Array (data structure using c++).PPT presentation
Basic of array and data structure, data structure basics, array, address calc...
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
array lecture engineeringinformatin_technology.pptx
UNIT I LINEAR DATA STRUCTURES – LIST .pptx

Similar to Sec 06 Basics Data Structure & Array Implementation .pdf (20)

PPTX
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
PPTX
Data structure and algorithm list structures
PPTX
EC2311 – Data Structures and C Programming
PPTX
Data structure
PPT
PPTX
Data structure , stack , queue
PDF
Chapter12 array-single-dimension
PPTX
هياكلبيانات
PDF
Define an ADT for a sequence of integers (remember that a sequenc.pdf
PPT
Arrays
PDF
SlideSet_4_Arraysnew.pdf
PDF
Implement the ListArray ADT-Implement the following operations.pdf
PDF
PPTX
Arrays_in_c++.pptx
PPT
PPTX
Data structures in c#
PPTX
Adt of lists
PPTX
795834179-DS-module-1.pptx for dta sffssystrseeg
DOC
CBSE Class XII Comp sc practical file
DATA STRUCTURE CLASS 12 COMPUTER SCIENCE
Data structure and algorithm list structures
EC2311 – Data Structures and C Programming
Data structure
Data structure , stack , queue
Chapter12 array-single-dimension
هياكلبيانات
Define an ADT for a sequence of integers (remember that a sequenc.pdf
Arrays
SlideSet_4_Arraysnew.pdf
Implement the ListArray ADT-Implement the following operations.pdf
Arrays_in_c++.pptx
Data structures in c#
Adt of lists
795834179-DS-module-1.pptx for dta sffssystrseeg
CBSE Class XII Comp sc practical file
Ad

More from AbdullahEmam4 (6)

PDF
IT-Lecture for information comunicazione technology 1.pdf
PDF
Robot-kinematics-and-dynamics for mechanical .pdf
PDF
Sec 04 Object-Oriented Programming OOP (Class).pdf
PDF
Lab1-FrontEndTraining For everybody..pdf
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PPTX
Moh.Abd-Ellatif_DataAnalysis1.pptx
IT-Lecture for information comunicazione technology 1.pdf
Robot-kinematics-and-dynamics for mechanical .pdf
Sec 04 Object-Oriented Programming OOP (Class).pdf
Lab1-FrontEndTraining For everybody..pdf
Arduino robotics embedded978-1-4302-3184-4.pdf
Moh.Abd-Ellatif_DataAnalysis1.pptx
Ad

Recently uploaded (20)

PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Structs to JSON How Go Powers REST APIs.pdf
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
DOCX
573137875-Attendance-Management-System-original
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PPTX
Construction Project Organization Group 2.pptx
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PPTX
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PPT
Project quality management in manufacturing
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
ETO & MEO Certificate of Competency Questions and Answers
PPTX
web development for engineering and engineering
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
Welding lecture in detail for understanding
PPTX
bas. eng. economics group 4 presentation 1.pptx
Embodied AI: Ushering in the Next Era of Intelligent Systems
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Structs to JSON How Go Powers REST APIs.pdf
Internet of Things (IOT) - A guide to understanding
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
573137875-Attendance-Management-System-original
Lesson 3_Tessellation.pptx finite Mathematics
Construction Project Organization Group 2.pptx
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
MET 305 MODULE 1 KTU 2019 SCHEME 25.pptx
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Project quality management in manufacturing
Foundation to blockchain - A guide to Blockchain Tech
ETO & MEO Certificate of Competency Questions and Answers
web development for engineering and engineering
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Strings in CPP - Strings in C++ are sequences of characters used to store and...
Welding lecture in detail for understanding
bas. eng. economics group 4 presentation 1.pptx

Sec 06 Basics Data Structure & Array Implementation .pdf

  • 1. Basics Data Structure & Array Implementation ADT Data Structure Sec 06 Prepared by: Abdullah Emam Fayoum international Technological University, Department of Information Technology
  • 2. Data Structures Definition: A data structure is a way of organizing and storing data so that it can be accessed and modified efficiently. Purpose: To process data logically and optimize performance in programs.
  • 3. Classification of Data Structures  Primitive Data Structures • Integer, Float, Character, Boolean  Non-Primitive Data Structures • Linear: Arrays, Linked Lists, Stacks, Queues • Non-Linear • Hash
  • 4. Arrays  Fixed-size, indexed collection of elements of the same type.  Pros: Fast access using indices (O(1)).  Cons: Static size, costly insert/delete.  Example: int arr[5] = {10, 20, 30, 40, 50};
  • 5. Linked Lists Dynamic data structure consisting of nodes pointing to the next node. Types: Singly, Doubly, Circular Pros: Dynamic size, efficient insert/delete. Cons: Slow access time (O(n)). Example Node Structure: class Node { int data; Node* next; };
  • 6. Stack (LIFO)  Last-In, First-Out structure.  Operations: push(), pop(), top(), isEmpty()  Used in: Function calls, expression parsing. stack<int> s; s.push(10);
  • 7. Queue (FIFO) Student s1; s1.name = "Alice"; s1.age = 20;
  • 8. Practical Applications of Data Structures ➢ Real-World Examples: • Trees: File system directories. • Graphs: Social network connections. • Hash Tables: Database indexing. • Heaps: Task scheduling systems. ➢ Case Study: ❑ Implementing a Contact List: • Array: Suitable for a fixed number of contacts with quick index-based access. • Linked List: Suitable for a dynamic list where contacts are frequently added or removed. • Hash Table: Suitable for quick search operations based on contact names.
  • 9. Introduction to ADT (Abstract Data Type)
  • 10. ADT (Abstract Data Type) • ADT is a logical description of how data is viewed and the operations on it. • Does not depend on implementation. • Examples of ADTs: List, Stack, Queue, Tree List ADT: • A collection of ordered elements. • Elements can be inserted or deleted at specific positions. • Types: Singly List, Doubly List, Circular List, Array- based List
  • 11. Array-Based List ADT Overview • Uses a fixed-size array to store elements. • Elements are contiguously stored in memory. • Efficient random access, but costly insertions/deletions in the middle.
  • 12. Operations in Array List ADT ❖Create Structure of Array ❖Insert(pos, value): Add element at given index ❖Remove(pos): Remove element at index ❖Search(value): Find index of element ❖Display(): Print all elements ❖isEmpty() / isFull(): Check list status
  • 13. Structure of Array-Based List class ArrayADT { private: int* arr; int capacity; int size; arr: Pointer to dynamic array capacity: Maximum number of elements the list can store size: Current number of elements
  • 14. Constructor & Destructor ArrayADT(int cap) { capacity = cap; size = 0; arr = new int[capacity]; } ~ArrayADT() { delete[] arr; } Explanation: Allocates dynamic memory using new. Frees memory in destructor.
  • 15. Check if the array is empty Or full // Check if the array is empty bool isEmpty() { return size == 0; } // Check if the array is full bool isFull() { return capacity == size; }
  • 16. Insert Operation void insert(int value, int pos) { if (isFull()) { cout << "Array is fulln"; return; } if (size >= capacity || pos < 0 || pos > size) { cout << "Insert failed.n"; return; } for (int i = size - 1; i >= pos; i--) { arr[i + 1] = arr[i];} arr[pos] = value; size++; }
  • 17. Remove Operation void remove(int pos) { if (isEmpty()) { cout << "Array is emptyn"; return; } if (pos < 0 || pos >= size) { cout << "Delete failed.n"; return; } for (int i = pos; i < size - 1; i++) arr[i] = arr[i + 1]; size--; }
  • 18. Search Operation int search(int value) { for (int i = 0; i < size; i++) { if (arr[i] == value) return i; } return -1; } Explanation: •Returns index of first occurrence or -1 if not found.
  • 19. Update Operation void update(int pos, int value) { if (pos < 0 || pos >= size) { cout << "Update failed.n"; return; } arr[pos] = value; } Explanation: •Directly updates value at given index.
  • 20. Get Operation int get(int pos) { if (pos < 0 || pos >= size) { cout << "Invalid position.n"; return -1; } return arr[pos]; } Explanation: •Returns value at a given index.
  • 21. Display Operation void display() { cout << "Array: "; for (int i = 0; i < size; i++) cout << arr[i] << " "; cout << endl; } Explanation: •Traverses and prints all elements.
  • 22. Main Function Example int main() { ArrayADT a(10); a.insert(10, 0); a.insert(20, 1); a.insert(15, 1); a.display(); a.remove(1); a.display(); int index = arr.Search(15); if (index != -1) cout << "Element found at index " << index << "n"; else cout << "Element not foundn"; cout << (arr.isEmpty() ? "Array is emptyn" : "Array is not emptyn"); cout << (arr.isFull() ? "Array is fulln" : "Array is not fulln"); return 0; }
  • 23. Complete Code class ArrayADT { private: int* arr; int capacity; int size; public: ArrayADT(int cap) { capacity = cap; size = 0; arr = new int[capacity]; } ~ArrayADT() { delete[] arr; } void insert(int value, int pos) { if (size >= capacity || pos < 0 || pos > size) { cout << "Insert failed.n"; return; } for (int i = size - 1; i >= pos; i--) { arr[i + 1] = arr[i];} arr[pos] = value; size++;} void remove(int pos) { if (pos < 0 || pos >= size) { cout << "Delete failed.n"; return; } for (int i = pos; i < size - 1; i++) arr[i] = arr[i + 1]; size--; } int search(int value) { for (int i = 0; i < size; i++) { if (arr[i] == value) return i; } return -1; }
  • 24. void update(int pos, int value) { if (pos < 0 || pos >= size) { cout << "Update failed.n"; return; } arr[pos] = value; } int get(int pos) { if (pos < 0 || pos >= size) { cout << "Invalid position.n"; return -1; } return arr[pos]; } void display() { cout << "Array: "; for (int i = 0; i < size; i++) cout << arr[i] << " "; cout << endl; } }; int main() { ArrayADT a(10); a.insert(10, 0); a.insert(20, 1); a.insert(15, 1); a.display(); a.remove(1); a.display(); cout << "Index of 20: " << a.search(20) << endl; a.update(1, 99); a.display(); cout << "Element at index 1: " << a.get(1) << endl; cout << (arr.isEmpty() ? "Array is emptyn" : "Array is not emptyn"); cout << (arr.isFull() ? "Array is fulln" : "Array is not fulln"); return 0; }