As you can see, graph 2 in this case, is also a Hamiltonian cycle or circuit. This means that the
path visits all the vertices before returning to the starting vertex of this graph.
2. Weighted matrix to weighted graph
Given is the following graph:
A B C D E F
A - 2 3 4 - -
B - - 1 - - 7
C 3 2 - - - 6
D - - - - 8 -
E - - - 7 - 4
F - 6 6 - - -
A. We need to draw the corresponding graph in Python.
Input =
, Computational Thinking – Assignment 5 (Artificial Intelligence Year 1)
Output =
I noticed that every time I clicked on “Run”, the weighted graph changed of shape. Here are
some examples:
All these weighted graphs are practically the same. Also, I noticed that I could change the
shape myself by dragging the vertices.
B. This graph is a mixed, weighted graph. Mixed, because it has both undirected (symmetric) and
directed (asymmetric) parts. Weighted, because every edge has a ‘weight’ assigned to it.
C. We need to show what the shortest path from A to F is.
A B C D E F
A - 2 3 4 - -
B - - 1 - - 7
C 3 2 - - - 6
D - - - - 8 -
E - - - 7 - 4
F - 6 6 - - -
Possible options to go from A to F:
A>B>F=2+7=9
A >C>F=3+6=9
A>B>C>F=2+1+6=9
A > C > B > F = 3 + 2 + 7 = 12
A > D > E > F = 4 + 8 + 4 = 16
As you can see there are 3 options with the same minimum weight. A path is a finite or infinite
sequence of edges which connect a sequence of vertices which are all distinct from one
another. The shortest path to get from A to F in this case is:
A via B to F;
A via C to F;
A via B via C to F.
It doesn’t matter which path of these 3 you choose, because they have the same weight.
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller TR19. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $5.97. You're not tied to anything after your purchase.