loader image
Skip to main content
If you continue browsing this website, you agree to our policies:
x

Topic outline

  • An array is a multi-dimensional fixed-size data structure that allows elements of the same data type to be stored in it. Each array element has a unique index associated with the value it stores. This unit introduces two-dimensional arrays and their applications.

    Completing this unit should take you approximately 6 hours.

    • Upon successful completion of this unit, you will be able to:

      • declare and use one-dimensional arrays;
      • create, initialize, and access multi-dimensional arrays; and
      • use enhanced for-loops to iterate over an arrays’ elements.
    • 7.1: Introduction to Arrays

      • This chapter introduces arrays, a common multi-dimensional data structure used to store data of the same type. (Note that a class is a "data type" in this sense.) Arrays have some number of dimensions and a number of elements in each dimension. These are established when the array is created. The range of the array's index in each dimension goes from zero to the number of that dimension's elements minus one. A for loop is commonly used to initialize, manipulate, and access the values in an array. Here, we treat one-dimensional arrays, sometimes called vectors.

      • This tutorial gives more examples of how to create, initialize, and access one-dimensional arrays. It also briefly illustrates the use of arrays to reference class objects.

    • 7.2: Two Dimensional Arrays

      • This chapter expands our discussion on one-dimensional arrays to two dimensional arrays. A two dimensional array is a data structure that contains a collection of cells laid out in a two dimensional grid, similar to a table with rows and columns although the values are still stored linearly in memory. Each cell in a two dimensional array can be accessed through two indexes that specify the row number and column number respectively. Like s one dimensional array, the range of each index is from zero to the size of the row or column minus one. A nested for loop is commonly used to initialize, manipulate, and access the values in a two dimensional array.

      • Attempt this ungraded quiz.

      • We can expand the whole idea of arrays to multiple dimensions, beyond one or two dimensions. Read these sections to see how this is done.

    • 7.3: Common Array Algorithms

      • This chapter discusses how a for loop can be used to iterate over the elements of a one-dimensional array. In addition, it also discusses enhanced for loops. The chapter demonstrates the use of arrays to solve common problems such as finding sum, average, maximum, and minimum values of numbers stored in array. Pay attention to some of the common programming errors one can make while using arrays.

      • Read this chapter about lists and the useful methods that are available for adding and inserting elements into a list. 

      • Study this program to get a sense of how to manipulate two-dimensional arrays.

    • Unit 7 Assessment

      • Take this assessment to see how well you understood this unit.

        • This assessment does not count towards your grade. It is just for practice!
        • You will see the correct answers when you submit your answers. Use this to help you study for the final exam!
        • You can take this assessment as many times as you want, whenever you want.