Swift 3 Fun Algorithms: Recursive Search through Binary Tree

preview_player
Показать описание
Recursion and implementing a recursive algorithm to perform search is pretty fun once you understand how the algorithm works. In today's lesson we'll go through a very commonly asked interview question of perform a search through a binary tree to find if a value is contained in the set of numbers.

At the very end of the video, we'll compare the efficiencies of this recursive search with a very basic index search that comes out of the box with Swift.

Enjoy.

Facebook Group

iOS Basic Training Course

Completed Source Code

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

What a fabulous step by step explanation and demonstration - THANKS!

rogerwprice
Автор

By far the best channel to learn swift and iOS development. Very well explained concepts, I've learned so much with your videos. Thank you!

everton_dev
Автор

I decided to use a switch because it looks nicer. I couldn't decide wether or not to use the guard statement, I decided to just put everything in the switch in the end because it looks neater that way. My attempt at the optimised search function:
func search(node: Node?, searchValue: Int) -> Bool {
switch node?.value {
case nil:
return false
case let value where value! > searchValue:
return search(node: node!.leftChild, searchValue: searchValue)
case let value where value! < searchValue:
return search(node: node!.rightChild, searchValue: searchValue)
default:
return true
}
}

PythonPlusPlus
Автор

pretty useful tutorial
and you made the algorithm easy to learn

巴貝里奇
Автор

Another great video!
I love watching your algorithm vidoes!

young_vz
Автор

Love fridays because of this series :)

marekchojecki
Автор

Hi there, I really like your video but I have an honest question, in your first implementation i.e. before you implement a solution for BST, isn't the complexity of your search O(n)? As your first solution does not appear to care whether or not there is any order, it searches every node from left (first) to right and since 20 is furthest right you should get 6 iterations, which is no better than a linear search on an array. Sorry if I am wrong or mistaken, and I would love for someone to explain why this is not the case.

perh
Автор

Algorithms class from university back to haunt me! haha Great lesson, Brian!

CodeWithChris
Автор

InterView question: Recursion Definition: is a computer programming technique involving the use of a procedure, subroutine, function, or algorithm that calls itself one or more times until a specified condition is met at which time the rest of each repetition is processed from the last one called to the first: in simple english: its a step by step repetition way of solving programming question using algorithm /class / function etc ultimately getting to a solution..

studentprogrammer
Автор

Great video! It would be cool if you upload more videos like this!

SRX
Автор

first :3 thank you so much for everything you're doing Brian! I'm currently following your Swift: Firebase 3 course :) will check this recursive search algorithm out!

cesaredecal
Автор

seeing list.index(where: {$0 == 20}) was neat! Never used it before, will come in handy! Great video, I've been confused about the binary tree and the Node() class implementation I've seen in Swift examples. This helped a ton! :) thanks

kenny_speaks
Автор

It was really helpful and now I can feel sweets of codding
Thank you.

amirrezaavani
Автор

Thank you for this great video. You made BST easy now. Please do sorting algorithms and other data structures too.

trishalapatne
Автор

Very well articulated video. Keep up the great work!

doublegdog
Автор

another greate video...What you think about crossover company ?

geomichelon
Автор

thanks for sharing this useful video, hoping to learn more data structures from you.

piyushsharma
Автор

Something different from twitter series and others, alghoritms are very important IMO... keep it up mate

developerios
Автор

Awesome video Brian! This is helping me prepare for my first live coding interview on Thursday. I wonder if the reason the "(4 times)" is shown when search value is 11 and "(5 times)" is shown with a search value of 20 is because the entire non-nil left side of the tree is searched before the right side. So in the case of searching 11... 5, 1, 14 & 11 nodes are searched.

timjohnson
Автор

Great video! Love algorithm lecture from your channel! Wish we could learn more lessons about data structure and algorithm in Swift here! Thank you Brian.

jincat