Nickles

30 Reputation

2 Badges

10 years, 119 days

MaplePrimes Activity


These are questions asked by Nickles

So if I have a procedure like 

with(GraphTheory)

tneighbors := proc (G::Graph)

local numvertices::integer, i::integer, currentvertex;

numvertices := nops(Vertices(G));

for i to numvertices do

currentvertex := Vertices(G)[i];

if nops(Neighbors(G, currentvertex)) = 2 then print(currentvertex)

end if;

end do;

end proc;

How do I make it so the output gets returned as a set?

For example, if I do  twoneighbors(G); and get
1

7

4

How do I make it so the output is listed as a set like {1,4,7}? Thanks.

I need to write a procedure that returns the cut vertices of a graph, but I think I'm having trouble defining my local variables. This is what I have so far.  I think my error might be in defining H since that's the line the error message I get keeps referencing.  Am I defining H incorrectly or in the wrong spot? Any advice would be appreciated. Thanks


cutvertices := proc (G)

local numvertices::integer, currentvertex, i::integer, H;

description "Returns a set of all the cut-vertices of the given graph";

numvertices := nops(Vertices(G));

for i to numvertices do

currentvertex := Vertices(G)[i]

H:=DeleteVertex(G, currentvertex)

 

if nops(ConnectedComponents(G)) = nops(ConnectedComponents(H)) then print(currentvertex)

end if;

end do;

end proc:

I have a question that says write a procedure that takes a random graph and three edges of that graph and returns true if those edges share a common vertex. So I was thinking of something along the lines of

proc55 := proc (G, {a, b}, {c, d})

if evalb({a, b} = {a, c} or {a, b} = {a, d} or {a, b} = {b, c} or {a, b} = {b, d}) then print(true)

else print(false)

end if;

end proc;

 

I guess my main question is how do I put edges in the parameters line? It will let me write proc (G, a, b, c, d) but not proc (G, {a, b}, {c, d}).

Is there just something I'm missing or am I approaching this in the wrong way?

 

1 2 Page 2 of 2