0

I have some problem understanding what the book lectured about graph.

According to the book, graph can be represented with adjacent list, and every vertex is assigned a unique number i (1<=i<=n, if there are n vertices).

Here is my problem, what I have is a bunch of names, say "simon, jack, logan, wallance", according to the book, I should assign each of them a number, but how should I determine which number should be assigned to whom?

1 Answer 1

1

It doesn't matter how you decide to map your String to ints, just make sure it is consistent, if you refer to a vertex once as k, make sure you always refer to it as k!
One possibility how to map String->int is lexicographical order.

Sign up to request clarification or add additional context in comments.

4 Comments

thanks for your reply, but what I thought is that, can I just simply pre-arrange those names in order, say "simon, jack, logan, wallance" --> "jack, logan, simon, wallance", then after the arrangement, I simply assign their indices to them as a unique number in the graph to represent them, Can I?
@Alcott: If I understood you correctly, you have thought exactly about lexicographical order, and it will work perfectly, as long as you don't change/add strings to your String->int map :)
one more question, am I supposed to maintain a map of the string:int?
@Alcott: You probably will have to, in order to know which vertex refers to where. note that there isn't much maintance in this map, since it's very static, it is built only once and never changes again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.