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)

PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Orientation - ARALprogram of Deped to the Parents.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
Cell Structure & Organelles in detailed.
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Orientation - ARALprogram of Deped to the Parents.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Final Presentation General Medicine 03-08-2024.pptx
Cell Structure & Organelles in detailed.
2.FourierTransform-ShortQuestionswithAnswers.pdf
Computing-Curriculum for Schools in Ghana
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Anesthesia in Laparoscopic Surgery in India
A systematic review of self-coping strategies used by university students to ...
O7-L3 Supply Chain Operations - ICLT Program
human mycosis Human fungal infections are called human mycosis..pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
FourierSeries-QuestionsWithAnswers(Part-A).pdf
O5-L3 Freight Transport Ops (International) V1.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…?