SlideShare uma empresa Scribd logo
1 de 11
Baixar para ler offline
Array(ADT)
Linear Data Structure




               www.eshikshak.co.in
What are Arrays ?
 ● An Aay is collection of elements stored in adjacent memory
   locations.
 ● By ‘finite’ – specific number of elements in an Aay
 ● By ‘similar’ – all the elements in an Aay are of the same data type




                        www.eshikshak.co.in
What are Arrays ? (cont.)
 ● An Aay containing number of element is reference
   using an index values 0, 1, …n-1
    ○ Lower bound–Lowest index value
    ○ Upper bound–Highest index value
 ● An Aay is set of pairs of an index and a value, for
   each index there is value associated with it.
 ● Various categories of Aay
    ○ 1D, 2D and Multi-D




                   www.eshikshak.co.in
What are Arrays ? (Cont.)
 ● The number of elements in the Aay is called its
   range.
 ● No matter how big an Aay is, its elements are
   always stored in contiguous memory locations.




                  www.eshikshak.co.in
Array Operations
Operation   Description
Traversal   Processing each element in the Aay
Search      Finding the location of an element with a given
            value
Insertion   Adding new element to an Aay
Deletion    Removing an element from an Aay
Sorting     Organizing the elements in some order
Merging     Combining two Aays into a single Aay
Reversing   Reversing the elements of an Aay




                     www.eshikshak.co.in
Row-Major and Column-Major
Arrangement
 ● All the elements of Aay are stored in adjacent memory.
 ● This leads to two possible Aangements of elements in memory
     ○ Row Major
     ○ ColumnMajor
 ● Base address , no. of rows ,& no. of columns helps to know any
   element in an Aay




                       www.eshikshak.co.in
Algorithm for Array Traversal
   ● Let A be a linear Aay with Lower Bound LB and Upper Bound UB. The
     following algorithm traverses A applying an operations PROCESS to each
     element of A
Step 1. Initialize Counter
       Set Counter = LB
Step 2. Repeat steps 3 and 4 while counter <= UB
       Else GoTo Step 5
Step 3. Visit element
       Apply PROCESS to A[counter]
Step 4. Increase Counter
       Set counter = counter + 1
       GoTo 2
Step 5. Exit

                             www.eshikshak.co.in
Algorithm for Insertion
Let A be a Linear Array, N is number of elements, k is the positive integer such
that k<=N, VAL to insert element at kth Position in an Array A
Step 1. Start
Step 2. Initialize Counter
          Set J = N
Step 3. Repeat Steps 3 and 4 while J>=k otherwise GoTo Step
Step 4. Move Jth element downward
          Set A[J+1] = A[J]
Step 5. Decrease Counter
          Set J = J + 1
       End of step 2 loop
Step 6. Insert element
          Set A[k] = ITEM
Step 7. Reset N
          Set N = N + 1
Step 8. Exit

                               www.eshikshak.co.in
Algorithm for Deletion
DELETE(A, N, K, VAL)
Let A be an linear Aay. N is the number of elements, k is the positive
integer such that k<=N. The algorithm deletes kth element from the
Aay.
Step 1. Start
Step 2. Set VAL = A[k]
Step 3. Repeat for J = k to N-1
[Move J+1 element Upward]
Set A[J] = A[J+1)
End of Loop
Step 4. Reset the number N of elements in A

Set N = N–     1
Step 5. Exit

                          www.eshikshak.co.in
Algorithm for Linear Search
Suppose A is linear Array with N elements, and VAL is the given item of
information. This algorithm finds the location LOC of item in A or sets LOC=0 if
search is unsuccessful
Step 1. Start
Step 2. [Insert VAL at the end of A]
        Set A[N+1] = VAL
Step 3. [Initialize counter]
        SET LOC = 1
Step 4. [Search for VAL]
        Repeat while A[LOC] != VAL
           Set LOC = LOC + 1
        [End of loop]
Step 5. [Successful ?]
        if LOC = N+1 then set LOC = 0
Step 6. Exit


                               www.eshikshak.co.in
Algorithm for sorting
Let A be an Aay of N elements. The following algorithm sorts
the elements of A.
Step 1. Start
Step 2. Repeat Steps 2 and 3 for k=1 to N-1
Step 3. Set PTR = 1 [Initialize pass pointer PTR]
Step 4. Repeat while PTR<=N-K [Execute Pass]
a. If A[PTR] > A[PTR+1], then
Interchange A[PTR] and A[PTR+1]
  [End of if structure]
b. Set PTR = PTR + 1
[End of inner loop]
[End of step1 outer loop]
Step 5. Exit

                          www.eshikshak.co.in

Mais conteúdo relacionado

Destaque

Coddrules 120309094807-phpapp01
Coddrules 120309094807-phpapp01Coddrules 120309094807-phpapp01
Coddrules 120309094807-phpapp01dhruv patel
 
Hypertextandhypermedia 120320065133-phpapp01
Hypertextandhypermedia 120320065133-phpapp01Hypertextandhypermedia 120320065133-phpapp01
Hypertextandhypermedia 120320065133-phpapp01dhruv patel
 
Marketing plan for souvenir shop in Hotel Z
Marketing plan for souvenir shop in Hotel ZMarketing plan for souvenir shop in Hotel Z
Marketing plan for souvenir shop in Hotel Zwangxueqing0227
 
Multimedia tools (sound)
Multimedia tools (sound)Multimedia tools (sound)
Multimedia tools (sound)dhruv patel
 

Destaque (6)

Coddrules 120309094807-phpapp01
Coddrules 120309094807-phpapp01Coddrules 120309094807-phpapp01
Coddrules 120309094807-phpapp01
 
Hypertextandhypermedia 120320065133-phpapp01
Hypertextandhypermedia 120320065133-phpapp01Hypertextandhypermedia 120320065133-phpapp01
Hypertextandhypermedia 120320065133-phpapp01
 
Marketing plan for souvenir shop in Hotel Z
Marketing plan for souvenir shop in Hotel ZMarketing plan for souvenir shop in Hotel Z
Marketing plan for souvenir shop in Hotel Z
 
Multimedia tools (sound)
Multimedia tools (sound)Multimedia tools (sound)
Multimedia tools (sound)
 
Presentacion
PresentacionPresentacion
Presentacion
 
sin nombre
sin nombresin nombre
sin nombre
 

Último

ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsPooky Knightsmith
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptxJonalynLegaspi2
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management systemChristalin Nelson
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Projectjordimapav
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWQuiz Club NITW
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 

Último (20)

ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"Mattingly "AI & Prompt Design: Large Language Models"
Mattingly "AI & Prompt Design: Large Language Models"
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 
Mental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young mindsMental Health Awareness - a toolkit for supporting young minds
Mental Health Awareness - a toolkit for supporting young minds
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptx
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
Concurrency Control in Database Management system
Concurrency Control in Database Management systemConcurrency Control in Database Management system
Concurrency Control in Database Management system
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
ClimART Action | eTwinning Project
ClimART Action    |    eTwinning ProjectClimART Action    |    eTwinning Project
ClimART Action | eTwinning Project
 
Mythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITWMythology Quiz-4th April 2024, Quiz Club NITW
Mythology Quiz-4th April 2024, Quiz Club NITW
 
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of EngineeringFaculty Profile prashantha K EEE dept Sri Sairam college of Engineering
Faculty Profile prashantha K EEE dept Sri Sairam college of Engineering
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 

Arraylineardatastructure21 110805065315-phpapp02-120309093537-phpapp02

  • 1. Array(ADT) Linear Data Structure www.eshikshak.co.in
  • 2. What are Arrays ? ● An Aay is collection of elements stored in adjacent memory locations. ● By ‘finite’ – specific number of elements in an Aay ● By ‘similar’ – all the elements in an Aay are of the same data type www.eshikshak.co.in
  • 3. What are Arrays ? (cont.) ● An Aay containing number of element is reference using an index values 0, 1, …n-1 ○ Lower bound–Lowest index value ○ Upper bound–Highest index value ● An Aay is set of pairs of an index and a value, for each index there is value associated with it. ● Various categories of Aay ○ 1D, 2D and Multi-D www.eshikshak.co.in
  • 4. What are Arrays ? (Cont.) ● The number of elements in the Aay is called its range. ● No matter how big an Aay is, its elements are always stored in contiguous memory locations. www.eshikshak.co.in
  • 5. Array Operations Operation Description Traversal Processing each element in the Aay Search Finding the location of an element with a given value Insertion Adding new element to an Aay Deletion Removing an element from an Aay Sorting Organizing the elements in some order Merging Combining two Aays into a single Aay Reversing Reversing the elements of an Aay www.eshikshak.co.in
  • 6. Row-Major and Column-Major Arrangement ● All the elements of Aay are stored in adjacent memory. ● This leads to two possible Aangements of elements in memory ○ Row Major ○ ColumnMajor ● Base address , no. of rows ,& no. of columns helps to know any element in an Aay www.eshikshak.co.in
  • 7. Algorithm for Array Traversal ● Let A be a linear Aay with Lower Bound LB and Upper Bound UB. The following algorithm traverses A applying an operations PROCESS to each element of A Step 1. Initialize Counter Set Counter = LB Step 2. Repeat steps 3 and 4 while counter <= UB Else GoTo Step 5 Step 3. Visit element Apply PROCESS to A[counter] Step 4. Increase Counter Set counter = counter + 1 GoTo 2 Step 5. Exit www.eshikshak.co.in
  • 8. Algorithm for Insertion Let A be a Linear Array, N is number of elements, k is the positive integer such that k<=N, VAL to insert element at kth Position in an Array A Step 1. Start Step 2. Initialize Counter Set J = N Step 3. Repeat Steps 3 and 4 while J>=k otherwise GoTo Step Step 4. Move Jth element downward Set A[J+1] = A[J] Step 5. Decrease Counter Set J = J + 1 End of step 2 loop Step 6. Insert element Set A[k] = ITEM Step 7. Reset N Set N = N + 1 Step 8. Exit www.eshikshak.co.in
  • 9. Algorithm for Deletion DELETE(A, N, K, VAL) Let A be an linear Aay. N is the number of elements, k is the positive integer such that k<=N. The algorithm deletes kth element from the Aay. Step 1. Start Step 2. Set VAL = A[k] Step 3. Repeat for J = k to N-1 [Move J+1 element Upward] Set A[J] = A[J+1) End of Loop Step 4. Reset the number N of elements in A Set N = N– 1 Step 5. Exit www.eshikshak.co.in
  • 10. Algorithm for Linear Search Suppose A is linear Array with N elements, and VAL is the given item of information. This algorithm finds the location LOC of item in A or sets LOC=0 if search is unsuccessful Step 1. Start Step 2. [Insert VAL at the end of A] Set A[N+1] = VAL Step 3. [Initialize counter] SET LOC = 1 Step 4. [Search for VAL] Repeat while A[LOC] != VAL Set LOC = LOC + 1 [End of loop] Step 5. [Successful ?] if LOC = N+1 then set LOC = 0 Step 6. Exit www.eshikshak.co.in
  • 11. Algorithm for sorting Let A be an Aay of N elements. The following algorithm sorts the elements of A. Step 1. Start Step 2. Repeat Steps 2 and 3 for k=1 to N-1 Step 3. Set PTR = 1 [Initialize pass pointer PTR] Step 4. Repeat while PTR<=N-K [Execute Pass] a. If A[PTR] > A[PTR+1], then Interchange A[PTR] and A[PTR+1] [End of if structure] b. Set PTR = PTR + 1 [End of inner loop] [End of step1 outer loop] Step 5. Exit www.eshikshak.co.in