SlideShare a Scribd company logo
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-Dimensional Array
 Two-Dimensional Array
 Multi-Dimensional Array
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

PPT
PPTX
Binary search
PPTX
Graph representation
PPTX
Basic of array and data structure, data structure basics, array, address calc...
PPTX
linked list in data structure
PDF
Data structure using c++
PPT
Arrays and structures
PDF
Searching and Sorting Techniques in Data Structure
Binary search
Graph representation
Basic of array and data structure, data structure basics, array, address calc...
linked list in data structure
Data structure using c++
Arrays and structures
Searching and Sorting Techniques in Data Structure

What's hot (20)

PPTX
Arrays in Data Structure and Algorithm
PDF
Algorithms Lecture 1: Introduction to Algorithms
PPTX
Array Introduction One-dimensional array Multidimensional array
PDF
Data structures
PDF
Data Structures Notes 2021
PPTX
asymptotic notation
PPTX
Presentation on array
PDF
CS3391 -OOP -UNIT – V NOTES FINAL.pdf
PPTX
Ppt presentation of queues
PDF
Problem solving methodology
PPTX
PDF
Data structure ppt
PDF
Graph Data Structure
PPTX
Complexity analysis in Algorithms
PDF
Algorithms Lecture 2: Analysis of Algorithms I
PPTX
Algorithm analysis (All in one)
PPTX
Data structures
PDF
linked lists in data structures
PPT
DATA STRUCTURES
PPT
Avl trees
Arrays in Data Structure and Algorithm
Algorithms Lecture 1: Introduction to Algorithms
Array Introduction One-dimensional array Multidimensional array
Data structures
Data Structures Notes 2021
asymptotic notation
Presentation on array
CS3391 -OOP -UNIT – V NOTES FINAL.pdf
Ppt presentation of queues
Problem solving methodology
Data structure ppt
Graph Data Structure
Complexity analysis in Algorithms
Algorithms Lecture 2: Analysis of Algorithms I
Algorithm analysis (All in one)
Data structures
linked lists in data structures
DATA STRUCTURES
Avl trees
Ad

Similar to Arrays (20)

PDF
Array.pdf
PPTX
Array ppt
PPTX
Arrays In C++
PPTX
arrayppt.pptx
PPTX
ARRAY PPT.pptx for mca finals placement
PPT
Presentation of array
PPTX
Arrays
 
PPTX
PDF
Array in C full basic explanation
PPTX
arrays in c
PPTX
Different type of Arrays and multidimensional arrays
PPT
Arrays Basics
PPT
PPT
PPTX
ARRAYS.pptx
PDF
Chapter 4 (Part I) - Array and Strings.pdf
PPTX
Various Operations Of Array(Data Structure Algorithm).pptx
PPT
arrayy.ppt
PDF
C_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 5.pdf
Array.pdf
Array ppt
Arrays In C++
arrayppt.pptx
ARRAY PPT.pptx for mca finals placement
Presentation of array
Arrays
 
Array in C full basic explanation
arrays in c
Different type of Arrays and multidimensional arrays
Arrays Basics
ARRAYS.pptx
Chapter 4 (Part I) - Array and Strings.pdf
Various Operations Of Array(Data Structure Algorithm).pptx
arrayy.ppt
C_Dayyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy 5.pdf
Ad

More from sana younas (16)

PPTX
7 habits of highly effective people
PPTX
Connectivity of graphs
PPTX
Shortest path algorithm
PPTX
Binary search
PPTX
circular linklist
PPTX
Link list 2
PPTX
Link list 1
PPT
Heapsort 1
PPTX
Enterpise system
PPT
Database administration
PPT
Encoders
PPTX
Universal logic gate
PPTX
Object oriented programming
PPT
Polymorphism
PPTX
Memory management
PPTX
Parallel adders
7 habits of highly effective people
Connectivity of graphs
Shortest path algorithm
Binary search
circular linklist
Link list 2
Link list 1
Heapsort 1
Enterpise system
Database administration
Encoders
Universal logic gate
Object oriented programming
Polymorphism
Memory management
Parallel adders

Recently uploaded (20)

PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Institutional Correction lecture only . . .
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
RMMM.pdf make it easy to upload and study
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Cell Types and Its function , kingdom of life
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Complications of Minimal Access Surgery at WLH
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Pre independence Education in Inndia.pdf
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Classroom Observation Tools for Teachers
PDF
VCE English Exam - Section C Student Revision Booklet
human mycosis Human fungal infections are called human mycosis..pptx
Institutional Correction lecture only . . .
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
RMMM.pdf make it easy to upload and study
Renaissance Architecture: A Journey from Faith to Humanism
Cell Types and Its function , kingdom of life
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Final Presentation General Medicine 03-08-2024.pptx
Supply Chain Operations Speaking Notes -ICLT Program
Abdominal Access Techniques with Prof. Dr. R K Mishra
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
Complications of Minimal Access Surgery at WLH
O7-L3 Supply Chain Operations - ICLT Program
Pre independence Education in Inndia.pdf
O5-L3 Freight Transport Ops (International) V1.pdf
Classroom Observation Tools for Teachers
VCE English Exam - Section C Student Revision Booklet

Arrays

  • 2. 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.
  • 3. 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.
  • 4. Types of Arrays:  One-Dimensional Array  Two-Dimensional Array  Multi-Dimensional Array
  • 5. 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
  • 6. 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
  • 7. Accessing element of array  Individual Element: Array_name[index];  Using Loop: int marks[5]; for(int i=0;i<=4;i++) marks[i]=i;
  • 8. 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
  • 9. 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.
  • 10. 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.
  • 11. 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
  • 12. Techniques Of Sorting Array There are two techniques of sorting array: o Selection Sort o Bubble Sort
  • 13. 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.
  • 14. 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.
  • 15. 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
  • 16. 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.
  • 17. 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