Bitwise Operators + Number Systems - Maths for DSA

Bitwise Operators + Number Systems - Maths for DSA

Kunal Kushwaha

2 года назад

330,446 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@arkashishsutradhar121
@arkashishsutradhar121 - 23.10.2021 09:17

The 2's compliment explaination is OP. Like no one ever explained y this happened. Hats off man.

Ответить
@vaibhavimishra763
@vaibhavimishra763 - 07.12.2023 06:35

I was scared of DSA but after watching his videos I just love to learn DSA and addicted to solve problems, really thankful,God bless u ❤❤❤❤❤

Ответить
@Chiller-wx6gp
@Chiller-wx6gp - 16.11.2023 18:12

this guy is this good : (10)^256<<16^256

Ответить
@AryanTewari-ls9nt
@AryanTewari-ls9nt - 21.10.2023 06:14

i believe setReset would work a lot better if we do it using XOR, since XOR of 1 with something gives you the complement of it and we can use leftshift to not update the original number!

Ответить
@mayank3411
@mayank3411 - 15.10.2023 20:26

please anyone tell me in last question what was the purpose of second loop and what does it do?

Ответить
@KAMLESHSINGH-vr3bl
@KAMLESHSINGH-vr3bl - 13.10.2023 21:25

Can i watch this if i only know C++ not java ?? pls tell

Ответить
@mayank3411
@mayank3411 - 10.10.2023 21:38

question 11 mai 1<<n-1 kyu hua? please explain

Ответить
@ESaiKathiroliP-EEE
@ESaiKathiroliP-EEE - 02.10.2023 15:46

Hey Kunal! In Question 5 doing the "or operation" might change the bits present before the "set bit"? Why aren't we worried about that? And in Question 6 we are careful about having the other bits other than the bit to be reset is "1" @Kunal

Ответить
@ESaiKathiroliP-EEE
@ESaiKathiroliP-EEE - 28.09.2023 20:02

Kunal! I wanna know how do you get so deeply into a Subject? What is your go to resources? Like I'm really eager to know How did you learn the negative number stuff so deeply to it's base? 🎉

Ответить
@AMITKumar-hg5ih
@AMITKumar-hg5ih - 24.09.2023 12:45

first math class watched with interest

Ответить
@alveeraN
@alveeraN - 13.09.2023 19:03

you are so intelligent ⭐

Ответить
@ANIME-ir6ku
@ANIME-ir6ku - 12.09.2023 05:11

Bhaiya mujhe kabhi kabhi bahut depression hota hai 😭

Ответить
@JSONY-ff2ni
@JSONY-ff2ni - 08.09.2023 14:15

i am unable to comprehend question 8 if anyone understood please comment your explanation here

Ответить
@sauravagrawal5013
@sauravagrawal5013 - 05.09.2023 21:27

Question - 08 Solution - Although not optimal I coded this. Please comment on how I can improve it.
import java.util.Arrays;


public class FindUniqueInThriceOccurrence {
public static void main(String[] args) {
int[] arr = {2, 2, 3, 2, 7,7, 8,7,8,8};
// sorting the array
Arrays.sort(arr);
// find the length of maximum value in binary.
int maxLength = (int) (Math.log(arr[arr.length-1])/Math.log(2))+ 1;
String sumOfNums = "";
// find the bit at an index and sum of all the 1s in that particular index.
for(int index=maxLength; index>=1; index--) {
int sumOfIndex = 0;
for (int i : arr) {
sumOfIndex += findithBit(i, index);
}
sumOfNums+=sumOfIndex;
}
String ans ="";
// take modulous of each index by 3 and append it to a string.
for(int i=0; i<sumOfNums.length();i++){
ans+=Integer.parseInt(String.valueOf(sumOfNums.charAt(i)))%3;
}
// convert binary to Integer.
System.out.println(Integer.parseInt(ans, 2));
}
static int findithBit(int num, int index){
int nums = (num & (1<<(index-1))) >> (index-1);
return nums;
}
}

Ответить
@sauravagrawal5013
@sauravagrawal5013 - 05.09.2023 20:04

For question no 7 - N & (-N) would give the value rather than the index of the right most set bit. We would have to do the right shift to get the position of the set index.

Ответить
@user-xe2rt7uz4p
@user-xe2rt7uz4p - 02.09.2023 15:13

N&(-N) is giving 4 as output for 100 ( Integer 4), it should be 3 right not 4?

Ответить
@divyansharya4974
@divyansharya4974 - 01.09.2023 13:49

Hey Kunal, in question 7 you said the rightmost set bit is equal to n & n-1.
But if we take an eg. 8, i.e. 1000 in binary, 8 & -8 is equal to 8 itself.
The answer should have been 4, please clear my doubt, Thanks

Ответить
@shubham57641
@shubham57641 - 30.08.2023 05:35

No one can give deep content in the free of cost like Kunal Kushwaha, Hats off to this man.👌👌👌

Ответить
@preetichib2254
@preetichib2254 - 29.08.2023 21:32

noice 👌

Ответить
@praveen6431
@praveen6431 - 29.08.2023 05:16

Can anyone help me by providing question no 8 solution???

Ответить
@TirtharajSen
@TirtharajSen - 26.08.2023 15:24

How can -N & N give the position of the rightmost set bit? It will not give.. it is a wrong solution

Ответить
@riyamandal2436
@riyamandal2436 - 23.08.2023 17:57

I am offended .Why this guy has only 6.1k likes?

Ответить
@ravindraverma8413
@ravindraverma8413 - 21.08.2023 18:39

Bro please create video on dynamic programming

Ответить
@siddhantmeshram4092
@siddhantmeshram4092 - 12.08.2023 15:02

public static int findSingleNumber(int[] nums) {
int result = 0; // This variable will store the single occurring number.

// We iterate through each bit position in a number (assuming 32-bit integers).
for (int i = 0; i < 32; i++) {
int sum = 0; // This will store the sum of bits at position i across all numbers.

// We go through each number in the array and count the bits at position i.
for (int num : nums) {
sum += (num >> i) & 1;
// (num >> i) shifts the bits of num to the right by i positions.
// The "& 1" operation isolates the bit at position i.
// We add the isolated bit to the sum.
}

sum %= 3; // Taking the sum modulo 3 eliminates bits appearing in triplets.

// Now, we set the corresponding bit in the 'result' using bitwise OR operation.
// We shift the calculated sum by i positions and then set the bit in 'result'.
result |= (sum << i);
}

return result; // The 'result' now holds the single occurring number.
}

Ответить
@HR-pz7ts
@HR-pz7ts - 11.08.2023 21:05

After learning how to create mask all my concepts were clear. I previously didn't know how to access any bit of an integer. Now I know how and rest of the logics are basic stuff.

Ответить
@dhamotharan1734
@dhamotharan1734 - 04.08.2023 17:28

👍

Ответить
@advrakshachaudhari3699
@advrakshachaudhari3699 - 01.08.2023 15:12

ncie video

Ответить
@puneetchhabra2578
@puneetchhabra2578 - 29.07.2023 08:58

OP Video

Ответить
@puneetchhabra2578
@puneetchhabra2578 - 28.07.2023 21:40

For those who are getting doubts in any bit manipulation solution explained in the video, just dry run 2 or 3 testcases and observe the changes to the bits. You will get the answer.

Ответить
@debarghabanerjee1748
@debarghabanerjee1748 - 26.07.2023 17:27

Man!!!!!! the Q8 what a pain, but when you understand the rightshift and leftshift will be crystal clear to you

Ответить
@Useful-sl1oh
@Useful-sl1oh - 04.07.2023 20:53

Q8 answer ----
public class Question8 {
public static void main(String[] args) {
int[]arr = {1,1,1,3,3,3,10,10,10,7};
System.out.println(detect(arr,3));
}
public static int detect(int[]arr,int repeatationTime){
int[] setBitArray = new int[32];
for (int i : arr) {
int index = 0;
while(i > 0){
setBitArray[index] += i & 1;
i = i >> 1;
index++;
}
}
for (int i= 0; i < setBitArray.length; i++) {
setBitArray[i] %= repeatationTime;
}

int ans = 0;
for (int i = 0; i < setBitArray.length; i++) {
ans += setBitArray[i] * (int)Math.pow(2, i);
}
return ans;
}
}

Ответить
@itshari5489
@itshari5489 - 04.07.2023 10:25

Video 25 Completed! For me it took quite a long time to understand.

Ответить
@BROOKnim
@BROOKnim - 02.07.2023 21:45

for question 12, will finding the right most set bit on n => (n&-n) say x and xoring it with n if it gives 0 , then they are same , (the rightmost set bit and the number) => its a power of two.

i mean,

int rightMostSetBit=n&-n;
if(rightMostSetBit^n==0) sout(power of two)
else sout(not power of two)

will this work.?

Ответить
@superfax
@superfax - 12.06.2023 19:32

For finding the i'th bit the answer should be ((n & (1 << (targetBit - 1))) >> (targetBit - 1))

Ответить
@anshulgoel1940
@anshulgoel1940 - 03.06.2023 17:21

Thanks for the video . Small point here. Left shift and right shift are not really bitwise operations. They are more like arithmetic operations which basically multiply or divide by 2

Ответить
@bNNikolov
@bNNikolov - 26.05.2023 20:26

Please enable the subtitles for the videos.

Ответить
@DeepMoment149
@DeepMoment149 - 22.05.2023 19:28

Salute bhai>>>
I have learned from your videos a lot of things.
I became fan of you after seeing this tuitorial. take love from BD <3

Ответить