Graph Colouring Problem - Backtracking

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

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

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

    Very clear. Would be great if also made topic on tsp, vehicle routing, LP dual to make them clear as well ..

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

    Great video man! the clarity! the explanation! :D

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

    Can't see how the code will backtrack as there is no resetting of color. It seems more of a greedy approach that we always try to color the graph with minimum color possible.

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

    minor mistakes but you are a life savior man

  • @pdzbw
    @pdzbw 9 ปีที่แล้ว +9

    such detail, much appreciation~

  • @saifulislamsalim9241
    @saifulislamsalim9241 8 ปีที่แล้ว +9

    I think it would be m^n possible ways to color n nodes with m colors.
    (From the video it is in 2:10 to 2:25 )

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

    Thanks Sir! Understood the solution in one go.💯

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

    But the algorithm will check all the colors for each vertex even if all nodes are colored. because on returning from last node, the for loop of calling function is still running.

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

    Why is this a backtracking problem? We are not making any changes in the previous node's color

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

    A really good explanation as well as clean code

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

    how can the diagnals be set as 1 of an adjacency matrix ..it is always 0..

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

    loved the explanation , thnkuuu so much for the video, it was really helpful

  • @truongvanloc8275
    @truongvanloc8275 8 ปีที่แล้ว +13

    In the code, you set x[k] = c;
    But I don't see the step of backtracking, I don't see where you reset the color if you want to go back ?

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

      when u backtrack at k'th node, k-1'th level will have x[k] = c but at k-1 we are limiting ourselves to only k-1 nodes so it doesnt matter what x[k] is coz we will replace it with another color later

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

      yup. The magic happens at graphColor(k+1). if it returns to parent function, the parent function will try another color.

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

      @@prateekkej2506 i think that return statement at last wont allow backtracking/looping for another color. If the return statement is written outside of the safecheck, then only it will backtrack and try for another color

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

      @@jinxblaze but in isSafe they check all the nodes from 0 to n.

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

    awesome dude, really cool explanation and the graphics were also pretty helpful. Thanks !!!

  • @21stcenturydigitalje
    @21stcenturydigitalje 8 ปีที่แล้ว +1

    In the future you could use 'a', 'b', 'c', 'd' for node names and 'red', 'green', 'blue' for color names so you don't have to use 0, 1, 2, 3 for everything - it would make this video even easier to understand

  • @AABB-fb4zy
    @AABB-fb4zy 8 ปีที่แล้ว

    very clear. organizing helps a lot.
    thanks very much, such big help.

  • @AnkitChoudhary-vh6gj
    @AnkitChoudhary-vh6gj 8 ปีที่แล้ว

    Great explanation... understood it in one go...keep up the good work!!

  • @Nikhil7857
    @Nikhil7857 8 ปีที่แล้ว

    thanks for this good video it helped me to understand programming logic more better

  • @VC-kj9yx
    @VC-kj9yx 8 ปีที่แล้ว +19

    your adjacency matrix is wrong from 0 to 0 there is no edge so it should be 0 not 1 and similarly for 1 to 1 and others

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

      right,
      or add an AND i != k to that if statement bool condition in isSafe()

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

      the node is adjacent to it self , you should consider that .

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

    Superb explanation.!

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

    What if I want to find out all possibilities of coloring ? all valid combinations ?

  • @bakrgroningen
    @bakrgroningen 8 ปีที่แล้ว

    Terrific explanation

  • @manishmaithani398
    @manishmaithani398 8 ปีที่แล้ว

    Nice explanation. But I think in graph coloring problem, we do not have the value 'm' from start. Our algorithm should compute the value of m and as well as x[] (that ur algorithm is computing).

    • @닐리아담
      @닐리아담 2 ปีที่แล้ว

      This one uses m. If it fails, you can try m+1

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

    This is amazing explanation. thanks :)

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

    does this solution work for big and more complex graphs lets say for example if we want to color the map of Europe with no more than 4 colors ?
    i know that Europe can be colored with 4 colors but does that recursive method would make it possible?

  • @AkshathGrover
    @AkshathGrover 9 ปีที่แล้ว

    beautifully explained :)
    tysm!

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

    Helps in today's exam

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

    Awesome Explanation. Saved me
    (Y)

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

    Would the time complexity of this algorithm be (m*n)^n ? Since the for loop in the isSafe function would run n times in every iteration?

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

    why 0,0 adjancy matrix 1

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

    you nailed it man!!!

  • @anweshkrishnanayak2561
    @anweshkrishnanayak2561 8 ปีที่แล้ว

    Will the algorithm work for directed graphs as well ?

  • @joseph_hieunguyen
    @joseph_hieunguyen 9 หลายเดือนก่อน

    how do we know m if they dont let you know

  • @giovanni.n
    @giovanni.n 8 ปีที่แล้ว

    any videos on forward checking ?

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

    It R was Really very Useful

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

    Sir,, can this program work on scilab software??

  • @aavashkuikel1341
    @aavashkuikel1341 7 หลายเดือนก่อน

    Thanks a lot

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

    Thanks

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

    doesn't work for larger graphs

  • @datawarehouse5961
    @datawarehouse5961 9 ปีที่แล้ว

    Best graph colouring video on youtube !

  • @farahuzma3920
    @farahuzma3920 8 ปีที่แล้ว

    (0,0) of adjacency matrix shud be 1.. similarle for 1,1 2,2 n 3,3

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

    wouldn't it be m^n possible ways(since for each vertex we have m choices)?...correct me if I'm wrong.

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

      You're right. And m^n is what is shown in the video. Look again

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

    great video thnks

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

    But if I dont have the "m" before coloring the graph?

    • @CSBreakdown
      @CSBreakdown  9 ปีที่แล้ว

      +Ilmer Oliveira Good question. It becomes a much more computationally challenging problem this way, and you have to try the problem with m = 1, m = 2, m = 3... until you find the min value for m where all of the nodes can take colour.

    • @CSBreakdown
      @CSBreakdown  9 ปีที่แล้ว

      To add, this is a known NP-Complete problem meaning there does not exist a solution that is polynomial time for large enough n.

    • @ilmeroliveira238
      @ilmeroliveira238 9 ปีที่แล้ว

      +CSBreakdown If I make a function that travels the entire array seeking for blank nodes and make my looop runs until it's false(therefore all the nodes are colored)...
      Might work?

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

      +Ilmer Oliveira With the backtracking algorithm, isSafe will return false if there aren't enough m (colours) to satisfy. The algorithm will reach the very end without colouring all of the nodes. In the 'if' statement for isSafe on the left block of code, add an else block and check to see if c = m. So if 'isSafe' = false, and c = m, you know that you don't have enough colours for m. Run the algorithm again, but this time make m 1 bigger.

    • @ilmeroliveira238
      @ilmeroliveira238 9 ปีที่แล้ว

      +CSBreakdown Can you say if I understood the idea?
      pastebin.com/7KbaYKGF

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

    link to the code?

  • @sudeshnaC
    @sudeshnaC 8 ปีที่แล้ว

    Which part of the code shows the backtracking?

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

      when we call graphColor(k+1) if it fails then it will return to the next iteration in its parent graphColor()'s for loop where it will continue to try other colors and if its does not returns that means its color was right from the first call.

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

    There is no backtracking step in the graphColor() method. x[k] should be set to 0 and tried for the next color c in the for loop.

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

      actually there is .when we call graphColor(k+1) if it fails then it will return to the next iteration in its parent graphColor()'s for loop where it will continue to try other colors and if its does not returns that means its color was right from the first call.

  • @TusharYadav-es1bq
    @TusharYadav-es1bq 6 ปีที่แล้ว

    shouldnt it be m^n ways ?

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

    There's no backtracing in the code. :D

  • @Kitabi.batein18
    @Kitabi.batein18 7 ปีที่แล้ว

    awesome

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

    Nice..

  • @anubhavgupta2831
    @anubhavgupta2831 9 ปีที่แล้ว

    best graph coloring video :D

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

    can u please explain c==x[i] part?

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

      +Sarbottam Chatterjee Hi, so x[i] is an array that holds colors if the nodes that have already been colored. So c == x[i] is checking if the current color that you are trying to place (c) is equal to the color value at x[i] (the already colored nodes). If 2 nodes are adjacent (meaning if G[k][i] == 1 AND the adjacent node at x[i] has the same color, then it returns false because we can't place the same colour next to it.

    • @SarbotamChatterje
      @SarbotamChatterje 9 ปีที่แล้ว

      Thant clears my doubt. Thanks for making time to reply to my comment. Do you have a Traveling Salesman Problem solution using Dynamic Programming?

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

      +Sarbottam Chatterjee I don't unfortunately. The travelling salesman problem is NP-Complete. If I had a true solution to the problem, I would be the worlds richest man!
      Travelling salesman is best done with approximation algorithms using current technologies. With a large enough value of N, travelling salesman cannot be accurately solved. Maybe there are solutions out there for small enough values of N, but I'm not aware of one and haven't attempted the problem.

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

    Is it possible to replace this recursion with for loop.

  • @majedulislam187
    @majedulislam187 8 ปีที่แล้ว

    very nice !!!!!!!!!

  • @NS-gr9cy
    @NS-gr9cy 3 ปีที่แล้ว

    Its greedy and not backtracking