Below is the following study question, with the book example, along with my atte
ID: 3748839 • Letter: B
Question
Below is the following study question, with the book example, along with my attempt at getting something to work.
Modify the “Graph” program given in the textbook (program 4.5.1) to create a program, “SubGraph,” by adding a method “subgraph()” that takes a SET as its argument and returns the induced subgraph. [MO7.2]
Note: The induced subgraph is the graph comprised of the specified vertices together with all edges from the original graph that connect any two of them.
Also modify the main method so that you would get the following sample runs.
>more graph.txt
A B
A C
C G
A G
H A
B C
B H
>more subgraph.txt
A C G
>java SubGraph subgraph.txt < graph.txt
The graph is
A: B C G H
B: A C H
C: A B G
G: A C
H: A B
The subgraph is
A: C G
C: A
G: A C
My current attempt:
public class Graph
{
private ST<String, SET<String>> st;
public Graph(){
st = new ST<String, SET<String>>(); }
public void addEdge(String v, Strin w){
//Put v in w's SET and w in v's SET.
if (!st.contains(v)) st.put(v, new SET<String>());
if (!st.contains(w)) st.put(w, new SET<String>());
st.get(v).add(w);
st.get(w).add(v);
}
public Iterable<String> adjacentTo(String v){
return st.get(v); }
public Iterable<String> vertices(){
return st.keys(); }
public static void main(String[] args) {
In in = new In(args[0]);
String[] data = in.readAllLines();
String[] tokens = data[0].split(" ");
SET<String> set = new SET<String>();
for(int i = 0; i < tokens.length; i++)
set.add(tokens[i]);
subgraph(set);
}
public static void subgraph(SET <String> set) {
Graph graph = new Graph(), subGraph = new Graph();
while (!StdIn.isEmpty()) {
String v = StdIn.readString();
String w = StdIn.readString();
if(set.contains(v) && set.contains(w))
subGraph.addEdge(v, w);
graph.addEdge(v, w);
}
// print out graph
StdOut.println("The graph is: ");
StdOut.println(graph);
StdOut.println("The subgraph is: ");
StdOut.println(subGraph);
}
}
Explanation / Answer
Answer 1:
After reading the given paper the four key things that I have learned about the topic are as follows:
Answer 2:
After going through the paper, I can relate many activities to my past job. In Infosys many of these activities are employed to keep employee motivated and increase their productivity.
Some of the activities that my past organization implemented were: Employee recognition programs:These programs keeps the employees motivated and keep their moral to work for employer high.
Complimentary food and snack: In order to appreciate employees for their contribution made in success of organization.
Company gyms: The company also has a gym at its premises. It is complimentary for employees.
Answer 3:
Although all the activities mentioned in the paper are appreciated by many, I would like to throw light on some of the impacts that are not fruitful for the organization.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.