Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

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

user-image
Question added by Mark Guirguis , IT Specialist , FAB Concepts
Date Posted: 2013/08/18
Mohammed El-Afifi
by 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
by 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

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.