René's URL Explorer Experiment


Title: Traveling Salesman Problem with Python: Greedy and Brute Force - AskPython

Open Graph Title: Traveling Salesman Problem with Python: Greedy and Brute Force - AskPython

X Title: Traveling Salesman Problem with Python: Greedy and Brute Force - AskPython

Description: Last quarter I had to plan a 12-stop delivery loop and the route my gut picked came out 38% longer than the version a small Python script returned in under a

Open Graph Description: Last quarter I had to plan a 12-stop delivery loop and the route my gut picked came out 38% longer than the version a small Python script returned in under a

X Description: Last quarter I had to plan a 12-stop delivery loop and the route my gut picked came out 38% longer than the version a small Python script returned in under a

Opengraph URL: https://www.askpython.com/python/examples/travelling-salesman-problem-python

X: @AskPython

Generator: WordPress 7.0

direct link

Domain: www.askpython.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@graph":[{"@type":["Person","Organization"],"@id":"https://www.askpython.com/#person","name":"Rnzo1zWtYm","sameAs":["https://twitter.com/AskPython"],"logo":{"@type":"ImageObject","@id":"https://www.askpython.com/#logo","url":"https://www.askpython.com/wp-content/uploads/2019/12/logo.svg","contentUrl":"https://www.askpython.com/wp-content/uploads/2019/12/logo.svg","caption":"Rnzo1zWtYm","inLanguage":"en-US"},"image":{"@type":"ImageObject","@id":"https://www.askpython.com/#logo","url":"https://www.askpython.com/wp-content/uploads/2019/12/logo.svg","contentUrl":"https://www.askpython.com/wp-content/uploads/2019/12/logo.svg","caption":"Rnzo1zWtYm","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.askpython.com/#website","url":"https://www.askpython.com","name":"Rnzo1zWtYm","publisher":{"@id":"https://www.askpython.com/#person"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.askpython.com/wp-content/uploads/2025/04/Traveling_Salesman_Problem_with_Python___1744317160.png","url":"https://www.askpython.com/wp-content/uploads/2025/04/Traveling_Salesman_Problem_with_Python___1744317160.png","width":"1200","height":"630","caption":"Featured Image For: Traveling Salesman Problem With Python: Greedy And Brute Force","inLanguage":"en-US"},{"@type":["WebPage","FAQPage"],"@id":"https://www.askpython.com/python/examples/travelling-salesman-problem-python#webpage","url":"https://www.askpython.com/python/examples/travelling-salesman-problem-python","name":"Traveling Salesman Problem with Python: Greedy and Brute Force - AskPython","datePublished":"2026-07-06T11:36:56+00:00","dateModified":"2026-07-06T11:36:56+00:00","isPartOf":{"@id":"https://www.askpython.com/#website"},"primaryImageOfPage":{"@id":"https://www.askpython.com/wp-content/uploads/2025/04/Traveling_Salesman_Problem_with_Python___1744317160.png"},"inLanguage":"en-US","mainEntity":[{"@type":"Question","url":"https://www.askpython.com/python/examples/travelling-salesman-problem-python#faq-question-1783337810781","name":"What is the travelling salesman problem in one sentence?","acceptedAnswer":{"@type":"Answer","text":"Given a list of cities and the distance between every pair, find the shortest loop that visits each city once and returns to the start. It is NP-hard in general."}},{"@type":"Question","url":"https://www.askpython.com/python/examples/travelling-salesman-problem-python#faq-question-1783337810782","name":"Is the greedy algorithm always optimal?","acceptedAnswer":{"@type":"Answer","text":"No. Greedy makes a locally optimal choice at every step and can miss the global optimum. On random inputs it typically lands 10% to 25% above the brute-force optimum."}},{"@type":"Question","url":"https://www.askpython.com/python/examples/travelling-salesman-problem-python#faq-question-1783337810783","name":"When is brute force practical?","acceptedAnswer":{"@type":"Answer","text":"Brute force is practical for n up to about 10 or 11. At n=10 the work is 9! = 362,880 permutations. At n=15 the work is 14! = 87 billion and the loop is no longer a practical option."}},{"@type":"Question","url":"https://www.askpython.com/python/examples/travelling-salesman-problem-python#faq-question-1783337810784","name":"What algorithm should I use for n between 12 and 20?","acceptedAnswer":{"@type":"Answer","text":"Held-Karp dynamic programming in O(n\u00b2 \u00b7 2\u207f) gives the exact answer and runs in seconds for n up to 20. Beyond that, switch to OR-Tools or a Lin-Kernighan heuristic."}}]},{"@type":"Person","@id":"https://www.askpython.com/author/rishabh","name":"Rishabh Das","url":"https://www.askpython.com/author/rishabh","image":{"@type":"ImageObject","@id":"https://secure.gravatar.com/avatar/0389ec298723119db63d64b1a087a2492d2b22fb1acd4dceb804e076e8a94465?s=96&d=mm&r=g","url":"https://secure.gravatar.com/avatar/0389ec298723119db63d64b1a087a2492d2b22fb1acd4dceb804e076e8a94465?s=96&d=mm&r=g","caption":"Rishabh Das","inLanguage":"en-US"}},{"@type":"BlogPosting","headline":"Traveling Salesman Problem with Python: Greedy and Brute Force - AskPython","keywords":"Travelling salesman","datePublished":"2026-07-06T11:36:56+00:00","dateModified":"2026-07-06T11:36:56+00:00","author":{"@id":"https://www.askpython.com/author/rishabh","name":"Rishabh Das"},"publisher":{"@id":"https://www.askpython.com/#person"},"description":"Last quarter I had to plan a 12-stop delivery loop and the route my gut picked came out 38% longer than the version a small Python script returned in under a","name":"Traveling Salesman Problem with Python: Greedy and Brute Force - AskPython","@id":"https://www.askpython.com/python/examples/travelling-salesman-problem-python#richSnippet","isPartOf":{"@id":"https://www.askpython.com/python/examples/travelling-salesman-problem-python#webpage"},"image":{"@id":"https://www.askpython.com/wp-content/uploads/2025/04/Traveling_Salesman_Problem_with_Python___1744317160.png"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.askpython.com/python/examples/travelling-salesman-problem-python#webpage"}}]}

og:localeen_US
og:typearticle
og:site_nameAskPython
article:sectionPython Programming Examples
og:imagehttps://www.askpython.com/wp-content/uploads/2025/04/Traveling_Salesman_Problem_with_Python___1744317160.png
og:image:secure_urlhttps://www.askpython.com/wp-content/uploads/2025/04/Traveling_Salesman_Problem_with_Python___1744317160.png
og:image:width1200
og:image:height630
og:image:altFeatured Image For: Traveling Salesman Problem With Python: Greedy And Brute Force
og:image:typeimage/png
article:published_time2026-07-06T11:36:56+00:00
twitter:cardsummary_large_image
twitter:creator@AskPython
twitter:imagehttps://www.askpython.com/wp-content/uploads/2025/04/Traveling_Salesman_Problem_with_Python___1744317160.png
twitter:label1Written by
twitter:data1Rishabh Das
twitter:label2Time to read
twitter:data25 minutes
msapplication-TileImagehttps://www.askpython.com/wp-content/uploads/2019/12/cropped-favicon-1-270x270.png

Links:

Skip to contenthttps://www.askpython.com/python/examples/travelling-salesman-problem-python#main
About AskPythonhttps://www.askpython.com/about
Bloghttps://www.askpython.com/blog
Contact Mehttps://www.askpython.com/contact-me
Free Online Developer Tools Hubhttps://www.askpython.com/free-online-tools
Homehttps://www.askpython.com/
Meet the Teamhttps://www.askpython.com/team
Privacy Policyhttps://www.askpython.com/privacy-policy
Pythonhttps://www.askpython.com/python-programming
Python Course for Beginners Online FREEhttps://www.askpython.com/python-course-for-beginners
Python Tutorial – Mega Indexhttps://www.askpython.com/python-tutorial-index
Terms and Conditionshttps://www.askpython.com/terms-and-conditions
Try YTGrowAI Freehttps://ytgrowai.com
Homehttps://www.askpython.com/
Bloghttps://www.askpython.com/blog
About AskPythonhttps://www.askpython.com/about
https://www.askpython.com/
Python Coursehttps://www.askpython.com/python-course-for-beginners
Start Herehttps://www.askpython.com/python-programming
https://www.askpython.com/
https://www.askpython.com/author/rishabh
Rishabh Dashttps://www.askpython.com/author/rishabh
Python Programming Exampleshttps://www.askpython.com/python/examples
https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fwww.askpython.com%2Fpython%2Fexamples%2Ftravelling-salesman-problem-python
https://twitter.com/intent/tweet?url=https%3A%2F%2Fwww.askpython.com%2Fpython%2Fexamples%2Ftravelling-salesman-problem-python&text=Traveling%20Salesman%20Problem%20with%20Python%3A%20Greedy%20and%20Brute%20Force
https://www.askpython.com/python/examples/travelling-salesman-problem-python
https://www.linkedin.com/shareArticle?url=https%3A%2F%2Fwww.askpython.com%2Fpython%2Fexamples%2Ftravelling-salesman-problem-python&title=Traveling%20Salesman%20Problem%20with%20Python%3A%20Greedy%20and%20Brute%20Force
https://www.askpython.com/author/rishabh
Articles: 47https://www.askpython.com/author/rishabh
Previous Post How to Find the Python3 Path on MacOS? https://www.askpython.com/python/examples/find-python3-path-macos
Next Post Adding Tuples to Lists in Python https://www.askpython.com/python/list/adding-tuples-to-lists
https://www.askpython.com/python/examples/fix-function-is-not-defined-error
How to Fix “Function is Not Defined” Error in Pythonhttps://www.askpython.com/python/examples/fix-function-is-not-defined-error
https://www.askpython.com/python/examples/unexpected-keyword-argument-typeerror
[SOLVED] ‘Unexpected Keyword Argument’ TypeError in Pythonhttps://www.askpython.com/python/examples/unexpected-keyword-argument-typeerror
https://www.askpython.com/python/examples/python-keylogger
How to Create a 10-Line Python Keyloggerhttps://www.askpython.com/python/examples/python-keylogger
GoLangDocshttps://golangdocs.com/
LinuxForDeviceshttps://www.linuxfordevices.com/
CodeForGeekhttps://codeforgeek.com
Python Programminghttps://www.askpython.com/python
Python Moduleshttps://www.askpython.com/python-modules
OOPS in Pythonhttps://www.askpython.com/python/oops
Python Programming Exampleshttps://www.askpython.com/python/examples
Strings in Pythonhttps://www.askpython.com/python/string
Python Programminghttps://www.askpython.com/python-programming
OOPS in Pythonhttps://www.askpython.com/python/oops/object-oriented-programming-python
Creating a Python Modulehttps://www.askpython.com/python-modules/creating-a-python-module
*args and **kwargs in Pythonhttps://www.askpython.com/python/args-kwargs-in-python
Python Dictionary (Dict) Tutorialhttps://www.askpython.com/python/dictionary/python-dictionary-dict-tutorial
Python List – 15 Things You MUST Knowhttps://www.askpython.com/python/list/python-list
Python Set – Things You MUST Knowhttps://www.askpython.com/python/set/python-set
Python String Functionshttps://www.askpython.com/python/string/python-string-functions
Homehttps://www.askpython.com
Python Coursehttps://www.askpython.com/python-course-for-beginners
Start Herehttps://www.askpython.com/python-programming
Bloghttps://www.askpython.com/blog
About AskPythonhttps://www.askpython.com/about
Credit Card Generator [Free Online]https://www.askpython.com/free-online-tools/credit-card-generator
How to Fix “Function is Not Defined” Error in Pythonhttps://www.askpython.com/python/examples/fix-function-is-not-defined-error
What is NLTK PUNKT? Explainedhttps://www.askpython.com/python-modules/nltk-punkt
[SOLVED] ‘Unexpected Keyword Argument’ TypeError in Pythonhttps://www.askpython.com/python/examples/unexpected-keyword-argument-typeerror
How to Create a 10-Line Python Keyloggerhttps://www.askpython.com/python/examples/python-keylogger

Viewport: width=device-width, initial-scale=1, maximum-scale=5, viewport-fit=cover

Robots: index, follow, max-snippet:-1, max-video-preview:-1, max-image-preview:large


URLs of crawlers that visited me.