ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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

user-image
تم إضافة السؤال من قبل Mark Guirguis , IT Specialist , FAB Concepts
تاريخ النشر: 2013/08/18
Mohammed El-Afifi
من قبل 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
من قبل 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.

المزيد من الأسئلة المماثلة

هل تحتاج لمساعدة في كتابة سيرة ذاتية تحتوي على الكلمات الدلالية التي يبحث عنها أصحاب العمل؟