Data Structure-graph Storage Structure Representation and traversal (DFS amp; BFS)
1. Graph structure represented by the adjacent matrix
/* Graph structure represented by the adjacent matrix */# include
# Include
# Include
# Include
# Include
# Include
Usi
Data structure experiment Graph Theory 1: breadth-first search traversal based on the adjacent matrix
Time Limit: 1000 ms memory limit: 65536 k any questions? Click Here ^_^
The topic description gives a undirected connected graph with vertex numbers ranging from 0 to n-1. it traverses through the breadth-first search (BFS) and outputs The
The breadth-first traversal of the Ten algorithms:In this paper, we describe the implementation of the breadth-first traversal algorithm of graph based on Java, and the detailed methods are as follows:Using adjacency matrix to store graph method:1. Determine the number of vertices and edges of the graph2. Input vertex
, complete the path (V0) function to implement the paths of the V0 vertex to the remaining vertices in the output diagram.Note: (1) using traversal implementation, (2) to consider the representation of the path and storage structure.That's how I realized it:vectorBOOL Is_in_vector (vector{int judge (0);for (size_t I (0); I{if (M==vec[i]) judge=1;}if (judge==1) return 1;else return 0;}The path function is applicable to the adjacency matrix with weighte
The depth traversal and breadth traversal of an image are similar to that of a binary tree. However, because it is a graph, you need an array to check whether the vertex has been traversed.
Code Implementation
/*** Source code name: graphiteratematrix. java * Date: * program function: graph depth and breadth
Breadth-First traversalBreadth-first traversal is a graph traversal method that is often seen and common, with the exception of BFS and DFS, which is the depth-first traversal method. I'll write it in my next blog post.Traversal processI believe every person who looks at this blog will be able to read and understand th
// ================================================ =// Graphic breadth first Traversal// ================================================ =# Include # Define MAXQUEUE 10 // maximum capacity of the storage node queue during Traversal# Define MAX 9Struct node // graph vertex Structure{Int vertex; // vertex InformationStruct node * nextnode; // indicates the next v
// ================================================ =// Graphic breadth first traversal// ================================================ =# Include # Define MAXQUEUE 10 // maximum capacity of the storage node queue during traversal# Define MAX 9Struct node // graph vertex structure{Int vertex; // vertex informationStruct node * nextnode; // indicates the next v
Graph Theory 2 of Data Structure experiment: breadth-first search traversal based on the adjacent table
Time Limit: 1000 ms memory limit: 65536 k any questions? Click Here ^_^
The topic description gives a undirected connected graph with vertex numbers ranging from 0 to n-1. it traverses through the breadth-first search (BFS) and outputs Th
The deep graph traversal is implemented in the adjacent table .....View code
# Include # Include # Deprecision max 100Typedef struct arcnode/* Table node */{Int adjvex;/* adjacent contacts */Struct arcnode * nextarc;/* pointer to the next arc */} Arcnode;Typedef struct vnode/* Header node */{Int data;/* fixed point information */Arcnode * firstarc;/* pointer to the first arc attached to the vertex */} Vnod
[Cpp]// Breadth-first traversal. cpp: Defines the entry point for the console application.//# Include "stdafx. h"# Include # Include Using namespace std;# Define MAXVEX 10# Define INFINITY 65535Typedef struct{Char vexs [MAXVEX];Int arc [MAXVEX] [MAXVEX];Int numVertexes;Int numEdges;} MGraph; // the data structure of the graph and the adjacent matrix.Void CreateMGraph (MGraph * pGraph, int numVexs, int num
PHP implements graph-based depth-first traversal to output the full arrangement of 1, 2, 3... n, php3... n
The example in this article describes how PHP implements a graph-based depth-first traversal to output the full arrangement of 1, 2, 3... n. We will share this with you for your reference. The details are as foll
#include #include using namespace Std;int e[100][100]; The graph is represented by the adjacency matrix, the general figure uses the array, the sparse graph can use vector dynamic representation to save resources.int book[100]; Use the book array to record whether the node has visitedint n,m; n vertices, M-edgevoid dfs (int cur){coutfor (int i=1;i{if (e[cur][i]==1book[i]==0){Book[i]=1;DFS (i);}}}int main ()
Python's diagram implementation has a lot of other people have already written (for example, I write the following is the reference python-graph), but not suitable for a beginning of the study of the person, I will simplify, to achieve depth first and breadth first traversal.
#!/usr/bin/env python#-*-Coding:utf8-*-
Class Graph (object):
def __init__ (self, *args,
This paper illustrates the storage and breadth of adjacency matrix and the method of depth first traversal in C + + implementation graph. Share to everyone for your reference. Specifically as follows:
Example: Creating a non-direction diagram as shown in the figure
It is known from the above figure that the figure has 5 vertices, a,b,c,d,e respectively, with 6 edges.Sample input (enter in this format):
Examples of dynamic statistics graph development using javascript, and javascript statistics Graph
This example describes how to use javascript to implement dynamic statistical graphs. Share it with you for your reference. The details are as follows:The running effect is as
CF24A "ring", graph Traversal
A. Ring road time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output
Nowadays the one-way traffic is introduced all over the world in order to improve driving safety and reduce traffic jams. The government of Berland decided to keep up with new trends. Formerly allNCities of Berland were connectedNTwo-way roads in the ring,
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.