I could use some help with simply pseudocode for a program in C I\'m writing: Th
ID: 3673871 • Letter: I
Question
I could use some help with simply pseudocode for a program in C I'm writing: The program will produce a maze using Prim's algorithm and the idea of a MST (minimal spanning tree). The edges of the gridgraph (of asterisks to represent a sort of GUI) produced will be different everytime because arbitrary (random) weights will be assigned everytime it runs as to produce a different maze everytime (accoring to the input from the user). The gridgraph will always be a perfect square (9, 25, 36, etc.[input from user]), and will be printed to the terminal (ultimately a file, but we'll leave that part out). The only input will be the square number of the random maze fo be made and -1 to quit. Also, the maze entrance will always be the top left of the graph, and the exit will be the bottom right. I have visited many websites with these algorithms but I cannot seem to adapt them as I need them for my program.
Explanation / Answer
hi these algorithms are may be help you for your program
For Perfect Square
1.Random Generated gridGraph Algorithm:
def dense_gnm_random_graph(n, m, seed=None):
"""Returns a `G_{n,m}` random graph.
In the `G_{n,m}` model, a graph is chosen uniformly at random from the set
of all graphs with `n` nodes and `m` edges.
This algorithm should be faster than :func:`gnm_random_graph` for dense
graphs.
Parameters
----------
n : int
The number of nodes.
m : int
The number of edges.
seed : int, optional
Seed for random number generator (default=None).
See Also
--------
gnm_random_graph()
References
----------
.. [1] Donald E. Knuth, The Art of Computer Programming,
Volume 2/Seminumerical algorithms, Third Edition, Addison-Wesley, 1997.
"""
mmax=n*(n-1)/2
if m>=mmax:
G=complete_graph(n)
else:
G=empty_graph(n)
G.name="dense_gnm_random_graph(%s,%s)"%(n,m)
if n==1 or m>=mmax:
return G
if seed is not None:
random.seed(seed)
u=0
v=1
t=0
k=0
while True:
if random.randrange(mmax-t)<m-k:
G.add_edge(u,v)
k+=1
if k==m: return G
t+=1
v+=1
if v==n: # go to next row of adjacency matrix
u+=1
v =u+1
2. Prim's algorithm
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.