Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Why is processing a sorted array faster than an unsorted array?

user-image
Question ajoutée par Mark Guirguis , IT Specialist , FAB Concepts
Date de publication: 2013/08/18
Mohammed El-Afifi
par Mohammed El-Afifi , chief engineer , valeo

If by processing you mean searching for example, sorted arrays allow using binary search if the sorting is based on the same criterion you're using to search the array.
Binary search has the complexity of O(log n), compared to a complexity of O(n) for the linear search used with unsorted arrays where n is the size of the array in both cases.
This's roughly used by most databases in executing SQL queries if the matching criteria are based on indexed columns.
When you have multiple indices on a table, this means that the records have several sortings corresponding to the difference indices applied on the table.

Abhijeet Thool
par Abhijeet Thool , IT Project Manager , US Confidentail Company

Well for starters, unsorted array contains everything which was fetched from Database or a collection so traversing/iterating through this collection takes a certain amount of time say x.
So while processing/finding something through this collection will take obviously more time since you have no clue of how to go about processing/searching it.
While in case of an sorted array the collection is fetched and then the sort criteria is applied.
This makes the processing a bit faster since we now have a clue of how to go about processing/searching, which in turn makes it faster.

More Questions Like This

Avez-vous besoin d'aide pour créer un CV ayant les mots-clés recherchés par les employeurs?