Page 323 - ComputerScience_Class_11
P. 323

arrayS




                                            11









                          Learning Objectives



                     11.1  Array                                  11.2  Need for an Array
                     11.3  Single-Dimensional Array               11.4  Different Operations on a Single-Dimensional Array
                     11.5  Insertion                              11.6  Deletion
                     11.7  Merging                                11.8  Double-Dimensional Array
                     11.9  Sorting vs. Searching                  11.10  Linear Search vs. Binary Search
                     11.11  Bubble Sort vs. Selection Sort        11.12  Single-Dimensional Array vs. Double-Dimensional Array
                     11.13  Finding Maximum or Minimum            11.14  Solving Systems of Linear Equations in Two Variables



                 You know that a variable can store one value at a time. Sometimes, the situation occurred that we need to store several
                 values of a similar type. In that case, we have to declare several variables. To avoid such situations, Java provides the
                 concept of an array. Java also provides strings to handle the textual information. In this chapter, we will learn about
                 arrays and strings.

                     11.1 ARRAY
                 An array is a collection of data of a similar type. In other words, an array is a group of variables accessed through
                 a common name. It can store a set of values of any primitive or non-primitive type. It is a composite data type.
                 The values stored in an array are known as array elements. In an array, the values are stored one after another and
                 each value has an index starting from 0 which means that the first value is stored at the 0th index, the second value is
                 stored at the 1st index and so on. For example,

                               Array Values/Elements    5    10     8     7      1     6     4      3    11

                                      Index             0     1     2     3      4     5     6      7     8
                                                                                                   st
                                                                     th
                 In the above example, you can see that value 5 is stored at 0  index, value 10 is stored at the 1  index and the last value
                 11 is stored at the 8  index. The number of elements specifies the length of the array. In the above example, there are
                                  th
                 nine elements in the array, so the length of the array is 9.

                                                               Definition

                       Arrays can be defined as a set of variables which contains values of same data types having same variable name but
                       different subscripts required to separate the values. Thus, we can say that an array is a composite data type.





                                                                                                           Arrays  321
   318   319   320   321   322   323   324   325   326   327   328