I will say it is the best data structure and algorithm course in python. Explanation, lecture speed, and demonstration are the best. Thank you very much.
Hi , I have a doubt in selecting course for nptel.. to learn python should I start with this course ( Programming, Data structure and Algorithms using Python) or should I enroll Programming in Python?
from array import* def gcd(x,y): vals = array('i',[]) for i in range(1,x+1): if(x%i==0): print(i) vals.append(i) print(vals) p = array('i',[]) for j in range(1,y+1): if(y%j==0): print(j) p.append(j) print(p) val = array('i',[]) for i in range(len(vals)): if(y % vals[i] ==0): print(vals[i]) val.append(vals[i]) print(val) t = max(val) return t m= int(input('enter the first number')) n= int(input('enter the second number')) gcd1 = gcd(m,n) print(gcd1)
#time complexity is important, this code is way more optimized than what's shown. def gcd(num1, num2): for i in range (min(num1, num2) - 1, 1, -1): if (num1 % i == 0) and (num2 % i == 0): return i return 1
# Another way of doing it: a = int(input('Enter the first number:')) b = int(input('Enter the second number:')) if a >= b : x = b else: x = a while(x >= 1): if(a%x==0 and b%x ==0): print('HCF is', x) break else: x = x-1
#sortest method to solve this problem def gcd(a,b): s1 = [i for i in range(1,a+1) if a%i==0] #finding numbers that divide by a s2 = [i for i in range(1,b+1) if b%i==0] #finding numbers that divide by b print(max(list(set(s1).intersection(s2)))) #finding largest number that divide by both a & b gcd(28,70) #calling function
If one the numbers is a large number when we find factors for that number it takes O(n) time complexity which is a worst case . So it is better for small numbers . we can also approach through Euclid division algorithm
@12:08 Or we could use the factors of the smaller digit, 14 in this case and check its factor to divide the larger digit 63, and compare if it has multiple common factors and reports the highest be them.
Another Way (optimized code): m=int(input("enter m")) n=int(input("enter n")) k=m while m>=2: if n%m==0 and k%m==0: print('gcd is',m) break else: m-=1 else: print("gcd is 1")
Thank you for the explanation. But then again wouldn't it be much easier if we just find out which number is smaller, find the factors for the smaller number, Then check if the factors also divide the larger one. The largest factor would give us the GCD.
As we now the purpose of computing is to find systematic solution and it may or may not be clever/intelligent (Here intelligent or clever is tied to efficiency)so what he is trying is to find a solution (brute force method)and what you're saying is an efficient solution.
print ("Enter the first no to find gcd of that no") a= input() print("enter the second number") b = input() print("the enter no is", a, b) a = int(a) b = int(b) if(a>b): for index in range(b,0,-1): if(a%index == 0 and b%index==0 ): print("the index is ", index) break else: for index in range(a, 0 , -1): if(a%index == 0 and b%index ==0): print ("the index is ", index) break
Thanks for the Lecture Sir. Sir, one small doubt ,for getting the factors of a number, isn't it fair enough to stop after it crosses half of the value of that number, like can't we stop getting factors for 14 after it crosses 14/2 i.e., 7 sir?
print ("Enter the first no to find gcd of that no") a= input() print("enter the second number") b = input() print("the enter no is", a, b) a = int(a) b = int(b) if(a>b): for index in range(b,0,-1): if(a%index == 0 and b%index==0 ): print("the index is ", index) break else: for index in range(a, 0 , -1): if(a%index == 0 and b%index ==0): print ("the index is ", index) break
you must be doing something wrong. The code in the lecture is all correct. Index Error suggests that you are trying to access an address(or index) in the list which has no element in it.
@G Sai Sundar Thousands of people are studying here! When a professional is acting like a amature what will i do being a grown up come on man!! Cangrats yourself for being a grown up 😂😂😂😂
This course is not at all helpful and the content is also out dated. Also, there are hidden criteria which can cause non-eligibility for the E-certificate. So, even if you get the passing marks you won't get your certificate. (Don't take this course if you are trying to get credits for MOOCs as an elective for college degree)
@@shaunsven3174 Hidden criteria was to pass in a programming assignment that was conducted at the very last of your Assignment and it consists of 25%, for which only selective questions were evaluated (specific questions) like A1, A3...etc and if you don't complete all of them you won't even pass.
I guess you are doing wrong not programming part but the gcd part because gcd defination is product of all the common factors not greatest common factor
The way you approach the problem shows your intelligent and maturity in this field.This is how one should teach concepts to the students.
I will say it is the best data structure and algorithm course in python. Explanation, lecture speed, and demonstration are the best. Thank you very much.
Hi , I have a doubt in selecting course for nptel.. to learn python should I start with this course ( Programming, Data structure and Algorithms using Python) or should I enroll Programming in Python?
come on r u serious
Sir just superb way of explaining... Enjoyed listening and understand your lectures... Just fantastic 🔥
from array import*
def gcd(x,y):
vals = array('i',[])
for i in range(1,x+1):
if(x%i==0):
print(i)
vals.append(i)
print(vals)
p = array('i',[])
for j in range(1,y+1):
if(y%j==0):
print(j)
p.append(j)
print(p)
val = array('i',[])
for i in range(len(vals)):
if(y % vals[i] ==0):
print(vals[i])
val.append(vals[i])
print(val)
t = max(val)
return t
m= int(input('enter the first number'))
n= int(input('enter the second number'))
gcd1 = gcd(m,n)
print(gcd1)
def GCD_1(m,n):
def factor(x):
return [i for i in range(1,x+1) if x%i==0]
x=factor(m)
y=factor(n)
return max(set(x).intersection(set(y)))
#time complexity is important, this code is way more optimized than what's shown.
def gcd(num1, num2):
for i in range (min(num1, num2) - 1, 1, -1):
if (num1 % i == 0) and (num2 % i == 0): return i
return 1
# Another way of doing it:
a = int(input('Enter the first number:'))
b = int(input('Enter the second number:'))
if a >= b :
x = b
else:
x = a
while(x >= 1):
if(a%x==0 and b%x ==0):
print('HCF is', x)
break
else:
x = x-1
Spoiler Alert:
Same code has been used at the end of second lecture of Week-1
Just watch the next video
#sortest method to solve this problem
def gcd(a,b):
s1 = [i for i in range(1,a+1) if a%i==0] #finding numbers that divide by a
s2 = [i for i in range(1,b+1) if b%i==0] #finding numbers that divide by b
print(max(list(set(s1).intersection(s2)))) #finding largest number that divide by both a & b
gcd(28,70) #calling function
Thank you
definitely not the shortest, it has 2 list comprehension, while you could just use a single loop...
Great!!
If one the numbers is a large number when we find factors for that number it takes O(n) time complexity which is a worst case . So it is better for small numbers . we can also approach through Euclid division algorithm
@12:08 Or we could use the factors of the smaller digit, 14 in this case and check its factor to divide the larger digit 63, and compare if it has multiple common factors and reports the highest be them.
def gcd(m,n):
x=min(m,n)
fx=[]
for i in range(1,x+1):
if (x%i)==0:
fx.append(i)
cf=[]
for f in fx:
if(n%f)==0:
cf.append(f)
return (max(cf))
#simple way is
m=int(input("enter the number m : "))
n=int(input("enter the number n : "))
def gcd(m,n):
count=0
if m
In the next video the second programme discussed uses the same Algorithm with less lines of code
Thank you very much for the way you explain sir😍
This is complete series yea uncompleted pls tell me
Hii...tell me how to read for this course
To pass in the exam?!!
1- Find the smaller no. and its factors first
2- Find the factors of the larger no. only through the factors of smaller no.
will it work?
yeah it is much more optimised.
we got the same thought
yeah...........good job.
Excellent explanation sir.. The only problem was low sound
use a volume booster for chrome
x=14
y=63
z=min(x,y)
print(z)
for i in range(1,z+1):
if x%i ==0 and y%i ==0:
gcd=i
print("GCD is : ",gcd);
Output:
14
GCD is : 7
Sir i just want to add one thing ,we can also use *return (max(cf))* instead of using indexing .
Great video
Another Way (optimized code):
m=int(input("enter m"))
n=int(input("enter n"))
k=m
while m>=2:
if n%m==0 and k%m==0:
print('gcd is',m)
break
else:
m-=1
else:
print("gcd is 1")
Thank you for the explanation.
But then again wouldn't it be much easier if we just find out which number is smaller,
find the factors for the smaller number,
Then check if the factors also divide the larger one.
The largest factor would give us the GCD.
As we now the purpose of computing is to find systematic solution and it may or may not be clever/intelligent (Here intelligent or clever is tied to efficiency)so what he is trying is to find a solution (brute force method)and what you're saying is an efficient solution.
😍😍love this lecture
print ("Enter the first no to find gcd of that no")
a= input()
print("enter the second number")
b = input()
print("the enter no is", a, b)
a = int(a)
b = int(b)
if(a>b):
for index in range(b,0,-1):
if(a%index == 0 and b%index==0 ):
print("the index is ", index)
break
else:
for index in range(a, 0 , -1):
if(a%index == 0 and b%index ==0):
print ("the index is ", index)
break
God bless you @Prithwijit Das
def gcd(a,b):
x=min(a,b)
for y in range(1,x+1):
if (a%y==0) and (b%y)==0:
hcf=y
return hcf
sir you are amazing
Sir you are just amazing.
Well explained.
Thanks for the Lecture Sir. Sir, one small doubt ,for getting the factors of a number, isn't it fair enough to stop after it crosses half of the value of that number, like can't we stop getting factors for 14 after it crosses 14/2 i.e., 7 sir?
Exactly. I was also thinking same
No, because here 14 is also a factor
Yes...
@@usharanidash2831
1 and n are, trivially, factors or divisors of n !
you can append 1 in advance and later append n to the list.
def gcd(a, b):
final_number = [i for in range(1, min(a, b)+1) if a % i == 0 and b % i == 0][-1]
return final_numbrer
Sir which book is best to study data structure and algorithm in Python ?
core python by r.nageshwar rao
@@pavankumar1004 thanks
provided 1 and that particular number will be always added as factors every time
one more doubt sir, why should not we stop getting factors for 63, the bigger among the two numbers, when it crosses 14., the smaller among them.
I have one doubt is algorithm means we can write code with minimum number of code or minimum computation time ?
Did this best course in Python........scored 66% in 2017
I'm finding it difficult.
Voice is too bad, I can't hear.
How can we justify that... f in the program is referred to as one of the factors in the list fm.?
it's just like assigning a variable to every item in the list.
This course for exllent best books
Can I get the pdf document of all the lectures here?
how can i get these slides ?
low sound sir
Crystal clear
low sound
please sure in indentation otherwise get an error
Are these all the lectures which r included in nptel course??
yes
Thanks for the lecture
where can we access assignments and quizes
you have to enroll on the official website i.e. NPTEL for this course
Is this class is from bascis about python
Jp here [comment number 125]
Thank you sir :)
Is this course good to understand and implement Linked Lists, Trees and OOPS?
Bullet points look like novel corona virus
The code is not working in Python, please help.
can you post the error which is shown ,so that it will be easy to help you sort the problem.
print ("Enter the first no to find gcd of that no")
a= input()
print("enter the second number")
b = input()
print("the enter no is", a, b)
a = int(a)
b = int(b)
if(a>b):
for index in range(b,0,-1):
if(a%index == 0 and b%index==0 ):
print("the index is ", index)
break
else:
for index in range(a, 0 , -1):
if(a%index == 0 and b%index ==0):
print ("the index is ", index)
break
please if someone can provide pdf associated with the above nptel course
Increase your video's sound clarity
Could you please share me the reference book or any materials
Sir. Plz use some higher sound levels..Facing Problems with the low voice
Ye kaun sa vergion hai python ka
Even with full volume I can hardly hear the lecture..
You should try using earphones
Change ur earphone and stop complaining
Anirban De how about u take ur suggestion n shove it up.
Read other comments to know about the volume problem with this video. Before ranting here.
low sound. very difficult to listen.
IndexError: list index out of range (what does it mean )
you must be doing something wrong. The code in the lecture is all correct.
Index Error suggests that you are trying to access an address(or index) in the list which has no element in it.
you are trying to visit an index(position) in list which has nothing stored in it and isn't defined
please send the link of next lecture
What is 'f'?
F for function
IndexError: list index out of range
in the last piece of code for cf, use (fm) and (fn) instead of [fm] and [fn]
TH-cam algorithm brought me here. Is that a signal?
Hahaha
can you please tell the pre-requisite for this course??
You should know python programming language
You should know maths till class 12th only
Audio is bull shit don't u people check video after uploading
low sound not listin
Evadiki vinapadatundi ra
slides link: www.cmi.ac.in/~madhavan/nptel-python-2016/
Sound is so low that also with headphone it makes problem 🙄🙄🙄
No
then buy a better earphones/headphones
Using Sony's headphone... this total faculty of nptel is taking 1k per exam and are fail to do a good Audio that's a real bogus!
@@PayelDasDewani dont know about that.. i can hear good from my earphones..so i got no complaints.. and also 1k is too cheap to get a certification
@G Sai Sundar Thousands of people are studying here! When a professional is acting like a amature what will i do being a grown up come on man!! Cangrats yourself for being a grown up 😂😂😂😂
Sounds is not audible
this is NOT NPTEL Lecture. please name it different
muj vale bkl abh yeh bakchodi ka bhi certificate dilare
This course is not at all helpful and the content is also out dated. Also, there are hidden criteria which can cause non-eligibility for the E-certificate. So, even if you get the passing marks you won't get your certificate.
(Don't take this course if you are trying to get credits for MOOCs as an elective for college degree)
Can you explain why it’s not helpful and what’s the hidden criteria. I am thinking of taking this course and your reply would be helpful.
@G Sai Sundar Talking about the platform
@@shaunsven3174 Hidden criteria was to pass in a programming assignment that was conducted at the very last of your Assignment and it consists of 25%, for which only selective questions were evaluated (specific questions) like A1, A3...etc and if you don't complete all of them you won't even pass.
I guess you are doing wrong not programming part but the gcd part because gcd defination is product of all the common factors not greatest common factor
The product of all Common "PRIME" Factors of any two numbers gives us the greatest common Factor aka HCF/GCD
Low sound