标签:relationships Springfield Fundamentals Graph shortest graph Neo4j example Struct
Neo4j Fundamentals
Graph Thinking
Property Graphs
Your First Graph
Your work here is done!
VIDEO
Graph Structure
VideoTranscriptGraph characteristics and traversal
There are a few types of graph characteristics to consider. In addition, there are many ways that a graph may be traversed to answer a question.
Directed vs. undirected graphs
In an undirected graph, relationships are considered to be bi-directional or symmetric.
An example of an undirected graph would include the concept of marriage. If Michael is married to Sarah, then it stands to reason that Sarah is also married to Michael.
A directed graph adds an additional dimension of information to the graph. Relationships with the same type but in opposing directions carry a different semantic meaning.
For example, if marriage is a symmetrical relationship, then the concept of love is asymmetrical. Although two people may like or love each other, the amount that they do so may vary drastically. Directional relationships can often be qualified with some sort of weighting. Here we see that the strength of the LOVES relationship describes how much one person loves another.
At a larger scale, a large network of social connections may also be used to understand network effects and predict the transfer of information or disease. Given the strength of connections between people, we can predict how information would spread through a network.
Weighted vs. unweighted graphs
The concept of love is also an example of a weighted graph.
In a weighted graph, the relationships between nodes carry a value that represents a variety of measures, for example cost, time, distance or priority.
A basic shortest path algorithm would calculate the shortest distance between two nodes in the graph. This could be useful for finding the fastest walking route to the local store or working out the most efficient route to travel from city to city.
In this example, the question that we might have for this graph is: What is the shortest drive from Springfield to Centerville? Using the HAS_ROAD relationships and the distance for these relationships, we can see that the shortest drive will be to start in Springfield, then go to Cliffside, then to Newtown, and finally arrive in Centerville.
More complex shortest path algorithms (for example, Dijkstra’s algorithm or A* search algorithm) take a weighting property on the relationship into account when calculating the shortest path. Say we have to send a package using an international courier, we may prefer to send the package by air so it arrives quickly, in which case the weighting we would take into account is the time it takes to get from one point to the next.
Inversely, if cost is an issue we may prefer to send the package by sea and therefore use a property that represents cost to send the package.
Graph traversal
How one answers questions about the data in a graph is typically implemented by traversing the graph. To find the shortest path between Springfield to Centerville, the application would need to traverse all paths between the two cities to find the shortest one.
-
Springfield-Newtown-Centerville = 26
-
Springfield-Cliffside-Newtown-Centerville = 23
-
Springfield-Cliffside-Melrose-Certerville = 49
Traversal implies that the relationships are followed in the graph. There are different types of traversals in graph theory that can impact application performance. For example, can a relationship be traversed multiple times or can a node be visited multiple times?
Neo4j’s Cypher query language is optimized for node traversal so that relationships are not traversed multiple times, which is a huge performance win for an application.
Check your understanding
1. How many paths are traversed?
Given this graph:
Suppose we have this graph where a relationship can be traversed multiple times. How many unique paths are traversed to go from Springfield to Centerville?
-
1
-
2
-
✓ 3
-
4
Summary
In this lesson you learned how graphs are structured where the relationships can have direction and weights. Next, you will learn about some common use cases for graphs.
Graph Elements 33% Graphs Are Everywhere标签:relationships,Springfield,Fundamentals,Graph,shortest,graph,Neo4j,example,Struct 来源: https://www.cnblogs.com/z-cm/p/16220554.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。