Coding Challenge #35.1: Traveling Salesperson

Sdílet
Vložit
  • čas přidán 25. 07. 2024
  • In Part 1 of this multi-part coding challenge, I introduce the classic computer science problem of the Traveling Salesperson (TSP) and discuss the pitfalls with a brute force solution. In Part 2, I discuss Lexicographic Ordering and demonstrate one algorithm to iterate over all the permutations of an array. In Part 3, I apply this algorithm to a brute-force solution of the TSP problem. Every single route permutation is checked one by one. In Part 4, I attempt to create a solution to the TSP problem with a genetic algorithm, and then I add a “crossover” algorithm in Part 5. Code: thecodingtrain.com/challenges...
    p5.js Web Editor Sketches:
    🕹️ Part 1: Traveling Salesperson (TSP): editor.p5js.org/codingtrain/s...
    🕹️ Part 2: Lexicographic Order: editor.p5js.org/codingtrain/s...
    🕹️ Part 3: TSP with Lexicographic Order: editor.p5js.org/codingtrain/s...
    🕹️ Part 4: TSP with Genetic Algorithm: editor.p5js.org/codingtrain/s...
    🕹️ Part 5: TSP with Genetic Algorithm and Crossover: editor.p5js.org/codingtrain/s...
    Other Parts of this Challenge:
    📺 Part 2: Lexicographic Order: • Coding Challenge #35.2...
    📺 Part 3: TSP with Lexicographic Order: • Coding Challenge #35.3...
    📺 Part 4: TSP with Genetic Algorithm: • Coding Challenge #35.4...
    📺 Part 5: TSP with Genetic Algorithm and Crossover: • Coding Challenge #35.5...
    🎥 Previous video: • Coding Challenge #34: ...
    🎥 Next video: • Coding Challenge #36: ...
    🎥 All videos: • Coding Challenges
    References:
    🌐 Traveling Salesman on Wikipedia: en.wikipedia.org/wiki/Travell...
    🗨️ Permutation Algorithm Using Lexicographic Ordering: www.quora.com/How-would-you-e...
    📝 Array on MDN: developer.mozilla.org/en/docs...
    📝 Array.includes() on MDN: developer.mozilla.org/en/docs...
    📝 Array.reverse() on MDN: developer.mozilla.org/en/docs...
    📝 ES6 Sets on MDN: developer.mozilla.org/en/docs...
    💾 The Nature of Code Part 2: github.com/shiffman/NOC-S17-2...
    📕 The Nature of Code: natureofcode.com/
    Videos:
    🎥 Improved Pool Selection: • 9.8: Genetic Algorithm...
    🎥 Genetic Algorithm Playlist: • 9: Genetic Algorithms ...
    🔴 Live Stream Archive #57: • Live Stream #57 - Trav...
    Related Coding Challenges:
    🚂 #29 Smart Rockets in p5.js: • Coding Challenge #29: ...
    🚂 #51 A* Pathfinding Algorithm: • A* Pathfinding Algorit...
    🚂 #69 Evolutionary Steering Behaviors: • Coding Challenge #69: ...
    🚂 #70 Nearest Neighbors Recommendation Engine: • Coding Challenge #70: ...
    Timestamps:
    00:00 Welcome to this coding challenge!
    00:50 What is the Traveling Salesperson problem?
    04:50 Code! Placing random cities on the canvas
    07:30 Go through the cities in order
    08:13 Shuffling the array with swaps
    11:35 Computing the distance and saving the shortest one
    15:20 Oups! Fixing an array index error
    17:00 How to make a copy of an array?
    19:43 Storing a copy of the best cities path ever
    20:24 Drawing the best cities path ever
    21:00 The limits of this brute force algorithm
    Editing by Mathieu Blanchette
    Animations by Jason Heglund
    Music from Epidemic Sound
    🚂 Website: thecodingtrain.com/
    👾 Share Your Creation! thecodingtrain.com/guides/pas...
    🚩 Suggest Topics: github.com/CodingTrain/Sugges...
    💡 GitHub: github.com/CodingTrain
    💬 Discord: / discord
    💖 Membership: czcams.com/users/thecodingtrainjoin
    🛒 Store: standard.tv/codingtrain
    🖋️ Twitter: / thecodingtrain
    📸 Instagram: / the.coding.train
    🎥 Coding Challenges: • Coding Challenges
    🎥 Intro to Programming: • Start learning here!
    🔗 p5.js: p5js.org
    🔗 p5.js Web Editor: editor.p5js.org/
    🔗 Processing: processing.org
    📄 Code of Conduct: github.com/CodingTrain/Code-o...
    This description was auto-generated. If you see a problem, please open an issue: github.com/CodingTrain/thecod...
    #travelingsalesperson #permutation #lexicographicordering #natureofcode #geneticalgorithm #evolution #bruteforce #factorial #arrays #p5js

Komentáře • 339

  • @neomage2021
    @neomage2021 Před 7 lety +355

    As a software engineer I enjoy watching these videos. I find them relaxing. You are really good at teaching. Keep up the good work!

    • @TheCodingTrain
      @TheCodingTrain  Před 7 lety +48

      That's so nice to hear thank you!

    • @insidioso4304
      @insidioso4304 Před 7 lety +21

      Derick Hess Me too! Actually it is relaxing but at the same time it makes you feel the need to code!
      I would call this new way of relaxing: "prograxing"

    • @ericowens9050
      @ericowens9050 Před 6 lety +1

      Derick Hess Same here. Makes me feel better to not be alone in that feeling. :-)

    • @Pradeep.Poonia
      @Pradeep.Poonia Před 4 lety

      @@TheCodingTrain Does Derick look like the guy who wrote this paper : czcams.com/video/goUlyp4rwiU/video.html @DerickHess

    • @amandixit3555
      @amandixit3555 Před 3 lety

      @@TheCodingTrain choo choo , abey bada ho ja bhai. choo choo

  • @clementbuchanan587
    @clementbuchanan587 Před 3 lety +3

    Seriously Dan, I luv, luv, luuuv the way you teach. I am a software developer in training and you make it so much more palatable to digest. I truly hope you continue this great work you're doing man. You're my go to resource when I need ANYTHING for coding.

  • @bikachu_
    @bikachu_ Před 3 lety +5

    you're a great teacher and thanks for being so enthusiastic about programming, it really keeps me going!

  • @manurok1901
    @manurok1901 Před 8 lety +1

    Love these videos! Been binge watching while I'm off work the past couple of days :p Keep it up man, you're inspiring

  • @jhokeypokey
    @jhokeypokey Před 5 lety +76

    I come from the future to let you know that this is still interesting.

    • @pretzels3273
      @pretzels3273 Před 5 lety +2

      Jared Fairchild and Pokémon go is relevant again

    • @Seedx
      @Seedx Před 4 lety +1

      Welp it’s 2020

    • @t__v_____290
      @t__v_____290 Před 4 lety

      Not anymore buddy

    • @bechirjamousi6696
      @bechirjamousi6696 Před 4 lety

      TSP needs to get back to its initial position and in this case, it is not
      , am i right?

    • @jetison333
      @jetison333 Před 3 lety

      Further in the future here, can confirm its still interesting

  • @Lehiannel
    @Lehiannel Před 7 lety

    Perfect! I am studying it for a project in my R coding class. Your logic explanation was clear, didatic and easy to understand. I enjoyed it :) Keep making videos like that!

  • @golfball_diver
    @golfball_diver Před 5 lety +59

    i know this is late, but i think the travelling salesman problem requires you to go back to your starting location after visiting every city.

  • @kevnar
    @kevnar Před 2 lety +4

    I took the formula for line intersection from your Ray Casting video and I just made the TSP algorithm swap the tails of two random intersecting lines in the path. Then I gave it 999 points, and it unscrambled the path in a matter of ten minutes or so. It's not the shortest path, but the amount of progress for that many points is amazing.

  • @nataliekidd2135
    @nataliekidd2135 Před 7 lety

    I really love these videos, they are super informative. I'm a Sophomore in college earning my degree in Computer Science. Even though I haven't learned Java or JavaScript, I really appreciate these videos.

  • @mihaitmf
    @mihaitmf Před 5 lety +2

    Man, that's awesome! So simple, yet so neat.

  • @Hyuts
    @Hyuts Před 5 lety +1

    I finally downloaded processing! Very cool and easy to install plus allows me to follow along and use all github projects. Thanks!

  • @nowar9220
    @nowar9220 Před 6 lety

    first channel ive ever subscribed to!! Really worth it :) Thanks! Apreciate it!!

  • @TheDogn
    @TheDogn Před 7 lety +20

    7:13 The bell was a hilariously unexpected touch.

  • @per1sher
    @per1sher Před 8 lety +1

    Fascinating video - always enjoy your channel - your enthusiasm is infectious :)

  • @sherhy3689
    @sherhy3689 Před 7 lety +2

    patient, adequately funny, and informative, please continue this as long as you can --tokyo

  • @nraynaud
    @nraynaud Před 4 lety +4

    I used a traveling salesman in a CNC application, when milling a bunch of pockets, to choose the order of the pockets.

  • @heavencanceller1863
    @heavencanceller1863 Před 3 lety

    These videos are both priceless information and entertainment

  • @ronraisch510
    @ronraisch510 Před 6 lety +39

    I yelled "SUM!!!" at the screen for like 4 min lol

  • @davidstephen2219
    @davidstephen2219 Před 8 lety +1

    Simple and easy as always.
    Keep go on.
    I wish I was one of your students in your class. );

  • @omaryahia
    @omaryahia Před 2 lety

    your videos are amazing, thank you Daniel

  • @seanhudson8453
    @seanhudson8453 Před 5 lety +5

    Came here for my uni course. Stayed for the flamboyancy

  • @deathvall3y
    @deathvall3y Před 5 lety

    Energetic.... and lots of love for you

  • @Ensii
    @Ensii Před 7 lety +1

    Your enthusiasm is priceless :) nice video

  • @omshrisn2909
    @omshrisn2909 Před 7 lety +3

    I like your approach of programming!!! , understood more clearly than what teachers teach in my college thanks 😃

  • @josbex1684
    @josbex1684 Před 7 lety

    Interesante gracias... aplicare ahora la heuristica anneling para calcular mas rápido la ruta mas corta

  • @sina-qh8wm
    @sina-qh8wm Před 3 lety +1

    I created a presentation in university based on this video, thanks a lot :)

  • @gadeichhorn
    @gadeichhorn Před 5 lety

    great stuff! would like to see ant colony simulation for the same problem or event multiple sales doing each multiple visits.

  • @Thijs-Kuiken
    @Thijs-Kuiken Před 5 lety +2

    What this video needs is.... more talking with the arms and hands.
    ;-)
    interesting stuff! though a lot flies over my head. You're an enthusiastic teacher.. fun watch.

  • @anonymousvevo8697
    @anonymousvevo8697 Před 4 lety +1

    i come from 2020 and your video is still awsome

  • @nickgooch6928
    @nickgooch6928 Před 7 lety +14

    You should use something like this to solve the Maze Generator you made ; )

  • @sairamankilambi5007
    @sairamankilambi5007 Před 3 lety

    2020 it is! Travelling back in time to understand Travelling Sales Person problem...

  • @aryamankejriwal5959
    @aryamankejriwal5959 Před 7 lety +3

    For the latest thing, the points would be shops where the Nintendo switch is possibly present...

  • @LorenzoLeonardini
    @LorenzoLeonardini Před 8 lety +15

    "What are the things in your world that you need to find the path way through?" everything in my room I guess

  • @dibibob1474
    @dibibob1474 Před 5 lety

    smart and helpful. thanks sir :)

  • @DodaGarcia
    @DodaGarcia Před rokem

    1:10: "Oh a Pokémon Go analogy, this will be easy to follow!"
    1:15: "N-dimensional? I'm lost"

  • @glenneric1
    @glenneric1 Před 2 lety

    I think one way of avoiding the trap that you see at 21:18 is to sometimes swap more than 2 points. Though that actually isn't a two point trap now that I look at it.

  • @Nerdthagoras
    @Nerdthagoras Před 7 lety

    I plan to use this to find the optimal route while shopping for various items at Walmart!

  • @gunot5656
    @gunot5656 Před 7 lety

    this guy is incredibly entertaining, lol

  • @Mosch822
    @Mosch822 Před 7 lety

    Great Video. Wanna see more

  • @assimez-zaky8363
    @assimez-zaky8363 Před 3 lety

    This is relaxing

  • @exorcistgg9833
    @exorcistgg9833 Před 5 lety

    lol I was trying to design a program that calculate the shortest distance to go to all pokestop😂 And then I found your vid

  • @-rXr-
    @-rXr- Před 8 lety

    Hi denial, love your vids, can you make a video on A* path finding algorithm plz

  • @amateuraaron6972
    @amateuraaron6972 Před 2 lety

    Hey Dan!
    Just wanted to say
    its 2022
    about 6 years later
    Pokemon Go is still relevant enough for this video hahaha

  • @kevnar
    @kevnar Před 6 lety +130

    Sally has 12 boyfriends. In order to keep them from finding out about each other, she insists on having her visits at the guy's houses. What route does she visit them in that saves her the most travel time so she can maximize the time she spends with each guy?

    • @MrCmon113
      @MrCmon113 Před 6 lety +23

      Damn, Sally is even worse than Chuck, who's always trying to spy on Alice and Bob.

    • @Violet-tb8xo
      @Violet-tb8xo Před 5 lety +3

      @@MrCmon113 eve?

    • @kyokarson8233
      @kyokarson8233 Před 5 lety +1

      @@MrCmon113 we used to have Darth spying on alice and bob when the love birds wanted to talked :p

    • @arumifitria5433
      @arumifitria5433 Před 4 lety +1

      Thanks u inspired me a lot

    • @kavinbharathi
      @kavinbharathi Před 3 lety +2

      _why? Just why?_

  • @bhavyabhatia2337
    @bhavyabhatia2337 Před 6 lety +1

    Is there a video for this solution using DP, not brute force ?

  • @ruyuehong2392
    @ruyuehong2392 Před 6 lety +1

    The dynamic network graph is amazing. I wonder how to create those dynamic animation. Is it a special drawing software or particular packages of some languages?

    • @DodaGarcia
      @DodaGarcia Před rokem

      I know this is 4 years ago, but just in case you didn't find it, this is p5js! It's a free JavaScript library that makes it easy to create these drawings, and it also has an in-browser editor you can use to get started. It's a fantastic tool and this channel has lots of tutorials for it.

  • @michaellazar9078
    @michaellazar9078 Před 6 lety +1

    does the salesman have to end up at home after hitting each point once or does he travel from job to job forever? #2 if you had a short repeatable solution. how would a person responsibly disseminate their findings?

  • @Tin98Tin
    @Tin98Tin Před 7 lety

    Please do more in Processing!

  •  Před 5 lety

    Hello! I'm working with TSP and genetic algorithms and now I'm trying to integrate local search into my algorithm. Can you provide me with a reference where I can find information about this problem?
    I already have some significant results from my genetic algorithm but to those results I want to apply local search to try to improve my results.
    Thanks for your attention!

  • @sensei0101
    @sensei0101 Před 7 lety

    Isn't it a good idea to cache parts of the system? So when it hits again, it is just to look it up instead of calculating everything all the time?

  • @jschoete3430
    @jschoete3430 Před 7 lety

    Hi ! Can I ask what studies you did, and what kind of work you do? I'm myself studying IT, and I love these videos and I would like to code like this all day long.
    also if it's not too much to ask, how much do you make with your job? I know it's a bit of a taboo question, so feel free to ignore ^^

  • @memporium240
    @memporium240 Před 3 lety

    You can actually reach an upper bound of n^2*2^n which is a better bound than n factorial.

  • @pqazx1
    @pqazx1 Před 3 lety +1

    how to take input from user for the dist bw points ??and then do this??

  • @stephfong4577
    @stephfong4577 Před 7 lety +1

    Wow, I hope I knew about your channel earlier!

  • @arhabersham
    @arhabersham Před 6 lety

    Help! At 10:05 , I don't see index (element?) [3]... I only see [0] to [2] . Did I miss something?

  • @luiginotcool
    @luiginotcool Před 3 lety

    Hey I’m from the future and this is actually really useful for solving shwolobatata-hmm problems

  • @earthx7463
    @earthx7463 Před 5 lety +1

    informative and funny XD

  • @rodneyjohnson9476
    @rodneyjohnson9476 Před rokem

    I want to use this algorithm but where can I find the listing that explains the Java functions in basic command set

  • @eldiagrama
    @eldiagrama Před 7 lety

    I can´t get the first part to work. I´m new to this. When I write cities.length it appears all red. I have the code exactly as in the video but it does not work :/
    var cities = [];
    var totalCities = 5;
    function setup() {
    createCanvas(400, 300);
    for (var i = 0; i < totalCities; i++) {
    var v = createVector(random(width), random(height));
    cities[i] = v;
    }
    function draw() {
    background(0);
    fill(255);
    for (var i = 0; i < cities.length; i++) {
    ellipse(cities[i].x, cities[i].y, 8, 8);
    }
    }

  • @ErikHarloff
    @ErikHarloff Před 7 lety +6

    You spoke about providing the Processing code to this example as well. Unfortunately, I didn't find is on github (github.com/CodingRainbow/Rainbow-Code/tree/master/challenges/CC_35_TSP/CC_35.1_TSP). Would you be so nice to provide the Processing code for TSP? Awesome!

  • @cesarrios3449
    @cesarrios3449 Před 7 lety +2

    Where are u programming this? Are you using an text editor or something else? I would appreciate so much if u can answer me. Excelent video, greetings from Mexico :)

    • @TheCodingTrain
      @TheCodingTrain  Před 7 lety +3

      Try some of these workflow videos! (let me know if they are helpful)
      sublime text: czcams.com/video/UCHzlUiDD10/video.html
      atom editor: czcams.com/video/d3OcFexe9Ik/video.html
      brackets: czcams.com/video/nmZbhManVcY/video.html
      codepen: czcams.com/video/5gfUgNpS6kY/video.html

  • @Codie__
    @Codie__ Před 7 lety

    What library would be good to use in Python to take care of drawing the lines and visually representing this algorithm?

    • @funxiobolic
      @funxiobolic Před 7 lety

      Check out pyGame. It's a Python library aimed at game developers, so it has a lot of drawing/graphics functions.

  • @epicmonckey25001
    @epicmonckey25001 Před 7 lety +1

    Noob here, what does the index.html file look like. I have it, but when i try to open it in my browser all i get is a black box. PLZ HELP!

  • @maxkolbl1527
    @maxkolbl1527 Před 7 lety +1

    Pokemon Go was actually the real reason I got interested in this problem... ^^'

  • @hymntosea
    @hymntosea Před 4 lety

    Thanks

  • @oskarkrogsgard3014
    @oskarkrogsgard3014 Před 7 lety

    Diiiing. You are so silly. I love it! :-D

  • @wardiofficial6945
    @wardiofficial6945 Před 7 lety

    could you please make a video to code a system that use GA for navigating the customer of supermarket when they are doing their grocery shopping task. The system should use the shelf's coordinate and the result will display a list of shelf label of the selected shelf from the distance calculated from the supermarket front door. tq

  • @yerkoantonioalvarez
    @yerkoantonioalvarez Před 5 lety +1

    Great video! But tsp requires to return to initial citie

  • @Invenitive
    @Invenitive Před 6 lety

    Why did you do linear paths instead of round trips? All of the examples I've seen of the TSP use round trips

  • @jwbonnett
    @jwbonnett Před 6 lety

    How would you going about adding obstacles?

  • @ea1thy
    @ea1thy Před 5 lety

    Could you please show what's in your index.html so far?

  • @RetroGamingClashOfClans

    traveling salesman problem is one of the hardest problem in math having no exact method/equation for finding the EXACT shortest route and its is one of the NP problems.... if you can find a quick way to solve this problem for any number of points, it will proof that P = NP and that will get you million dollars as it is one of the 1million$ millennium problem

  • @joesmith2715
    @joesmith2715 Před 7 lety

    why does he do some challenges in p5 and others in processing? Is it just because one is better for certain things than the other, if so what's better for what?

  • @sudhamahajan2272
    @sudhamahajan2272 Před 3 lety +1

    how do u make that animation part??what do u use??

  • @unchaynd7266
    @unchaynd7266 Před rokem

    5:29 I am here because I'm trying to make a program that can come up with the optimal arrangement for a bunch of chunks of music to form a song, such that the arrangement follows some given rules (e.g., what chunks are allowed to follow what other chunks, minimal repetition of chunks)

  • @zyzo99
    @zyzo99 Před 6 lety

    One thing i dont get is why the upper boundary in the loops use to be < and not

  • @Teth47
    @Teth47 Před 7 lety +11

    So it turns out Windows 10's calculator can handle some pretty big numbers, 3000! is ~4.19^9130. Not bad.

    • @lumschente
      @lumschente Před 5 lety

      My Android calculators max is 13547! = 1.085^50089

    • @Tuberex
      @Tuberex Před 4 lety

      4,1493596034378540855568670930866 with 9130 zeros

    • @Tuberex
      @Tuberex Před 4 lety

      @@lumschente the biggest on windows 10 is 3248

  • @tythedev9582
    @tythedev9582 Před 3 lety

    I am a simple man. I see your videos in my recommendations. I watch. LMBO @16:11 "shmoley-patat-in"?

  • @tiffsea8876
    @tiffsea8876 Před 4 lety +1

    I love that you chose to use 'salesperson' as opposed to traditional 'salesman' term - obviously not all sales persons are 'men'. Thank you for thinking at that level! Makes a huge difference for mental processing!

  • @makarandlahane3904
    @makarandlahane3904 Před 7 lety

    as you said we want the total sum of all distances,then why haven't you returned the sum from calcDistance function?

  • @muhammadzeeshan6965
    @muhammadzeeshan6965 Před 6 lety

    very good

  • @davatron5000
    @davatron5000 Před 8 lety

    👍🏻 for "schmullivatatani"

  • @izoumashka
    @izoumashka Před 7 lety

    well you can narrow down possible paths by just working out which are "edge" vertices and starting from them.

  • @tubememax
    @tubememax Před 3 lety

    Sorry, I'm new here. Is it possible to open his completed java travelling salesperson project to try something out?

  • @felc_9415
    @felc_9415 Před 6 lety

    is that have a relation with the chinese postman problem ?

  • @rafageist
    @rafageist Před rokem

    If you don't have the restriction of returning to the starting city, then you have leftover combinations. A B C would be the same as C B A, and so on.

  • @johnkarippery9919
    @johnkarippery9919 Před 4 lety

    can you please make a video about VRP algorithm?

  • @amit_awadhi
    @amit_awadhi Před 3 lety

    It should be renamed to "Catching-Pokemon-Problem"😂👌

  • @DinGDonGvideoProduction

    finlly got u

  • @shubhampokhriyal8491
    @shubhampokhriyal8491 Před 3 lety

    How you making the animations any source to learn this

  • @louis1001
    @louis1001 Před 7 lety +2

    Starting 2017 and people already finds old Pokémon GO :/
    Great Video!!

  • @florianreichelt
    @florianreichelt Před 6 lety

    cool!:)

  • @sujals7108
    @sujals7108 Před 5 lety +1

    instead of writing 'bestEver = cities.slice();', you can just write 'bestEver = cities;'. It copies the array exactly

    • @rankail
      @rankail Před 5 lety

      He did it that way first and then "corrected" it. XD

  • @sudhamahajan2272
    @sudhamahajan2272 Před 3 lety +1

    How to stop this prog after iterations are completed..?

  • @MuhammadAfzal-tk9xl
    @MuhammadAfzal-tk9xl Před 3 lety

    You explain very well
    But i have a question on another day i was watching your A* search algorithm video
    whats the difference between this concept and that A* search ?
    Secondly can i make code of this in c++?
    Please do reply

    • @satishkpradhan
      @satishkpradhan Před 2 lety

      A* is for calculating the shortest distance between a node pair... but for tsp, it is tour that starts and end at the same node. That makes the problem hard and can't be solved by exact methods.

  • @Habbxor
    @Habbxor Před 7 lety +1

    Would Prim's algorithm work better? I searched up and this is an O(V^2), and Prim's is O(|E| log |V|). (V = vertex, E = edge/path b/w points)

    • @stoobertb
      @stoobertb Před 7 lety +2

      Prim's is slightly different. Prim's will give you the Minimum Spanning Tree, which will be the shortest path that connects all cities to at least one other city, however, it may not be the shortest when traversing all cities as you may have to double back on yourself. Think of Prim's as a way of connecting all cities so all cities can be traversed using the least amount of road, however traversing that road may not be the shortest route as going directly.

    • @Habbxor
      @Habbxor Před 7 lety

      You're right. Prim's could lead to having to travel the same path again because it doesn't guarantee a linear path.

  • @Shafitrumboo
    @Shafitrumboo Před 4 lety

    Do you have graph partition

  • @Gegellibu
    @Gegellibu Před 8 lety

    For the different path calculations the formula is actually n!/2 as ABC is the same path as CBA

    • @vernonalbayeros4719
      @vernonalbayeros4719 Před 7 lety +2

      Still, since when talking about time and space complexities we are referring to very large N counts, the problem's upper bound is still called n! or factorial, since any constant (in your comment's case = (1/2) * n! ) multiplying the n is "irrelevant"

  • @kaal_bhairav_23
    @kaal_bhairav_23 Před 4 lety

    The time complexity can be reduces from n! to (n-1)! since we can fix a point and permute the remaining (n-1) points.

    • @BradHouser
      @BradHouser Před 3 lety

      And assuming the distance from A to B equals the distance from B to A, you can divide (n-1)! by 2.

  • @joonsungkim1218
    @joonsungkim1218 Před 7 lety +13

    don't you need to return to the starting point?

    • @kevnar
      @kevnar Před 4 lety +4

      No. The salesman left his wife and family and never plans to go back.

    • @Caleb-zj9xi
      @Caleb-zj9xi Před 4 lety

      That’s called something else.

    • @Matt-yp7io
      @Matt-yp7io Před 4 lety +1

      @@Caleb-zj9xi no its not