algorithms and programming: simple gcd

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ธ.ค. 2024

ความคิดเห็น • 125

  • @sachinsan7503
    @sachinsan7503 6 ปีที่แล้ว +74

    The way you approach the problem shows your intelligent and maturity in this field.This is how one should teach concepts to the students.

  • @kamrulislam9767
    @kamrulislam9767 4 ปีที่แล้ว +51

    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.

    • @HariKrishnan-qp1tm
      @HariKrishnan-qp1tm ปีที่แล้ว

      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?

    • @DashingData66666
      @DashingData66666 8 หลายเดือนก่อน

      come on r u serious

  • @engineerspodcast1986
    @engineerspodcast1986 2 ปีที่แล้ว +7

    Sir just superb way of explaining... Enjoyed listening and understand your lectures... Just fantastic 🔥

  • @GoogleMathtube
    @GoogleMathtube 5 ปีที่แล้ว +4

    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)

  • @dhanunjaydola
    @dhanunjaydola 4 ปีที่แล้ว +10

    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)))

  • @primedecay13
    @primedecay13 4 ปีที่แล้ว +4

    #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

  • @ShashwatPandeyindia
    @ShashwatPandeyindia 6 ปีที่แล้ว +10

    # 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

    • @kunaldineshpatil
      @kunaldineshpatil 4 ปีที่แล้ว +2

      Spoiler Alert:
      Same code has been used at the end of second lecture of Week-1
      Just watch the next video

  • @ravisiswaliya7422
    @ravisiswaliya7422 6 ปีที่แล้ว +3

    #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

    • @ruturajjadhav8905
      @ruturajjadhav8905 4 ปีที่แล้ว

      Thank you

    • @primedecay13
      @primedecay13 4 ปีที่แล้ว

      definitely not the shortest, it has 2 list comprehension, while you could just use a single loop...

  • @sachinrajbhardseudwarka8246
    @sachinrajbhardseudwarka8246 ปีที่แล้ว +2

    Great!!

  • @nvcse136
    @nvcse136 ปีที่แล้ว

    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

  • @BilalAhmed-ib3yw
    @BilalAhmed-ib3yw 4 ปีที่แล้ว

    @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.

    • @kunaldineshpatil
      @kunaldineshpatil 4 ปีที่แล้ว

      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))

  • @shahidzain9714
    @shahidzain9714 5 ปีที่แล้ว

    #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

    • @kunaldineshpatil
      @kunaldineshpatil 4 ปีที่แล้ว

      In the next video the second programme discussed uses the same Algorithm with less lines of code

  • @ramachandrudu198
    @ramachandrudu198 2 ปีที่แล้ว +2

    Thank you very much for the way you explain sir😍

    • @alkapandey3038
      @alkapandey3038 2 ปีที่แล้ว

      This is complete series yea uncompleted pls tell me

    • @sandhiyap3614
      @sandhiyap3614 2 หลายเดือนก่อน

      Hii...tell me how to read for this course
      To pass in the exam?!!

  • @yuvrajsinghchauhan4442
    @yuvrajsinghchauhan4442 6 ปีที่แล้ว +17

    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?

    • @pswalia2u
      @pswalia2u 5 ปีที่แล้ว

      yeah it is much more optimised.

    • @wemake4u444
      @wemake4u444 4 ปีที่แล้ว

      we got the same thought

    • @seemaverma279
      @seemaverma279 4 ปีที่แล้ว

      yeah...........good job.

  • @abhijeet56
    @abhijeet56 6 ปีที่แล้ว +32

    Excellent explanation sir.. The only problem was low sound

  • @prabakart3531
    @prabakart3531 2 ปีที่แล้ว +2

    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

  • @akashgahlot6796
    @akashgahlot6796 4 ปีที่แล้ว +8

    Sir i just want to add one thing ,we can also use *return (max(cf))* instead of using indexing .

  • @vidit9024
    @vidit9024 5 ปีที่แล้ว +2

    Great video

  • @wemake4u444
    @wemake4u444 4 ปีที่แล้ว +7

    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")

  • @debaleenaghosh851
    @debaleenaghosh851 4 ปีที่แล้ว +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.

    • @soumojitbasu9244
      @soumojitbasu9244 3 ปีที่แล้ว +3

      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.

  • @muskaankushwaha6
    @muskaankushwaha6 2 ปีที่แล้ว +1

    😍😍love this lecture

  • @gitsof3727
    @gitsof3727 6 ปีที่แล้ว +1

    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

  • @amandebnath2593
    @amandebnath2593 3 ปีที่แล้ว

    God bless you @Prithwijit Das

  • @SHRESHTHAGUPTAnullRA
    @SHRESHTHAGUPTAnullRA 4 ปีที่แล้ว +2

    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

  • @subramaniank8086
    @subramaniank8086 3 ปีที่แล้ว

    sir you are amazing

  • @DebmallarDasgupta
    @DebmallarDasgupta 4 หลายเดือนก่อน

    Sir you are just amazing.

  • @ritiksaxenaofficial
    @ritiksaxenaofficial 4 ปีที่แล้ว +2

    Well explained.

  • @anandikts3432
    @anandikts3432 5 ปีที่แล้ว +4

    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?

    • @shubh13272anand
      @shubh13272anand 5 ปีที่แล้ว

      Exactly. I was also thinking same

    • @usharanidash2831
      @usharanidash2831 4 ปีที่แล้ว +2

      No, because here 14 is also a factor

    • @mamathamaddur4593
      @mamathamaddur4593 4 ปีที่แล้ว

      Yes...

    • @hallo-xp2wh
      @hallo-xp2wh 2 ปีที่แล้ว +1

      @@usharanidash2831
      1 and n are, trivially, factors or divisors of n !
      you can append 1 in advance and later append n to the list.

  • @SA-qi7sg
    @SA-qi7sg 3 ปีที่แล้ว

    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

  • @souravkumarshaw7090
    @souravkumarshaw7090 5 ปีที่แล้ว +1

    Sir which book is best to study data structure and algorithm in Python ?

    • @pavankumar1004
      @pavankumar1004 5 ปีที่แล้ว +1

      core python by r.nageshwar rao

    • @seemaverma279
      @seemaverma279 4 ปีที่แล้ว +1

      @@pavankumar1004 thanks

  • @anandikts3432
    @anandikts3432 5 ปีที่แล้ว

    provided 1 and that particular number will be always added as factors every time

  • @anandikts3432
    @anandikts3432 5 ปีที่แล้ว

    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.

  • @SA-qi7sg
    @SA-qi7sg 3 ปีที่แล้ว

    I have one doubt is algorithm means we can write code with minimum number of code or minimum computation time ?

  • @jindagi_ka_safar
    @jindagi_ka_safar 5 ปีที่แล้ว +4

    Did this best course in Python........scored 66% in 2017

    • @uzeirselot
      @uzeirselot 3 หลายเดือนก่อน

      I'm finding it difficult.

  • @You-t1g
    @You-t1g ปีที่แล้ว +12

    Voice is too bad, I can't hear.

  • @chakradharreddy6381
    @chakradharreddy6381 5 ปีที่แล้ว +1

    How can we justify that... f in the program is referred to as one of the factors in the list fm.?

    • @SlickShitt
      @SlickShitt 3 ปีที่แล้ว

      it's just like assigning a variable to every item in the list.

  • @SANTOSHSHARMA-ni1hi
    @SANTOSHSHARMA-ni1hi 2 ปีที่แล้ว +1

    This course for exllent best books

  • @debjyotisaha4129
    @debjyotisaha4129 4 ปีที่แล้ว

    Can I get the pdf document of all the lectures here?

  • @siddheshdhanawade3709
    @siddheshdhanawade3709 2 ปีที่แล้ว

    how can i get these slides ?

  • @anithaselvam1823
    @anithaselvam1823 6 ปีที่แล้ว +3

    low sound sir

  • @pareshkumarsahoo3421
    @pareshkumarsahoo3421 4 ปีที่แล้ว

    Crystal clear

  • @LocalMarket-book-delivery-app
    @LocalMarket-book-delivery-app 7 ปีที่แล้ว +5

    low sound

  • @gitsof3727
    @gitsof3727 6 ปีที่แล้ว

    please sure in indentation otherwise get an error

  • @AgamdeepSingh1603
    @AgamdeepSingh1603 4 ปีที่แล้ว

    Are these all the lectures which r included in nptel course??

  • @varuncomesback
    @varuncomesback 7 ปีที่แล้ว

    Thanks for the lecture

  • @akshay321jain
    @akshay321jain 4 ปีที่แล้ว

    where can we access assignments and quizes

    • @prateekgupta8875
      @prateekgupta8875 4 ปีที่แล้ว

      you have to enroll on the official website i.e. NPTEL for this course

  • @hemanthsamudrala1748
    @hemanthsamudrala1748 4 ปีที่แล้ว

    Is this class is from bascis about python

  • @Jaimin_Bariya
    @Jaimin_Bariya 2 หลายเดือนก่อน

    Jp here [comment number 125]
    Thank you sir :)

  • @synchrobeast343
    @synchrobeast343 4 ปีที่แล้ว +1

    Is this course good to understand and implement Linked Lists, Trees and OOPS?

  • @nirbhay_raghav
    @nirbhay_raghav 4 ปีที่แล้ว +1

    Bullet points look like novel corona virus

  • @GSaiRajesh
    @GSaiRajesh 6 ปีที่แล้ว

    The code is not working in Python, please help.

    • @kasmitharam982
      @kasmitharam982 6 ปีที่แล้ว

      can you post the error which is shown ,so that it will be easy to help you sort the problem.

    • @gitsof3727
      @gitsof3727 6 ปีที่แล้ว

      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

  • @nikhilsrivastava2309
    @nikhilsrivastava2309 6 ปีที่แล้ว +1

    please if someone can provide pdf associated with the above nptel course

  • @r.k.navinganeshapaandiyan3702
    @r.k.navinganeshapaandiyan3702 6 ปีที่แล้ว +2

    Increase your video's sound clarity

  • @chaitanyakumar8431
    @chaitanyakumar8431 4 ปีที่แล้ว +1

    Could you please share me the reference book or any materials

  • @flyingangel8761
    @flyingangel8761 6 ปีที่แล้ว +3

    Sir. Plz use some higher sound levels..Facing Problems with the low voice

  • @firefly6630
    @firefly6630 4 ปีที่แล้ว

    Ye kaun sa vergion hai python ka

  • @VikasKM
    @VikasKM 5 ปีที่แล้ว +5

    Even with full volume I can hardly hear the lecture..

    • @Shivani-ex1iv
      @Shivani-ex1iv 4 ปีที่แล้ว

      You should try using earphones

    • @anirbandey5608
      @anirbandey5608 4 ปีที่แล้ว

      Change ur earphone and stop complaining

    • @VikasKM
      @VikasKM 4 ปีที่แล้ว

      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.

  • @sanjayguptacg486
    @sanjayguptacg486 5 ปีที่แล้ว +7

    low sound. very difficult to listen.

  • @rockets1582
    @rockets1582 6 ปีที่แล้ว

    IndexError: list index out of range (what does it mean )

    • @maker72460
      @maker72460 6 ปีที่แล้ว

      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.

    • @adityatripathy2107
      @adityatripathy2107 6 ปีที่แล้ว

      you are trying to visit an index(position) in list which has nothing stored in it and isn't defined

  • @saikumarnaik1298
    @saikumarnaik1298 7 ปีที่แล้ว

    please send the link of next lecture

  • @shri0809
    @shri0809 ปีที่แล้ว +1

    What is 'f'?

    • @LAVETI-28
      @LAVETI-28 10 หลายเดือนก่อน

      F for function

  • @lakshaypiplani3522
    @lakshaypiplani3522 6 ปีที่แล้ว

    IndexError: list index out of range

    • @himanshu2471
      @himanshu2471 5 ปีที่แล้ว

      in the last piece of code for cf, use (fm) and (fn) instead of [fm] and [fn]

  • @diazsoul38
    @diazsoul38 5 ปีที่แล้ว +1

    TH-cam algorithm brought me here. Is that a signal?

  • @dolcyrao5763
    @dolcyrao5763 4 ปีที่แล้ว +1

    can you please tell the pre-requisite for this course??

  • @Hackersgroundhck
    @Hackersgroundhck 5 ปีที่แล้ว

    Audio is bull shit don't u people check video after uploading

  • @ravimeena5866
    @ravimeena5866 6 ปีที่แล้ว +1

    low sound not listin

  • @ramsubhash5465
    @ramsubhash5465 ปีที่แล้ว +1

    Evadiki vinapadatundi ra

  • @sarveshwaranjayaraman1175
    @sarveshwaranjayaraman1175 3 ปีที่แล้ว +1

    slides link: www.cmi.ac.in/~madhavan/nptel-python-2016/

  • @PayelDasDewan
    @PayelDasDewan 5 ปีที่แล้ว

    Sound is so low that also with headphone it makes problem 🙄🙄🙄

    • @girijadevi3010
      @girijadevi3010 5 ปีที่แล้ว

      No

    • @avinashdwivedi2015
      @avinashdwivedi2015 5 ปีที่แล้ว

      then buy a better earphones/headphones

    • @PayelDasDewan
      @PayelDasDewan 5 ปีที่แล้ว

      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!

    • @avinashdwivedi2015
      @avinashdwivedi2015 5 ปีที่แล้ว +1

      @@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

    • @PayelDasDewan
      @PayelDasDewan 5 ปีที่แล้ว +1

      @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 😂😂😂😂

  • @dharshinidharshu3079
    @dharshinidharshu3079 10 หลายเดือนก่อน

    Sounds is not audible

  • @soumyadeeptaghosh7469
    @soumyadeeptaghosh7469 3 ปีที่แล้ว

    this is NOT NPTEL Lecture. please name it different

  • @uchihaitachi5404
    @uchihaitachi5404 4 หลายเดือนก่อน +1

    muj vale bkl abh yeh bakchodi ka bhi certificate dilare

  • @asmitsaraf9002
    @asmitsaraf9002 5 ปีที่แล้ว +3

    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
      @shaunsven3174 5 ปีที่แล้ว +1

      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.

    • @asmitsaraf9002
      @asmitsaraf9002 5 ปีที่แล้ว

      @G Sai Sundar Talking about the platform

    • @asmitsaraf9002
      @asmitsaraf9002 5 ปีที่แล้ว

      @@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.

  • @harshgarg7025
    @harshgarg7025 5 ปีที่แล้ว

    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

    • @kunaldineshpatil
      @kunaldineshpatil 4 ปีที่แล้ว

      The product of all Common "PRIME" Factors of any two numbers gives us the greatest common Factor aka HCF/GCD

  • @ashlysimon5861
    @ashlysimon5861 6 ปีที่แล้ว +4

    Low sound