1.5.1 Time Complexity #1

Поділитися
Вставка
  • Опубліковано 17 січ 2018
  • Finding Time Complexity of Different kind of snippets
    PATREON : www.patreon.com/bePatron?u=20...
    Courses on Udemy
    ================
    Java Programming
    www.udemy.com/course/java-se-...
    Data Structures using C and C++
    www.udemy.com/course/datastru...
    C++ Programming
    www.udemy.com/course/cpp-deep...

КОМЕНТАРІ • 937

  • @achajackson5898
    @achajackson5898 3 роки тому +1074

    I used all your videos when I was in the university studying for my Computer Sc degree. I'm working now and I just come back here to smile at how amazing of a teacher you are. Stay blessed!

    • @achajackson5898
      @achajackson5898 2 роки тому +36

      @@Abdulrhman146. Honestly, efficiency and optimization counts only when you’re some sort of senior developer. This is actually what is used to different a pro dev from a beginner. Sometimes is not just about the solution, it’s about how good your solution is. So, if you’re just starting your job, relax you’ll learn and eventually understand because you follow this channel ; )

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

      Bro which channel is best for Daa?

    • @ubuntudebian3748
      @ubuntudebian3748 Рік тому +2

      @TheOneAndOnly ​ @Acha Jackson Hi everyone, first many thanx for Mr. AbdulBari.
      I remember this videos when i try to resolve a problem in Codingame last 2 week.
      The exercise is to write a simple method that take an array of int (size can be huge , ex 5_000_000 entrees or more) and return (int) the smallest range from its elements.
      Example : [7, 15, -7, 20, 100] -> return 5 because the range between 15 and 20 is the smallest one.
      [1, -15, 122, 2] -> 1 range between 1 and 2
      Try to solve it and see the time difference between all solutions.
      Sorry for my bad english.

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

      @@achajackson5898 faak give me a job now....

    • @AbdulxamidFayziev
      @AbdulxamidFayziev Рік тому

      no bro , he looks so angry like I ain't got shit to say.

  • @jl_woodworks
    @jl_woodworks 4 роки тому +3035

    I just love how he stops for a while after explaining something and looks at the camera like saying: "Did you understand, you fool?" :D

    • @jl_woodworks
      @jl_woodworks 4 роки тому +94

      @@abdul_bari Thank you for putting together this material. Your lessons are invaluable.

    • @nahidiac
      @nahidiac 4 роки тому +46

      lol, I noticed it too. I have seen many old people do that while teaching something to their younger ones.

    • @rahulsonvane8141
      @rahulsonvane8141 4 роки тому +5

      :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D :D

    • @swapnilbhai
      @swapnilbhai 3 роки тому +27

      I read this comment before and den watched
      seriously i was more attentive to avoid me fool....but video is good..

    • @_Ahmed_15
      @_Ahmed_15 3 роки тому +23

      lol same. It feels like you're actually in the class with him

  • @ansuman4233
    @ansuman4233 4 роки тому +582

    When you pause after a statement, it feels like I am actually physically sitting in the class and you are giving me a few seconds to grasp the information and proceeding after I have said Yes Sir! This feels so real! THANK YOU for doing this :) God bless you.

  • @avrillovugne
    @avrillovugne 6 років тому +871

    This channel is a youtube hidden gem

    • @samiamuhammad8140
      @samiamuhammad8140 5 років тому +19

      exactly

    • @hasanrizvi2047
      @hasanrizvi2047 4 роки тому +15

      Hardy hidden, tbh. I type Algorithm on my YT search and his was the first playlist that popped up.

    • @NOOne-rs6pe
      @NOOne-rs6pe 3 роки тому

      @@hasanrizvi2047 english pe dhyaan de 66666ke

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

      Ghanta ka gem .....kuch aata nhi isko waste of time

    • @geekyprogrammer4831
      @geekyprogrammer4831 2 роки тому +1

      This is no more hidden. He got average views of 500k.

  • @xteerfnie5724
    @xteerfnie5724 3 роки тому +195

    I’m from Nigeria and I watch all the ads just to As a way of saying thank you 😂❤️

    • @abdul_bari
      @abdul_bari  3 роки тому +53

      Thanks Dear.

    • @shammahagwor9205
      @shammahagwor9205 3 роки тому +10

      Hey Stephanie that’s definitely a cool thing to do , I do the same

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

      @@shammahagwor9205 💕

    • @webuye
      @webuye 2 роки тому +2

      On it too, he deserves it.

  • @masfiqmahmud145
    @masfiqmahmud145 2 роки тому +95

    Sir didn't used music, any intro didn't waste any time, straight to the point. And his way of explaining I find it simply the best. I'm currently doing his udemy DSA and I find his way of teaching and explaining so easy. Huge respect for him.

    • @raunakkumar9460
      @raunakkumar9460 Рік тому

      Kasa course hai theory part or coding?

    • @masfiqmahmud145
      @masfiqmahmud145 Рік тому

      @@raunakkumar9460সে সবগুলো টবে কি কভার করেছে থিউরি এবং কোডিং দুইটাই।

  • @VirulentVendetta
    @VirulentVendetta Місяць тому +7

    7:45 for those who were lost like I was when he immediately goes into setting P = k(k+1)/2... Look up the "Gauss Addition Trick". Essentially this is a recognized addition sequence (1+2+3... etc) that is represented by that equation. He's assuming we know how he got there, or forgot to explain it.

    • @PriyanshEm
      @PriyanshEm 7 днів тому

      thanks bro

    • @iamcarlostovias
      @iamcarlostovias 4 дні тому

      This one got me for a little bit too, was thinking I missed something but it just wasn't explained! Lol. He did a great job regardless.

    • @Alexander-mm9qk
      @Alexander-mm9qk 7 годин тому

      Thank you so much. I already had seen that concept years ago, and I never thought I'd use it 😂

  • @ankitabasu81
    @ankitabasu81 3 роки тому +152

    Honestly everybody commented so accurately my feelings are exactly the same as every body in the comment section. I wish I could have got a teacher like you sir, when I was still in my college which ended the last month. Completed my graduation but this 'Time complexity' was not something which I understood for all my graduation years. But then discovering your channel and this lecture series ... make me feel blessed . Thanks a lot

  • @SunilSamantaSinghar
    @SunilSamantaSinghar 5 місяців тому +16

    So beautiful explained. I am preparing fir exams & interview watching your videos.
    A little mistake at 5:30
    f(n)= (n^2 + n) /2

  • @simbamulenga5430
    @simbamulenga5430 3 роки тому +83

    corona epidemic came when I just begun my major😢 your tutorials are really helping me thanks sir. You are great man👌

  • @Noushin
    @Noushin 2 роки тому +15

    Your channel is a hidden gem! I came from a different background and now studying computer science. I was having really hard time understanding these concepts in algorithm. Your videos just saved me. Big thumbs up! Keep bringing more videos like these. All the best to your channel. :)

  • @acj10896
    @acj10896 6 років тому +247

    Best teacher I had ever seen...its like u born for teaching..
    keep going sir..👍👍

    • @shivani-fq8eq
      @shivani-fq8eq 2 роки тому +1

      u doing btech

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

      @@shivani-fq8eq i guess only btech students watch this.

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

      @@padmnabh3603 noooooo

  • @Abdullah-mg5zl
    @Abdullah-mg5zl Рік тому +40

    *Key Takeaways:*
    - time complexity analysis is basically trying to find out *how the number of instructions/steps required changes as a function of the input size*
    - you do this by basically seeing how many times each instruction/step of the algorithm/code executes for each input
    - if there is an instruction inside a for loop, and the for loop goes from 0 to n (n being the size of your input), then the instruction gets executed n times...this is pretty straightforward
    - if there is a for loop nested within a for loop, and both loops go from 0 to n, then the instruction in the *nested* loop will be executed n x n times. This is because the inner loop is executed n times, and each time the inner loop is executed, the instruction in it is executed n times, so in total, that instruction is executed n by n times
    - if you have an outter for loop that goes from 0 to n, but the inner for loop goes from 0 to i of the outter loop, let's take a look at how many times the inner loop code gets executed for each iteration of the outer loop. During the first iteration of the outter loop, the code in the inner loop gets executed 1 time (from 0 to i, which is 1). During the second iteration of the outter loop, the code in the inner loop gets executed 2 times (from 0 to i, which is now 2). During the third iteration, the code in the inner loop gets executed 3 times (from 0 to i, which is now 3), and so on. You basically have a little triangle here, with height n, and base n. To find the area, you do (n x n / 2)
    I may be off by 1, but I wanted to keep the explanation simple.
    Thanks again for the amazing videos

    • @zyadtarek-1385
      @zyadtarek-1385 Рік тому

      i read that with abdul bari voice specially when i read one time , i just want to say how amazing he is♥

    • @sereneorb
      @sereneorb 11 місяців тому

      Thanks so much for writing this❤

    • @dominic9714
      @dominic9714 10 місяців тому

      I didn't get some of youtuber for outter loop like i

    • @rumanaislam4758
      @rumanaislam4758 8 місяців тому

      Hello there!
      Can you please explain that (j

    • @niddynoddy
      @niddynoddy 8 місяців тому +3

      ​@@rumanaislam4758 I'm not sure I understand it fully either, but if you do go the manual route of trying to calculate how many times does the innermost statement of the two for loops run, you'd get that mathematical formula of (n(n+1))/2. If n is 10, the innermost statement is run 55 times following both manual calculations and the formula given. I'm still struggling finding out how exactly we got to that mathematical formulae.

  • @Bikashics
    @Bikashics 2 роки тому +16

    For those who are New here, I would like to say that this Teacher here, have helped millions of students to learn DS and grab product based companies... A Moment of Respect...

  • @indiancuriousvoice8773
    @indiancuriousvoice8773 2 роки тому +44

    This teacher is far better than the IIT teachers, He has a great ability to teach complex things In very simple way.

  • @comedykickers32
    @comedykickers32 Рік тому +12

    I love it when you stare into my soul after finishing an answer

  • @AnkitKumar-ge8st
    @AnkitKumar-ge8st 3 роки тому +15

    "Let us Analyze" every time whenever sir says this, there is a curiosity in my mind. Awesome Explanation

  • @islamkamran332
    @islamkamran332 3 роки тому +11

    Sir, I have seen the first person explaining this topic in so much detail with easy examples

  • @Azhagi-Transliteration-Apps
    @Azhagi-Transliteration-Apps 5 років тому +6

    What a Teacher! What a Teaching! In order to help my son understand O(n) fully well, I was searching for some videos. I was not satisfied with any of them until I found this video [and the series of videos on O(n) to follow this]. Mighty helpful - all of the videos in this series. My son (CSE first year) very quickly understood O(n) to the hilt. Once again, I reiterate: "What a Teacher! What a Teaching!" Pranams ever.

  • @shubhamsaini4012
    @shubhamsaini4012 4 роки тому +16

    The way he stops and look is a teacher look. Sir you nailed it...

  • @amith89rm
    @amith89rm 4 роки тому +5

    Thank you so much Sir. Referred so many websites, blogs, wikis, spent hours to understand and your explanation made me get the concepts right within 10 minutes. Thank you so much Sir!!!

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

    Wow I think this is the by far one of the best videos on time complexity in code. Thank you so much for helping!

  • @DeepakSingh-bt7nn
    @DeepakSingh-bt7nn 5 років тому +97

    When I get stuck on solution.
    Sir : Let us analyse!!!!
    Me: 😇😌😌

  • @Shubh22
    @Shubh22 5 років тому +27

    Ooi that headmaster look in between the lectures! I imagined a flying duster :D. Jokes apart, this guys is a great teacher and he has raised the bar of how programming tutorials should be made.

  • @ilovemisachan5231
    @ilovemisachan5231 2 роки тому +9

    I got a job sir. It was only possible because of your easy-to-understand explanation. I can remember from my 2nd year I actually was able to understand the concept of t.c. from these videos. Your Udemy's course on Data Structures was also crucial in building the base. Thanks for your teaching.

  • @cristhianmalakian296
    @cristhianmalakian296 5 років тому +41

    I am from Colombia and I enjoy your videos :D

  • @sankaranarayanan348
    @sankaranarayanan348 4 роки тому +5

    I'm so happy to view your courses. The way you explain make people to understand very clear. I would request you to publish the courses on entire data structures topics.

  • @prost5514
    @prost5514 2 роки тому +6

    I don't know what to say or how to describe your lessons in words, but I really understand this subject at once watching your videos, without any doubts you are far more better than my professors in the university

  • @GhDnFghDt177
    @GhDnFghDt177 3 роки тому +6

    Thank you from Yemen, best channel to explain Algorithm and DataStructure

  • @codingwithelhacen990
    @codingwithelhacen990 3 роки тому +6

    I love the way Mr.Abdul bari teaches. He makes things understandable. His courses on C++ (Udemy) prove these traits.

  • @manuvtomson8052
    @manuvtomson8052 3 роки тому +1

    This is NIIIIICCCEEE....
    once in a while we get to find teachers who love their job and enjoy teaching like this gentleman.....

  • @alexebarlescu9502
    @alexebarlescu9502 3 роки тому +3

    This guy is a legend, i can not find better person to explain this kind of topics

  • @mustapharaimilawal8053
    @mustapharaimilawal8053 3 роки тому +5

    There are teachers and there are teachers !, you rate among the very best Sir, thanks for doing this video.

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

    The videos are really amazing.....I'm overwhelmed

  • @niteshhebbare3339
    @niteshhebbare3339 4 роки тому +1

    Sir the way you teach complex algorithms so easily is just remarkable thank you sir!

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

    Thank you. Thank you. This by far the most detailed explanation I’ve come across on UA-cam. I love how you break it down on the board

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

      1. Consider the following two functions. What are the time complexities of the functions? Please do explain and describe in details on how you derive the complexity of those two functions.
      int f1(int n) {
      if (n

  • @c.danielpremkumar8495
    @c.danielpremkumar8495 6 років тому +5

    Wow ! I have never seen such a wonderful explanation on Big O, ....... so far. Wish I had seen this earlier

  • @subrothosamantha9331
    @subrothosamantha9331 6 років тому +5

    Mera kal Abstract Algebra ka exam hai aur aaj mai Algorithms sikh raha hu. koi fikar nahi hai, atleast kuch tho samaj aaraha hai. ThankYou sir

  • @RobertoMartinez-pz7im
    @RobertoMartinez-pz7im 2 роки тому +1

    Best teacher ever. Thanks a lot for creating this channel and sharing your knowlege. I wish all the best in the world to you. Thanks again for helping me learning CS.

  • @sudaminis1302
    @sudaminis1302 2 роки тому +1

    What an amazing teacher! Greatly appreciate the clear explanations and enthusiasm!

  • @prajunathunt
    @prajunathunt 5 років тому +422

    Exam tomorrow, 1.5x speed

    • @shivamsompura1549
      @shivamsompura1549 4 роки тому +16

      XD anyways I watch all videos at 1.25 now its normal for me. if i see 1X it seems very slow XD

    • @anirbansarkar6690
      @anirbansarkar6690 4 роки тому +1

      Me 2

    • @maneesh685
      @maneesh685 4 роки тому +11

      @@shivamsompura1549 I READ THAT IN 2X SPEED

    • @haiderali-xz9se
      @haiderali-xz9se 4 роки тому +4

      exam after one hour... speed 1.0 😋legends

    • @1aniket
      @1aniket 4 роки тому +17

      exam after 30 min and just reading comments :D ULTRA LEGENDS

  • @serhatsualp7692
    @serhatsualp7692 5 років тому +90

    Thanx alot from Turkey you should be instructor at university here dear AbdulBahri abi:)

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

    One of the best tutorial for beginners and the way of explanation was simply awesome.

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

    when i have any problem,i go to this chennel to find solution of problem in depth way,thanks for giving us the best thinks ever

  • @Kinjen_
    @Kinjen_ 8 місяців тому +6

    ... I am currently a cs student, and have been struggling with this to the point of panic attacks and dropping out. Or switching majors.... You might have just saved my degree.... Thank you

    • @GlitchingLater
      @GlitchingLater 7 місяців тому +2

      NEVER BACK DOWN NEVER WHAT?

    • @notsohappy2565
      @notsohappy2565 6 місяців тому +1

      @@GlitchingLater NEVER GIVE UP!!!!!!!!!!

  • @anuragreddy8077
    @anuragreddy8077 5 років тому +17

    5:53 -->(n^2 +n)/2

  • @gayathri-gd4bf
    @gayathri-gd4bf 3 роки тому

    beat DSA teacher I have ever seen. Explains concept very clearly. Thank you very much sir

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

    I discovered this channel last month . May Allah blessed you. This channel is very useful for my education. Thanks for everything. Still keep watching

  • @brandonasdfd3232
    @brandonasdfd3232 6 років тому +31

    ABDUL, HAVENT STARTED THIS VIDEO AND YET YOU're SAVING MY LIFE LOL

  • @reazrahman1850
    @reazrahman1850 3 роки тому +16

    I got scared after he paused for few second. I thought he was gonna pick on me and I was thinking about the answer.

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

    The Sound of this Video is So Good. Its So Smooth. Not Annoying. THats Good. And The Style of Teaching of Sir is very Nice. Thanks

  • @VasudhaJoshi
    @VasudhaJoshi 4 роки тому +2

    Thank you so much sir, your videos are amazing! I understand the concept of time and space complexity very well now.

  • @iqraabdulrauf3402
    @iqraabdulrauf3402 3 роки тому +3

    I just love how he stops for a while after explaining something- the real teacher - BEST

    • @jos3008
      @jos3008 3 роки тому +1

      1. Consider the following two functions. What are the time complexities of the functions? Please do explain and describe in details on how you derive the complexity of those two functions.
      int f1(int n) {
      if (n

  • @faisalmominbhiwandi
    @faisalmominbhiwandi Рік тому +5

    for(int i=0; i

    • @user-qs1lh1qv1d
      @user-qs1lh1qv1d 25 днів тому

      yes absolutely correct u are

    • @Anand_Kumar88
      @Anand_Kumar88 2 дні тому

      He wants to say condition is checked n+1 times
      But the loop statements will be executed n times

  • @abhilashadeshwar8382
    @abhilashadeshwar8382 3 роки тому +1

    I always have fear Of DSA but your lecture inspire me and try to complete all lecture .Ty so much sir 👍

  • @zohayer.mehtab
    @zohayer.mehtab 8 місяців тому +1

    Thank you. Finally, someone who can teach the things from the basics.

  • @walterwhite0107
    @walterwhite0107 5 років тому +15

    Nsquare +n by 2 at 5:52 . However degree of polynomial remains same

  • @ravindrashekhawat1989
    @ravindrashekhawat1989 3 роки тому +10

    "Tum Jo Aaye Zindagi Mein Baat Ban Gayi
    DSA Mazhab, DSA Meri Zaat Ban Gayi"

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

    Clear, simple explanations, well done. Many thanks, this video is helpful in comprehending programming algorithm notation.

  • @ragv3300
    @ragv3300 5 років тому +2

    sir ur concepts are really awesome stay blessed always for sharing ur such priceless knowledge.......

  • @ketkiambekar3789
    @ketkiambekar3789 2 роки тому +4

    @ 5:27 it should be (n^2 + n)/2 and not (n^2+1)/2. Thanks for making these freely available on youtube

    • @devinosborne3396
      @devinosborne3396 Рік тому

      Yes! I found the same! Thanks for the free videos as well: :D

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

      @@devinosborne3396 for last problem ? how he got root n .why not n square.

    • @devinosborne3396
      @devinosborne3396 Рік тому

      @@armoorshailesh4891 I think he just overlooked the second 'n' for the sake of simplicity!

  • @faizalhasan6933
    @faizalhasan6933 3 роки тому +3

    You are so wonderful. Pls start teaching again

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

    Thankyou sir...
    I was struggling with these concepts for a long time.
    but now all clear...
    thankyou very much

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

    im reviewing for interviews and stumbled upon your videos. youre the greatest.

  • @alialmancie
    @alialmancie 3 роки тому +5

    5:20 correction: (n(n+1))/2 = (n^2 + n)/2

  • @ShawnDypxz
    @ShawnDypxz 3 роки тому +6

    Here's my explanation for the order of n^(1/2). So, when i=1, the program control goes inside the loop and the assignment statement (p=p+i) runs. This is the first time this statement executed. Let's keep track of i and p values. At first, when i =1, p =1. Now, move on to the second iteration. This time i=2 and p= (1+2). Now for the 3rd iteration, i=3 and p=1+2+3. Let's move on to fourth iteration. Now i=4 and p=1+2+3+4. Let's observe a pattern here. In total, we have run the assignment FOUR times till now which is exactly equal to the value of i. So when i= 10 (suppose) , the assignment statement will run 10 times. So when the value of i reaches k, the assignment will run for k times. We have to be aware that we are looking for how many times the assignment statement will run. So, that's k times. We found it but it's not as a function of n. So when i=k, p=(k(k+1))/2. It's a series formula for summing natural numbers upto k. This loop will stop when p>n. So (k^2+K)/2 > n . We solve this inequality and get k = (2n-k)^0.5. So, that's O(n^0.5).

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

      Thanks

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

      Thanks man

    • @leandrawoods8568
      @leandrawoods8568 Рік тому

      Thank you! Thank you! Thank you!

    • @rushbh3452
      @rushbh3452 Рік тому

      "We have to be aware that we are looking for how many times the assignment statement will run. So, that's k times."
      This! I needed to understand. thank you

    • @mowafkmha4505
      @mowafkmha4505 Рік тому

      you are a true legend

  • @akternasrin1561
    @akternasrin1561 Рік тому

    Thank you for this video. You teach hard things in a very simple way. Your way of explaining really amazed me.

  • @merchant100
    @merchant100 3 роки тому +1

    You explained it much better than my university professor, thanks a lot man!

  • @michamacioek7831
    @michamacioek7831 Рік тому +9

    Do you think that there's an error in the third example that starts around 2:50? In the time units calculation, in my opinion, instead of 1 + 2 +3 + ... + n, there should be 1 + 2 + 3 + ... + n-1. Because when i = n, the for loop will be terminated. What do you guys think?

    • @user-oh8fo2eq7s
      @user-oh8fo2eq7s Рік тому +1

      yes ,you are correct. BUT in the video he told ......if the condition is less than equal to n, but he missed it. So, 1 + 2 +3+ ... + n is correct for i

    • @sakarmichel5556
      @sakarmichel5556 6 місяців тому

      @@user-oh8fo2eq7s
      To @abdul_bari Thank you much for sharing your knowledge. Thank you so much for all the work that goes in the videos. Your videos are perfect! I would like to help keep them that way! Based on @user-oh8fo2eq7s and @michamacioek7831 said what do you think? Happy Holidays by the way.

  • @Eduardo-ow8mo
    @Eduardo-ow8mo 2 роки тому +3

    at 5:49, actually F(n) = (n^2 + n) / 2 [instead of (n^2 +1) / 2], the result is the same since we only take care of the n with biggest exponential

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

    You're the best. Thank you for all your videos about time Complexity. I tried to understand at College but you are superior then them!!!

  • @amanpahari690
    @amanpahari690 2 роки тому +2

    it was so , soothing,, to watch,, at 1x speed,,
    1st time enjoying the deptness & deepness of an Experienced Teacher

  • @Rockstar-xt5cw
    @Rockstar-xt5cw 2 роки тому +3

    The best time complexity for his videos is watching in 1.5x speed😌

  • @omkard8878
    @omkard8878 3 роки тому +8

    5:30 The value of f(n) should be (n^2 + n) / 2. and NOT (n^2 + 1)/2

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

      sir, can you please explain to me why 1 + 2 + 3 + 4 +.....n = n(n+1)/2 ???? where n(n+1)/2 comes from?

    • @Omar-ic3wc
      @Omar-ic3wc 3 роки тому +10

      @@muhammadakmalbinmohdsabri9036 n(n+1) /2 is a formula to calculate the sum , let's say you want to know the sum of the numbers from 1 to 4, so you have 1+2+3+4 the result is 10 right? Very easy indeed but what if we have a long list of numbers would you add them one by one? No that wouldn't be efficient right? So here comes the formula let's substitute N with the number 4 from the first example we have: 4*(4+1)/2 and here you have the same result from the sum one by one. I hope was clear enough, if you have any doubts tell me.

    • @muhammadakmalbinmohdsabri9036
      @muhammadakmalbinmohdsabri9036 3 роки тому +1

      @@Omar-ic3wc Ouh now i understand how its work, thank you very much on your explaination sir. Very helpful for me! 👍🙏

    • @Omar-ic3wc
      @Omar-ic3wc 3 роки тому +1

      @@muhammadakmalbinmohdsabri9036 you are welcome :) have a great day

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

      @@Omar-ic3wc Thanks alot for the clarity Omar i was almost losing track because of this.

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

    Thank you so much sir for explaining it so clearly. This is so good for the beginners.....

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

    it was wonderful lesson for me .although my english's bad I understand time complexity on loops with your clear explanation

  • @gaurav0883
    @gaurav0883 4 роки тому +11

    Machine gun at 4:28 , watch in 2x

  • @dipikamadan2149
    @dipikamadan2149 3 роки тому +4

    5:25 why it's not n* (n(n+1)/2)? why first loop's n executions not considered?

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

      same question here..

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

      That's because we are accounting for all of the j iterations for given i. Here, for each i, our j will get executed for different number of times. For e.g. for i=0, j will be executed for 0 times, then for i=1,1time, for i=2, 2 times and so on. Whereas, have a look at previous example, for each and every i, j is executed for n times, so we take it as (n+1)*(n) times for j and thus n*n times for the statement.

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

    awesome, when I search on youtube and see your video, it's my top priority. and it's true, easily understood. jazakumullah khairan.

  • @subramaniyanvg6367
    @subramaniyanvg6367 3 роки тому +1

    I never skipped the ads because of the effort you put into this video. Very nicely explained with examples thank you sir.

    • @pesetmekyok4038
      @pesetmekyok4038 3 роки тому +1

      as a programmer you should use adblocker :D but you re right he deserves it..

  • @kerryokpere8036
    @kerryokpere8036 5 років тому +4

    I had noticed a problem in 5:54 since it is a nested loop then the inner loop should run f(n) = n((n^2 + n) /2) making O(n) = n^3

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

      its not the formula for inner loop, the summation that he did is for number of times the statement is going to execute and it will execute for order of (n2)

  • @heroalom1295
    @heroalom1295 2 роки тому +3

    Sir in last program, you said i will run for k times, but actually value of p is deciding whether stmt has to be executed or not, when value of p is 6(which is greater than n) the stmt will not be executed.
    So if we see, i is executed for (1,2,3,4) i.e 4 times(n+1) and the statement p=p+i will execute for 3 times only. So the time complexity should be O(n).. is this correct or not?

    • @vinothn5205
      @vinothn5205 2 роки тому +2

      What if n = 5, but the statement executed only 3 times, which is less than n. Similarly if n is very large number, then the statement will execute less than n. Here, the value of k is not exact it's just an approximate value.

  • @xyz-pc3tl
    @xyz-pc3tl 2 роки тому +1

    Thanks for your all hardwork & making concepts easy to understand ..

  • @Someone-wb8cc
    @Someone-wb8cc 2 роки тому +1

    Thank you I have been stressing for 2 weeks and you have answered my prayers🙏🏽🙏🏽

  • @vinicius_7
    @vinicius_7 11 місяців тому +3

    Thanks!

  • @ashutoshjoge6664
    @ashutoshjoge6664 4 роки тому +25

    5:30 ,sir, you have made incorrect multiplication of f(n). It should be f(n) = (n^2 + n )/2.

    • @Ghareonn
      @Ghareonn 4 роки тому +1

      I noticed that too. Although n would be dropped because it is smaller than n^2

    • @Polarwhite43
      @Polarwhite43 4 роки тому +3

      I’m not the only one then!
      I thought I wasn’t getting it right
      Thanks for your comment buddy

    • @xeboox
      @xeboox 4 роки тому +1

      i noticed that too but can you please tell me why he took the result and divided by 2 ??

    • @matpro0
      @matpro0 4 роки тому +12

      @@xeboox he didn't. it's the formula for the sum of n natural numbers.
      1+2+3+...+n= n(n+1)/2

    • @xeboox
      @xeboox 4 роки тому +1

      @@matpro0 It's cool when someone respond , thanks buddy

  • @dreamer9375
    @dreamer9375 5 років тому +2

    2 minutes in and I already feel smarter. Thanks a ton, Sir!

  • @yolandepretorius3236
    @yolandepretorius3236 4 роки тому +2

    Great video watching all his videos wish he was my lecture from New Zealand

  • @anjumaddi5595
    @anjumaddi5595 5 років тому +3

    sir shouldn't the function be n(n-1)/2 because 'i' cannot have value 'n'

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

      for i := 0; i < 10; i++ {
      for j := 0; j < i; j++ {
      fmt.Println("Times: ", ++times, " I value : ", i, " J value : ", j)
      times++
      }
      Last OutPut : Times: 45 I value : 9 J value : 8
      Yes Your are correct It should be n(n-1)/2

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

      he later said i am taking n value also

  • @funtrip6491
    @funtrip6491 5 років тому +10

    5:54 f(n) = ( (n^2) + n ) / 2 , shouldn't n be mulitpled to 1 or am I missing something ?

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

      Yup u r right !

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

      I had noticed the same problem on 5:54 since it is a nested loop then the inner loop would run for f(n)= n((n^2) + n )/2 making O(n)=n^3

    • @PBNinja
      @PBNinja 4 роки тому +2

      @@kerryokpere8036 its not O(n) = n^3 its O(n)=n^2 because the inner loop run at most N iterations and the external loop runs at most N iterations, but exactly: both loops were represented by the sum from 1 to N so there was no need to multiply again by N

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

      kerry okpere no it’s O(n) = n^2/3 and n/2 but we take n^2 because it is a more dominant contributor

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

      @@PBNinja Thank you for your explanation. Can you please explain me the logic behind dividing it by 2 ?

  • @jerinkjohn545
    @jerinkjohn545 Місяць тому +1

    7:37 for who did not understand the difference between k and n,assume n=10,then the loop runs for k times=4 times;p=1+2+3+4=10.That means k(value=4)

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

    I enjoy your videos.Great explanation!
    Thank you Sir

  • @akankshakeshri1892
    @akankshakeshri1892 4 роки тому +3

    @5:50 see something?

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

      Ya
      N(N+1) = N2+N not N2+1 👍👍

  • @manojthatipigari8176
    @manojthatipigari8176 4 роки тому +3

    R u watching in 2020

  • @user-mk8bt3ej4e
    @user-mk8bt3ej4e 4 роки тому +1

    Thank you for this video and all video you create . You are helping me a lot ❤️❤️❤️

  • @thasan8255
    @thasan8255 4 роки тому +1

    I wish I could catch up with you at my University. your Teaching level is excellent Sir. Love and Salam from Bangladesh.

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

    Your explanations are too clear and lucid!

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

    Comprehensive and great lecture. Thanks a lot Sir.

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

    Really awesome explanation, thank you sir making it too clear...

  • @behnamseydabadi8819
    @behnamseydabadi8819 Рік тому

    You are a great person, a great teacher. Thank you so much.