The traversal algorithm of graphs

Source: Internet
Author: User
1. Width-First search (BFS) (1) algorithm ideas for connected graphs
Preparation: Beginning V and an empty queue Q.
① will mark V with an access tag. And put v into the queue Q.
② Remove Queue Q's first element U. Searches for all vertices adjacent to U. If w is adjacent to U and is not interviewed, then W is flagged. And put W into the queue Q.
③ repeatedly ②. Until the queue q is empty

(2) Algorithm code:
(3) Complexity analysis

(4) Width first spanning tree
2, the general figure of the width of the first traversal
3. Depth-first search for connected graphs (DFS)

(3) Depth-first spanning tree

The traversal algorithm of graphs

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.