SlideShare ist ein Scribd-Unternehmen logo
1 von 18
This PPT will helpful for your project and self study also.
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
* Prepared by .. .
1. Kaushal Mehta … .. twitter@kaushalmehta96
2. Jigar Patel … .. twitter@jigarpatel_jp

Weitere ähnliche Inhalte

Was ist angesagt? (20)

STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
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
 
2D Array
2D Array 2D Array
2D Array
 
Arrays
ArraysArrays
Arrays
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Array
ArrayArray
Array
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Linked list
Linked listLinked list
Linked list
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Selection sorting
Selection sortingSelection sorting
Selection sorting
 
Structure in C
Structure in CStructure in C
Structure in C
 
Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
single linked list
single linked listsingle linked list
single linked list
 
Two dimensional array
Two dimensional arrayTwo dimensional array
Two dimensional array
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
 
Array data structure
Array data structureArray data structure
Array data structure
 

Andere mochten auch

Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)EngineerBabu
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structurestudent
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentationNeveen Reda
 
Multiplication arrays ppt
Multiplication arrays pptMultiplication arrays ppt
Multiplication arrays pptrryan80
 
Multiplication jeopardy game
Multiplication jeopardy gameMultiplication jeopardy game
Multiplication jeopardy gamerryan80
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURESbca2010
 
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
 
Lecture 2 data structures & algorithms - sorting techniques
Lecture 2  data structures & algorithms - sorting techniquesLecture 2  data structures & algorithms - sorting techniques
Lecture 2 data structures & algorithms - sorting techniquesDharmendra Prasad
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm designNahid Hasan
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examplesgreatqadirgee4u
 

Andere mochten auch (20)

Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 
Arrays
ArraysArrays
Arrays
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Arrays Data Structure
Arrays Data StructureArrays Data Structure
Arrays Data Structure
 
Array in C
Array in CArray in C
Array in C
 
Arrays Class presentation
Arrays Class presentationArrays Class presentation
Arrays Class presentation
 
Multiplication arrays ppt
Multiplication arrays pptMultiplication arrays ppt
Multiplication arrays ppt
 
Arrays
ArraysArrays
Arrays
 
Multiplication jeopardy game
Multiplication jeopardy gameMultiplication jeopardy game
Multiplication jeopardy game
 
Arrays In C++
Arrays In C++Arrays In C++
Arrays In C++
 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
 
2.DS Array
2.DS Array2.DS Array
2.DS 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)
A Presentation About Array Manipulation(Insertion & Deletion in an array)
 
Chapter 3 Arrays in Java
Chapter 3 Arrays in JavaChapter 3 Arrays in Java
Chapter 3 Arrays in Java
 
Lecture 2 data structures & algorithms - sorting techniques
Lecture 2  data structures & algorithms - sorting techniquesLecture 2  data structures & algorithms - sorting techniques
Lecture 2 data structures & algorithms - sorting techniques
 
Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]
 
3 Array operations
3   Array operations3   Array operations
3 Array operations
 
Our presentation on algorithm design
Our presentation on algorithm designOur presentation on algorithm design
Our presentation on algorithm design
 
[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance[OOP - Lec 20,21] Inheritance
[OOP - Lec 20,21] Inheritance
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
 

Ähnlich wie Array ppt (20)

Arrays
ArraysArrays
Arrays
 
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
 
Ap Power Point Chpt6
Ap Power Point Chpt6Ap Power Point Chpt6
Ap Power Point Chpt6
 
Arrays
ArraysArrays
Arrays
 
arrays in c
arrays in carrays in c
arrays in c
 
Unit 4
Unit 4Unit 4
Unit 4
 
Array
ArrayArray
Array
 
Array.ppt
Array.pptArray.ppt
Array.ppt
 
array.ppt
array.pptarray.ppt
array.ppt
 
Arrays in C.pptx
Arrays in C.pptxArrays in C.pptx
Arrays in C.pptx
 
Array in c
Array in cArray in c
Array 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
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
 
Arrays accessing using for loops
Arrays accessing using for loopsArrays accessing using for loops
Arrays accessing using for loops
 
ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
Data Structure
Data StructureData Structure
Data Structure
 
DSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notesDSA UNIT II ARRAY AND LIST - notes
DSA UNIT II ARRAY AND LIST - notes
 

Kürzlich hochgeladen

Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsResearcher Researcher
 
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithm
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithmComputer Graphics Introduction, Open GL, Line and Circle drawing algorithm
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithmDeepika Walanjkar
 
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHTEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHSneha Padhiar
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating SystemRashmi Bhat
 
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书rnrncn29
 
Forming section troubleshooting checklist for improving wire life (1).ppt
Forming section troubleshooting checklist for improving wire life (1).pptForming section troubleshooting checklist for improving wire life (1).ppt
Forming section troubleshooting checklist for improving wire life (1).pptNoman khan
 
Theory of Machine Notes / Lecture Material .pdf
Theory of Machine Notes / Lecture Material .pdfTheory of Machine Notes / Lecture Material .pdf
Theory of Machine Notes / Lecture Material .pdfShreyas Pandit
 
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESCME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESkarthi keyan
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewsandhya757531
 
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.pptROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.pptJohnWilliam111370
 
Cost estimation approach: FP to COCOMO scenario based question
Cost estimation approach: FP to COCOMO scenario based questionCost estimation approach: FP to COCOMO scenario based question
Cost estimation approach: FP to COCOMO scenario based questionSneha Padhiar
 
Levelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodLevelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodManicka Mamallan Andavar
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxsiddharthjain2303
 
Immutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfImmutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfDrew Moseley
 
CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfBalamuruganV28
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating SystemRashmi Bhat
 
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...Stork Webinar | APM Transformational planning, Tool Selection & Performance T...
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...Stork
 
Robotics Group 10 (Control Schemes) cse.pdf
Robotics Group 10  (Control Schemes) cse.pdfRobotics Group 10  (Control Schemes) cse.pdf
Robotics Group 10 (Control Schemes) cse.pdfsahilsajad201
 

Kürzlich hochgeladen (20)

Novel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending ActuatorsNovel 3D-Printed Soft Linear and Bending Actuators
Novel 3D-Printed Soft Linear and Bending Actuators
 
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithm
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithmComputer Graphics Introduction, Open GL, Line and Circle drawing algorithm
Computer Graphics Introduction, Open GL, Line and Circle drawing algorithm
 
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACHTEST CASE GENERATION GENERATION BLOCK BOX APPROACH
TEST CASE GENERATION GENERATION BLOCK BOX APPROACH
 
Main Memory Management in Operating System
Main Memory Management in Operating SystemMain Memory Management in Operating System
Main Memory Management in Operating System
 
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
『澳洲文凭』买麦考瑞大学毕业证书成绩单办理澳洲Macquarie文凭学位证书
 
Forming section troubleshooting checklist for improving wire life (1).ppt
Forming section troubleshooting checklist for improving wire life (1).pptForming section troubleshooting checklist for improving wire life (1).ppt
Forming section troubleshooting checklist for improving wire life (1).ppt
 
Theory of Machine Notes / Lecture Material .pdf
Theory of Machine Notes / Lecture Material .pdfTheory of Machine Notes / Lecture Material .pdf
Theory of Machine Notes / Lecture Material .pdf
 
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTESCME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
CME 397 - SURFACE ENGINEERING - UNIT 1 FULL NOTES
 
Artificial Intelligence in Power System overview
Artificial Intelligence in Power System overviewArtificial Intelligence in Power System overview
Artificial Intelligence in Power System overview
 
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.pptROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
ROBOETHICS-CCS345 ETHICS AND ARTIFICIAL INTELLIGENCE.ppt
 
Cost estimation approach: FP to COCOMO scenario based question
Cost estimation approach: FP to COCOMO scenario based questionCost estimation approach: FP to COCOMO scenario based question
Cost estimation approach: FP to COCOMO scenario based question
 
Levelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument methodLevelling - Rise and fall - Height of instrument method
Levelling - Rise and fall - Height of instrument method
 
Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptx
 
Immutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdfImmutable Image-Based Operating Systems - EW2024.pdf
Immutable Image-Based Operating Systems - EW2024.pdf
 
CS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdfCS 3251 Programming in c all unit notes pdf
CS 3251 Programming in c all unit notes pdf
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
Virtual memory management in Operating System
Virtual memory management in Operating SystemVirtual memory management in Operating System
Virtual memory management in Operating System
 
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...Stork Webinar | APM Transformational planning, Tool Selection & Performance T...
Stork Webinar | APM Transformational planning, Tool Selection & Performance T...
 
Designing pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptxDesigning pile caps according to ACI 318-19.pptx
Designing pile caps according to ACI 318-19.pptx
 
Robotics Group 10 (Control Schemes) cse.pdf
Robotics Group 10  (Control Schemes) cse.pdfRobotics Group 10  (Control Schemes) cse.pdf
Robotics Group 10 (Control Schemes) cse.pdf
 

Array ppt

  • 1. This PPT will helpful for your project and self study also.
  • 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
  • 18. * Prepared by .. . 1. Kaushal Mehta … .. twitter@kaushalmehta96 2. Jigar Patel … .. twitter@jigarpatel_jp