Learn and practice Aptitude questions and answers with explanation for interview, competitive exam (Pariksha Corner )

Friday, January 24, 2020

A municipality stored details about every house in its pervi

A municipality stored details about every house in its perview as a ‘structure'. each containing a large number of details. These are to be sorted. The best approach is
Asort them directly
Bstore them in an array and sort the array
Cstore pointers to them in an array and sort the array
Dstore them in a linked list and sort the linked list.

Answer:  store pointers to them in an array and sort the array

Explanation:

In general, an array of pointers can be used to point to an array of data items with each element of the pointer array pointing to an element of the data array. Data items can be accessed either directly in the data array, or indirectly by dereferencing the elements of the pointer array. The advantage of a pointer array is that the pointers can be reordered in any manner without moving the data items. 

For example, the pointer array can be reordered so that the successive elements of the pointer array point to data items in sorted order without moving the data items. Reordering pointers is relatively fast compared to reordering large data items such as data records or strings. This approach saves a lot of time, with the additional advantage that the data items remain available in the original order.

Akilesh Kharvi
answered Dec 8 '2016 at 22:3

All Comments

Post your answers here:

Post

Post your comments here:

Post

Categories