Page 390 - ComputerScience_Class_11
P. 390

4.  What is the difference between a single-dimensional and multi-dimensional array?
                Ans.  A single-dimensional array holds a single list of elements, while a multi-dimensional array contains multiple lists, effectively
                    creating rows and columns.
                  5.  How do you find the length of an array in Java?
                Ans.  The length of an array in Java is found using the array.length property.
                  6.  What is binary search? How does it work?
                Ans.  Binary search is a process of finding an element in an array. In binary search, firstly, the array is arranged in ascending or descending
                    order. Then the sorted array (in ascending order) is divided into two equal halves. The element to be searched is checked with
                    the middle element. If it matches, then the loop breaks, else it checks whether the searched element is larger or smaller than
                    the middle element. If it is smaller than the middle element, then the left side is again divided into two halves and the process
                    continues.
                  7.  What is selection sort technique? Explain its working.
                Ans.  Selection sort is a technique to arrange the elements of an array is ascending or descending order. Using this technique, the
                    smallest element is first found and then the first element is interchanged with the smallest element. Thus, the first element after
                    one iteration is the smallest. Then the second element is compared and interchanged with the second smallest element and
                    swapped, if required. This procedure keeps on continuing with every element being compared, till the list finally gets sorted.
                  8.  What is deletion in an array? How does it work?
                Ans.  Deletion is the process of deleting or removing an element from the array from the given position. In this technique, the index
                    position is taken from the user and then the value found at that index is deleted. Also, the number to be deleted can also be taken
                    from the user. In that case, the given number is first checked (for its presence in the array) using any searching technique and
                    then, if it is there in the array it is deleted.
                  9.  Differentiate between single-dimensional and double-dimensional arrays.
                Ans.              Single-dimensional array                      Double-dimensional array

                     Two  or more elements arranged row-wise containing  A double-dimensional array or 2D array is a type of array
                     separate  subscript values indicating the position  of the  which is used when we need to refer to data, stored in a
                     element is known as a single-dimensional array or 1D array tabular form.
                     Single-dimensional array access using single index.   Double-dimensional array accessed using multiple indices.
                     It is used for simple collection of data.      It is used to represent data in tabular form or matrices.
                     For example,                                   For example,
                     int[] numbers = {1, 2, 3, 4};                  int[][] matrix = {{1, 2}, {3, 4}};
                 10.  Discuss the advantages and disadvantages of using arrays in programming.
                Ans.  The advantages of using array in programming are:
                     Efficient memory usage: Arrays are a compact data structure and they use a contiguous block of memory.
                     Fast access: Arrays makes operations such as retrieving, updating or deleting an element faster compared to other data structures.
                     Simple structure: Arrays are easy to implement and understand, making them ideal for basic data storage and operations.
                     The disadvantages of using array in programming are:
                     Fixed size: The size of an array must be defined at the time of creation, which can be a limitation if the size is not known in
                    advance. This leads to wasted memory if the array is underused or a need for resizing if the array overflows.
                     Homogeneous elements: Arrays can only store elements of the same data type, which reduces flexibility when dealing with data
                    of different types.
                     Inefficient for large data sets: For operations like inserting or deleting elements, arrays can be inefficient, as they require shifting
                    elements around.

              D.  Higher Order Thinking Skills (HOTS)
                  1.  Explain the concept of an anonymous array in Java. How does it differ from a regular array?
                Ans.  An anonymous array in Java is an array that is created without being assigned to a variable. It is typically used when you need an
                    array temporarily, like when passing it as an argument to a method.
                     The differences between anonymous array and regular array are:
                     •  An anonymous array is created without being assigned to a variable. A regular array is assigned to a variable, which allows it
                       to be referenced and used throughout the program.
                     •  Anonymous arrays are usually created for a one-time use, such as in method calls or as part of an expression. Regular arrays,
                       on the other hand, are declared and used throughout the program



                  388  Touchpad Computer Science (Ver. 3.0)-XI
   385   386   387   388   389   390   391   392   393   394   395