SlideShare a Scribd company logo
1 of 19
Awais Alam
Topic
Arrays
What is Arrays ?
• An array is a group of consective memory locations with same name and data type.
• Simple variable is a single memory location with unique name and a type. But an
Array is collection of different adjacent memory locations. All these memory
locations have one collective name and type.
• The memory locations in the array are known as elements of array.The total
number of elements in the array is called length.
• The elements of array is accessed with reference to its position in array, that is call
index or subscript.
Advantages / Uses of Arrays
• Arrays can store a large number of value with single name.
• Arrays are used to process many value easily and quickly.
• The values stored in an array can be sorted easily.
• The search process can be applied on arrays easily.
Types of Arrays:
• One-DimensionalArray
• Two-DimensionalArray
• Multi-DimensionalArray
One-D Array
A type of array in which all elements are arranged in the form of a list is known as
1-D array or single dimensional array or linear list.
Declaring 1-D Array:
data_type identifier[length]; e.g: int marks[5];
o Data _type: Data type of values to be stored in the array.
o Identifier: Name of the array.
o Length: Number of elements. 0 1 2 3 4
int marks
One-D array Intialization
The process of assigning values to array elements at the time of array declaration is
called array initialization.
Syntax:
data_type identifier[length]={ List of values }; e.g: int marks[5]={70,54,82,96,49};
o Data _type: Data type of values to be stored in the array.
o Identifier: Name of the array.
o Length: Number of elements
o List of values: Values to initialize the array. Initializing values must be constant
70 54 82 96 49
Accessing element of array
• Individual Element:
Array_name[index];
• Using Loop:
int marks[5];
for(int i=0;i<=4;i++)
marks[i]=i;
Searching In Array
Searching is a process of finding the required data in the array. Searching
becomes more important when the length of the array is very large.
There are two techniques to searching elements in array as follows:
• Sequential search
• Binary search
Sequential Search
Sequential search is also known as linear or serial search. It follows the following
step to search a value in array.
• Visit the first element of array and compare its value with required value.
• If the value of array matches with the desired value, the search is complete.
• If the value of array does not match, move to next element an repeat same process.
Binary Search
Binary search is a quicker method of searching for value in the array. Binary search
is very quick but it can only search an sorted array. It cannot be applied on an
unsorted array.
o It locates the middle element of array and compare with desired number.
o If they are equal, search is successful and the index of middle element is returned.
o If they are not equal, it reduces the search to half of the array.
o If the search number is less than the middle element, it searches the first half of array.
Otherwise it searches the second half of the array.The process continues until the required
number is found or loop completes without successful search.
Sorting Arrays
Sorting is a process of arranging the value of array in a particular order. An
array can be sorted in two order.
o Ascending Order
o Descending Order
12 25 33 37 48
48 37 33 25 12
Techniques Of Sorting Array
There are two techniques of sorting array:
o Selection Sort
o Bubble Sort
Selection Sort
Selection sort is a technique that sort an array. It selects an element in the
array and moves it to its proper position. Selection sort works as follows:
1. Find the minimum value in the list.
2. Swap it with value in the first position.
3. Sort the remainder of the list excluding the first value.
Bubble Sort
Bubble Sort is also known as exchange sort. It repeatedly visits the array and
compares two items at a time. It works as follows:
o Compare adjacent element. If the first is greater than the second, swap them.
o Repeat this for each pair of adjacent element, starting with the first two and ending
with the last two. (at this point last element should be greatest).
o Repeat the step for all elements except the last one.
o Keep repeating for one fewer element each time until there are no pairs to compare.
Two-D Arrays
Two-D array can be considered as table that consists of rows and columns. Each
element in 2-D array is refered with the help of two indexes. One index indicates
row and second indicates the column.
Declaring 2-D Array:
Data_type Identifier[row][column]; e.g: int arr[4][3];
o Data _type: Data type of values to be stored in the array.
o Identifier: Name of the array.
o Rows : # of Rows in the table of array.
o Column : # of Columns in the table of array.
0,0 0,1 0,2
1,0 1,1 1,2
2,0 2,1 2,2
3,0 3,1 3,2
Two-D array Intialization
The two-D array can also be initialized at the time of declaration. Initialization is
performed by assigning the initial values in braces seperated by commas.
Some important points :
o The elements of each row are enclosed within braces and seperated by comma.
o All rows are enclosed within braces.
o For number arrays, if all elements are not specified , the un specified elements are initialized by
zero.
Two-D array Intialization
Syntax:
int arr[4][3]={ {12,5,22},
{95,3,41},
{77,6,53},
{84,59,62} }
12 5 22
95 3 41
77 6 53
84 59 62
Column indexes
Row indexes
0
2
1
3
10 2
Thank you 

More Related Content

What's hot

What's hot (20)

C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Arrays
ArraysArrays
Arrays
 
Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive Data Types - Premetive and Non Premetive
Data Types - Premetive and Non Premetive
 
Linked list
Linked listLinked list
Linked list
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 
Arrays
ArraysArrays
Arrays
 
Queue
QueueQueue
Queue
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
 
Arrays
ArraysArrays
Arrays
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
Data structure
Data structureData structure
Data structure
 
Arrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | EdurekaArrays In Python | Python Array Operations | Edureka
Arrays In Python | Python Array Operations | Edureka
 
sparse matrix in data structure
sparse matrix in data structuresparse matrix in data structure
sparse matrix in data structure
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Stack
StackStack
Stack
 
Data Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search TreeData Structure and Algorithms Binary Search Tree
Data Structure and Algorithms Binary Search Tree
 
Data structures & algorithms lecture 3
Data structures & algorithms lecture 3Data structures & algorithms lecture 3
Data structures & algorithms lecture 3
 

Similar to Arrays Guide - Everything You Need to Know About Arrays

Similar to Arrays Guide - Everything You Need to Know About Arrays (20)

Arrays
ArraysArrays
Arrays
 
Array.pdf
Array.pdfArray.pdf
Array.pdf
 
arrayppt.pptx
arrayppt.pptxarrayppt.pptx
arrayppt.pptx
 
Presentation of array
Presentation of arrayPresentation of array
Presentation of array
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
Arrays
ArraysArrays
Arrays
 
Unit 4
Unit 4Unit 4
Unit 4
 
Arrays
ArraysArrays
Arrays
 
Arrays in C.pptx
Arrays in C.pptxArrays in C.pptx
Arrays in C.pptx
 
Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6
 
Array
ArrayArray
Array
 
Array in c
Array in cArray in c
Array in c
 
arrays in c
arrays in carrays in c
arrays in c
 
Acm aleppo cpc training seventh session
Acm aleppo cpc training seventh sessionAcm aleppo cpc training seventh session
Acm aleppo cpc training seventh session
 
Array.ppt
Array.pptArray.ppt
Array.ppt
 
array.ppt
array.pptarray.ppt
array.ppt
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
Arrays accessing using for loops
Arrays accessing using for loopsArrays accessing using for loops
Arrays accessing using for loops
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
 
Unit 2 linear data structures
Unit 2   linear data structuresUnit 2   linear data structures
Unit 2 linear data structures
 

Recently uploaded

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 

Arrays Guide - Everything You Need to Know About Arrays

  • 3. What is Arrays ? • An array is a group of consective memory locations with same name and data type. • Simple variable is a single memory location with unique name and a type. But an Array is collection of different adjacent memory locations. All these memory locations have one collective name and type. • The memory locations in the array are known as elements of array.The total number of elements in the array is called length. • The elements of array is accessed with reference to its position in array, that is call index or subscript.
  • 4. Advantages / Uses of Arrays • Arrays can store a large number of value with single name. • Arrays are used to process many value easily and quickly. • The values stored in an array can be sorted easily. • The search process can be applied on arrays easily.
  • 5. Types of Arrays: • One-DimensionalArray • Two-DimensionalArray • Multi-DimensionalArray
  • 6. One-D Array A type of array in which all elements are arranged in the form of a list is known as 1-D array or single dimensional array or linear list. Declaring 1-D Array: data_type identifier[length]; e.g: int marks[5]; o Data _type: Data type of values to be stored in the array. o Identifier: Name of the array. o Length: Number of elements. 0 1 2 3 4 int marks
  • 7. One-D array Intialization The process of assigning values to array elements at the time of array declaration is called array initialization. Syntax: data_type identifier[length]={ List of values }; e.g: int marks[5]={70,54,82,96,49}; o Data _type: Data type of values to be stored in the array. o Identifier: Name of the array. o Length: Number of elements o List of values: Values to initialize the array. Initializing values must be constant 70 54 82 96 49
  • 8. Accessing element of array • Individual Element: Array_name[index]; • Using Loop: int marks[5]; for(int i=0;i<=4;i++) marks[i]=i;
  • 9. Searching In Array Searching is a process of finding the required data in the array. Searching becomes more important when the length of the array is very large. There are two techniques to searching elements in array as follows: • Sequential search • Binary search
  • 10. Sequential Search Sequential search is also known as linear or serial search. It follows the following step to search a value in array. • Visit the first element of array and compare its value with required value. • If the value of array matches with the desired value, the search is complete. • If the value of array does not match, move to next element an repeat same process.
  • 11. Binary Search Binary search is a quicker method of searching for value in the array. Binary search is very quick but it can only search an sorted array. It cannot be applied on an unsorted array. o It locates the middle element of array and compare with desired number. o If they are equal, search is successful and the index of middle element is returned. o If they are not equal, it reduces the search to half of the array. o If the search number is less than the middle element, it searches the first half of array. Otherwise it searches the second half of the array.The process continues until the required number is found or loop completes without successful search.
  • 12. Sorting Arrays Sorting is a process of arranging the value of array in a particular order. An array can be sorted in two order. o Ascending Order o Descending Order 12 25 33 37 48 48 37 33 25 12
  • 13. Techniques Of Sorting Array There are two techniques of sorting array: o Selection Sort o Bubble Sort
  • 14. Selection Sort Selection sort is a technique that sort an array. It selects an element in the array and moves it to its proper position. Selection sort works as follows: 1. Find the minimum value in the list. 2. Swap it with value in the first position. 3. Sort the remainder of the list excluding the first value.
  • 15. Bubble Sort Bubble Sort is also known as exchange sort. It repeatedly visits the array and compares two items at a time. It works as follows: o Compare adjacent element. If the first is greater than the second, swap them. o Repeat this for each pair of adjacent element, starting with the first two and ending with the last two. (at this point last element should be greatest). o Repeat the step for all elements except the last one. o Keep repeating for one fewer element each time until there are no pairs to compare.
  • 16. Two-D Arrays Two-D array can be considered as table that consists of rows and columns. Each element in 2-D array is refered with the help of two indexes. One index indicates row and second indicates the column. Declaring 2-D Array: Data_type Identifier[row][column]; e.g: int arr[4][3]; o Data _type: Data type of values to be stored in the array. o Identifier: Name of the array. o Rows : # of Rows in the table of array. o Column : # of Columns in the table of array. 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 3,0 3,1 3,2
  • 17. Two-D array Intialization The two-D array can also be initialized at the time of declaration. Initialization is performed by assigning the initial values in braces seperated by commas. Some important points : o The elements of each row are enclosed within braces and seperated by comma. o All rows are enclosed within braces. o For number arrays, if all elements are not specified , the un specified elements are initialized by zero.
  • 18. Two-D array Intialization Syntax: int arr[4][3]={ {12,5,22}, {95,3,41}, {77,6,53}, {84,59,62} } 12 5 22 95 3 41 77 6 53 84 59 62 Column indexes Row indexes 0 2 1 3 10 2