Count the number of one's in binary representation of given no. || Competitive Programming ||

Sdílet
Vložit
  • čas přidán 28. 08. 2024
  • In this video we are going to discuss very interesting algorithm in bitwise operator to count the number of one's in the binary representation of given number.competitive programming. codecehef solution also in hello world.
    ----------------------------------------------------------------------------------------
    Code in this video : github.com/Pri...
    Pdf of this video : github.com/Pri...
    ASCII Table link : www.cs.cmu.edu...
    Home-work Questions : www.codechef.c...
    *Follow me on Instagram *
    Instagram► / helloworldbyprince
    *Follow me on Twitter *
    Twitter► / prince_king_
    Our Students Contacts Form:-
    Form link : docs.google.co...
    ------------------------------------------------------------------------
    Our mission is to provide a free course for all students in Hindi in better way or in friendly way.
    Competitive programming or CP is a buzzword when a guy is a freshie in computer science branch and most of the guys don't have proper guidance that is needed. So in this series of video lectures I will be guiding you through various problems, myths, future scopes and a lot more related exclusively to competitive programming.
    #competitiveprogramming #helloworld #codechef

Komentáře • 45

  • @devanshgoel3433
    @devanshgoel3433 Před 3 lety +3

    Bro, you have explained amazingly. But, one point to note is that if number is zero then it will give output as 1.

  • @Ji-yoon
    @Ji-yoon Před 4 lety

    Your channel is awesome......continue making videos of this kind.....

  • @AnuragSingh-iy7fz
    @AnuragSingh-iy7fz Před 4 lety

    sir log question kare ya na kare, ye unki problem hai, aap videos banate rehna competitive coding par, ham sab aapke saath hain.
    Appreciate your efforts

  • @manojkumar-qm4mx
    @manojkumar-qm4mx Před 3 lety

    What a nice job
    Sir AAP bahut achha padate hain 🙌🙌

  • @aniketjaiswal3874
    @aniketjaiswal3874 Před 4 lety +2

    sir
    c=0;
    while(n)
    {
    if(n%2==1)
    c++;
    n=n/2;
    }
    this will do in O(log n) which in worst case better than O(k) (=O(n))....
    #completed

  • @samarth9467
    @samarth9467 Před 10 měsíci +1

    public class Main {
    public static void main(String[] args) {
    int number = 23; // Change this to the number you want to count 1's in binary for
    int count = countOnes(number);
    System.out.println("Number of 1's in binary representation of " + number + ": " + count);
    }
    public static int countOnes(int n) {
    int count = 0;
    while (n > 0) {
    count += n & 1; // Check the least significant bit
    n = n >> 1; // Right shift to check the next bit
    }
    return count;
    }
    }

  • @nimssinha5373
    @nimssinha5373 Před 3 lety

    Good job Brother✌

  • @7949RAJ
    @7949RAJ Před 4 lety +1

    sir,
    can we run a loop and check if(n&(1

  • @pankajnavale744
    @pankajnavale744 Před rokem

    #Completed

  • @ketandoshi5641
    @ketandoshi5641 Před 3 lety +2

    #completed

  • @pankajnavale744
    @pankajnavale744 Před rokem

    Completed

  • @rockytapader4643
    @rockytapader4643 Před 5 lety +1

    nice

  • @pradeexsu
    @pradeexsu Před 4 lety +1

    we can also use __builtin_popcount() no header file require
    #completed

  • @RANJEETSINGH-dd8ru
    @RANJEETSINGH-dd8ru Před 4 lety +1

    sir please give some good question in home work. It is too easy .

  • @Dragoon102
    @Dragoon102 Před 4 lety

    Thank you sir for ur help

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 4 lety

      Your welcome buddy ... Please share this channel to different college and with your friends

  • @teores8312
    @teores8312 Před 3 lety

    It works, thx Dude!

  • @AnuragSingh-iy7fz
    @AnuragSingh-iy7fz Před 4 lety

    #completed
    #include
    using namespace std;
    int main()
    {
    int t,n;
    cin>>t;
    while(t--)
    {
    cin>>n;
    if(n

  • @surajkumarsaw7398
    @surajkumarsaw7398 Před 4 lety

    #complete

  • @rishabhpandey8892
    @rishabhpandey8892 Před 4 lety

    #include
    using namespace std;
    int main() {
    int t;
    cin>>t;
    while(t--){
    int n;
    cin>>n;
    if(n

  • @abhishekshetty9138
    @abhishekshetty9138 Před 3 lety +2

    question is repeated

  • @ShubhamChhimpa
    @ShubhamChhimpa Před 4 lety

    #completed
    #include
    using namespace std;
    int main()
    {
    int T;
    cin >> T;
    while(T--){
    int x;
    cin >> x;
    if(x < 10){
    cout

  • @parikshitsharma5651
    @parikshitsharma5651 Před 4 lety

    #done

  • @itz_me_imraan02
    @itz_me_imraan02 Před 3 lety +1

    count=0;
    while(n!=0)
    { n=n&(n-1);
    count++;
    }
    cout

  • @chetankumar1487
    @chetankumar1487 Před 4 lety

    why count is taken as 1...it should be initialised with 0.

  • @azrallex
    @azrallex Před 4 lety

    homework question is repeated, sir.

  • @amansohani4620
    @amansohani4620 Před 5 lety

    sir par agar sare 1 ho binary representation me toh worst case me toh is algorithm ki bhi log(n) complexity hogi na.

    • @HelloWorldbyprince
      @HelloWorldbyprince  Před 5 lety +1

      But Aman, aap ye v to dekhiye at max aap sareee one's wale number kya lijiyega .. for example : 111111111111111111111111111111 --> mann lo aaapne ye liya ...and first of all ye itna badda number hai ki aap calculate nahi Kar sakte but fir v ..iska complexity O ( 30 ) jayega jo ki mathematically bahut kam aata hai .. your point is right but in actuality itna big number se hmlog deal nahi karte ... Thank you ..

    • @amansohani4620
      @amansohani4620 Před 5 lety +1

      @@HelloWorldbyprince ha samagh gaya sir thanks

  • @chidambarjoshi3470
    @chidambarjoshi3470 Před 4 lety

    #servantcompleted

  • @vaibhavsingh964
    @vaibhavsingh964 Před rokem

    how and why this logic?

  • @md.azharulkarimanik1273

    #completed

  • @sourjyapal945
    @sourjyapal945 Před 4 lety

    #completed

  • @rajumolla4212
    @rajumolla4212 Před 4 lety

    #completed

  • @pawansinghal585
    @pawansinghal585 Před 4 lety

    #completed

  • @rohananand9905
    @rohananand9905 Před 4 lety

    #completed

  • @tarunprajapat2240
    @tarunprajapat2240 Před 4 lety

    #completed

  • @amitjaiswal6594
    @amitjaiswal6594 Před 5 lety

    #completed