Random graph algorithm

An algorithm is a set of instructions that explain how to compute something. It is like a recipe, only for making data instead of food.

An algorithm has three parts:

  1. Input (like the ingredients of a recipe)
  2. Output (like the title of a recipe: "chile con carne, serves 12")
  3. The steps of the algorithm (like the steps of the recipe)

The following algorithm describes the creation of a random graph.

Random Graph Algorithm:

Input:

  1. Node set V, with |V|>1

Output:

  1. Graph G=(V,E), with E={{x,y}: x∈V and y∈V and x≠y} (i.e., a clique)

Steps:

  1. Define E = { } and G=(V,E)
  2. Choose random pair of nodes x, y that are non-adjacent
  3. Add element {x,y} to set E
  4. If |E| = |V|*(|V|-1)/2 then we're done
  5. Go to step 2

Note: The main point of most algorithms is generating output, just as the main reason for most recipes is serving food. For example, a sorting algorithm is useful as a way to alphabetize names, and Google's PageRank algorithm is useful as a way to list the most popular and influential Web pages first.

Our random graph algorithm, however, does not generate interesting output. It creates a clique using a more complicated sequence of steps than is necessary to create a clique. The point of the algorithm is the journey it describes, not the destination where it eventually arrives.

 
Joomla Templates by Joomlashack