SlideShare a Scribd company logo
ِ‫ن‬َ‫م‬ْ‫ح‬‫ه‬‫الر‬ ِ ‫ه‬
‫اَّلل‬ ِ‫م‬ْ‫س‬ِ‫ب‬
‫يم‬ ِ‫ح‬‫ه‬‫الر‬
Data Structures
& Algorithm
Lecture No. 5
By: Azhar Iqbal
Even / odd Algorithm
 Step 1: Start
Step 2: [ Take Input ] Read: Number
Step 3: Check: If Number%2 == 0 Then
Print : N is an Even Number.
Else
Print : N is an Odd Number.
Step 4: Exit
Array
 An array is a collection of items stored at contiguous memory locations. The
idea is to store multiple items of the same type together.
Applications on Array
1.Array stores data elements of the same data type.
2.Arrays can be used for CPU scheduling.
3.Used to Implement other data structures like Stacks, Queues, Heaps, Hash tables etc.
int arr[5] = { 10, 20, 30, 40, 50 };
int arr[5];
Declaration & initialization
int values[5];
printf("Enter 5 integers: "); // taking input and storing it in an array
for(int i = 0; i < 5; ++i)
{
scanf("%d", &values[i]);
}
Array Types
Single Dimensional Array / One Dimensional Array
 single dimensional arrays are used to store list of values of same
datatype. In other words, single dimensional arrays are used to store a
row of values. In single dimensional array, data is stored in linear form.
Single dimensional arrays are also called as one-dimensional arrays,
Linear Arrays or simply 1-D Arrays.
int rollNumbers [60] ;
int marks [6] = { 89, 90, 76, 78, 98, 86 } ;
2D Array
A two-dimensional array can be
thought of as a matrix with rows and
columns. The general syntax used to
declare a two-dimensional array is
int my_array[5][3];
int main()
{
int my_array[5][3] = {
{1, 2, 3}, //row 1
{4, 5, 6}, //row 2
{7, 8, 9}, //row 3
{10, 11, 12}, //row 4
{13, 14, 15} //row 5
};
Initializing two-dimensional arrays
int main()
{
int my_array[5][3] = {1, 2, 3, 4, 5,
6, 7, 8,9, 10, 11, 12, 13, 14, 15};
}
Array Operations
Here, we have accessed the
second value of the array using
its index, which is 1. The output
of this will be 200, which is
basically the second value of
the balanced array.
printf(balance[1])
Insert
With this operation, you can insert one or more items into an array at the beginning, end, or any
given index of the array. This method expects two arguments index and value.
SYNTAX
arrayName.insert(index, value)
Delete
With this operation, you can delete one item from an array by value. This method accepts
only one argument, value. After running this method, the array items are re-arranged, and
indices are re-assigned
arrayName.remove(value)
UPDATE
This operation is quite similar to the insert method, except that it will replace the existing
value at the given index. This means will simply assign a new value at the given index.
This method expects two arguments index and value.
arrayName.udpate(index, value)
SEARCH & Traversing
Thank You. . . . .
Any Question…?

More Related Content

PPTX
Array in c programming
PPTX
Array in c programming
PPTX
Basic array in c programming
PPTX
Array in (C) programing
PDF
Data structure lecture 2 (pdf)
PDF
Array and Collections in c#
PPT
Arrays Basics
Array in c programming
Array in c programming
Basic array in c programming
Array in (C) programing
Data structure lecture 2 (pdf)
Array and Collections in c#
Arrays Basics

What's hot (20)

PPTX
Presentation on array
PPTX
7array in c#
DOC
Data structure lecture 2
PPTX
Arrays in c language
PPTX
PPTX
PPTX
Control statements
PPT
One dimensional 2
PPTX
arrays in c
PPTX
Arrays in c
PPT
Array in c
PPTX
Arrays In C Language
PPTX
C++ programming (Array)
PPTX
Arrays In C++
PPTX
Arrays in c
PPTX
Presentation on queue
PPTX
Array in C
PPTX
concept of Array, 1D & 2D array
Presentation on array
7array in c#
Data structure lecture 2
Arrays in c language
Control statements
One dimensional 2
arrays in c
Arrays in c
Array in c
Arrays In C Language
C++ programming (Array)
Arrays In C++
Arrays in c
Presentation on queue
Array in C
concept of Array, 1D & 2D array
Ad

Similar to Data structures Lecture 5 (20)

PPTX
Module_3_Arrays - Updated.pptx............
PPTX
Unit4pptx__2024_11_ 11_10_16_09.pptx
PPT
Array 31.8.2020 updated
PPTX
PPTX
Chapter 13.pptx
PDF
Arrays-Computer programming
PDF
SlideSet_4_Arraysnew.pdf
PDF
Homework Assignment – Array Technical DocumentWrite a technical .pdf
PPTX
Array 2 hina
PDF
Arrays In C- Logic Development Programming
PPTX
Array
PPTX
UNIT-5_Array in c_part1.pptx
PPT
Lecture 15 Arrays with C++ programming.ppt
PPT
358 33 powerpoint-slides_5-arrays_chapter-5
PPTX
Ch-11-Arrays.ppt-1.pptx eurhrbdhdbdhrhdhdh
PDF
PPTX
Various Operations Of Array(Data Structure Algorithm).pptx
PPTX
unit 2.pptx
PPTX
Arrays
PPTX
ARRAYS.pptx
Module_3_Arrays - Updated.pptx............
Unit4pptx__2024_11_ 11_10_16_09.pptx
Array 31.8.2020 updated
Chapter 13.pptx
Arrays-Computer programming
SlideSet_4_Arraysnew.pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Array 2 hina
Arrays In C- Logic Development Programming
Array
UNIT-5_Array in c_part1.pptx
Lecture 15 Arrays with C++ programming.ppt
358 33 powerpoint-slides_5-arrays_chapter-5
Ch-11-Arrays.ppt-1.pptx eurhrbdhdbdhrhdhdh
Various Operations Of Array(Data Structure Algorithm).pptx
unit 2.pptx
Arrays
ARRAYS.pptx
Ad

Recently uploaded (20)

PPTX
Cell Structure & Organelles in detailed.
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PDF
Insiders guide to clinical Medicine.pdf
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Lesson notes of climatology university.
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Classroom Observation Tools for Teachers
PDF
RMMM.pdf make it easy to upload and study
PPTX
Institutional Correction lecture only . . .
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Basic Mud Logging Guide for educational purpose
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Cell Structure & Organelles in detailed.
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Microbial diseases, their pathogenesis and prophylaxis
Insiders guide to clinical Medicine.pdf
PPH.pptx obstetrics and gynecology in nursing
Supply Chain Operations Speaking Notes -ICLT Program
Lesson notes of climatology university.
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
TR - Agricultural Crops Production NC III.pdf
Classroom Observation Tools for Teachers
RMMM.pdf make it easy to upload and study
Institutional Correction lecture only . . .
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Basic Mud Logging Guide for educational purpose
Module 4: Burden of Disease Tutorial Slides S2 2025
VCE English Exam - Section C Student Revision Booklet
Chapter 2 Heredity, Prenatal Development, and Birth.pdf

Data structures Lecture 5

  • 1. ِ‫ن‬َ‫م‬ْ‫ح‬‫ه‬‫الر‬ ِ ‫ه‬ ‫اَّلل‬ ِ‫م‬ْ‫س‬ِ‫ب‬ ‫يم‬ ِ‫ح‬‫ه‬‫الر‬
  • 2. Data Structures & Algorithm Lecture No. 5 By: Azhar Iqbal
  • 3. Even / odd Algorithm  Step 1: Start Step 2: [ Take Input ] Read: Number Step 3: Check: If Number%2 == 0 Then Print : N is an Even Number. Else Print : N is an Odd Number. Step 4: Exit
  • 4. Array  An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together. Applications on Array 1.Array stores data elements of the same data type. 2.Arrays can be used for CPU scheduling. 3.Used to Implement other data structures like Stacks, Queues, Heaps, Hash tables etc.
  • 5. int arr[5] = { 10, 20, 30, 40, 50 }; int arr[5]; Declaration & initialization int values[5]; printf("Enter 5 integers: "); // taking input and storing it in an array for(int i = 0; i < 5; ++i) { scanf("%d", &values[i]); }
  • 6. Array Types Single Dimensional Array / One Dimensional Array  single dimensional arrays are used to store list of values of same datatype. In other words, single dimensional arrays are used to store a row of values. In single dimensional array, data is stored in linear form. Single dimensional arrays are also called as one-dimensional arrays, Linear Arrays or simply 1-D Arrays. int rollNumbers [60] ; int marks [6] = { 89, 90, 76, 78, 98, 86 } ;
  • 7. 2D Array A two-dimensional array can be thought of as a matrix with rows and columns. The general syntax used to declare a two-dimensional array is int my_array[5][3]; int main() { int my_array[5][3] = { {1, 2, 3}, //row 1 {4, 5, 6}, //row 2 {7, 8, 9}, //row 3 {10, 11, 12}, //row 4 {13, 14, 15} //row 5 }; Initializing two-dimensional arrays int main() { int my_array[5][3] = {1, 2, 3, 4, 5, 6, 7, 8,9, 10, 11, 12, 13, 14, 15}; }
  • 8. Array Operations Here, we have accessed the second value of the array using its index, which is 1. The output of this will be 200, which is basically the second value of the balanced array. printf(balance[1])
  • 9. Insert With this operation, you can insert one or more items into an array at the beginning, end, or any given index of the array. This method expects two arguments index and value. SYNTAX arrayName.insert(index, value) Delete With this operation, you can delete one item from an array by value. This method accepts only one argument, value. After running this method, the array items are re-arranged, and indices are re-assigned arrayName.remove(value) UPDATE This operation is quite similar to the insert method, except that it will replace the existing value at the given index. This means will simply assign a new value at the given index. This method expects two arguments index and value. arrayName.udpate(index, value) SEARCH & Traversing
  • 10. Thank You. . . . . Any Question…?