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!
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
Yep, the thing with algorithms is that more often than not we forget to explain why it's important to know how to do these things. An example of comparing efficiencies is extremely helpful.
These algorithms are quite fun and challenging, definitely very rewarding when coding this out on the interview whiteboard. I've found myself using similar coding techniques when solving tree structures at work.
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.
12:45 You seem to be a little mistaken, your tree search iterated over every element in the array which made it take just as long (probably even longer due to dereferencing). To make a fair comparison you must also take into account the iteration which returns true at the end, so you are actually seeing 6 iterations, same as the list search. The list search said 7 times but it is also including the call for index, so it's actually 6.
Yes the video took a while to record and I’m no longer sure I was able to show the original intended result. Recording live coding is a nightmare that I don’t recommend people get into.
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.
Great!! I will wait for the happy Friday night d==(^o^)b Maybe we could use some questions from Leetcode for reference? Such as from sorting, array, linked list, string, then to tree, queue, searching, etc.
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 } }
Your videos are great man, thank you so much. Would you maybe consider doing a video on security with iOS? A lot of jobs really love when a developer understands how to have secure data in apps and what not and a lecture from you would be so awesome to have.
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.
Hmm... I looked through all the comments and I think it may have been left in the comments of another video. If I come across the explanation, I'll copy/reference it here.
Yeah, this is a very very common interview question for students right out of college. If you can understand and write out similar algorithms to this, you should be able to get past a lot of interviews.
Hi Brian! Great videos! Can you make a tutorial video and explain, how to use requests with cookies parsing and set them back? It is very difficult to understand that using stack overflow etc...
Thanks for the amazing tutorial Brian, I have a question what if we want to search for an item which does not present in tree ? how we handle that case ? its getting crash when I search for a value which does not present in Tree.
This is really good, thanks for the great video. I got an interview question once of how to balance and unbalance tree and then find the number, any thoughts?
Hello, thanks for your tutorials are simple. I have one request , you could do other videos: Heap, Hash table, BST, red-black, Kruskal., prim, Belmann-Ford, Dijkstra and Rabin-Karp. Thanks
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..
Great video Brian, thank you! I have 2 questions and a possible error. First, what is a practical application of data being structured in a tree...maybe a flat database like Firebase? Second, who would do the structuring of the data? And finally, when I enter 6-9 as the searchValue, it is false but doesn't show the number of times it runs through the function. Every other number in the series 1...20 works. Thanks again for the great exercises.
I would assume that the list.index operation on an array is a O(N). But since its sorted you could do a binary search on the array to get it to log N. Not sure tho if swift has a method for a binary search on an array. Also as a sidenote; If the binary tree is unbalanced, in worst case your recursion could be as slow as the array search.
O(n) is also my guess for list.index from what the iteration count shows. For binary searching log(n) is quite ok on the sorted list. Good analysis on the unbalanced tree scenario, I had already forgotten about that case.
Yo Brian is a MacBook Air good enough to run on Xcode and swift. What's the appropriate hardware? Do I need more RAM? More SSD? A better processor? I wanna get into app development.
I am kinda new to binary trees...Yes this method looks cool but ....The example shown above has only 6 elements....and you constructed each node and each element. What if there were 100 elements? Do we write down each and every case? Won't binary searching method b much more less code?
hello sir, I hope you are well. first of all i would like to thank you for the tutorials I love to see them. I have a request for you, can you make tutorial about converting any website or WordPress blog into iPhone app if you do it would be very helpful for me I want to learn that.
I don't think I use a whole lot of shortcuts, just the typical tabbing and CMD + LEFT or CMD + RIGHT. Perhaps I tend to type a little fast so I don't put you guys to sleep.
My question is... Why? Why do companies do this? What is the real world application of this and why I want to learn about this aside from interviews? I'm sure there is a case for this but I have never found it
What a fabulous step by step explanation and demonstration - THANKS!
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!
Another great video!
I love watching your algorithm vidoes!
Thanks Viraj.
Great!! You are No1 Developer ..
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!
pretty useful tutorial
and you made the algorithm easy to learn
Nice and easy to understand, cheers
Great video! It would be cool if you upload more videos like this!
Very well articulated video. Keep up the great work!
Love fridays because of this series :)
Great to hear that, friday's are great indeed.
I gotta agree with this comment, I hope every friday has good data structures and algorithms like this one
nice video for introducing recursive
It was really helpful and now I can feel sweets of codding
Thank you.
thanks for sharing this useful video, hoping to learn more data structures from you.
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
Yep, the thing with algorithms is that more often than not we forget to explain why it's important to know how to do these things. An example of comparing efficiencies is extremely helpful.
Loving these algorithm videos.
These are amazing! Please do more
I am so glad I've subscribed to your channel! You're awesome!
Really good job, improving every video👍
Great to hear you guys learning so much from these short lessons.
This was superb man. I like these shorts :)
Algorithms class from university back to haunt me! haha Great lesson, Brian!
These algorithms are quite fun and challenging, definitely very rewarding when coding this out on the interview whiteboard. I've found myself using similar coding techniques when solving tree structures at work.
Lets Build That App it's been ages since conducting or taking any interview for me so I'm pretty rusty with them. Thanks for doing the series!
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.
12:45 You seem to be a little mistaken, your tree search iterated over every element in the array which made it take just as long (probably even longer due to dereferencing). To make a fair comparison you must also take into account the iteration which returns true at the end, so you are actually seeing 6 iterations, same as the list search. The list search said 7 times but it is also including the call for index, so it's actually 6.
Yes the video took a while to record and I’m no longer sure I was able to show the original intended result. Recording live coding is a nightmare that I don’t recommend people get into.
Nicely explained
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.
Yeah, every Friday we'll have an algorithms exercise. Stay tuned.
Great!! I will wait for the happy Friday night d==(^o^)b Maybe we could use some questions from Leetcode for reference? Such as from sorting, array, linked list, string, then to tree, queue, searching, etc.
very well explained
Excellent video with really good explanation 👌
+Ziga Besal thanks, explaining this took a few tries but glad I finally got it down.
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
}
}
Thank you for this great video. You made BST easy now. Please do sorting algorithms and other data structures too.
+trishala patne I haven't decided what to do for next Friday yet.
Great video! Thanks to you!
Hi brian, very interesting , learned many new concepts! cheers ;)
Many more fun algorithms to come in the future.
Something different from twitter series and others, alghoritms are very important IMO... keep it up mate
Your videos are great man, thank you so much. Would you maybe consider doing a video on security with iOS? A lot of jobs really love when a developer understands how to have secure data in apps and what not and a lecture from you would be so awesome to have.
another greate video...What you think about crossover company ?
great video man!
Great video!
This is so cool thank you Brian!
Could you please make Bitap algorithm and Horspool algorithm in string matching too? Thank you.
Very very helpful
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.
Hi Tim, someone explained why in the comments below but I can't remember the answer.
Hmm... I looked through all the comments and I think it may have been left in the comments of another video. If I come across the explanation, I'll copy/reference it here.
I was once asked in a interview and I could not write the algorithm, I knew how it works though. :(
thanks for this video.
Yeah, this is a very very common interview question for students right out of college. If you can understand and write out similar algorithms to this, you should be able to get past a lot of interviews.
Hi Brian! Great videos! Can you make a tutorial video and explain, how to use requests with cookies parsing and set them back? It is very difficult to understand that using stack overflow etc...
Hi can you please create videos for DFS / BFS in Swift ? Thanks
Thanks for the amazing tutorial Brian, I have a question what if we want to search for an item which does not present in tree ? how we handle that case ? its getting crash when I search for a value which does not present in Tree.
if node == nil { return false }
This is really good, thanks for the great video.
I got an interview question once of how to balance and unbalance tree and then find the number, any thoughts?
Hello, thanks for your tutorials are simple.
I have one request , you could do other videos: Heap, Hash table, BST, red-black, Kruskal., prim, Belmann-Ford, Dijkstra and Rabin-Karp. Thanks
All these terms from college which is a decade ago for me...
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..
Great video Brian, thank you! I have 2 questions and a possible error. First, what is a practical application of data being structured in a tree...maybe a flat database like Firebase? Second, who would do the structuring of the data? And finally, when I enter 6-9 as the searchValue, it is false but doesn't show the number of times it runs through the function. Every other number in the series 1...20 works. Thanks again for the great exercises.
You can't trust playgrounds, you should go through the iterations in your head, similar to a live interview.
Could you do sorting algorithm? THank you!
Sorting.....perhaps next week.
I would assume that the list.index operation on an array is a O(N). But since its sorted you could do a binary search on the array to get it to log N. Not sure tho if swift has a method for a binary search on an array.
Also as a sidenote; If the binary tree is unbalanced, in worst case your recursion could be as slow as the array search.
O(n) is also my guess for list.index from what the iteration count shows. For binary searching log(n) is quite ok on the sorted list.
Good analysis on the unbalanced tree scenario, I had already forgotten about that case.
Thank you!
Id like to know how you create it dinamically instead of manually creating instances of a case you know
Yo Brian is a MacBook Air good enough to run on Xcode and swift. What's the appropriate hardware? Do I need more RAM? More SSD? A better processor? I wanna get into app development.
Yes.
I am kinda new to binary trees...Yes this method looks cool but ....The example shown above has only 6 elements....and you constructed each node and each element. What if there were 100 elements? Do we write down each and every case? Won't binary searching method b much more less code?
When you search on google, it could be binary searching through all possible matches for your keywords, which are millions and millions of pages.
hello sir, I hope you are well. first of all i would like to thank you for the tutorials I love to see them. I have a request for you, can you make tutorial about converting any website or WordPress blog into iPhone app if you do it would be very helpful for me I want to learn that.
what is the "let" ? is that a java function ?
+Nat D it's just swifts way of declaring a constant variable
Indirect enums are great for representing trees:
indirect enum BinaryTree {
case Branch(value: Int, left: BinaryTree, right: BinaryTree)
case Leaf(value: Int)
case Stump
static func LeftBranch(value: Int, child: BinaryTree) -> BinaryTree {
return .Branch(value: value, left: child, right: .Stump)
}
static func RightBranch(value: Int, child: BinaryTree) -> BinaryTree {
return .Branch(value: value, left: .Stump, right: child)
}
}
let oneNode = BinaryTree.Leaf(value: 1)
let fiveNode = BinaryTree.LeftBranch(value: 5, child: oneNode)
let elevenNode = BinaryTree.Leaf(value: 11)
let twentyNode = BinaryTree.Leaf(value: 20)
let fourteenNode = BinaryTree.Branch(value: 14, left: elevenNode, right: twentyNode)
let tenRootNode = BinaryTree.Branch(value: 10, left: fiveNode, right: fourteenNode)
func search(_ tree: BinaryTree, for searchValue: Int) -> Bool {
switch (tree) {
case .Branch(let value, _, _) where value == searchValue,
.Leaf(let value) where value == searchValue:
return true
case .Branch(let value, let child, _) where value > searchValue,
.Branch(let value, _, let child) where value < searchValue:
return search(child, for: searchValue)
default:
return false
}
}
search(tenRootNode, for: 20)
Best videos ever
I agreed wholeheartedly.
Mmmm i learned this in college with Python, but we were looking for files in a directory. Very identical!
maybe you should do a video on xcode keyboard shortcuts...
I don't think I use a whole lot of shortcuts, just the typical tabbing and CMD + LEFT or CMD + RIGHT. Perhaps I tend to type a little fast so I don't put you guys to sleep.
My question is... Why? Why do companies do this? What is the real world application of this and why I want to learn about this aside from interviews? I'm sure there is a case for this but I have never found it
This is literally used to search through google results to make it faster.
If the distribution is unknown or random, this algorithm will not work. Use pivot points to divide and conquer the array.
But the search algorithm will get called 5 times when you search for 20.
One thing I don't like about this channel
WHY can't we leave infinite likes on each video!?