improving naive gcd

  Рет қаралды 321,219

NOC16 CS11

NOC16 CS11

Күн бұрын

Пікірлер: 51
@ANAND-zw1on
@ANAND-zw1on 2 жыл бұрын
We can further simplify this by starting the loop from min(m, n) /2 to 1 and seperate sentence for testing the min(m, n) . Eg: if we take 100 and want to know the factors, first 100 is a factor, then there is no factor from 99 to 51. So we can skip that part completely. This is true for every other numbers.
@tavilefty
@tavilefty 2 жыл бұрын
exactly man. this comment needs to be pinned.
@girish8579
@girish8579 Жыл бұрын
What about odd numbers?
@mrtalksick6178
@mrtalksick6178 5 ай бұрын
@@girish8579 instead of dividing by 2, take the quotient of the division i.e. min(m, n)//2.
@abhishek-wt5xm
@abhishek-wt5xm 4 жыл бұрын
i dont know why people are getting difficulties in understanding but i would must say i there cant be an easier explanation. really a great resource for understanding the algorithm syntax and know the best solution you also explained the way to decrease the time and ans space complexity of the algorithm thankyou
@coldcoke9254
@coldcoke9254 2 жыл бұрын
probably because it s the first lecture and we are already using concepts of functions and loops and lists...I'd recommend watching a one shot lecture on python by codewithharry and then coming to this that's what I did and now all this seems really simple...don't even need to watch all of it only till chapter 8.
@ruturajjadhav8905
@ruturajjadhav8905 4 жыл бұрын
def gcd(num1,num2): return max(list(set([i for i in range(1,num1+1) if num1 % i == 0]).intersection(set([i for i in range(1,num1+1) if num1 % i == 0])))) ## intersection : combines the common factors of given two sets ##just two lines
@SlickShitt
@SlickShitt 3 жыл бұрын
after intersection you used the first parameter instead of num2
@adityamehra7238
@adityamehra7238 2 жыл бұрын
My brain literally exploded after realising there was 1 another way to write code for this gcd...... Meanwhile professor : you said 1? Wait hold my mike...... 💥💥... A beautiful lecture
@sameers8510
@sameers8510 3 жыл бұрын
You are simply superb sir Awesome explanation
@coldcoke9254
@coldcoke9254 2 жыл бұрын
probably because it s the first lecture and we are already using concepts of functions and loops and lists...I'd recommend watching a one shot lecture on python by codewithharry and then coming to this that's what I did and now all this seems really simple...don't even need to watch all of it only till chapter 8.
@ashishkumarsharma1323
@ashishkumarsharma1323 Жыл бұрын
def gcd(m, n): i= min(m, n) while(i>0): if (m%i == 0 and n%i== 0): return(i) else: i=i- 1 x=gcd(21, 9) print(x)
@mandarchincholkar7250
@mandarchincholkar7250 5 жыл бұрын
Marvelous logic... Amazing... 👏👏👏👏🎉🎉🎊🎊🎊 only experienced programmers will get it..🔥🔥🔥
@panthrohit
@panthrohit 5 жыл бұрын
Not an experienced programmer, still I get it... :)
@mandarchincholkar7250
@mandarchincholkar7250 5 жыл бұрын
@@panthrohit then you nailed it hardly.. 😎😎😎😎
@panthrohit
@panthrohit 5 жыл бұрын
@@mandarchincholkar7250 This reminds me of the saying 'working hard or working hardly'. Whats my takeaway here....🤔😛😬
@mandarchincholkar7250
@mandarchincholkar7250 5 жыл бұрын
@@panthrohit bhai baat ko mat ghumaya kar.. 😂😂😂😂😂
@panthrohit
@panthrohit 5 жыл бұрын
@@mandarchincholkar7250 😉
@Jaimin_Bariya
@Jaimin_Bariya 2 ай бұрын
Jp here again [comment number 51] Thank you, sir, :)
@bhargavdobariya5859
@bhargavdobariya5859 3 жыл бұрын
great explanation....thanks a lot sir
@mritunjay3723
@mritunjay3723 4 жыл бұрын
A one line code -- print(next(a for a in range(63,0,-1) if 8888%a==0 and 63%a==0))
@anshulojha5699
@anshulojha5699 4 жыл бұрын
The algo that u explain if I will learn that methods to minimize the all codes with time and memory then I will be the rank 1 in Google contests 🙏🙏
@sravanchilumula5213
@sravanchilumula5213 5 жыл бұрын
classes are in not the correct order please correct it!
@arpitaingermany
@arpitaingermany 6 жыл бұрын
The shorter python program was confusing min(m, n) this part
@vatsalgupta00
@vatsalgupta00 6 жыл бұрын
Divisor of a number cannot be larger than the number. Since we are trying to find common divisors, only divisors of smaller number are suffcient.
@DineshJunjariyaBEE
@DineshJunjariyaBEE 5 жыл бұрын
min(m,n) gives least of the two numbers
@anshulojha5699
@anshulojha5699 4 жыл бұрын
Like min(6,8) so dono me vo common no hoga vo 6 se thoe hamesha less hi hoga like 2 here . That's why they used this concept ✅
@vatsal_gamit
@vatsal_gamit 4 жыл бұрын
def gcd3(m,n): return max([i for i in range(1,min(m,n)+1) if ((m%i)==0 and (n%i)==0)]) print(gcd3(3575,978))
@BiswajitDas-lk7pp
@BiswajitDas-lk7pp 2 жыл бұрын
Amazing 😀😀😀
@tavilefty
@tavilefty 2 жыл бұрын
wonderful lecture.
@bhupiagra1
@bhupiagra1 6 жыл бұрын
you said actually any common factor must be less than min(m, n) but how this statement is justifying gcd of (2, 4) ?
@tabassumhebbalkar
@tabassumhebbalkar 6 жыл бұрын
including the minimum of both.
@panthrohit
@panthrohit 5 жыл бұрын
Must be less than or equal to min(m,n)
@DineshJunjariyaBEE
@DineshJunjariyaBEE 5 жыл бұрын
he meant min or less than min
@sanjayguptacg486
@sanjayguptacg486 5 жыл бұрын
low sound.
@prashnatdivase8523
@prashnatdivase8523 4 жыл бұрын
def gcd(m,n): fm=[] # list down factor of m in fm fn=[] # list down factor of m in fn for i in range(1,m+1): if (m%i ==0): fm.append(i) print("fm is",fm) for j in range(1,n+1): if (n%j ==0): fn.append(j) print("fn is",fn) cf=[] # for returning largest value for k in fm: if k in fm: cf.append(k) print("The largest GCD is: %d "%cf[-1]) gcd(10,8) above programs give correct output but i would like to understand why below program is not giving same output: def gcd(m,n): i=min(m,n) while i>=0: if m%i==0 and n%i==0: return i else: i=i-1 v=gcd(10,8) print(v) Sorry if i am missing anything and would be great if someone explain last optimize example in details
@coldcoke9254
@coldcoke9254 2 жыл бұрын
the code works just fine tho, just chane
@venkatashasidharreddychali7485
@venkatashasidharreddychali7485 Жыл бұрын
give the brackets correctly, it worked for me, I alos got the wrong output when i used this (m%i) ==0 & (n%i) ==0 after tweaking it to this ((m%i) ==0) & ((n%i) ==0), i got the correct output
@prashnatdivase8523
@prashnatdivase8523 Жыл бұрын
@@venkatashasidharreddychali7485 thank you
@exploringlife2904
@exploringlife2904 4 жыл бұрын
not running in python mrcf
@izharkhankhattak
@izharkhankhattak 3 жыл бұрын
nice
@gauravjoshi7589
@gauravjoshi7589 3 жыл бұрын
i am not getting any error and also not getting any output
@pratapkhandekar8322
@pratapkhandekar8322 5 жыл бұрын
You are explaining code directly It is hard to understand
@sagarsagar-xr7bo
@sagarsagar-xr7bo 4 жыл бұрын
Low sound boring ,speak loudly sir
@sumitbhattacharyya2058
@sumitbhattacharyya2058 6 жыл бұрын
sound quality is not satisfactory
@pk15692
@pk15692 5 жыл бұрын
You can use a volume booster for chrome to enhance the sound volume
@sagarsagar-xr7bo
@sagarsagar-xr7bo 4 жыл бұрын
@@pk15692 try chesaa ,no use
@LAVETI-28
@LAVETI-28 10 ай бұрын
Use ear phones
euclid's algorithm for gcd
23:55
NOC16 CS11
Рет қаралды 290 М.
assignment statement, basic types - int, float, bool
21:58
NOC16 CS11
Рет қаралды 261 М.
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 53 МЛН
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 33 МЛН
Подсадим людей на ставки | ЖБ | 3 серия | Сериал 2024
20:00
ПАЦАНСКИЕ ИСТОРИИ
Рет қаралды 572 М.
8 Data Structures Every Programmer Should Know
17:09
ForrestKnight
Рет қаралды 205 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 721 М.
Fastest way to learn Data Structures and Algorithms
8:42
Sahil & Sarra
Рет қаралды 277 М.
Coding Was HARD Until I Learned These 5 Things...
8:34
Elsa Scola
Рет қаралды 779 М.
functions
18:28
NOC16 CS11
Рет қаралды 160 М.
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 208 М.
10 Math Concepts for Programmers
9:32
Fireship
Рет қаралды 1,9 МЛН
Python Tutorials - Program To Find out the GCD of Two Positive Numbers
13:11
“Don’t stop the chances.”
00:44
ISSEI / いっせい
Рет қаралды 53 МЛН