Selection Sort Tutorial in Java: The Snail's Guide to Sorting

Поделиться
HTML-код
  • Опубликовано: 30 июл 2024
  • Let's learn the Selection Sort algorithm, and code it in Java!
    ☕ Complete Java course: codingwithjohn.thinkific.com/...
    Selection Sort is a great sorting algorithm for beginning programmers to learn. It's just a few lines of code and makes a great coding exercise. But Selection Sort isn't exactly the fastest algorithm out there...
    Learn or improve your Java by watching it being coded live!
    Hi, I'm John! I'm a Lead Java Software Engineer and I've been in the programming industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java learners.
    Let me know what else you'd like to see!
    Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.
    00:00 What we're gonna do
    00:19 How Selection Sort Works
    03:05 The Code
    10:43 How Fast is It?
    12:33 What about 1 million?
    📕 THE best book to learn Java, Effective Java by Joshua Bloch
    amzn.to/36AfdUu
    📕 One of my favorite programming books, Clean Code by Robert Martin
    amzn.to/3GTPVhf
    🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial
    www.audibletrial.com/johnclean...
    🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)
    bit.ly/3QPNGko
    📹Camera I use for recording:
    amzn.to/3wlXcmR
    🎙️Microphone I use (classy, I know):
    amzn.to/3AYGdbz
    Donate with PayPal (Thank you so much!)
    www.paypal.com/donate/?hosted...
    ☕Complete Java course:
    codingwithjohn.thinkific.com/...
    codingwithjohn.com

Комментарии • 64

  • @richardhasting6046
    @richardhasting6046 Год назад +52

    I wrote my first bubble sort, selection sort, and shell sort in 1981 in BASIC. I have no need to learn to sort anything, but I watch this because I love how you present it so nicely. You do a great job John!

  • @TheDeathMongrel
    @TheDeathMongrel Год назад +30

    I like your presentation style, other RUclipsrs could learn much from this. You start by explaining what we're going to be doing before starting. You continue to explain as you go. And you do it all at a moderate speed that doesn't sound like you're trying to finish a 20 min lesson in 5 min (or on 400 tabs of speed). Also great is the lack of background music everyone thinks they have to add some but it only competes with one's voice.

  • @oof4dayz
    @oof4dayz 10 месяцев назад +8

    I am currently taking a Data Structures and Algorithms course using Java and one of my assignments was to implement a variety of different sorting algorithms. You explain them and their implementations in a very understandable way, honestly better than my professor does. You just earned yourself a new subscriber!

  • @Blezerker
    @Blezerker Год назад +7

    Love the content as always! I look forward to a spring tutorial:)

  • @misterwoody_
    @misterwoody_ Год назад +1

    Great to see more content from you John. I assume I would mentally file this in the beginner programmer category as it's a great little teaching exercise or test for someone.

  • @notme-b3r
    @notme-b3r Год назад

    great video, just what i needed. couldn't understand selection sort for the past two three months

  • @michael_scarn_
    @michael_scarn_ 7 месяцев назад

    Thank you John🙂You're such an amazing teacher.

  • @yikechen1470
    @yikechen1470 3 месяца назад

    your explanation is truly amazing! Thanks!

  • @sekharsamanta6266
    @sekharsamanta6266 Год назад

    Hi @John you make us visualize so well..
    I need to work with a single loop to optimize though I've not tried it yet

  • @mirabugata
    @mirabugata Год назад

    Thanks John! This was really helpful.

  • @hbfl3x50
    @hbfl3x50 9 месяцев назад

    The best youtuber yet on data structures presentation, bravo mate 🫡❤🔥

  • @ravenklaus711
    @ravenklaus711 3 месяца назад

    After watching several videos and still not understanding the core principal, your video helped me understand it clearly. Thanks a lot.

  • @CarlosCed
    @CarlosCed Год назад +1

    This is very nice. I'll watch your quick sort and merge sort algorithms. I imagine that you will use an Arraylist, because you explain in your other videos that these are faster for searches (use constant time), but I am a coding noob theorizing. I am excited to see how you do it.

  • @sandeepsindhu1420
    @sandeepsindhu1420 2 месяца назад

    Hi sir, you are doing gods work for java beginners, you really are the John 🙏

  • @ytprem4709
    @ytprem4709 Год назад

    Thank you so much! Keep it up

  • @Speiger
    @Speiger Год назад

    Huh your code example actually showed me a small bug in my library, where i didn't do the "to-1" in the outer loop.
    And just fixed that.
    Luckily it was just a tiny oversight ^^ (I have unit test run on it but that one didn't get caught xD)
    Great video!

  • @rubens_cube
    @rubens_cube Год назад +3

    Hello John,
    I don't comment often, but I would just like to take the opportunity to thank you for all your videos. Your tutorials are simply incredible and I wish more people taught in the style you teach in. Whenever I forget how to work with something, rather than looking for an example online I often just rewatch your videos.
    I am not sure if you take requests for topics to cover, but there is one topic I would absolutely love to see on your channel. I have been messing around with Serialization recently and the fact that it even exists kind of blows my mind. I don't understand how it works at all and I cannot find any good explanations of it that I understood. I am unsure if this topic is simply not very well known or if it is too advanced, but I would love to actually understand how it works, because right now, it feels like absolutely magic!
    I totally understand if you do not want to cover this, I know any other topic you cover will be equally amazing, but if you do consider it, it would make me very happy! If you are not interested in this topic, do you perhaps know a good source to learn how serialization works? Anyways, keep doing what you do, because your videos are simply wonderful!

  • @dennisysj8868
    @dennisysj8868 Год назад +2

    Hey can you do a tutorial on network programming for Java? Such as sockets, network client servers, application level protocols etc. Please it would be a big help as your the best teacher for java on RUclips so far.

  • @Roberto-lb5or
    @Roberto-lb5or 8 месяцев назад

    I like the way you explain.

  • @amaralensheriff
    @amaralensheriff Год назад +1

    More videos on Java APIs please John 😁🙏

  • @MrSome1body
    @MrSome1body 9 месяцев назад

    You Rock John!

  • @cylorun
    @cylorun Год назад

    best java youtuber ever

  • @jeloabmelak9783
    @jeloabmelak9783 Год назад

    patiently waiting for the socket programming turtorial🙃

  • @mminahid9662
    @mminahid9662 Год назад

    in javaFX Application is an abstract class. In this abstract class there have some abstract methods which are overridden in main class which extends abstract Application class and also have static launch() method in abstract class Application. The launch() method calls from the main method in main class. Now how is it possible launch() method calls these abstract methods and for these calls overridden methods in main class are executes? please help to understand

  • @user-zt6vk2jq5w
    @user-zt6vk2jq5w Год назад

    Really nice... So I ve got a question. What is the purpose of using selection sort if it is so slow?

  • @megasusmegajos4321
    @megasusmegajos4321 Год назад +1

    Can you make a video about JPA(Java Persistence API) specification and JPQL(Java Persistence Query Language)?

  • @user-hp9np5pb6s
    @user-hp9np5pb6s 2 месяца назад

    thanks for another great video. can you post the link to this code please!

  • @manarsalem1685
    @manarsalem1685 2 месяца назад

    What happens if the element, of the outer loop, that we are comparing happens to be the smallest element anyway? The swap method will still work, and it will use the index of the element previously compared and the swapping would still be done...

  • @miguelangelavilagalan790
    @miguelangelavilagalan790 10 месяцев назад

    NIce videos buddy and really useful. By the way, you might consider to make a tutorial about javaFX in order to design some nice interfaces and afterward develop the beautiful logic. I am not by any mean a developer (yet) but I'm working myself in a small project (just for fun) about a calculator.

  • @khenparas3427
    @khenparas3427 Год назад

    Gonna use my luck with Bogo-Sort algorithm

  • @VercilJuan
    @VercilJuan Год назад

    could you do heap sort?

  • @lowkee9731
    @lowkee9731 9 месяцев назад

    John this is awesome...can i do all this on Java NetBeans as well? I am a new to coding. Or should i get intellij to perform this?

    • @CodingWithJohn
      @CodingWithJohn  3 месяца назад

      Any IDE you're comfortable with is fine!

  • @asanokatana
    @asanokatana 11 месяцев назад

    Tried an array size of one billion and left the random range at 100K and immediately got an out of memory error, so I assume it ran out of space on the heap even before it could seed the initial array (Mac Mini M1 with 8 GB memory) 😅. Tried 10M array size with 100K random range and needed to get back to work after 90 minutes so escaped out of it.

  • @clingyking2774
    @clingyking2774 Год назад +6

    I'm the first here I guess. To more years of Java & an incoming Springboot video.

    • @toke7342
      @toke7342 Год назад +1

      I was here first. 1 min after upload.

    • @falconheavy595
      @falconheavy595 Год назад

      @@toke7342 stop measuring and comparing D

    • @toke7342
      @toke7342 Год назад

      @@falconheavy595 ???

  • @kallolbhattacharya488
    @kallolbhattacharya488 Год назад

    Please explain insertion sort

  • @rahulchavan6488
    @rahulchavan6488 Год назад +2

    Sir can you provide a step by step approach for preparing for DSA?

  • @deepak-rajak
    @deepak-rajak Год назад

    I like your text editor especially the dark theme. Can you please give me a reference to install the same.❤❤

  • @vedantjha2327
    @vedantjha2327 Год назад

    Why subtopic suggests Vectors and multithreading?

    • @CodingWithJohn
      @CodingWithJohn  Год назад

      I copy pasted the last video's description and forgot to update the part that does the chapters >_>
      I updated it, but sometimes RUclips takes its time for that to take effect. Sorry about that!

    • @vedantjha2327
      @vedantjha2327 Год назад

      @@CodingWithJohn np John , you r great

  • @hashamyounas3864
    @hashamyounas3864 Год назад

    What is that theme BTW??

  • @davidscully2476
    @davidscully2476 Год назад +1

    The timestamps are from a previous video fyi

    • @CodingWithJohn
      @CodingWithJohn  Год назад

      Thanks! Removed for now till I have time to update later.

    • @davidscully2476
      @davidscully2476 Год назад +1

      @@CodingWithJohn No worries, love the videos! Feel free to delete my comment :)

    • @CodingWithJohn
      @CodingWithJohn  Год назад +1

      @David Scully Nah I don't mind the bit of humiliation

    • @misterwoody_
      @misterwoody_ Год назад

      Everyone makes mistakes and if you haven't yet, the day is fast approaching 🙂 Update - I guess I should have said that's why we have unit tests

  • @FreshThanatos
    @FreshThanatos Год назад

    At the time i watched the video, it had 69 likes c: and I .. I just destroyed it and liked the video. Sorry John. Sad to see the 69 move away but nice to see the video anyway.
    As a challange I coded the sort after your explanation and after that I watched the video to see if I'm right.
    I didnt done the length - 1 part in the first loop :/ and I did the printing of those arrays with a loop going over the array and printing it ( because I forgot that the Arrays class can do it as well. But I'm still proud to code it alone by just your explanation ^-^

    • @CodingWithJohn
      @CodingWithJohn  Год назад

      There's always tons of ways to do the same thing. Nice job!

  • @kemalali5683
    @kemalali5683 Год назад

    here is my code which is before the video coded public class Main {
    public static void main(String[] args) {
    //int []arr1={4,5,1,2,3,9,1,2,8,0,7};
    int []arr1=new int[300000];
    Random random=new Random();
    for (int i=0; i

  • @Saiyan412
    @Saiyan412 3 месяца назад

    I tried with 10k and it took ,95ms .

  • @begumsubas7787
    @begumsubas7787 Год назад

    I think I'm in love with you 😍💫

  • @muhammedefeorhanl7055
    @muhammedefeorhanl7055 2 месяца назад

    only bald dude i like

  • @user-zn3qw8qd4v
    @user-zn3qw8qd4v 3 месяца назад

    just starting with these sorting algorithms and I can already tell this one seems highly inefficient.

  • @yon1623
    @yon1623 Год назад

    MAN THIS IS SUCH A BAD WAY OF TEACHING IT.
    why not start from concept explain the algorithm and write the code one at a time . he showed us how he would write it not teach it. Students i suggest finding another video

    • @CodingWithJohn
      @CodingWithJohn  Год назад +2

      The whole first section describes how the algorithm works, with a visual example, before we dive into any code at all.
      Thanks for watching!

  • @Ro-ln6wm
    @Ro-ln6wm Год назад

    Hi John, you doing an amazing job by explaining in such understandable way, really enjoying your videos, I would like to ask you a question, maybe you can make a video concerning to "stream api"
    I can't find explanation on how functional interfaces work inside of the "Stream" methods, for example SomeStream.filter(x->x%2==0), as I understand here is "Predicate", but he is not called inside of the brackets, only implementing, that's confusing.