Swift: Merge Sort Algorithm (iOS Interview Prep) 2022

preview_player
Показать описание
In this video we will learn how to implement the popular sorting algorithm known as Merge Sort. Popular in interview questions, merge sort is based on the concept of divide and conquer. We will split input arrays by two and re-build merged sorted arrays for the final result. We will walk through the algorithm together and implement it in Swift 5 and Xcode 13.

** Popular Series

** Get Skillshare free for 2 Months and learn iOS

** Manage all your investments from app earnings on Betterment!

** Grow your own Youtube tech channel with TubeBuddy:

#swift #algorithms #mergeSort
Рекомендации по теме
Комментарии
Автор

Don't stop making swift Algorithm, Full Support :)

talalbadreddine
Автор

Without any bull shit, every second in this video is informative. This is how an informative video should be. Keep up the great work. 👍

thejask
Автор

Great stuff. Thank you for all your videos. Keep up the great work

vinrbi
Автор

I'm pleasure you are making swift algorithm! thanks!

bbuyooo
Автор

Will interview prep all be on the YT channel, or will plus members get content too?

sxteesx
Автор

Please make more videos on swift logical thing

asadgillani
Автор

Hi Sir,
Is there any video available for multiple schemas in xcode ( within one source code how to maintain more than clients projects/app - white label application I can say)
It will change app name, launch screen, app logo and some content and alert messages based on schema selection while building/running project.

mallikarjunhanagandi
Автор

Thank you for the video ! I would like to ask you, could you give me directions how to set up a basic CRUD application ( books and other material ) ? Also, could a timer that fires every second be implemented in terminal window ( such as a real time clock ) without the buttons of UI ? I have the code from another source, but I’m missing something to make it work in the terminal :/

VlasiosSokorelosTheDarkwavist
Автор

How much time do you lose or gain by using this method as opposed to just .sort() on the array?

HazardOfExistance
Автор

You probably forgot to mention the time/space

laurapotter
Автор

class Program {
func mergeSort(_ array: [Int]) -> [Int] {
guard array.count > 1 else {
return array
}

let midIndex = array.count / 2
var leftArray =
var rightArray =

return sortArrays(leftArray, rightArray)
}

private func sortArrays(_ leftArray: [Int], _ rightArray: [Int]) -> [Int] {
var leftIndex = 0
var rightIndex = 0

let capacity = leftArray.count + rightArray.count
var result = [Int]()


while leftIndex < leftArray.count && rightIndex < rightArray.count {
let leftElement = leftArray[leftIndex]
let rightElement = rightArray[rightIndex]

if leftElement < rightElement {
result.append(leftElement)
leftIndex += 1
} else if leftElement > rightElement {
result.append(rightElement)
rightIndex += 1
} else {
result.append(leftElement)
leftIndex += 1
result.append(rightElement)
rightIndex += 1
}
}

while leftIndex < leftArray.count {

leftIndex += 1
}

while rightIndex < rightArray.count {

rightIndex += 1
}

return result
}
}

let program = Program()
let sortedArray = program.mergeSort([7, 2, 3, 4, 5, 5, 6, 7, 8, 9, 0, 3, 4, 5, 6, 7])
print(sortedArray)

DenisBrilliantov