▲ 2 r/vce
Graph ADT signatures & Free Algorithmics Study Resources
Graphs as Abstract data types (ADTs) have signatures that define the standard operations in terms of the inputs and outputs that are required to apply them.
| Graph ADT Operations as defined by Signatures | |
|---|---|
| name graph; import node,edge,list,integer,boolean; operations newGraph:→graph; allNodes:graph→list; allEdges:graph→list; addNode:graph×node→graph; deleteNode:graph×node→graph; NodeExists:graph×node→boolean; addEdge:graph×edge→graph; deleteEdge:graph×edge→graph; EdgeExists:graph×edge→boolean; neighbours:graph×node→list; startNode:edge→node; endNode:edge→node; incident:graph×node→list; | # Python3/Trinket networkx examples # https://networkx.org/documentation/stable/tutorial.html import networkx as nx G = nx.Graph() # create a graph G.add_node(1) # add node 1 G.add_nodes_from([1,2,3]) # add from list G.add_edge(1,2) # add edge G.add_edges_from([(1,2),(1,3)]) # add from list print('degree of node 1=',G.degree(1)) # degree of node 1 print('neighbors of node 1=',list(G.neighbors(1))) # neighbors of node 1 # all the nodes print('all the nodes=',G.nodes) G.remove_node(2) # remove node 2 G.remove_edge(1,3) # remove edge # all the edges print('all the edges=',G.edges) print(' |
u/Dry_Style8831 — 3 days ago