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

**URL:** <https://forums.kodeco.com/t/data-structures-algorithms-in-swift-binary-search-raywenderlich-com/62386>\
**Category:** 🎓 Courses & Articles\
**Created:** [February 16, 2019, 5:20pm UTC](https://forums.kodeco.com/t/data-structures-algorithms-in-swift-binary-search-raywenderlich-com/62386 "2019-02-16T17:20:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![catie](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/catie/32/110937_2.png) [@catie](https://forums.kodeco.com/u/catie)\
**Post date:** [February 16, 2019, 5:20pm UTC](https://forums.kodeco.com/t/data-structures-algorithms-in-swift-binary-search-raywenderlich-com/62386/1 "2019-02-16T17:20:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![oneway101](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/oneway101/32/81494_2.png) [@oneway101](https://forums.kodeco.com/u/oneway101)\
**Post date:** [July 10, 2019, 10:38pm UTC](https://forums.kodeco.com/t/data-structures-algorithms-in-swift-binary-search-raywenderlich-com/62386/2 "2019-07-10T22:38:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [August 22, 2019, 1:46am UTC](https://forums.kodeco.com/t/data-structures-algorithms-in-swift-binary-search-raywenderlich-com/62386/3 "2019-08-22T01:46:07Z")

</div>

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

[https://developer.apple.com/documentation/swift/randomaccesscollection](https://developer.apple.com/documentation/swift/randomaccesscollection)

I hope it helps!

---

<div class="post-metadata">

**Author:** ![carlos](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/carlos/32/102075_2.png) [@carlos](https://forums.kodeco.com/u/carlos)\
**Post date:** [July 9, 2022, 3:50am UTC](https://forums.kodeco.com/t/data-structures-algorithms-in-swift-binary-search-raywenderlich-com/62386/4 "2022-07-09T03:50:19Z")

</div>

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.
