尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
Data Structure
(2130702)
Topic:- Arrays
Prepared by- Vasava Aarti .G
Roll no_6140
(I.T department)
1
 The Array is the most commonly used Data Structure.
 An array is a collection of data elements that are of the same type (e.g., a
collection of integers, collection of characters, collection of doubles).
OR
 Array is a data structure that represents a collection of the same types of
data.
 The values held in an array are called array elements
 An array stores multiple values of the same type – the element type
 The element type can be a primitive type or an object reference
 Therefore, we can create an array of integers, an array of characters, an array
of String objects, an array of Coin objects, etc.
2
 Given a list of test scores, determine the maximum and minimum scores.
 Read in a list of student names and rearrange them in alphabetical order
(sorting).
 Given the height measurements of students in a class, output the names of
those students who are taller than average.
3
 Syntax:
<type> <arrayName>[<array_size>]
Ex. int Ar[10];
 The array elements are all values of the type <type>.
 The size of the array is indicated by <array_size>, the number
of elements in the array.
 <array_size> must be an int constant or a constant expression.
Note that an array can have multiple dimensions.
4
// array of 10 uninitialized ints
int Ar[10];
5
-- -- ----Ar -- -- ---- -- --
4 5 630 2 8 971
0 1 2 3 4 5
 Declare an array of 10 integers:
int Ar[10]; // array of 10 ints
 To access an individual element we must apply a subscript to array named
Ar.
› A subscript is a bracketed expression.
 The expression in the brackets is known as the index.
› First element of array has index 0.
Ar[0]
› Second element of array has index 1, and so on.
Ar[1], Ar[2], Ar[3],…
› Last element has an index one less than the size of the array.
Ar[9]
 Incorrect indexing is a common error.
6
7
// array of 10 uninitialized ints
int Ar[10];
Ar[3] = 1;
int x = Ar[3];
-- -- 1--Ar -- -- ---- -- --
4 5 630 2 8 971
Ar[4] Ar[5] Ar[6]Ar[3]Ar[0] Ar[2] Ar[8] Ar[9]Ar[7]Ar[1]
#include <stdio.h>
int main ()
{
int n[10]; /* n is an array of 10 integers */
int i,j;
/* initialize elements of array n to 0 */
for ( i = 0; i < 10; i++ )
{
n[ i ] = i + 100; /* set element at location i to i + 100 */
}
/* output each array element's value */
for (j = 0; j < 10; j++ )
{
printf("Element[%d] = %dn", j, n[j] );
}
return 0;
}
8
 An array can have many dimensions – if it has more than one dimension,
it is called a multidimensional array
 Each dimension subdivides the previous one into the specified number of
elements
 Each dimension has its own length constant
 Because each dimension is an array of array references, the arrays within
one dimension can be of different lengths
10
Multiple dimensions get difficult to visualize graphically.
•
double Coord[100][100][100];
11
2 Dimensional 3 Dimensional
Processing Multi-dimensional Arrays
The key to processing all cells of a multi-dimensional array is
nested loops.
[0] [1] [2] [3]
[0]
[1]
[2]
10 11 12 13
14 15 16 17
18 19 20 21
22 23 24 25
26 27 28 29
[3]
[4]
for (int row=0; row!=5; row++) {
for (int col=0; col!=4; col++) {
System.out.println( myArray[row][col] );
}
}
for (int col=0; col!=4; col++) {
for (int row=0; row!=5; row++) {
System.out.println( myArray[row][col] );
}
}
12
13
two
dimensions
one
dimension
• A one-dimensional array stores a list of elements
• A two-dimensional array can be thought of as a table of
elements, with rows and columns
A two-dimensional array consists of a certain number of rows and columns:
const int NUMROWS = 3;
const int NUMCOLS = 7;
int Array[NUMROWS][NUMCOLS];
14
Array[2][5] 3rd value in 6th column
Array[0][4] 1st value in 5th column
The declaration must specify the number of rows and the number of columns,
and both must be constants.
0 1 2 3 4 5 6
0 4 18 9 3 -4 6 0
1 12 45 74 15 0 98 0
2 84 87 75 67 81 85 79
 In computing, row-major order and column-major order describe methods
for storing multidimensional arrays in linear memory.
 By following standard matrix notation, rows are numbered by the first
index of a two-dimensional array and columns by the second index.
 Array layout is critical for correctly passing arrays between programs
written in different languages. It is also important for performance when
traversing an array because accessing array elements that are contiguous
in memory is usually faster than accessing elements which are not, due
to caching.
15
 In row-major storage, a multidimensional array in linear memory is
organized such that rows are stored one after the other. It is the
approach used by the C programming language, among others.
 For example, consider this 2×3 array:
 An array declared in C as
int A[2][3] = { {1, 2, 3}, {4, 5, 6} };
is laid out contiguously in linear memory as:
1 2 3 4 5 6
16
1 2 3
4 5 6
 To traverse this array in the order in which it is laid out in memory, one
would use the following nested loop:
for (row = 0; row < 2; row++)
for (column = 0; column < 3; column++)
printf("%dn", A[row][column]);
17
 Column-major order is a similar method of flattening arrays
onto linear memory, but the columns are listed in sequence.
 The scientific programming languages Fortran and Julia, the
matrix-oriented languages MATLAB and Octave, use
column-major ordering. The array
 if stored contiguously in linear memory with column-major
order looks like the following:
1 4 2 5 3 6
18
1 2 3
4 5 6
THANK YOU….. !!!
19

More Related Content

What's hot

Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
Awais Alam
 
Array
ArrayArray
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
Smit Parikh
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java language
Hareem Naz
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
Neeru Mittal
 
Array lecture
Array lectureArray lecture
Array lecture
Joan Saño
 
Arrays in c
Arrays in cArrays in c
Arrays in c
Jeeva Nanthini
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)
Imdadul Himu
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
Gagan Deep
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
أحمد محمد
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
HNDE Labuduwa Galle
 
Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]
Muhammad Hammad Waseem
 
2D Array
2D Array 2D Array
2D Array
Ehatsham Riaz
 
Array Presentation
Array PresentationArray Presentation
Array Presentation
Deep Prajapati Microplacer
 
Arrays
ArraysArrays
Arrays C#
Arrays C#Arrays C#
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
imtiazalijoono
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
Neveen Reda
 
Array
ArrayArray
Array
PRN USM
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
Rajendran
 

What's hot (20)

Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
Array
ArrayArray
Array
 
Multidimensional array in C
Multidimensional array in CMultidimensional array in C
Multidimensional array in C
 
Arrays in java language
Arrays in java languageArrays in java language
Arrays in java language
 
Two dimensional arrays
Two dimensional arraysTwo dimensional arrays
Two dimensional arrays
 
Array lecture
Array lectureArray lecture
Array lecture
 
Arrays in c
Arrays in cArrays in c
Arrays in c
 
A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)A Presentation About Array Manipulation(Insertion & Deletion in an array)
A Presentation About Array Manipulation(Insertion & Deletion in an array)
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]
 
2D Array
2D Array 2D Array
2D Array
 
Array Presentation
Array PresentationArray Presentation
Array Presentation
 
Arrays
ArraysArrays
Arrays
 
Arrays C#
Arrays C#Arrays C#
Arrays C#
 
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
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
 
Array
ArrayArray
Array
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 

Viewers also liked

MA3696 Lecture 6
MA3696 Lecture 6MA3696 Lecture 6
MA3696 Lecture 6
Brunel University
 
1-D array
1-D array1-D array
Hub102 - Lesson4 - Data Structure
Hub102 - Lesson4 - Data StructureHub102 - Lesson4 - Data Structure
Hub102 - Lesson4 - Data Structure
Tiểu Hổ
 
Data Structures - Lecture 5 [Stack]
Data Structures - Lecture 5 [Stack]Data Structures - Lecture 5 [Stack]
Data Structures - Lecture 5 [Stack]
Muhammad Hammad Waseem
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structure
student
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
EngineerBabu
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
JavaTpoint.Com
 

Viewers also liked (7)

MA3696 Lecture 6
MA3696 Lecture 6MA3696 Lecture 6
MA3696 Lecture 6
 
1-D array
1-D array1-D array
1-D array
 
Hub102 - Lesson4 - Data Structure
Hub102 - Lesson4 - Data StructureHub102 - Lesson4 - Data Structure
Hub102 - Lesson4 - Data Structure
 
Data Structures - Lecture 5 [Stack]
Data Structures - Lecture 5 [Stack]Data Structures - Lecture 5 [Stack]
Data Structures - Lecture 5 [Stack]
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structure
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 
C Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpointC Programming Language Tutorial for beginners - JavaTpoint
C Programming Language Tutorial for beginners - JavaTpoint
 

Similar to Arrays

Data structure array
Data structure  arrayData structure  array
Data structure array
MajidHamidAli
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
HEMAHEMS5
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
Swarup Boro
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
rohinitalekar1
 
Algo>Arrays
Algo>ArraysAlgo>Arrays
Algo>Arrays
Ain-ul-Moiz Khawaja
 
01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg
01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg
01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg
wrushabhsirsat
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
Kashif Nawab
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
Munazza-Mah-Jabeen
 
Array
ArrayArray
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
Appili Vamsi Krishna
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
aroraopticals15
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
Thesis Scientist Private Limited
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
SajalFayyaz
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
HarmanShergill5
 
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
LATHA LAKSHMI
 
02 arrays
02 arrays02 arrays
02 arrays
Rajan Gautam
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
Ashim Lamichhane
 
Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...
nsitlokeshjain
 
unit1Intro_final.pptx
unit1Intro_final.pptxunit1Intro_final.pptx
unit1Intro_final.pptx
DEEPAK948083
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
vrgokila
 

Similar to Arrays (20)

Data structure array
Data structure  arrayData structure  array
Data structure array
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
 
Arrays and library functions
Arrays and library functionsArrays and library functions
Arrays and library functions
 
C (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptxC (PPS)Programming for problem solving.pptx
C (PPS)Programming for problem solving.pptx
 
Algo>Arrays
Algo>ArraysAlgo>Arrays
Algo>Arrays
 
01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg
01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg
01245xsfwegrgdvdvsdfgvsdgsdfgsfsdgsdgsdgdg
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 
Array
ArrayArray
Array
 
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
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
Introduction to Arrays in C
Introduction to Arrays in CIntroduction to Arrays in C
Introduction to Arrays in C
 
Data structure.pptx
Data structure.pptxData structure.pptx
Data structure.pptx
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
Arrays in C++ in Tamil - TNSCERT SYLLABUS PPT
 
02 arrays
02 arrays02 arrays
02 arrays
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 
Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...
 
unit1Intro_final.pptx
unit1Intro_final.pptxunit1Intro_final.pptx
unit1Intro_final.pptx
 
Array 31.8.2020 updated
Array 31.8.2020 updatedArray 31.8.2020 updated
Array 31.8.2020 updated
 

More from Chirag vasava

indian standard for Hard-Drawn Copper Conductors for Over Head Power Transmis...
indian standard for Hard-Drawn Copper Conductors for Over Head Power Transmis...indian standard for Hard-Drawn Copper Conductors for Over Head Power Transmis...
indian standard for Hard-Drawn Copper Conductors for Over Head Power Transmis...
Chirag vasava
 
Copper conductor
Copper conductorCopper conductor
Copper conductor
Chirag vasava
 
Hard-Drawn Copper Conductors for Over Head Power Transmission
Hard-Drawn Copper Conductors for Over Head Power TransmissionHard-Drawn Copper Conductors for Over Head Power Transmission
Hard-Drawn Copper Conductors for Over Head Power Transmission
Chirag vasava
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
Chirag vasava
 
type of ohmmeter
type of ohmmetertype of ohmmeter
type of ohmmeter
Chirag vasava
 
(S.C.E.T) Appliction of pll fm demodulation fsk demodulation
(S.C.E.T) Appliction of pll fm demodulation fsk demodulation(S.C.E.T) Appliction of pll fm demodulation fsk demodulation
(S.C.E.T) Appliction of pll fm demodulation fsk demodulation
Chirag vasava
 

More from Chirag vasava (6)

indian standard for Hard-Drawn Copper Conductors for Over Head Power Transmis...
indian standard for Hard-Drawn Copper Conductors for Over Head Power Transmis...indian standard for Hard-Drawn Copper Conductors for Over Head Power Transmis...
indian standard for Hard-Drawn Copper Conductors for Over Head Power Transmis...
 
Copper conductor
Copper conductorCopper conductor
Copper conductor
 
Hard-Drawn Copper Conductors for Over Head Power Transmission
Hard-Drawn Copper Conductors for Over Head Power TransmissionHard-Drawn Copper Conductors for Over Head Power Transmission
Hard-Drawn Copper Conductors for Over Head Power Transmission
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
type of ohmmeter
type of ohmmetertype of ohmmeter
type of ohmmeter
 
(S.C.E.T) Appliction of pll fm demodulation fsk demodulation
(S.C.E.T) Appliction of pll fm demodulation fsk demodulation(S.C.E.T) Appliction of pll fm demodulation fsk demodulation
(S.C.E.T) Appliction of pll fm demodulation fsk demodulation
 

Recently uploaded

Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
simrangupta87541
 
Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...
Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...
Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...
Banerescorts
 
Lateral load-resisting systems in buildings.pptx
Lateral load-resisting systems in buildings.pptxLateral load-resisting systems in buildings.pptx
Lateral load-resisting systems in buildings.pptx
DebendraDevKhanal1
 
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
IJCNCJournal
 
My Airframe Metallic Design Capability Studies..pdf
My Airframe Metallic Design Capability Studies..pdfMy Airframe Metallic Design Capability Studies..pdf
My Airframe Metallic Design Capability Studies..pdf
Geoffrey Wardle. MSc. MSc. Snr.MAIAA
 
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Dr.Costas Sachpazis
 
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
sonamrawat5631
 
Online train ticket booking system project.pdf
Online train ticket booking system project.pdfOnline train ticket booking system project.pdf
Online train ticket booking system project.pdf
Kamal Acharya
 
Microsoft Azure AD architecture and features
Microsoft Azure AD architecture and featuresMicrosoft Azure AD architecture and features
Microsoft Azure AD architecture and features
ssuser381403
 
🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...
🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...
🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...
AK47
 
Call Girls Goa (india) ☎️ +91-7426014248 Goa Call Girl
Call Girls Goa (india) ☎️ +91-7426014248 Goa Call GirlCall Girls Goa (india) ☎️ +91-7426014248 Goa Call Girl
Call Girls Goa (india) ☎️ +91-7426014248 Goa Call Girl
sapna sharmap11
 
Data Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdfData Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdf
Kamal Acharya
 
🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...
🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...
🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...
dulbh kashyap
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
Lubi Valves
 
Cricket management system ptoject report.pdf
Cricket management system ptoject report.pdfCricket management system ptoject report.pdf
Cricket management system ptoject report.pdf
Kamal Acharya
 
Literature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.pptxLiterature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.pptx
LokerXu2
 
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Poonam Singh
 
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Tsuyoshi Horigome
 
Intuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sdeIntuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sde
ShivangMishra54
 
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdfSri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Balvir Singh
 

Recently uploaded (20)

Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
 
Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...
Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...
Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...
 
Lateral load-resisting systems in buildings.pptx
Lateral load-resisting systems in buildings.pptxLateral load-resisting systems in buildings.pptx
Lateral load-resisting systems in buildings.pptx
 
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
 
My Airframe Metallic Design Capability Studies..pdf
My Airframe Metallic Design Capability Studies..pdfMy Airframe Metallic Design Capability Studies..pdf
My Airframe Metallic Design Capability Studies..pdf
 
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
 
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
 
Online train ticket booking system project.pdf
Online train ticket booking system project.pdfOnline train ticket booking system project.pdf
Online train ticket booking system project.pdf
 
Microsoft Azure AD architecture and features
Microsoft Azure AD architecture and featuresMicrosoft Azure AD architecture and features
Microsoft Azure AD architecture and features
 
🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...
🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...
🔥Independent Call Girls In Pune 💯Call Us 🔝 7014168258 🔝💃Independent Pune Esco...
 
Call Girls Goa (india) ☎️ +91-7426014248 Goa Call Girl
Call Girls Goa (india) ☎️ +91-7426014248 Goa Call GirlCall Girls Goa (india) ☎️ +91-7426014248 Goa Call Girl
Call Girls Goa (india) ☎️ +91-7426014248 Goa Call Girl
 
Data Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdfData Communication and Computer Networks Management System Project Report.pdf
Data Communication and Computer Networks Management System Project Report.pdf
 
🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...
🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...
🚺ANJALI MEHTA High Profile Call Girls Ahmedabad 💯Call Us 🔝 9352988975 🔝💃Top C...
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
 
Cricket management system ptoject report.pdf
Cricket management system ptoject report.pdfCricket management system ptoject report.pdf
Cricket management system ptoject report.pdf
 
Literature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.pptxLiterature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.pptx
 
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
 
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
Update 40 models( Solar Cell ) in SPICE PARK(JUL2024)
 
Intuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sdeIntuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sde
 
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdfSri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
 

Arrays

  • 1. Data Structure (2130702) Topic:- Arrays Prepared by- Vasava Aarti .G Roll no_6140 (I.T department) 1
  • 2.  The Array is the most commonly used Data Structure.  An array is a collection of data elements that are of the same type (e.g., a collection of integers, collection of characters, collection of doubles). OR  Array is a data structure that represents a collection of the same types of data.  The values held in an array are called array elements  An array stores multiple values of the same type – the element type  The element type can be a primitive type or an object reference  Therefore, we can create an array of integers, an array of characters, an array of String objects, an array of Coin objects, etc. 2
  • 3.  Given a list of test scores, determine the maximum and minimum scores.  Read in a list of student names and rearrange them in alphabetical order (sorting).  Given the height measurements of students in a class, output the names of those students who are taller than average. 3
  • 4.  Syntax: <type> <arrayName>[<array_size>] Ex. int Ar[10];  The array elements are all values of the type <type>.  The size of the array is indicated by <array_size>, the number of elements in the array.  <array_size> must be an int constant or a constant expression. Note that an array can have multiple dimensions. 4
  • 5. // array of 10 uninitialized ints int Ar[10]; 5 -- -- ----Ar -- -- ---- -- -- 4 5 630 2 8 971 0 1 2 3 4 5
  • 6.  Declare an array of 10 integers: int Ar[10]; // array of 10 ints  To access an individual element we must apply a subscript to array named Ar. › A subscript is a bracketed expression.  The expression in the brackets is known as the index. › First element of array has index 0. Ar[0] › Second element of array has index 1, and so on. Ar[1], Ar[2], Ar[3],… › Last element has an index one less than the size of the array. Ar[9]  Incorrect indexing is a common error. 6
  • 7. 7 // array of 10 uninitialized ints int Ar[10]; Ar[3] = 1; int x = Ar[3]; -- -- 1--Ar -- -- ---- -- -- 4 5 630 2 8 971 Ar[4] Ar[5] Ar[6]Ar[3]Ar[0] Ar[2] Ar[8] Ar[9]Ar[7]Ar[1]
  • 8. #include <stdio.h> int main () { int n[10]; /* n is an array of 10 integers */ int i,j; /* initialize elements of array n to 0 */ for ( i = 0; i < 10; i++ ) { n[ i ] = i + 100; /* set element at location i to i + 100 */ } /* output each array element's value */ for (j = 0; j < 10; j++ ) { printf("Element[%d] = %dn", j, n[j] ); } return 0; } 8
  • 9.  An array can have many dimensions – if it has more than one dimension, it is called a multidimensional array  Each dimension subdivides the previous one into the specified number of elements  Each dimension has its own length constant  Because each dimension is an array of array references, the arrays within one dimension can be of different lengths 10
  • 10. Multiple dimensions get difficult to visualize graphically. • double Coord[100][100][100]; 11 2 Dimensional 3 Dimensional
  • 11. Processing Multi-dimensional Arrays The key to processing all cells of a multi-dimensional array is nested loops. [0] [1] [2] [3] [0] [1] [2] 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 [3] [4] for (int row=0; row!=5; row++) { for (int col=0; col!=4; col++) { System.out.println( myArray[row][col] ); } } for (int col=0; col!=4; col++) { for (int row=0; row!=5; row++) { System.out.println( myArray[row][col] ); } } 12
  • 12. 13 two dimensions one dimension • A one-dimensional array stores a list of elements • A two-dimensional array can be thought of as a table of elements, with rows and columns
  • 13. A two-dimensional array consists of a certain number of rows and columns: const int NUMROWS = 3; const int NUMCOLS = 7; int Array[NUMROWS][NUMCOLS]; 14 Array[2][5] 3rd value in 6th column Array[0][4] 1st value in 5th column The declaration must specify the number of rows and the number of columns, and both must be constants. 0 1 2 3 4 5 6 0 4 18 9 3 -4 6 0 1 12 45 74 15 0 98 0 2 84 87 75 67 81 85 79
  • 14.  In computing, row-major order and column-major order describe methods for storing multidimensional arrays in linear memory.  By following standard matrix notation, rows are numbered by the first index of a two-dimensional array and columns by the second index.  Array layout is critical for correctly passing arrays between programs written in different languages. It is also important for performance when traversing an array because accessing array elements that are contiguous in memory is usually faster than accessing elements which are not, due to caching. 15
  • 15.  In row-major storage, a multidimensional array in linear memory is organized such that rows are stored one after the other. It is the approach used by the C programming language, among others.  For example, consider this 2×3 array:  An array declared in C as int A[2][3] = { {1, 2, 3}, {4, 5, 6} }; is laid out contiguously in linear memory as: 1 2 3 4 5 6 16 1 2 3 4 5 6
  • 16.  To traverse this array in the order in which it is laid out in memory, one would use the following nested loop: for (row = 0; row < 2; row++) for (column = 0; column < 3; column++) printf("%dn", A[row][column]); 17
  • 17.  Column-major order is a similar method of flattening arrays onto linear memory, but the columns are listed in sequence.  The scientific programming languages Fortran and Julia, the matrix-oriented languages MATLAB and Octave, use column-major ordering. The array  if stored contiguously in linear memory with column-major order looks like the following: 1 4 2 5 3 6 18 1 2 3 4 5 6
  翻译: