Graph traversal method (depth first and breadth first algorithm)

Source: Internet
Author: User

There are two ways to traverse a graph:
1 Depth First
The algorithm is similar to the first root traversal of a tree;

2 Breadth First
The algorithm is similar to the hierarchical traversal of trees;
  
Case:
650) this.width=650; "src=" http://img.blog.csdn.net/20150719154004657 "alt=" here write a picture describing "title=" "/>
Depth-First traversal order: V1–V2–V4–V8–V5–V3–V6–V7
Breadth-First traversal order: V1–V2–V3–V4–V5–V6–V7–V8
  
3 precautions
1) A graph, it's depth first and breadth first is not unique, can have multiple!
2) The general situation is to give the adjacency table or adjacency matrix depth first and breadth first, at this time, depth first and breadth first is unique, because when your storage structure fixed, depth first and breadth first also fixed!


This article is from the "Sanghaidan blog column" blog, please be sure to keep this source http://10602803.blog.51cto.com/10592803/1683047

Graph traversal method (depth first and breadth first algorithm)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.