SlideShare a Scribd company logo
1 of 10
ِ‫ن‬َ‫م‬ْ‫ح‬‫ه‬‫الر‬ ِ ‫ه‬
‫اَّلل‬ ِ‫م‬ْ‫س‬ِ‫ب‬
‫يم‬ ِ‫ح‬‫ه‬‫الر‬
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

What's hot (20)

Presentation on array
Presentation on array Presentation on array
Presentation on array
 
7array in c#
7array in c#7array in c#
7array in c#
 
Data structure lecture 2
Data structure lecture 2Data structure lecture 2
Data structure lecture 2
 
Arrays in c language
Arrays in c languageArrays in c language
Arrays in c language
 
Array
ArrayArray
Array
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
Control statements
Control statementsControl statements
Control statements
 
Arrays
ArraysArrays
Arrays
 
One dimensional 2
One dimensional 2One dimensional 2
One dimensional 2
 
arrays in c
arrays in carrays in c
arrays in c
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
array
array array
array
 
Array in c
Array in cArray in c
Array in c
 
Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C Language
 
C++ programming (Array)
C++ programming (Array)C++ programming (Array)
C++ programming (Array)
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
Presentation on queue
Presentation on queuePresentation on queue
Presentation on queue
 
Array in C
Array in CArray in C
Array in C
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
 

Similar to Data structures Lecture 5 (20)

Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Array
ArrayArray
Array
 
Ch08
Ch08Ch08
Ch08
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
6_Array.pptx
6_Array.pptx6_Array.pptx
6_Array.pptx
 
Computer programming 2 Lesson 13
Computer programming 2  Lesson 13Computer programming 2  Lesson 13
Computer programming 2 Lesson 13
 
Arrays
ArraysArrays
Arrays
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
About Array
About ArrayAbout Array
About Array
 
Array
ArrayArray
Array
 
Chap 6 c++
Chap 6 c++Chap 6 c++
Chap 6 c++
 
07+08slide.pptx
07+08slide.pptx07+08slide.pptx
07+08slide.pptx
 
Array&amp;string
Array&amp;stringArray&amp;string
Array&amp;string
 
C_Arrays.pptx
C_Arrays.pptxC_Arrays.pptx
C_Arrays.pptx
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Arrays
ArraysArrays
Arrays
 

Recently uploaded

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 

Recently uploaded (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 

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…?