Arrays.pptx

Arrays
Definition:
An array is defined as a set of finite number of homogeneous
elements or same data items:
Declaration of array is as follows:
Syntax: Data type Array Name [Size];
Example: int arr[10];
Where int specifies the data type or type of elements arrays stores.
“arr” is the name of array & the number specified inside the
square brackets is the number of elements an array can store, this
is also called sized or length of array.
• Calculating the length of the array:
• The elements of array will always be stored in the consecutive
(continues) memory location.
• The number of elements that can be stored in an array, that is
the size of array or its length is
• given by the following equation:
• A[n] is the array size or length of n elements.
• The length of the array can be calculated by:
• L = UB – LB + 1
• Example:
If an array A has values 10, 20, 30, 40, 50, stored in location
0,1, 2, 3, 4 the UB = 4 and LB=0
Size of the array L = 4 – 0 + 1 = 5
Classification of linear arrays
• A linear array is a list of fixed size number of similar data type
elements.
Arrays are categorized as Single /one-dimensional array and
multidimensional arrays
• Single Dimension Array:
• Array with one subscript
– Ex: int A[i];
• Two Dimension Array
– Array with two subscripts (Rows and Column)
– Ex: int A[i][j];
• Multi Dimension Array:
– Array with Multiple subscripts
– Ex: int A[i][j]..[n];
Arrays.pptx
• Representation of linear arrays in memory:
• The elements of linear array are stored in consecutive memory locations.
• It is shown below:
•
•
.
• Index starts with 0.
• Array length is 8 which means it can store 8 elements.
• Each element can be accessed via its index. For example, we can fetch element at
index 6 as 27.
• In linear array location of element A[i] can be calculated using following equation:
• LOC( A[i])=Base_Address+W*(i)
• Base_address is the adress of the frist element in the array
• W is the word size.It means number of bytes occupied by each element.
Operations on array:
• Traversing: means to visit all the elements of the array in an
operation is called traversing.
• Insertion: means to put values into an array
• Deletion / Remove: to delete a value from an array.
• Sorting: Re-arrangement of values in an array in a specific order
(Ascending or Descending) is called sorting.
• Searching: The process of finding the location of a particular
element in an array is called searching.
• Traversing:
It is used to access each data item exactly once so that it
can be processed:
• We have linear array A as below:
1 2 3 4 5
10 20 30 40 50
• Here we will start from beginning and will go till last
element and during this process we will access value of
each element exactly once as below:
• A [0] = 10
• A [1] = 20
• A [2] = 30
• A [3] = 40
• A [4] = 50
Arrays.pptx
• Insertion into Array:
• Insertion:
• It is used to add a new data item in the given collection of data
items.
• it is quite easy to insert the element in the end of array
provided sufficient memory location are present to
accommodate the additional element.
• To insert the element at our desired locations like some
where in the middle of array, all the elements must be moved
to next locations to add new element and to keep their order.
• If we are inserting an element in the beginning of an
array, then all the elements should be moved to next locations
to accommodate the new element.
• Algorithm: Insert (A,N,LOC,ITEM)
• Here A is a linear array with N elements. LOC is the location. Where
ITEM is to inserted.
1. set I=N
[ initialize Counter ]
2. Repeat While (I >= LOC)
3. Set A [ I + 1 ] = A [ I ]
[Move elements to next locations]
4. Set I = I - 1
[Decrease counter by 1]
5. Set A [ LOC ] = ITEM
[ Insert element at LOC Position]
6. Set N = N + 1
[ Increment N by 1]
7. Exit
• Visual Representation :
• Example:
• Let's take an array of 5 integers.
• 1, 20, 5, 78, 30.
• If we need to insert an element 100 at position 2, the
execution will be,
• Insert element in array
• 1. We need to insert element 100 at position 2.
• 2. Move all the elements from the last index(4) to the
position(2) to one position right.
• arr[4] (30) will be placed in arr[5].
• arr[3] (78) will be placed in arr[4].
• arr[2] (5) will be placed in arr[3].
• 3. Finally, the element 100 is placed at the position 2.
• Insert an element in to an array:
• Deletion from Array:
• Deletion: It is used to delete an existing data item from the given collection
of data Items.
• It is quite easy to delete the element from the end of array. To delete the
element from our desired location like some where in the middle of the
array or beginning of the array then all the subsequent elements must be
moved one location left to keep the order of array.
• Deletion 30 from Array at Pos 3
• A [0] = 10
• A [1] = 20
• A [2] = 30
• A [3] = 40
• A [4] = 50
Arrays.pptx
• Two Dimensional Array :
• Arrays which have elements with two subscripts are known as two
dimensional arrays. A two dimensional array consist of rows and columns.
• It is also known as double dimensional arrays .
• The general format of two dimensional array is :
• Data type arrayname[size-1][size-2];
• Here data type represents type of elements stored in the array such as int,
float,char,double.
• Array name is the name of the array.
• Size-1 and Size-2 specifies the maximum number of elements can be stored
in the array.
• Size-1 specifies row size, size-2 specifies column size.
• Example:
• int A[3][4];
• A is a two dimensional array which contains 3 Rows and 4 Columns.
• Multi Dimensional Array:
– Array with Multiple subscripts
– Ex: int A[i][j]..[n];
– EX: A[3][3][3]
– A is a 3D array is essentially an array of arrays of arrays .it is a
collection of 2D arrays.
Arrays.pptx
• Memory Representation of Multi dimensional array:
• 1. Row – Major Representation
• 2. Column – Major Representation
Row – Major Representation:
In this method elements of an array are arranged sequentially Row by Row.
Ex: int A[3][3] = { 1,2,3,4,5,6,7,8,9}
And it will be represented in memory with row major representation as follows
A[0][0]
1
A[0][1]
2
A[0][2]
3
A[1][0]
4
A[1][1]
5
A[1][2]
6
A[2][0]
7
A[2][1]
8
A[2][2]
9
A[0][0]
1
A[0][1]
2
A[0][2]
3
A[1][0]
4
A[1][1]
5
A[1][2]
6
A[2][0]
7
A[2][1]
8
A[2][2]
9
• The location of element A[i,j] can be obtained by evaluating Expression.
• LOC(A[i,j])=Base_Address +W[M(i) +(j)]
• Base_Address is the address of the first element of the array
• W is the word size it means number of bytes occupied by each element
• N is number of rows in array
• M is number of columns in array
2. Column – Major Representation
In this method elements of an array are arranged sequentially Column by Column.
Ex: int A[3][3] = { 1,2,3,4,5,6,7,8,9}
And it will be represented in memory with Column major representation as follows
A[0][0]
1
A[0][1]
2
A[0][2]
3
A[1][0]
4
A[1][1]
5
A[1][2]
6
A[2][0]
7
A[2][1]
8
A[2][2]
9
A[0][0]
1
A[1][0]
2
A[2][0]
3
A[0][1]
4
A[1][1]
5
A[2][1]
6
A[0][2]
7
A[1][2]
8
A[2][2]
9
• The location of element A[i,j] can be obtained by evaluating Expression.
• LOC(A[i,j])=Base_Address +W[N(j) +(i)]
• Base_Address is the address of the first element of the array
• W is the word size it means number of bytes occupied by each element
• N is number of rows in array
• M is number of columns in array
1 von 21

Recomendados

ARRAYS.pptxARRAYS.pptx
ARRAYS.pptxMamataAnilgod
7 views39 Folien
arrays.pptxarrays.pptx
arrays.pptxHarmanShergill5
10 views41 Folien
cluod.pdfcluod.pdf
cluod.pdfssuser92d367
7 views36 Folien
ArraysArrays
ArraysSARITHA REDDY
26K views50 Folien

Más contenido relacionado

Similar a Arrays.pptx(20)

ArrayArray
Array
Fahuda E35 views
Python arrayPython array
Python array
Arnab Chakraborty168 views
Data structure pptData structure ppt
Data structure ppt
Prof. Dr. K. Adisesha117K views
Unit 2 dsa LINEAR DATA STRUCTUREUnit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTURE
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK35 views
Unit 2   linear data structuresUnit 2   linear data structures
Unit 2 linear data structures
Senthil Murugan49 views
Lecture7Lecture7
Lecture7
Ahmad Al-Bakry176 views
DS Unit 1.pptxDS Unit 1.pptx
DS Unit 1.pptx
chin46367010 views
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
eShikshak1.8K views
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
blessyboban9285 views
Arrays In C++Arrays In C++
Arrays In C++
Awais Alam20.3K views
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
Ashim Lamichhane2.1K views
Two Dimensional ArrayTwo Dimensional Array
Two Dimensional Array
dincyjain117 views
DSA UNIT II ARRAY AND LIST - notesDSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notes
swathirajstar64 views
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
pramod5999393 views
unit 2.pptxunit 2.pptx
unit 2.pptx
researchgrad822 views
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
ETTEverythingistrueO10 views

Más de Koteswari Kasireddy(20)

unit-3_Chapter1_RDRA.pdfunit-3_Chapter1_RDRA.pdf
unit-3_Chapter1_RDRA.pdf
Koteswari Kasireddy1 view
DBMS_UNIT_1.pdfDBMS_UNIT_1.pdf
DBMS_UNIT_1.pdf
Koteswari Kasireddy26 views
business analyticsbusiness analytics
business analytics
Koteswari Kasireddy43 views
CHAPTER -12 it.pptxCHAPTER -12 it.pptx
CHAPTER -12 it.pptx
Koteswari Kasireddy4 views
WEB_DATABASE_chapter_4.pptxWEB_DATABASE_chapter_4.pptx
WEB_DATABASE_chapter_4.pptx
Koteswari Kasireddy4 views
Evolution Of WEB_students.pptxEvolution Of WEB_students.pptx
Evolution Of WEB_students.pptx
Koteswari Kasireddy3 views
Presentation1.pptxPresentation1.pptx
Presentation1.pptx
Koteswari Kasireddy4 views
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
Koteswari Kasireddy7 views
Control_Statements_in_Python.pptxControl_Statements_in_Python.pptx
Control_Statements_in_Python.pptx
Koteswari Kasireddy58 views
Python_Functions_Unit1.pptxPython_Functions_Unit1.pptx
Python_Functions_Unit1.pptx
Koteswari Kasireddy10 views
parts_of_python_programming_language.pptxparts_of_python_programming_language.pptx
parts_of_python_programming_language.pptx
Koteswari Kasireddy5 views
linked_list.pptxlinked_list.pptx
linked_list.pptx
Koteswari Kasireddy3 views
matrices_and_loops.pptxmatrices_and_loops.pptx
matrices_and_loops.pptx
Koteswari Kasireddy2 views
algorithms_in_linkedlist.pptxalgorithms_in_linkedlist.pptx
algorithms_in_linkedlist.pptx
Koteswari Kasireddy4 views
Control_Statements.pptxControl_Statements.pptx
Control_Statements.pptx
Koteswari Kasireddy4 views
Files in Python.pptxFiles in Python.pptx
Files in Python.pptx
Koteswari Kasireddy12 views
Algorithm.pptxAlgorithm.pptx
Algorithm.pptx
Koteswari Kasireddy15 views

Último(20)

GSoC 2024GSoC 2024
GSoC 2024
DeveloperStudentClub1049 views
Classification of crude drugs.pptxClassification of crude drugs.pptx
Classification of crude drugs.pptx
GayatriPatra1449 views
NS3 Unit 2 Life processes of animals.pptxNS3 Unit 2 Life processes of animals.pptx
NS3 Unit 2 Life processes of animals.pptx
manuelaromero201389 views
Universe revised.pdfUniverse revised.pdf
Universe revised.pdf
DrHafizKosar84 views
Class 10 English  lesson plansClass 10 English  lesson plans
Class 10 English lesson plans
TARIQ KHAN172 views
ICANNICANN
ICANN
RajaulKarim2057 views
Narration  ppt.pptxNarration  ppt.pptx
Narration ppt.pptx
TARIQ KHAN62 views
Material del tarjetero LEES Travesías.docxMaterial del tarjetero LEES Travesías.docx
Material del tarjetero LEES Travesías.docx
Norberto Millán Muñoz57 views
Drama KS5 BreakdownDrama KS5 Breakdown
Drama KS5 Breakdown
WestHatch50 views
Azure DevOps Pipeline setup for Mule APIs #36Azure DevOps Pipeline setup for Mule APIs #36
Azure DevOps Pipeline setup for Mule APIs #36
MysoreMuleSoftMeetup75 views
ACTIVITY BOOK key water sports.pptxACTIVITY BOOK key water sports.pptx
ACTIVITY BOOK key water sports.pptx
Mar Caston Palacio132 views
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptxGopal Chakraborty Memorial Quiz 2.0 Prelims.pptx
Gopal Chakraborty Memorial Quiz 2.0 Prelims.pptx
Debapriya Chakraborty221 views
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}
ANATOMY AND PHYSIOLOGY UNIT 1 { PART-1}
DR .PALLAVI PATHANIA156 views
231112 (WR) v1  ChatGPT OEB 2023.pdf231112 (WR) v1  ChatGPT OEB 2023.pdf
231112 (WR) v1 ChatGPT OEB 2023.pdf
WilfredRubens.com100 views
Dance KS5 BreakdownDance KS5 Breakdown
Dance KS5 Breakdown
WestHatch52 views
Scope of Biochemistry.pptxScope of Biochemistry.pptx
Scope of Biochemistry.pptx
shoba shoba110 views

Arrays.pptx

  • 1. Arrays Definition: An array is defined as a set of finite number of homogeneous elements or same data items: Declaration of array is as follows: Syntax: Data type Array Name [Size]; Example: int arr[10]; Where int specifies the data type or type of elements arrays stores. “arr” is the name of array & the number specified inside the square brackets is the number of elements an array can store, this is also called sized or length of array.
  • 2. • Calculating the length of the array: • The elements of array will always be stored in the consecutive (continues) memory location. • The number of elements that can be stored in an array, that is the size of array or its length is • given by the following equation: • A[n] is the array size or length of n elements. • The length of the array can be calculated by: • L = UB – LB + 1 • Example: If an array A has values 10, 20, 30, 40, 50, stored in location 0,1, 2, 3, 4 the UB = 4 and LB=0 Size of the array L = 4 – 0 + 1 = 5
  • 3. Classification of linear arrays • A linear array is a list of fixed size number of similar data type elements. Arrays are categorized as Single /one-dimensional array and multidimensional arrays • Single Dimension Array: • Array with one subscript – Ex: int A[i]; • Two Dimension Array – Array with two subscripts (Rows and Column) – Ex: int A[i][j]; • Multi Dimension Array: – Array with Multiple subscripts – Ex: int A[i][j]..[n];
  • 5. • Representation of linear arrays in memory: • The elements of linear array are stored in consecutive memory locations. • It is shown below: • • . • Index starts with 0. • Array length is 8 which means it can store 8 elements. • Each element can be accessed via its index. For example, we can fetch element at index 6 as 27. • In linear array location of element A[i] can be calculated using following equation: • LOC( A[i])=Base_Address+W*(i) • Base_address is the adress of the frist element in the array • W is the word size.It means number of bytes occupied by each element.
  • 6. Operations on array: • Traversing: means to visit all the elements of the array in an operation is called traversing. • Insertion: means to put values into an array • Deletion / Remove: to delete a value from an array. • Sorting: Re-arrangement of values in an array in a specific order (Ascending or Descending) is called sorting. • Searching: The process of finding the location of a particular element in an array is called searching.
  • 7. • Traversing: It is used to access each data item exactly once so that it can be processed: • We have linear array A as below: 1 2 3 4 5 10 20 30 40 50 • Here we will start from beginning and will go till last element and during this process we will access value of each element exactly once as below: • A [0] = 10 • A [1] = 20 • A [2] = 30 • A [3] = 40 • A [4] = 50
  • 9. • Insertion into Array: • Insertion: • It is used to add a new data item in the given collection of data items. • it is quite easy to insert the element in the end of array provided sufficient memory location are present to accommodate the additional element. • To insert the element at our desired locations like some where in the middle of array, all the elements must be moved to next locations to add new element and to keep their order. • If we are inserting an element in the beginning of an array, then all the elements should be moved to next locations to accommodate the new element.
  • 10. • Algorithm: Insert (A,N,LOC,ITEM) • Here A is a linear array with N elements. LOC is the location. Where ITEM is to inserted. 1. set I=N [ initialize Counter ] 2. Repeat While (I >= LOC) 3. Set A [ I + 1 ] = A [ I ] [Move elements to next locations] 4. Set I = I - 1 [Decrease counter by 1] 5. Set A [ LOC ] = ITEM [ Insert element at LOC Position] 6. Set N = N + 1 [ Increment N by 1] 7. Exit
  • 11. • Visual Representation : • Example: • Let's take an array of 5 integers. • 1, 20, 5, 78, 30. • If we need to insert an element 100 at position 2, the execution will be, • Insert element in array • 1. We need to insert element 100 at position 2. • 2. Move all the elements from the last index(4) to the position(2) to one position right. • arr[4] (30) will be placed in arr[5]. • arr[3] (78) will be placed in arr[4]. • arr[2] (5) will be placed in arr[3]. • 3. Finally, the element 100 is placed at the position 2.
  • 12. • Insert an element in to an array:
  • 13. • Deletion from Array: • Deletion: It is used to delete an existing data item from the given collection of data Items. • It is quite easy to delete the element from the end of array. To delete the element from our desired location like some where in the middle of the array or beginning of the array then all the subsequent elements must be moved one location left to keep the order of array. • Deletion 30 from Array at Pos 3 • A [0] = 10 • A [1] = 20 • A [2] = 30 • A [3] = 40 • A [4] = 50
  • 15. • Two Dimensional Array : • Arrays which have elements with two subscripts are known as two dimensional arrays. A two dimensional array consist of rows and columns. • It is also known as double dimensional arrays . • The general format of two dimensional array is : • Data type arrayname[size-1][size-2]; • Here data type represents type of elements stored in the array such as int, float,char,double. • Array name is the name of the array. • Size-1 and Size-2 specifies the maximum number of elements can be stored in the array. • Size-1 specifies row size, size-2 specifies column size.
  • 16. • Example: • int A[3][4]; • A is a two dimensional array which contains 3 Rows and 4 Columns. • Multi Dimensional Array: – Array with Multiple subscripts – Ex: int A[i][j]..[n]; – EX: A[3][3][3] – A is a 3D array is essentially an array of arrays of arrays .it is a collection of 2D arrays.
  • 18. • Memory Representation of Multi dimensional array: • 1. Row – Major Representation • 2. Column – Major Representation Row – Major Representation: In this method elements of an array are arranged sequentially Row by Row. Ex: int A[3][3] = { 1,2,3,4,5,6,7,8,9} And it will be represented in memory with row major representation as follows A[0][0] 1 A[0][1] 2 A[0][2] 3 A[1][0] 4 A[1][1] 5 A[1][2] 6 A[2][0] 7 A[2][1] 8 A[2][2] 9 A[0][0] 1 A[0][1] 2 A[0][2] 3 A[1][0] 4 A[1][1] 5 A[1][2] 6 A[2][0] 7 A[2][1] 8 A[2][2] 9
  • 19. • The location of element A[i,j] can be obtained by evaluating Expression. • LOC(A[i,j])=Base_Address +W[M(i) +(j)] • Base_Address is the address of the first element of the array • W is the word size it means number of bytes occupied by each element • N is number of rows in array • M is number of columns in array
  • 20. 2. Column – Major Representation In this method elements of an array are arranged sequentially Column by Column. Ex: int A[3][3] = { 1,2,3,4,5,6,7,8,9} And it will be represented in memory with Column major representation as follows A[0][0] 1 A[0][1] 2 A[0][2] 3 A[1][0] 4 A[1][1] 5 A[1][2] 6 A[2][0] 7 A[2][1] 8 A[2][2] 9 A[0][0] 1 A[1][0] 2 A[2][0] 3 A[0][1] 4 A[1][1] 5 A[2][1] 6 A[0][2] 7 A[1][2] 8 A[2][2] 9
  • 21. • The location of element A[i,j] can be obtained by evaluating Expression. • LOC(A[i,j])=Base_Address +W[N(j) +(i)] • Base_Address is the address of the first element of the array • W is the word size it means number of bytes occupied by each element • N is number of rows in array • M is number of columns in array