algorithms and programming: simple gcd

Поділитися
Вставка
  • Опубліковано 12 жов 2024

КОМЕНТАРІ • 125

  • @sachinsan7503
    @sachinsan7503 6 років тому +73

    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 роки тому +50

    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 6 місяців тому

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

  • @abhijeet56
    @abhijeet56 6 років тому +32

    Excellent explanation sir.. The only problem was low sound

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

  • @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 3 роки тому

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

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

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

  • @sachinrajbhardseudwarka8246
    @sachinrajbhardseudwarka8246 Рік тому +2

    Great!!

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

  • @akashgahlot6796
    @akashgahlot6796 4 роки тому +8

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

  • @ramachandrudu198
    @ramachandrudu198 2 роки тому +2

    Thank you very much for the way you explain sir😍

    • @alkapandey3038
      @alkapandey3038 Рік тому

      This is complete series yea uncompleted pls tell me

    • @sandhiyap3614
      @sandhiyap3614 26 днів тому

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

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

  • @nvcse136
    @nvcse136 10 місяців тому

    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

  • @vidit9024
    @vidit9024 4 роки тому +2

    Great video

  • @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 2 роки тому +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.

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

  • @You-t1g
    @You-t1g Рік тому +12

    Voice is too bad, I can't hear.

  • @jindagi_ka_safar
    @jindagi_ka_safar 5 років тому +4

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

    • @uzeirselot
      @uzeirselot Місяць тому

      I'm finding it difficult.

  • @muskaankushwaha6
    @muskaankushwaha6 2 роки тому +1

    😍😍love this lecture

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

  • @amandebnath2593
    @amandebnath2593 3 роки тому

    God bless you @Prithwijit Das

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

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

  • @subramaniank8086
    @subramaniank8086 3 роки тому

    sir you are amazing

  • @DebmallarDasgupta
    @DebmallarDasgupta 2 місяці тому

    Sir you are just amazing.

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

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

  • @ritiksaxenaofficial
    @ritiksaxenaofficial 4 роки тому +2

    Well explained.

  • @flyingangel8761
    @flyingangel8761 6 років тому +3

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

  • @Jaimin_Bariya
    @Jaimin_Bariya 22 дні тому

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

  • @chakradharreddy6381
    @chakradharreddy6381 4 роки тому +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.

  • @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 4 роки тому

      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.

  • @anandikts3432
    @anandikts3432 5 років тому

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

  • @synchrobeast343
    @synchrobeast343 4 роки тому +1

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

  • @pareshkumarsahoo3421
    @pareshkumarsahoo3421 4 роки тому

    Crystal clear

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

  • @sanjayguptacg486
    @sanjayguptacg486 5 років тому +7

    low sound. very difficult to listen.

  • @nirbhay_raghav
    @nirbhay_raghav 4 роки тому +1

    Bullet points look like novel corona virus

  • @VikasKM
    @VikasKM 4 роки тому +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.

  • @anithaselvam1823
    @anithaselvam1823 6 років тому +3

    low sound sir

  • @SANTOSHSHARMA-ni1hi
    @SANTOSHSHARMA-ni1hi 2 роки тому +1

    This course for exllent best books

  • @hemanthsamudrala1748
    @hemanthsamudrala1748 4 роки тому

    Is this class is from bascis about python

  • @LocalMarket-book-delivery-app
    @LocalMarket-book-delivery-app 7 років тому +5

    low sound

  • @debjyotisaha4129
    @debjyotisaha4129 4 роки тому

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

  • @varuncomesback
    @varuncomesback 7 років тому

    Thanks for the lecture

  • @r.k.navinganeshapaandiyan3702
    @r.k.navinganeshapaandiyan3702 6 років тому +2

    Increase your video's sound clarity

  • @nikhilsrivastava2309
    @nikhilsrivastava2309 5 років тому +1

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

  • @gitsof3727
    @gitsof3727 6 років тому

    please sure in indentation otherwise get an error

  • @sarveshwaranjayaraman1175
    @sarveshwaranjayaraman1175 3 роки тому +1

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

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

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

  • @chaitanyakumar8431
    @chaitanyakumar8431 4 роки тому +1

    Could you please share me the reference book or any materials

  • @AgamdeepSingh1603
    @AgamdeepSingh1603 4 роки тому

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

  • @diazsoul38
    @diazsoul38 5 років тому +1

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

  • @shri0809
    @shri0809 Рік тому +1

    What is 'f'?

  • @siddheshdhanawade3709
    @siddheshdhanawade3709 2 роки тому

    how can i get these slides ?

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

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

  • @firefly6630
    @firefly6630 3 роки тому

    Ye kaun sa vergion hai python ka

  • @saikumarnaik1298
    @saikumarnaik1298 7 років тому

    please send the link of next lecture

  • @dolcyrao5763
    @dolcyrao5763 4 роки тому +1

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

  • @dharshinidharshu3079
    @dharshinidharshu3079 8 місяців тому

    Sounds is not audible

  • @soumyadeeptaghosh7469
    @soumyadeeptaghosh7469 3 роки тому

    this is NOT NPTEL Lecture. please name it different

  • @Hackersgroundhck
    @Hackersgroundhck 4 роки тому

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

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

  • @ramsubhash5465
    @ramsubhash5465 Рік тому +1

    Evadiki vinapadatundi ra

  • @ravimeena5866
    @ravimeena5866 6 років тому +1

    low sound not listin

  • @uchihaitachi5404
    @uchihaitachi5404 2 місяці тому +1

    muj vale bkl abh yeh bakchodi ka bhi certificate dilare

  • @harshgarg7025
    @harshgarg7025 4 роки тому

    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

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

  • @ashlysimon5861
    @ashlysimon5861 6 років тому +4

    Low sound