top of page

Graph Implementation in Ruby

A graph consists of nodes and edges. An edge is an (unordered) pair of two distinct nodes in the graph. We create a new empty graph from the class Graph. We use the add_node method to add a single node and the add_nodes method to add multiple nodes. Nodes are identified by unique symbols. We call add_edge with two nodes to add an edge between a pair of nodes belonging to the graph. We can also ask a graph for the number of nodes and edges it contains, and for a list of its nodes and edges. The to_s method returns a string representing the graph's adjacency lists.

Methods should not change the graph if called with invalid arguments, e.g., adding an edge that is already in the graph or that references a node that does not already belong to the graph. Your code does not have to generate the exact transcript that follows but it should provide this basic functionality. (make the code simple as you can with comments, do not use require_relative)


if you need solution of this assignment please send your assignment solution request at contact@codersarts.com and you can buy source code at minimum charge

We provide programming assignment help, programming assignment solution on demands at affordable price rate. If you need help/solution simply reply to chat, we are online to help you or send your assignment request at contact@codersarts.com

Comments


bottom of page