Home Up Feedback Contents Search

Algorithms                                              
       A Heavenly Help to CS Students

 

[Under Construction]

Home
Up

 

 

 Hit Counter

Algorithms are intelligent steps to follow, in order to solve a problem.

Algorithms:

bulletDepth First search
 Breath first Search
The Algorithm of DFS :

tree_type
dfs_stack(tree_type tree, BOOL (*predicate)(tree_type))
{
  stack_type stack = create_stack();
  tree_type guess;

  push(tree, stack);
  while (empty_stack(stack) == FALSE)
    {
      guess = pop(stack);
      if (empty_tree(guess) == TRUE)
        continue;
      if (predicate(guess) == TRUE)
        return guess;
      push(left_child(guess), stack);
      push(right_child(guess), stack);
    }
  return the_empty_tree;
}

 

 

 

The Algorithm of BFS :

tree_type
bfs_queue(tree_type tree, BOOL (*predicate)(tree_type))
{
  queue_type queue = create_queue();
  tree_type guess;

  enqueue(tree, queue);
  while (empty_(queue) == FALSE)
    {
      guess = dequeue(queue);
      if (empty_tree(guess) == TRUE)
        continue;
      if (predicate(guess) == TRUE)
        return guess;
      enqueue(left_child(guess), queue);
      enqueue(right_child(guess), queue);
    }
  return the_empty_tree;
}
 

Data structures:

2 - 4 Trees

Creating and Deleting

 

 

The Following Was my lecture notes taught by G.Toussaint at McGill in 2001.

Information is subject to Authors rights

 Click on Images to enlarge

 

 

 

 

Send mail to [email protected] with questions or comments about this web site.
Copyright © 2001 SIK YUEN .DOTCOM
Last modified: January 09, 2002