Page 297 - computer science (868) class 11
P. 297
The output of the preceding program is as follows:
4 1
8 7
4 5
1 8
Sum of diagonals :38
10.9 SORTING VS. SEARCHING
The differences between sorting and searching are given below:
Sorting Searching
1. Arranging the array elements in ascending or 1. Finding an element in the array.
descending order.
2. Two types of sorting are: Bubble sort and Selection 2. Two types of searching are: Linear search and Binary
sort. search.
10.10 LINEAR SEARCH VS. BINARY SEARCH
The differences between linear search and binary search are given below:
Linear Search Binary Search
1. Array elements may or may not be in sorted order. 1. Array elements should be in sorted order.
2. Execution is slow. 2. Execution is fast.
3. Searching begins from the first element and proceeds 3. Search begins from the middle element and proceeds
to the last. either to the left or to the right depending on the
value of the searched element.
10.11 BUBBLE SORT VS. SELECTION SORT
The differences between bubble sort and selection sort are given below:
Bubble Sort Selection Sort
1. It compares the number with the next element and 1. It selects the minimum element from the unsorted
swaps if the condition matches. part of the array and places it in the next position in
the sorted part of the array.
2. Execution is slow. 2. Execution is fast.
3. It is less efficient. 3. It is more efficient.
10.12 SINGLE-DIMENSIONAL ARRAY VS. DOUBLE-DIMENSIONAL ARRAY
The differences between single-dimensional array and double-dimensional array are given below:
Single-Dimensional Array Double-Dimensional Array
1. It contains single row and multiple columns. 1. It contains multiple rows and multiple columns.
2. The variables are having the same name with a single 2. The variables are having the same name with two
subscript value. subscript values one for row and one for column.
3. To declare the array: 3. To declare the array:
int ar[ ]=new int[10]; int ar[ ][ ]=new int[2][4];
295
Arrays 295

