## Graph
Graph is a useful data structure for representing most of the real world problems involving a set of users/candidates/nodes and their relations. A Graph consists of two parameters :
```
V = a set of vertices
E = a set of edges
```
Each edge in `E` connects any two vertices from `V`. Based on the type of edge, graphs can be of two types:
1. **Directed**: The edges are directed in nature which means that when there is an edge from node `A` to `B`, it does not imply that there is an edge from `B` to `A`.
An example of directed edge graph the **follow** feature of social media. If you follow a celebrity, it doesn't imply that s/he follows you.
2. **Undirected**: The edges don't have any direction. So if `A` and `B` are connected, we can assume that there is edge from both `A` to `B` and `B` to `A`.
Example: Social media graph, where if two persons are friend, it implies that both are friend with each other.
### Components of a Graph
**Vertices:** Vertices are the fundamental units of the graph. Sometimes, vertices are also known as vertex or nodes. Every node/vertex can be labeled or unlabelled.
**Edges:** Edges are drawn or used to connect two nodes of the graph. It can be ordered pair of nodes in a directed graph. Edges can connect any two nodes in any possible way. There are no rules. Sometimes, edges are also known as arcs. Every edge can be labeled/unlabelled.
Graphs are used to solve many real-life problems. Graphs are used to represent networks. The networks may include paths in a city or telephone network or circuit network. Graphs are also used in social networks like linkedIn, Facebook. For example, in Facebook, each person is represented with a vertex(or node). Each node is a structure and contains information like person id, name, gender, locale etc.
### Graph Representation:
Graph can be represented in the following ways:
**Set Representation:** Set representation of a graph involves two sets: Set of vertices V = {V1, V2, V3, V4} and set of edges E = {{V1, V2}, {V2, V3}, {V3, V4}, {V4, V1}}. This representation is efficient for memory but does not allow parallel edges.
**Sequential Representation:** This representation of a graph can be represented by means of matrices: Adjacency Matrix, Incidence matrix and Path matrix.
**Adjacency Matrix:** This matrix includes information about the adjacent nodes. Here, aij = 1 if there is an edge from Vi to Vj otherwise 0. It is a matrix of order V×V.
**Incidence Matrix:** This matrix includes information about the incidence of edges on the nodes. Here, aij = 1 if the jth edge Ej is incident on ith vertex Vi otherwise 0. It is a matrix of order V×E.
**Path Matrix:** This matrix includes information about the simple path between two vertices. Here, Pij = 1 if there is a path from Vi to Vj otherwise 0. It is also called as reachability matrix of graph G.
**Linked Representation:** This representation gives the information about the nodes to which a specific node is connected i.e. adjacency lists. This representation gives the adjacency lists of the vertices with the help of array and linked lists. In the adjacency lists, the vertices which are connected with the specific vertex are arranged in the form of lists which is connected to that vertex.
### Real-Time Applications of Graph:
Graphs are used to represent flow of control in computers.
Graphs are used in social networking sites where users act as nodes and connection between them acts as edges.
In an operating system, graphs are used as resource allocation graphs.
Graphs are used in Google maps to find the shortest route.
Graphs are also used in airlines system for effective route optimization.
In-state transition diagrams, the graph is used to represent their states and their transition.
In transportation, graphs are used to find the shortest path.
In circuits, graphs can be used to represent circuit points as nodes and wires as edges.
Graphs are used in solving puzzles with only one solution, such as mazes.
Graphs are used in computer networks for Peer to peer (P2P) applications.
Graphs basically in the form of DAG(Directed acyclic graph) are used as alternative to blockchain for cryptocurrency. For example crypto like IOTA, Nano are mainly based on DAG.
### Advantages of Graph:
By using graphs we can easily find the shortest path, neighbors of the nodes, and many more.
Graphs are used to implement algorithms like DFS and BFS.
It is used to find minimum spanning tree which has many practical applications.
It helps in organizing data.
Because of its non-linear structure, helps in understanding complex problems and their visualization.
### Disadvantages of Graph:
Graphs use lots of pointers which can be complex to handle.
It can have large memory complexity.
If the graph is represented with an adjacency matrix then it does not allow parallel edges and multiplication of the graph is also difficult.
### Representation
1. **Adjacency Lists**: Each node is represented as an entry and all the edges are represented as a list emerging from the corresponding node. So if vertex `1` has eadges to 2,3, and 6, the list corresponding to 1 will have 2,3 and 6 as entries. Consider the following graph.
```
0: 1-->2-->3
1: 0-->2
2: 0-->1
3: 0-->4
4: 3
```
It means there are edges from 0 to 1, 2 and 3; from 1 to 0 and 2 and so on.
2. **Adjacency Matrix**: The graph is represented as a matrix of size `|V| x |V|` and an entry 1 in cell `(i,j)` implies that there is an edge from i to j. 0 represents no edge.
The mtrix for the above graph:
```
0 1 2 3 4
0 0 1 1 1 0
1 1 0 1 0 0
2 1 1 0 0 0
3 1 0 0 0 1
4 0 0 0 1 0
```
没有合适的资源?快使用搜索试试~ 我知道了~
Java 算法实现代码.rar
共724个文件
java:693个
md:13个
yml:8个
需积分: 5 0 下载量 19 浏览量
2023-06-18
18:05:51
上传
评论
收藏 627KB RAR 举报
温馨提示
1.排序的定义: 所谓排序算法,即通过特定的算法因式将一组或多组数据按照既定模式进行重新排序。这种新序列遵循着一定的规则,体现出一定的规律,因此,经处理后的数据便于筛选和计算,大大提高了计算效率。 对于排序,我们首先要求其具有一定的稳定性,即当两个相同的元素同时出现于某个序列之中,则经过一定的排序算法之后,两者在排序前后的相对位置不发生变化。换言之,即便是两个完全相同的元素,它们在排序过程中也是各有区别的,不允许混淆不清。 排序(Sorting) 是计算机程序设计中的一种重要操作,它的功能是将一个数据元素(或记录)的任意序列,重新排列成一个关键字有序的序列。 2.排序的方式: 排序就是把集合中的元素按照一定的次序排序在一起,排序大的分类可以分为两种:内排序和外排序。在排序过程中,全部记录存放在内存,则称为内排序,如果排序过程中需要使用外存,则称为外排序。下面讲的排序都是属于内排序。 内排序有可以分为以下几类: 插入排序: 直接插入排序、二分法插入排序、希尔排序 选择排序: 简单选择排序、堆排序 交换排序: 冒泡排序、快速排序 归并排序 基数排序
资源推荐
资源详情
资源评论
收起资源包目录
Java 算法实现代码.rar (724个子文件)
.clang-format 4KB
CODEOWNERS 34B
Dockerfile 1KB
.gitignore 449B
AES.java 47KB
Blowfish.java 30KB
KDTree.java 13KB
FibonacciHeap.java 12KB
ClosestPair.java 12KB
MemoryManagementAlgorithms.java 12KB
SinglyLinkedList.java 12KB
DoublyLinkedList.java 12KB
DES.java 11KB
MatrixGraphs.java 11KB
SquareFreeIntegerTest.java 10KB
SkipList.java 10KB
LinkListSort.java 10KB
BinaryTree.java 9KB
BSTRecursiveGeneric.java 9KB
RedBlackBST.java 9KB
ConwayTest.java 9KB
CheckIfBinaryTreeBalanced.java 9KB
KochSnowflake.java 9KB
FFT.java 8KB
QuickSelectTest.java 8KB
HashMapCuckooHashing.java 8KB
Mandelbrot.java 8KB
ColumnarTranspositionCipher.java 7KB
Dijkstra.java 7KB
RgbHsvConversion.java 7KB
HorspoolSearch.java 7KB
A_Star.java 7KB
Deques.java 7KB
BankersAlgorithm.java 6KB
MazeRecursion.java 6KB
MatrixUtil.java 6KB
GenericTree.java 6KB
CRCAlgorithm.java 6KB
Luhn.java 6KB
BSTIterative.java 6KB
HillCipher.java 6KB
RegexMatching.java 6KB
MonteCarloTreeSearch.java 6KB
SkylineAlgorithm.java 6KB
Anagrams.java 6KB
AVLTree.java 6KB
Area.java 6KB
Verhoeff.java 6KB
PerlinNoise.java 6KB
AnyBaseToAnyBase.java 6KB
DynamicArray.java 6KB
BellmanFord.java 6KB
GrahamScan.java 5KB
BinarySearch2dArrayTest.java 5KB
SinglyLinkedListTest.java 5KB
PriorityQueues.java 5KB
SortingAlgorithmTest.java 5KB
CursorLinkedList.java 5KB
BufferedReader.java 5KB
MaxHeap.java 5KB
LazySegmentTree.java 5KB
MinHeap.java 5KB
Implementing_auto_completing_features_using_trie.java 5KB
QueueUsingTwoStacks.java 5KB
OptimalJobScheduling.java 5KB
NQueens.java 4KB
FFTTest.java 4KB
Kosaraju.java 4KB
EulerMethod.java 4KB
BSTRecursive.java 4KB
ColorContrastRatio.java 4KB
LRUCache.java 4KB
WordBoggle.java 4KB
StrassenMatrixMultiplication.java 4KB
LinearDiophantineEquationsSolver.java 4KB
TarjansAlgorithm.java 4KB
LinkedQueue.java 4KB
TopologicalSort.java 4KB
MRUCache.java 4KB
StackArray.java 4KB
CircularBufferTest.java 4KB
TrieImp.java 4KB
Kruskal.java 4KB
NodeStack.java 4KB
FibonacciJavaStreams.java 4KB
EditDistance.java 4KB
AESEncryption.java 4KB
Graphs.java 4KB
Queues.java 4KB
MiniMaxAlgorithm.java 4KB
QuickSelect.java 4KB
LFUCache.java 4KB
KnightsTour.java 4KB
InverseOfMatrix.java 4KB
DutchNationalFlagSortTest.java 4KB
Damm.java 4KB
SkylineProblem.java 4KB
InsertionSortTest.java 4KB
BFPRT.java 4KB
MinPriorityQueue.java 4KB
共 724 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
野生的狒狒
- 粉丝: 3392
- 资源: 2436
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功