SlideShare a Scribd company logo
Data Structures and Algorithms




      Processing
      Arrays

Arrays
   @     Often advantageous for a user to store several
         values for the same variable in the internal
         memory of the computer because it decreases
         processing time.
   @     This multiple storage means there has to be
         more than one memory location in the
         computer for each variable name.
   @     When more than one memory location is
         designated for a single variable, it is called
         an array.

Static Arrays
   @     This means that once the computer is told
         how many locations to save, that number
         cannot be changed unless the instruction is
         changed.
Processing Arrays                                      *Property of STI
                                                          Page 1 of 17
Data Structures and Algorithms




        Processing
        Arrays

Dynamic Arrays
 @     When using dynamic arrays, the programmer
       designates the number of array locations as a
       variable, which can be expanded or contracted
       during the execution of the solution.

Base-Zero System
 @     Because computers are zero-based, for
       counting purposes, many programming
       languages are also zero-based.
 @     This means that the first array element is
       numbered zero and not one.

Base-One System
 @     Base one is easier for the programmer to
       understand since the first element will have
       an index of 1.
Processing Arrays                                    *Property of STI
                                                        Page 2 of 17
Data Structures and Algorithms




        Processing
        Arrays

Base-Zero Versus Base-One Arrays




Processing Arrays                                 *Property of STI
                                                     Page 3 of 17
Data Structures and Algorithms




        Processing
        Arrays


One-Dimensional Arrays




Processing Arrays                       *Property of STI
                                           Page 4 of 17
Data Structures and Algorithms




        Processing
        Arrays


Parallel Arrays




Processing Arrays                   *Property of STI
                                       Page 5 of 17
Data Structures and Algorithms




        Processing
        Arrays

Entering Data into an Array

               Algorithm            Flowchart

                                            A




       LOOP:R = 1 TO N STEP 1
                                            R
                                      1           N
          ENTER A(R)
                                            1

       LOOP-END:R

                                          ENTER
                                           A(R)




        R = Counter
                                            R
        N = Number of elements in
               the array

        A(R) = Element R                    B
               in the A array

Processing Arrays                                              *Property of STI
                                                                  Page 6 of 17
Data Structures and Algorithms




        Processing
        Arrays
                    Algorithm         Flowchart
                                                 A




                                                R=0
         1. R = 0
         2. REPEAT                                   REPEAT



                     R = R+1                  R=R+1

                     ENTER A(R)

                    UNTIL A(R) = -1           ENTER
                                               A(R)


         *3. N = R-1
                                      F        UNTIL
                                              A(R) = -1



                                                      T

                                          *
                                              N=R-1




                                                 B

Processing Arrays                                                *Property of STI
                                                                    Page 7 of 17
Data Structures and Algorithms




        Processing
        Arrays
                    Algorithm     Flowchart
                                            A




           1. R = 1                       R=1

           2. ENTER A(R)
           3. WHILE A(R) <> -1
                                         ENTER
                                          A(R)
                     R = R+1
                     ENTER A(R)
                                         WHILE       F
                                        A(R) <> -1
                    WHILE - END

           *4. N = R-1
                                        R=R+1




                                         ENTER
                                          A(R)




                                    *
                                        N=R+1




                                            B




Processing Arrays                                         *Property of STI
                                                             Page 8 of 17
Data Structures and Algorithms




        Processing
        Arrays

Printing an Array
                    Algorithm   Flowchart


                                      A

     LOOP: R=1 TO N STEP 1
       PRINT A(R)                     R
                                 1           N
                                       1
     LOOP-END: R


                                     PRINT
     R = Element number               A(R)


     N = Total number
          of elements
                                      R

     A(R) = Rth element of
           the A array
                                      B




Processing Arrays                                *Property of STI
                                                    Page 9 of 17
Data Structures and Algorithms




        Processing
        Arrays

Accumulating the Elements of an Array
                    Algorithm                  Flowchart
                                                       A
         LOOP:R = 1 TO N STEP 1
           SUM = SUM + A(R)
                                                       R
                                                 1          N
         LOOP-END: R                                   1




         N = Number of elements                  SUM = SUM
                                                   + A(R)
         R = Element number
         SUM = Sum of the                              R
               elements of A
         A(R) = Rth element of the
                array                                  B


               TEST:                    R       SUM
                         A
                     1   2            1 2 3     2 6 12
                                     4 5 6 7   20 30 42
                     2   4
                     3   6
                     4   8              N
                     5   10
                                        6
                     6   12



Processing Arrays                                                   *Property of STI
                                                                      Page 10 of 17
Data Structures and Algorithms




        Processing
        Arrays

Two-Dimensional Arrays
  @ A two-dimensional array is a block of memory
       locations associated with a single memory variable
       name and designated by row and column numbers.




Processing Arrays                                       *Property of STI
                                                          Page 11 of 17
Data Structures and Algorithms




        Processing
        Arrays

Loading a Two-Dimensional Array

                                     Row by Row

@ You load a two-       Data Block
                                            A


  dimensional array        1
                                                                     Array

  with nested loops.       2                R            A
                           3          1             3
  The data are
                                                             C
                                                                 1     2   3    4
                           4                1           R

  normally loaded          5                                 1   1     2   3    4
                           6                                 2   5     6   7    8
  row by row. When         7                C                3   9    10 11 12

  you load the data        8
                           9
                                      1
                                            1
                                                    4
                                                             The row remains
  row by row, the          10                                 constant as the
                                                              column varies.
                           11
  outer         loop       12
                                          ENTER
  represents the row,                     A(R, C)

  and the inner loop
  represents the
                                            C
  column.                                                        C = Column




                                            R                         R = Row




                                            B




Processing Arrays                                                    *Property of STI
                                                                       Page 12 of 17
Data Structures and Algorithms




        Processing
        Arrays

 Printing a Two-Dimensional Array
                                      A




                                     PRINT
                                    COLUMN
                                   HEADINGS




                                      R
                               1          NR
                                      1




                               PRINT ROW
                               HEADING (R)




                                      C
                               1          NC
                                      1



                               PRINT A(R,C)
                               W/O CURSOR

      R = Row                    RETURN




      NR = Number of rows             C




      C = Column                   RETURN
                                   CURSOR




      NC = Number of columns          R




                                      B


Processing Arrays                                             *Property of STI
                                                                Page 13 of 17
Data Structures and Algorithms




        Processing
        Arrays

Accumulating the Rows and Columns of a Two-
Dimensional Array




     @ Column 5 holds the sum of each of the rows
     @ Row 4 holds the sum of each of the columns
     @ A (4,5) holds the grand total



Processing Arrays                                    *Property of STI
                                                       Page 14 of 17
Data Structures and Algorithms




        Processing
        Arrays

                    Algorithm      Flowchart
                                           A




     LOOP:R = 1 TO NR STEP 1               R
                                     1         NR
                                           1
     LOOP: C = 1 TO NC STEP 1
       A(R,NC + 1) = A(R,NC + 1)           C
                                     1         NC
           + A(R,C)                        1
       A(NR + 1,C) = A(NR + 1,C)
           + A(R,C)                   A(R, NC + 1) =
                                      A(R, NC + 1) +
                                         A(R,C)
     LOOP-END: C

                                      A(NR + 1,C)=
     A(NR + 1,NC + 1) =               A(NR + 1,C) +
                                         A(R,C)
      A(NR + 1, NC + 1)
          +A(R, NC + 1)
                                          C
     LOOP-END: R
                                     A(NR + 1,NC + 1)
                                    =A(NR + 1, NC + 1)
                                      +A(R, NC + 1)




                                           R




                                           B



Processing Arrays                                      *Property of STI
                                                         Page 15 of 17
Data Structures and Algorithms




        Processing
        Arrays

Multidimensional Arrays
In some cases there is a need for arrays with a third or
even a fourth dimension. These arrays are called
multidimensional arrays.


Advantages :
     @ Facilitate   an
       understanding
       of the data
     @ Improve     the
       readability of
       algorithms
     @ Facilitate
       processing




Processing Arrays                                      *Property of STI
                                                         Page 16 of 17
Data Structures and Algorithms




        Processing
        Arrays
Table Look-up Technique
 @ A common application for arrays is using a value to look up another
   value in a table. A one-dimensional array would be used if the
   element number can be utilized as the given value. A two-
   dimensional array with two columns would be used if the element
   number cannot be utilized.

              element   DAYS     Algorithm                FLOWCHART:


                1        31    1. ENTER MONTH
                               2. DAYS_OF_THE_MONTH =          START
                               DAYS(MONTH)
                2        28
                               3. PRINT DAYS_OF_MONTH
                               4. END
                3        31
                                                               ENTER
                4        30                                    MONTH


                5        31

                6        30                                DAYS_OF_THE_
                                                              MONTH =
                                                            DAYS(MONTH)
                7        31

                8        31
                                                               PRINT
                                                             DAYS_OF_
                9        30                                   MONTH


                10       31

                11       30
                                                                END

                12       31


Processing Arrays                                                       *Property of STI
                                                                          Page 17 of 17

More Related Content

PPT
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
PDF
Solution 3.
PPTX
Combinatorial Optimization
PDF
Genetic Algorithm (GA) Optimization - Step-by-Step Example
PDF
Lecture 3 insertion sort and complexity analysis
PPT
Elementary data organisation
PDF
Optics ordering points to identify the clustering structure
PPTX
distributed depth-first search
358 33 powerpoint-slides_4-introduction-data-structures_chapter-4
Solution 3.
Combinatorial Optimization
Genetic Algorithm (GA) Optimization - Step-by-Step Example
Lecture 3 insertion sort and complexity analysis
Elementary data organisation
Optics ordering points to identify the clustering structure
distributed depth-first search

What's hot (20)

PPTX
Adversarial search
PDF
Tree terminology and introduction to binary tree
PPT
ppt
PPTX
Arithmetic and RISC pipeline
PDF
PDF
Algorithms Lecture 2: Analysis of Algorithms I
PPTX
And or graph
PPT
Minimum spanning tree
PDF
Linear Algebra – A Powerful Tool for Data Science
PPTX
Trees data structure
PPT
Heuristic Search Techniques Unit -II.ppt
PPTX
linked list in data structure
PPTX
Birch Algorithm With Solved Example
PDF
Healthcare Monitoring Using Wireless Sensor Networks
PPT
Binary Search
PDF
Intro to Discrete Mathematics
PPTX
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PDF
Deep Learning in Healthcare
PPT
Logistic regression
PPTX
Linked list
Adversarial search
Tree terminology and introduction to binary tree
ppt
Arithmetic and RISC pipeline
Algorithms Lecture 2: Analysis of Algorithms I
And or graph
Minimum spanning tree
Linear Algebra – A Powerful Tool for Data Science
Trees data structure
Heuristic Search Techniques Unit -II.ppt
linked list in data structure
Birch Algorithm With Solved Example
Healthcare Monitoring Using Wireless Sensor Networks
Binary Search
Intro to Discrete Mathematics
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
Deep Learning in Healthcare
Logistic regression
Linked list
Ad

Similar to 9 processing arrays (20)

PDF
Plc (1)
PPT
PPTX
Plc (1)
PPS
02 ds and algorithm session_02
PPS
02 ds and algorithm session_02
PDF
PPTX
Data structure basic concepts and sparse
PDF
7 problem solving with loops
PDF
12111 data structure
PDF
PDF
CSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdf
PPTX
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
PDF
3 programming concepts
PPTX
Arrays in Java
PDF
Data Structures (BE)
PPTX
III_Data Structure_Module_1.pptx
PDF
05211201 Advanced Data Structures And Algorithms
PDF
05211201 A D V A N C E D D A T A S T R U C T U R E S A N D A L G O R I...
PDF
07 A1 Ec01 C Programming And Data Structures
PPT
III_Data Structure_Module_1.ppt
Plc (1)
Plc (1)
02 ds and algorithm session_02
02 ds and algorithm session_02
Data structure basic concepts and sparse
7 problem solving with loops
12111 data structure
CSE031.Lecture_07-FlowCharts_Pseudocode .Part_II.pdf
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
3 programming concepts
Arrays in Java
Data Structures (BE)
III_Data Structure_Module_1.pptx
05211201 Advanced Data Structures And Algorithms
05211201 A D V A N C E D D A T A S T R U C T U R E S A N D A L G O R I...
07 A1 Ec01 C Programming And Data Structures
III_Data Structure_Module_1.ppt
Ad

More from Rheigh Henley Calderon (20)

PDF
10 data structures
PDF
8 problem solving with the case logic structure
PDF
6 problem solving with decisions
PDF
5 problem solving with the sequential logic structure
PDF
4 introduction to programming structure
PDF
2 beginning problem solving concepts for the computer
PDF
1 introduction to problem solving and programming
PPTX
9 technical support
PPTX
8 customer service
PPTX
7 laptop repair
PPTX
6 laptop basics
PPTX
5 pc maintenance
PPTX
PPTX
PPTX
2 pc assembly
PPTX
1 hardware fundamentals
PPTX
8 cyber crimes
PPTX
7 computer ethics
PPTX
6 professional ethics
PPTX
5 business ethics
10 data structures
8 problem solving with the case logic structure
6 problem solving with decisions
5 problem solving with the sequential logic structure
4 introduction to programming structure
2 beginning problem solving concepts for the computer
1 introduction to problem solving and programming
9 technical support
8 customer service
7 laptop repair
6 laptop basics
5 pc maintenance
2 pc assembly
1 hardware fundamentals
8 cyber crimes
7 computer ethics
6 professional ethics
5 business ethics

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Approach and Philosophy of On baking technology
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
cuic standard and advanced reporting.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Spectroscopy.pptx food analysis technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Mobile App Security Testing_ A Comprehensive Guide.pdf
Encapsulation theory and applications.pdf
Review of recent advances in non-invasive hemoglobin estimation
Advanced methodologies resolving dimensionality complications for autism neur...
“AI and Expert System Decision Support & Business Intelligence Systems”
The Rise and Fall of 3GPP – Time for a Sabbatical?
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Approach and Philosophy of On baking technology
NewMind AI Weekly Chronicles - August'25 Week I
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Unlocking AI with Model Context Protocol (MCP)
cuic standard and advanced reporting.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Encapsulation_ Review paper, used for researhc scholars
Dropbox Q2 2025 Financial Results & Investor Presentation
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx

9 processing arrays

  • 1. Data Structures and Algorithms Processing Arrays Arrays @ Often advantageous for a user to store several values for the same variable in the internal memory of the computer because it decreases processing time. @ This multiple storage means there has to be more than one memory location in the computer for each variable name. @ When more than one memory location is designated for a single variable, it is called an array. Static Arrays @ This means that once the computer is told how many locations to save, that number cannot be changed unless the instruction is changed. Processing Arrays *Property of STI Page 1 of 17
  • 2. Data Structures and Algorithms Processing Arrays Dynamic Arrays @ When using dynamic arrays, the programmer designates the number of array locations as a variable, which can be expanded or contracted during the execution of the solution. Base-Zero System @ Because computers are zero-based, for counting purposes, many programming languages are also zero-based. @ This means that the first array element is numbered zero and not one. Base-One System @ Base one is easier for the programmer to understand since the first element will have an index of 1. Processing Arrays *Property of STI Page 2 of 17
  • 3. Data Structures and Algorithms Processing Arrays Base-Zero Versus Base-One Arrays Processing Arrays *Property of STI Page 3 of 17
  • 4. Data Structures and Algorithms Processing Arrays One-Dimensional Arrays Processing Arrays *Property of STI Page 4 of 17
  • 5. Data Structures and Algorithms Processing Arrays Parallel Arrays Processing Arrays *Property of STI Page 5 of 17
  • 6. Data Structures and Algorithms Processing Arrays Entering Data into an Array Algorithm Flowchart A LOOP:R = 1 TO N STEP 1 R 1 N ENTER A(R) 1 LOOP-END:R ENTER A(R) R = Counter R N = Number of elements in the array A(R) = Element R B in the A array Processing Arrays *Property of STI Page 6 of 17
  • 7. Data Structures and Algorithms Processing Arrays Algorithm Flowchart A R=0 1. R = 0 2. REPEAT REPEAT R = R+1 R=R+1 ENTER A(R) UNTIL A(R) = -1 ENTER A(R) *3. N = R-1 F UNTIL A(R) = -1 T * N=R-1 B Processing Arrays *Property of STI Page 7 of 17
  • 8. Data Structures and Algorithms Processing Arrays Algorithm Flowchart A 1. R = 1 R=1 2. ENTER A(R) 3. WHILE A(R) <> -1 ENTER A(R) R = R+1 ENTER A(R) WHILE F A(R) <> -1 WHILE - END *4. N = R-1 R=R+1 ENTER A(R) * N=R+1 B Processing Arrays *Property of STI Page 8 of 17
  • 9. Data Structures and Algorithms Processing Arrays Printing an Array Algorithm Flowchart A LOOP: R=1 TO N STEP 1 PRINT A(R) R 1 N 1 LOOP-END: R PRINT R = Element number A(R) N = Total number of elements R A(R) = Rth element of the A array B Processing Arrays *Property of STI Page 9 of 17
  • 10. Data Structures and Algorithms Processing Arrays Accumulating the Elements of an Array Algorithm Flowchart A LOOP:R = 1 TO N STEP 1 SUM = SUM + A(R) R 1 N LOOP-END: R 1 N = Number of elements SUM = SUM + A(R) R = Element number SUM = Sum of the R elements of A A(R) = Rth element of the array B TEST: R SUM A 1 2 1 2 3 2 6 12 4 5 6 7 20 30 42 2 4 3 6 4 8 N 5 10 6 6 12 Processing Arrays *Property of STI Page 10 of 17
  • 11. Data Structures and Algorithms Processing Arrays Two-Dimensional Arrays @ A two-dimensional array is a block of memory locations associated with a single memory variable name and designated by row and column numbers. Processing Arrays *Property of STI Page 11 of 17
  • 12. Data Structures and Algorithms Processing Arrays Loading a Two-Dimensional Array Row by Row @ You load a two- Data Block A dimensional array 1 Array with nested loops. 2 R A 3 1 3 The data are C 1 2 3 4 4 1 R normally loaded 5 1 1 2 3 4 6 2 5 6 7 8 row by row. When 7 C 3 9 10 11 12 you load the data 8 9 1 1 4 The row remains row by row, the 10 constant as the column varies. 11 outer loop 12 ENTER represents the row, A(R, C) and the inner loop represents the C column. C = Column R R = Row B Processing Arrays *Property of STI Page 12 of 17
  • 13. Data Structures and Algorithms Processing Arrays Printing a Two-Dimensional Array A PRINT COLUMN HEADINGS R 1 NR 1 PRINT ROW HEADING (R) C 1 NC 1 PRINT A(R,C) W/O CURSOR R = Row RETURN NR = Number of rows C C = Column RETURN CURSOR NC = Number of columns R B Processing Arrays *Property of STI Page 13 of 17
  • 14. Data Structures and Algorithms Processing Arrays Accumulating the Rows and Columns of a Two- Dimensional Array @ Column 5 holds the sum of each of the rows @ Row 4 holds the sum of each of the columns @ A (4,5) holds the grand total Processing Arrays *Property of STI Page 14 of 17
  • 15. Data Structures and Algorithms Processing Arrays Algorithm Flowchart A LOOP:R = 1 TO NR STEP 1 R 1 NR 1 LOOP: C = 1 TO NC STEP 1 A(R,NC + 1) = A(R,NC + 1) C 1 NC + A(R,C) 1 A(NR + 1,C) = A(NR + 1,C) + A(R,C) A(R, NC + 1) = A(R, NC + 1) + A(R,C) LOOP-END: C A(NR + 1,C)= A(NR + 1,NC + 1) = A(NR + 1,C) + A(R,C) A(NR + 1, NC + 1) +A(R, NC + 1) C LOOP-END: R A(NR + 1,NC + 1) =A(NR + 1, NC + 1) +A(R, NC + 1) R B Processing Arrays *Property of STI Page 15 of 17
  • 16. Data Structures and Algorithms Processing Arrays Multidimensional Arrays In some cases there is a need for arrays with a third or even a fourth dimension. These arrays are called multidimensional arrays. Advantages : @ Facilitate an understanding of the data @ Improve the readability of algorithms @ Facilitate processing Processing Arrays *Property of STI Page 16 of 17
  • 17. Data Structures and Algorithms Processing Arrays Table Look-up Technique @ A common application for arrays is using a value to look up another value in a table. A one-dimensional array would be used if the element number can be utilized as the given value. A two- dimensional array with two columns would be used if the element number cannot be utilized. element DAYS Algorithm FLOWCHART: 1 31 1. ENTER MONTH 2. DAYS_OF_THE_MONTH = START DAYS(MONTH) 2 28 3. PRINT DAYS_OF_MONTH 4. END 3 31 ENTER 4 30 MONTH 5 31 6 30 DAYS_OF_THE_ MONTH = DAYS(MONTH) 7 31 8 31 PRINT DAYS_OF_ 9 30 MONTH 10 31 11 30 END 12 31 Processing Arrays *Property of STI Page 17 of 17