The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998 The.Algorithm.Design.Manual.Springer-Verlag.1998

18.04.2013 Views

Exercises positions, while has been shifted k=4 positions. ❍ Suppose you know what k is. Give an O(1) algorithm to find the largest number in A. ❍ Suppose you do not know what k is. Give an algorithm to find the largest number in A. For partial credit, you may give an O(n) algorithm. 12. (*) Suppose that you are given a sorted sequence of distinct integers . Give an algorithm to determine whether there exists an index i such at . For example, in , . In , there is no such i. Next: Implementation Challenges Up: Breaking Problems Down Previous: Square and Other Roots Algorithms Mon Jun 2 23:33:50 EDT 1997 file:///E|/BOOK/BOOK2/NODE57.HTM (4 of 4) [19/1/2003 1:29:01]

The Friendship Graph Next: Data Structures for Graphs Up: Graph Algorithms Previous: Graph Algorithms The Friendship Graph Figure: A portion of the friendship graph To demonstrate the importance of proper modeling, let us consider a graph where the vertices are people, and there is an edge between two people if and only if they are friends. This graph is well-defined on any set of people, be they the people in your neighborhood, at your school or place of business, or even the entire world. There are many interesting aspects of people that are best understood as properties of this friendship graph. We use this opportunity to define important graph theory terminology. ``Talking the talk'' proves to be an important part of ``walking the walk''. ● If I am your friend, does that mean you are my friend? A graph is undirected if edge (x,y) always implies (y,x). Otherwise, the graph is said to be directed. The ``heard-of'' graph is directed, since many famous people who I have heard of have never heard of me! The ``had-sex-with'' graph is presumably undirected, since the critical operation always requires a partner. I'd like to think that the ``friendship'' graph is always an undirected graph. ● Am I my own friend? An edge of the form (x,x) is said to be a loop. If x was y's friend several times over, we can model this relationship using multiedges, multiple edges between the same pair of vertices. A graph is said to be simple if it contains no loops and no multiple edges. Simple graphs really are often simpler to work with in practice. Therefore, we might be better off if no one was their own friend. ● How close a friend are you? A graph is said to be weighted if each edge has an associated numerical attribute. We could model file:///E|/BOOK/BOOK2/NODE60.HTM (1 of 3) [19/1/2003 1:29:02]

<strong>The</strong> Friendship Graph<br />

Next: Data Structures for Graphs Up: Graph <strong>Algorithm</strong>s Previous: Graph <strong>Algorithm</strong>s<br />

<strong>The</strong> Friendship Graph<br />

Figure: A portion of the friendship graph<br />

To demonstrate the importance of proper modeling, let us consider a graph where the vertices are people,<br />

and there is an edge between two people if and only if they are friends. This graph is well-defined on any<br />

set of people, be they the people in your neighborhood, at your school or place of business, or even the<br />

entire world. <strong>The</strong>re are many interesting aspects of people that are best understood as properties of this<br />

friendship graph.<br />

We use this opportunity to define important graph theory terminology. ``Talking the talk'' proves to be an<br />

important part of ``walking the walk''.<br />

● If I am your friend, does that mean you are my friend?<br />

A graph is undirected if edge (x,y) always implies (y,x). Otherwise, the graph is said to be<br />

directed. <strong>The</strong> ``heard-of'' graph is directed, since many famous people who I have heard of have<br />

never heard of me! <strong>The</strong> ``had-sex-with'' graph is presumably undirected, since the critical<br />

operation always requires a partner. I'd like to think that the ``friendship'' graph is always an<br />

undirected graph.<br />

● Am I my own friend?<br />

An edge of the form (x,x) is said to be a loop. If x was y's friend several times over, we can model<br />

this relationship using multiedges, multiple edges between the same pair of vertices. A graph is<br />

said to be simple if it contains no loops and no multiple edges. Simple graphs really are often<br />

simpler to work with in practice. <strong>The</strong>refore, we might be better off if no one was their own friend.<br />

● How close a friend are you?<br />

A graph is said to be weighted if each edge has an associated numerical attribute. We could model<br />

file:///E|/BOOK/BOOK2/NODE60.HTM (1 of 3) [19/1/2003 1:29:02]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!