Swift Interview Algorithms: Stacks and Generics

Поділитися
Вставка
  • Опубліковано 20 гру 2024

КОМЕНТАРІ • 72

  • @aalenazi3101
    @aalenazi3101 7 років тому +35

    I don't know if it's just me or everyone. I think your tutorials has intrinsic value and being so unique !!!

    • @aalenazi3101
      @aalenazi3101 7 років тому +1

      I am one of those who learn with practical examples which It never goes out of my head. Not theory type person

  • @arrinal
    @arrinal 2 роки тому

    Great explanation about Generics!

  • @swiftlandacademy3193
    @swiftlandacademy3193 4 роки тому

    Generics are really powerfull.. Thanks Brian

  • @masudhussain4428
    @masudhussain4428 5 років тому

    Was a bit confused about Generics implementation back in my Data Structures class, but this explained it so much better! Thanks Brian Voong!

  • @karunakarbandikatla9462
    @karunakarbandikatla9462 7 років тому

    Excellent example for swift generics.... Thanks for sharing.... Appreciate your effort on your videos

  • @nikhiilrajesh3484
    @nikhiilrajesh3484 7 років тому +11

    Love your algorithm videos! :)

  • @mike_zander
    @mike_zander 7 років тому

    Awesome i love these ! Cool to see these algorithms in swift. I just did the past two in school, except c++

  • @young_vz
    @young_vz 7 років тому

    Love watching your Friday algorithm shows! Keep up the amazing content!

  • @kenny_speaks
    @kenny_speaks 7 років тому

    I really appreciate this one Brian! This will help me a lot.

    • @LetsBuildThatApp
      @LetsBuildThatApp  7 років тому

      Excellent, these stack questions are always fun to go through.

  • @raousama4276
    @raousama4276 5 років тому

    keep doing the good work brian !!!

  • @gerryramosftw
    @gerryramosftw 7 років тому

    keep up the excellent algorithm videos!!

  • @bakrmohamed1463
    @bakrmohamed1463 7 років тому

    U are Awesome Instructor very easy to understand thank you :)

    • @LetsBuildThatApp
      @LetsBuildThatApp  7 років тому

      Excellent, programming is super easy and fun to understand once you get the basics down.

  • @StoreyofGee
    @StoreyofGee 7 років тому

    Another great video, thank you.

  • @jimmychang231
    @jimmychang231 5 років тому

    I like the video very much. However, do you have about Queue video?

  • @Traoreee
    @Traoreee 7 років тому

    Data Structures And Algorithms yayy!!

  • @belfort777
    @belfort777 5 років тому +1

    can you tell me why don't you just use an array and push to the end and pop from the end?

    • @afaaqahmedsaqi
      @afaaqahmedsaqi 3 роки тому

      What will be size of array? This put limit to stack, that how much items you can push on stack. More you can search about linklists.

  • @Immortalsantee
    @Immortalsantee 7 років тому

    Great tutorial. Loved it.
    Can you give some best examples where I can use Stack?
    Thanks

  • @jennifersipila8393
    @jennifersipila8393 6 років тому +1

    Hi Brian, Another awesome tutorial! Thank you!!!
    I have two questions: 1. Could you give one or two practical examples when you might use this stack/linked list pattern when developing an app? It seems like it could come in handy in certain scenarios.
    2. When you create the Node class could you make the Node a struct instead? I understand the copy value vs. copy reference difference between the two. Just wondering what your thinking was here for choosing class.
    Thank you again for creating such awesome tutorials!!!!!!

    • @LetsBuildThatApp
      @LetsBuildThatApp  6 років тому

      Trees use a linked list pattern when we keep a reference to the next child

    • @applepie7282
      @applepie7282 5 років тому

      or when you reading a byte buffer

  • @youtubeaddict6128
    @youtubeaddict6128 Рік тому +1

    Why can't we use orderedset instead of creating a stack

  • @SWATversion3
    @SWATversion3 6 років тому +1

    When you popped 3, you only returned the value 3 and modified the current top. The Value 3 wasn't really removed. Does the ARC do this for us as you have no way of referencing the value 3 after you pop it and deallocate the memory?

    • @afaaqahmedsaqi
      @afaaqahmedsaqi 3 роки тому

      Amazing question, should be answered brain.

  • @teijarosen2961
    @teijarosen2961 7 років тому +2

    Excellent!

  • @oleksandr_honcharov
    @oleksandr_honcharov 7 років тому

    Thank you very much! I love your videos :)
    Could you please show, how to programmatically add constraints for different size classes(compact, regular) like we can do using storyboards?
    For example, for regular&compact constraint constant is 40, but for regular®ular it will be 70.

    • @w0mblemania
      @w0mblemania 7 років тому

      I'd advise simply not using Apple's size classes. Their classes are far too broad (and meaningless) when you're trying to to work across iPhones to iPads. And Storyboard/IB support is woeful; buggy, inconsistent. Apple really dropped the ball with the whole concept of Size Classes. Instead, I'd get the device current dimensions, and work your constraints dynamically from those dimensions. For example, if the device width is _currently_ below a certain threshold, you'd use one set of attributes (constraints, views, nibs, whatever), and if the width is above it, you'd use a different set of attributes. This way, you can make your own "size class" system, but with a much greater degree of accuracy, customised to exactly what you need. You would update your metrics when you get notified of a size transition.

  • @wensmusic8636
    @wensmusic8636 2 роки тому

    Hi thank you for this video. Im not sure if you've done this in 2022... or earlier, but your Mic sounds kinda weird, there's like this frequency coming from it.

  • @UK-lp7no
    @UK-lp7no 3 роки тому

    Opps! Is the last element or first element in Stack is considered "top"? I thought index 0 is the first pop, no?

  • @Денис-ж3ф5р
    @Денис-ж3ф5р 3 роки тому

    why is the stack represented as a class instead of a struct?

  • @piyushsharma1638
    @piyushsharma1638 6 років тому

    Really helpful

  • @sminkly
    @sminkly 7 років тому

    HI, useful but I have a question. When you make oldTop = top, as top is a class it is a reference to the top object. When you then re-initialize top = Node(etc) surely the oldtop which is referencing top is set to the same object ? ie a new Node ? Or have I completely misunderstood the reference type of class compared to struct ?

    • @LetsBuildThatApp
      @LetsBuildThatApp  7 років тому +1

      Good question and you'll get the most out of this exercise but running through it yourself with breakpoints or print statements. Good luck.

  • @kasperjosefsen2985
    @kasperjosefsen2985 7 років тому

    Nice vid!

  • @erhanbakrc6619
    @erhanbakrc6619 4 роки тому

    The questions comes from 2017 :)
    Can we use struct instead of class ?

    • @johnsalvador2713
      @johnsalvador2713 4 роки тому

      In this case it’s better to use Struct for Stack since we’re just holding values.

    • @afaaqahmedsaqi
      @afaaqahmedsaqi 3 роки тому

      Can do.

  • @avella2506
    @avella2506 5 років тому

    noob question: why does push have "(_ value: Int)" and pop have "-> Int"? In other words, why are they formatted differently even if they are both functions?

    • @GuerraDeAjedrez
      @GuerraDeAjedrez 5 років тому

      because . when u push or add , u need something to add , and the pop is for returning something.
      example .
      func addMoneyToMyCash ( _ money : Int){ . // u need to know the quantity u will add to MyCash,, (_ money : int ) is a parameter,
      myCash = myCash + money
      }
      func showMyCash()->Int { . //u dont need anything, u will just show/or return how much cash u have
      return myCash
      }
      i hope u understand :S

    • @brandonfong9998
      @brandonfong9998 5 років тому

      what you put in the parenthesis are the parameters you pass into the function. when you push, you have to tell it what you are adding or "pushing" to the stack. there's no "-> Int" in push because the arrow denotes what you return from the function. in push, you don't return anything, you just add to the stack.
      pop has nothing in the parenthesis because you don't have to tell it what you are popping, it just removes the top item from the stack. it has something after the arrow because it returns the item it pops.

  • @doublegdog
    @doublegdog 6 років тому

    are stacks recommended to be implemented using linkedlists? For example, if I get asked in an interview to implement a stack should i use a linkedlist over another implementation? great vid btw.

  • @krutomjer
    @krutomjer 7 років тому

    I love these videos

  • @boblee5399
    @boblee5399 7 років тому

    你好,鄙人英语不太好,能否推出中文的iOS 开发教程?谢谢,非常期待您的回复!

  • @jimmyporter8941
    @jimmyporter8941 6 років тому +1

    I wouldn't use a linked list for a stack in this day and age. Just use a Swift array. It already has functions for adding and removing items from the end. And it's easier to understand than a custom coded linked list. Bjarne Stroustrup did a talk on why rolling your own linked list solution is generally slower than simply using a built in collection type. And whilst he was using C++ to demonstrate it, the arguments apply equally to Swift.
    If your application performance relies on the stack, you might want to benchmark it when it comes time to look at optimisation. But certainly for a first pass, just use a Swift array.

    • @LetsBuildThatApp
      @LetsBuildThatApp  6 років тому

      Correct, nonetheless its a good idea to understand the implementation behind stacks. You'll never know when you run into these age old questions during an interview!

  • @mashfique
    @mashfique 7 років тому

    I think a good challenge after this tutorial is to implement a Queue, supporting enqueue and dequeue operations! Let me know if I can make any improvements to my one below :)
    class Node {
    var val: T
    var next: Node?
    init(val: T) {
    self.val = val
    }
    }
    class Queue {
    var head: Node?
    var tail: Node?
    // Add to the tail
    func enqueue(_ val: T) {
    if tail == nil {
    tail = Node(val: val)
    head = tail // Make head point to tail
    }
    else {
    tail?.next = Node(val: val)
    tail = tail?.next
    }
    }
    // Remove from the head
    func dequeue() -> T? {
    let currentHead = head
    head = head?.next
    if head == nil {
    tail = nil // Need to do this because of ARC
    }
    return currentHead?.val
    }
    }

  • @sambio2122
    @sambio2122 7 років тому

    awesome I bow ,good algorithm

  • @russel_dev
    @russel_dev 7 років тому +1

    Osthir !!! means Awesome :) :)

  • @ikajava
    @ikajava 7 років тому

    What if we change all the "Int"'-s to "Any"-s, instead of using Generics?

    • @LetsBuildThatApp
      @LetsBuildThatApp  7 років тому +2

      +Ika Javakhishvili generics give you a huge advantage because you tell the compiler what the type is, I suggest researching more on generics

  • @silver10188
    @silver10188 7 років тому +1

    Brian, can you think of anytime you needed a good algorithm to solve a real problem in an app? I develop a lot of apps for both android and iOS, but can't remember a time I needed algorithms.

    • @w0mblemania
      @w0mblemania 7 років тому +1

      You need algorithms all the time. Even the basic types you use (e.g. NSArray/Array, NSDictionary/Dictionary) use very sophisticated, fast algorithms. Not only that, but they implement different algorithms depending on what type of data you're feeding them, and how much data.
      An obvious example of needing to write your own algorithms is any time you are doing something that required performance. If, for example, you need to display 10,000 images, you need to load them asynchronously, parse them, cache them, build the equivalent of mipmaps, look them up efficiently, etc. How efficient your caching, sorting, lookup algos are will determine how fluid, useful, attractive the app will be.

    • @theAppleWizz
      @theAppleWizz 7 років тому +1

      a simple function is considered an algorithm. I think what you mean is the BigO notation or how efficient an algorithm is

    • @DanBarzhard
      @DanBarzhard 6 років тому

      Well if your are programming you are using algorithms, so I think you should probably be more specific.

  • @applepie7282
    @applepie7282 5 років тому

    thanks

  • @minchaejeong5010
    @minchaejeong5010 7 років тому

    You are the best

  • @eggikh
    @eggikh 4 роки тому

    very good videos and explanation!) but for people who don't speak english well, very difficult to get itttt) any way thank you!

  • @owenmoore3782
    @owenmoore3782 7 років тому +1

    + Letsbuildthatapp is that Instagram I see? Is there going to be a series on creating Instagram anytime soon? Love to see this!

    • @sambio2122
      @sambio2122 7 років тому

      Owen Moore I'm waiting for this series

    • @owenmoore3782
      @owenmoore3782 7 років тому

      Samuel BIO would be awesome 👌🏽

  • @valuegaptrader7243
    @valuegaptrader7243 6 років тому

    not Enough Clear here Pleasr explain with graphical

  • @mindelight2010
    @mindelight2010 6 років тому

    Thanks :-)