Sort an integer array using single for loop [Java]

Поделиться
HTML-код
  • Опубликовано: 7 сен 2024
  • Sort an integer array using single for loop [Java]
    #sorting
    #dataStructure
    #algorithm
    #interview

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

  • @adrianharkin5471
    @adrianharkin5471 10 месяцев назад +1

    the best explination on this topic i've found - thanks so much!

  • @manux7739
    @manux7739 8 месяцев назад +1

    tysm!! your explanation helped a lot!! 💖💖💖💖

  • @MuSHTaQAR
    @MuSHTaQAR 2 года назад +1

    Thank you so much. such a simple explanation

  • @martinmiciciday5235
    @martinmiciciday5235 2 года назад +1

    thank you for your nice and valuable explanation🙏

    • @CodingEnv
      @CodingEnv  2 года назад

      Glad it was helpful!

  • @a.s.5959
    @a.s.5959 Год назад

    Thank you for your concise explanation!

  • @RavindraSingh-zg9eq
    @RavindraSingh-zg9eq Год назад

    very nice explanation

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

    excellent and precise

  • @simm5622
    @simm5622 2 года назад

    So beautifully explained. 🏆🏆🏆🏆🏆

    • @CodingEnv
      @CodingEnv  2 года назад +1

      Glad it was helpful!

  • @amosmbekenga8179
    @amosmbekenga8179 2 года назад

    good explanation be blessed

  • @vrashikeshpatil9315
    @vrashikeshpatil9315 2 года назад

    man your dam good at coding
    i have subscribed , keep good work up

    • @CodingEnv
      @CodingEnv  2 года назад

      Thanks Vrashikesh for your appreciation and support.

  • @nikhilbhangale5894
    @nikhilbhangale5894 2 года назад

    very very nice explanation sir ....

  • @Varohm
    @Varohm 2 года назад

    Your explanation is really good and Already subscribed your channel too

    • @CodingEnv
      @CodingEnv  2 года назад

      Thank you so much 🙂

  • @SurajSharma-fw5fg
    @SurajSharma-fw5fg Год назад

    Great explanation

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

    Thank you sir

  • @aditiroy7890
    @aditiroy7890 3 года назад

    Very nice👍🏻

  • @rampageriotsop7287
    @rampageriotsop7287 3 года назад

    Very good😊

  • @saurabhpanwar4255
    @saurabhpanwar4255 3 года назад

    Brilliant

  • @vijaysahani8379
    @vijaysahani8379 2 года назад

    Why are we running loop till (i

    • @CodingEnv
      @CodingEnv  2 года назад +1

      Its because, in the body of for loop, we are comparing array[i] with array[i+1], if we go till array.length, at last iteration, we will get indexOutOfBound exception.

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

    You're using nested loop... Btw nice for beginners

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

      Yes you are correct. Logically it is using nested loop only and that's why the time complexity will be also n^2, but on paper it is one loop only.

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

    please provides data structure and algorithms in java

  • @rampageriots8526
    @rampageriots8526 3 года назад

    Nice

  • @indrdeepwhatsappstutas6908
    @indrdeepwhatsappstutas6908 3 года назад

    Good

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

    Greetinngs sir why you are importing package

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

      Greetings Venkata, just to print. It was not required anyway.

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

    what will be its time complexity

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

      It will be n square only

  • @mominimran1344
    @mominimran1344 2 года назад

    hi quick question - why could you not have reset the index to 0 instead of -1?

  • @utkarshgupta6091
    @utkarshgupta6091 2 года назад

    bro can we use Arrays class methods for solving such questions in interview? As Arrays class has direct sort method. And can we use collections for solving interview questions?

    • @CodingEnv
      @CodingEnv  2 года назад

      If question main task is not sorting but doing other job, then we can take help of in built sort method of Array class or collection class, but if the question itself ask to sort then we cannot use it.

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

      Really? I guess most of the interviews are based on using user defined methods and not using much libraries to solve problems. And moreover sort method will sort in nlogn TC.

  • @FizaBagwan1
    @FizaBagwan1 2 года назад

    What is time complexity?

    • @CodingEnv
      @CodingEnv  2 года назад

      It will be of order of n^2 as we are resetting the index again and again.

  • @nehemyayisihak6130
    @nehemyayisihak6130 2 года назад

    the time complexity is still n2

    • @CodingEnv
      @CodingEnv  2 года назад +1

      Yes , you are correct. its is jus a trick o complete the program in one for loop.

  • @tarusharma4304
    @tarusharma4304 2 года назад

    sir what is the worst case time complexity of this sort

    • @CodingEnv
      @CodingEnv  2 года назад

      Its o(n^2) as we are resetting the index every time.

    • @tarusharma4304
      @tarusharma4304 2 года назад

      @@CodingEnv sir is their any algorithm to sort an array in O(N)time complexity

    • @CodingEnv
      @CodingEnv  2 года назад

      Yes, but their should not be any limitations on space complexity...

    • @tarusharma4304
      @tarusharma4304 2 года назад

      @@CodingEnv sir can u tell me which algorithm there is no need for limitations of space complexity

    • @CodingEnv
      @CodingEnv  2 года назад

      You can go through this link stackoverflow.com/questions/12240997/sorting-array-in-on-run-time#:~:text=Yes.,o(n)%20time%20complexity.

  • @pavandrake386
    @pavandrake386 2 года назад

    May i know the time complexity

    • @CodingEnv
      @CodingEnv  2 года назад +1

      Even though we are using single for loop, the time complexity will remain O(n^2) only.

    • @vijaysahani8379
      @vijaysahani8379 2 года назад

      @@CodingEnv Is it beacuse we using Arrays.toString(); function or what ?

    • @CodingEnv
      @CodingEnv  2 года назад

      No, because we keep on resetting the index inside the for loop

  • @simirnac7364
    @simirnac7364 6 месяцев назад

    Can you send Tamil language pls

  • @brianawadis5622
    @brianawadis5622 3 года назад

    Good