ICSE Class 10 Computer Applications Question 2 of 59

Arrays — Question 2

Back to all questions
2
Question

Question 2

Differentiate between the following.

i. Array Declaration and Initialisation

Answer

Array declaration tells the compiler about the size and data type of the array so that the compiler can reserve the required memory for the array. This reserved memory is still empty. Array Initialisation assigns values to the array elements i.e. it stores values in the memory reserved for the array elements.

ii. int a[10] and char a[10]

int a[10] is an array of int data type that can hold 10 integer values whereas char a[10] is an array of char data type that can hold 10 characters.

iii. Sorting and Searching

SortingSearching
Sorting means to arrange the elements of the array in ascending or descending order.Searching means to search for a term or value in an array.
Bubble sort and Selection sort are examples of sorting techniques.Linear search and Binary search are examples of search techniques.

iv. Linear search and Binary search

Linear SearchBinary Search
Linear search works on sorted and unsorted arraysBinary search works on only sorted arrays (ascending or descending)
Each element of the array is checked against the target value until the element is found or end of the array is reachedArray is successively divided into 2 halves and the target element is searched either in the first half or in the second half
Linear Search is slowerBinary Search is faster

v. Selection sort and Bubble sort

Selection sortBubble sort
Selection Sort selects the smallest element from unsorted sub-array and swaps it with the leftmost unsorted element.Bubble Sort compares adjacent elements and swaps them if they are in wrong order.
Performs lesser number of swaps to sort the same array relative to Bubble SortPerforms more number of swaps to sort the array
Selection Sort is fasterBubble Sort is slower