Showing posts with label graphs. Show all posts
Showing posts with label graphs. Show all posts

Wednesday, 19 May 2010

Algorithms – Quick Graph Terminology

This post will be brief. It just contains a load of terminology for parts of graphs, such as:

  • Spanning Trees
  • Back Edges
  • etc…

Tuesday, 18 May 2010

Algorithms – Depth/Breadth First Search

We have seen some of the key concepts to Graphs; What a node is, an edge – as well as definitions for Digraphs and Undirected Graphs – and other bits ‘n’ bobs :) .

But one question stills looms; How do we traverse a Graph?

Here we shall look at two of the key traversing algorithms for Graphs:

  • Depth First Search (DFS), and
  • Breadth First Search (BFS).

Algorithms – Adjacency Lists and Matrices

Nodes can be connected to other nodes – otherwise it would be a bleeding useless graph! :D

But how do we know which node is connected to which nodes? Welcome to the wonderful world of Adjacency Lists and Matrices!

Also, i apologise for the long pause in posts! :(

Tuesday, 9 February 2010

Algorithms - Traversals

Traversals


What is a traversal? It's when you visit every node of a tree or graph using the edges.

Tree traversal


Let's talk about 3 methods of traversing trees (Note: Always start at the root)

  • Depth-First-Search: Visit all the descendants of a node before visiting the sibling nodes. You have to visit some nodes more than once in a DFS, this is called backtracking

  • Breadth-First-Search: Visit all children of a node before visiting sibling nodes

  • Priority Search: Nodes are given priorities, and the children of the node that haven't been visited yet with the highest priority are visited first


So let's try these on a tree. Here's one I made earlier:

Monday, 8 February 2010

Algorithms - More graphs

More Graphs (yay)


Note: This is a direct follow on (or a sequel if you want) to this post, so you might want to read that first!

Representing graphs


So you've seen what graphs are and how they can be classified. But how do you represent them in code? For example, do we put them in an array, a vector or a linked list? There isn't one definite answer, so let's go through some of the methods of representing them.