Data Structures & Algorithms in Swift · Binary Search | raywenderlich.com


This is a companion discussion topic for the original entry at https://www.raywenderlich.com/977854-data-structures-algorithms-in-swift/lessons/13

What is a random access collection? Can someone explain in simple terms please?

@oneway101 Please check out the following link when you get a chance:

https://developer.apple.com/documentation/swift/randomaccesscollection

I hope it helps!

At the end of the video binary search video the following statement is given
“Also, if you are given data that would be costly to search, consider sorting before searching, so you can use a binary search to reduce that cost.”

This does not make a lot of sense to me. The sorting algorithm would take for merge sort O(n*log(n)). That in itself is more expensive than O(n) that would take to compare each element in the collection. So not a good idea to sort if you want to search for something on an unordered collection.