Explore the Online Activity: The Bridges of Konigsberg – an early example of Graph Theory in Mathematics https://www.mathsisfun.com/activity/seven-bridges-konigsberg.html
Complete the Online Activity: Khan Academy. https://www.khanacademy.org/computing/computer-science/algorithms/graph-representation/a/describing-graphs
Try a graph terminology crossword from https://crosswordlabs.com/view/graph-theory-12 online, or print it out, check the solutions.
Try another graph terminology crossword from https://crosswordlabs.com/view/graph-theory-recap online, or print it out, check the solutions.
Need more examples? Checkout https://tech.io/playgrounds/5470/graph-theory-basics/basics
Examples of Graph Implementation in the Python3/Trinket using the library networkx Reference: Networkx tutorial are shown below.
Examples of Graph and other ADT Implementations in SnapApps/Edgy Follow along with this recorded tutorial session: https://youtu.be/hrhPu9X9HwA
Example 1:Graph Implementation in the Python3/Trinket using the library networkx Reference: Networkx tutorial
# 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('|V|=',G.number_of_nodes())
print('|E|=',G.number_of_edges())
# remove all nodes, edges from graph
G.clear()
Example 2: Directed Graph Implementation in the Python3/Trinket using the library networkx Reference: Networkx tutorial
# Python3/Trinket networkx examples
# https://networkx.org/documentation/stable/tutorial.html
import networkx as nx
DG = nx.DiGraph() # create a directed graph
DG.add_node(1, time='5pm') # add nodes and attributes
DG.add_nodes_from([3], time='2pm')
print(DG.nodes[1])
DG.add_edge(1, 3) # add edge
DG[1][3]['color'] = "blue" # assign edge attribute
print(DG.edges[1, 3])
# add edges and attributes
DG.add_edge(1, 2, weight=4.7 )
DG.add_edges_from([(3, 4), (4, 5)], color='red')
DG.add_edges_from([(1, 2, {'color': 'blue'}), (2, 3, {'weight': 8})])
DG[1][2]['weight'] = 4.7
print(DG.edges[2, 3])
# successors of node 1
print('children node 1 =',list(DG.successors(1)))