Question

In: Computer Science

This is the homework given by the teacher. I don't have more information Complete the below...

This is the homework given by the teacher. I don't have more information

Complete the below code so that your program generates a random walk on the given graph. The length of your walk should also be random.

/******************************************************************/

#include
#include
#include

typedef struct NODE_s *NODE;
typedef struct NODE_s{
   char name;
   NODE link[10];
}NODE_t[1];

#define nodeA 0
#define nodeB 1
#define nodeC 2
#define nodeD 3
#define nodeE 4
#define nodeF 5

int main() {
   srandom(time(NULL));
   //printf("%d\n", random());

   NODE_t node[6];
   node[nodeA]->name = 'A';
   node[nodeB]->name = 'B';
   node[nodeC]->name = 'C';
   node[nodeD]->name = 'D';
   node[nodeE]->name = 'E';
   node[nodeF]->name = 'F';

   int i, j;
   for (i = 0; i < 6; i++) {
       for (j = 0; j < 10; j++) {
           node[i]->link[j] = NULL;
       }
   }

   //a -> c,d,e,f.
   node[nodeA]->link[0] = node[nodeC];
   node[nodeA]->link[1] = node[nodeD];
   node[nodeA]->link[2] = node[nodeE];
   node[nodeA]->link[3] = node[nodeF];

   //b -> c,f.
   node[nodeB]->link[0] = node[nodeC];
   node[nodeB]->link[1] = node[nodeF];

   //c -> a,b,e.
   node[nodeC]->link[0] = node[nodeA];
   node[nodeC]->link[1] = node[nodeB];
   node[nodeC]->link[2] = node[nodeE];

   //d -> a,e,f.
   node[nodeD]->link[0] = node[nodeA];
   node[nodeD]->link[1] = node[nodeE];
   node[nodeD]->link[2] = node[nodeF];

   //e -> a,c,d.
   node[nodeE]->link[0] = node[nodeA];
   node[nodeE]->link[1] = node[nodeC];
   node[nodeE]->link[2] = node[nodeD];

   //f -> a,b,d.
   node[nodeF]->link[0] = node[nodeA];
   node[nodeF]->link[1] = node[nodeB];
   node[nodeF]->link[2] = node[nodeD];

   //Random walk.

   int choice = random() % 6;
   printf("%c\n", node[choice]->name);

   return 0;
}

/******************************************************************/


random walk on a graph . complete the form,then choose the appropriate button at the bottom.   

Solutions

Expert Solution

May be the code is like this:

include <stdio.h>
#include<math.h>
#include<time.h>

typedef struct NODE_s *NODE;
typedef struct NODE_s{
   char name;
   NODE link[10];
}NODE_t[1];

#define nodeA 0
#define nodeB 1
#define nodeC 2
#define nodeD 3
#define nodeE 4
#define nodeF 5

int main() {
   srandom(time(NULL));
   //printf("%d\n", random());

   NODE_t node[6];
   node[nodeA]->name = 'A';
   node[nodeB]->name = 'B';
   node[nodeC]->name = 'C';
   node[nodeD]->name = 'D';
   node[nodeE]->name = 'E';
   node[nodeF]->name = 'F';

   int i, j;
   for (i = 0; i < 6; i++) {
       for (j = 0; j < 10; j++) {
           node[i]->link[j] = NULL;
       }
   }

   //a -> c,d,e,f.
   node[nodeA]->link[0] = node[nodeC];
   node[nodeA]->link[1] = node[nodeD];
   node[nodeA]->link[2] = node[nodeE];
   node[nodeA]->link[3] = node[nodeF];

   //b -> c,f.
   node[nodeB]->link[0] = node[nodeC];
   node[nodeB]->link[1] = node[nodeF];

   //c -> a,b,e.
   node[nodeC]->link[0] = node[nodeA];
   node[nodeC]->link[1] = node[nodeB];
   node[nodeC]->link[2] = node[nodeE];

   //d -> a,e,f.
   node[nodeD]->link[0] = node[nodeA];
   node[nodeD]->link[1] = node[nodeE];
   node[nodeD]->link[2] = node[nodeF];

   //e -> a,c,d.
   node[nodeE]->link[0] = node[nodeA];
   node[nodeE]->link[1] = node[nodeC];
   node[nodeE]->link[2] = node[nodeD];

   //f -> a,b,d.
   node[nodeF]->link[0] = node[nodeA];
   node[nodeF]->link[1] = node[nodeB];
   node[nodeF]->link[2] = node[nodeD];

   //Random walk.

   int choice = random() % 6;
   printf("%c\n", node[choice]->name);

Int lenthofwalk = random%6;

Printf("%c",choice.lenth);

   return 0;
}


Related Solutions

I have a homework class, but I don't really understand anything and I have to submit...
I have a homework class, but I don't really understand anything and I have to submit my homework next week. Homework must be written in C ++ program language. Can someone help me please... Working with classes (everything written below is one task): Define a class Date that contains integer variables for day, month, and year. 1.1. Create the necessary methods for the class: set, get, default constructor, constructor with arguments. 1.2. Create a method that calculates the number of...
My Teacher keeps telling me I don't have a Thesis. I thought I hada good thesis....
My Teacher keeps telling me I don't have a Thesis. I thought I hada good thesis. Please help! Bud Light in advertising             One of the most effective ways for businesses to thrive is to use effective advertising, whether the ad is on TV, magazines, social media or even movies. The goal is to create enticement for a purchase over the competitor’s product. Budweiser is great example of a billion dollar company that has always maintained a strong record of...
Below is a diffraction problem. I have the solutions to the problem but I don't know...
Below is a diffraction problem. I have the solutions to the problem but I don't know how to arrive at these solutions. A) In an experiment two slits are separated by 0.22mm and illuminated by light of wavelength 640nm. How far must a screen be placed in order for the bright fringes to be separated by 5 mm? (1.72 m) B) A soap film is illuminated by white light normal to its surface. The index of refraction of the film...
I have trouble when solving this problem. I don't understand "There are more than half of...
I have trouble when solving this problem. I don't understand "There are more than half of the Final scores " could refer to which? Please help me in solving this. Test the hypothesis that there are more than half of the Final scores that are 5 or below, at the significance level of 5%. Final Scores 9.2 4.8 6.6 5.8 3.4 5 5.8 3.4 2.2
More than anything I need 5 - 7 of this homework. You have been asked by...
More than anything I need 5 - 7 of this homework. You have been asked by your supervisors at A&L Engineering to design a roller coaster for a new theme park. Because this design is in the initial stages, you have been asked to create a track for the ride. Your coaster should have at least two peaks and two valleys, and launch from an initial height of 75 meters. Each peak and valley should represent a vertical change of...
Hi! I have a homework question I'm not sure if I'm doing it correctly. Below is...
Hi! I have a homework question I'm not sure if I'm doing it correctly. Below is the information from the question and my answer in bold. Glass Company makes glass orders based on the customer specifications, so the company uses job costing to track costs. The company uses direct labor hours as the cost driver for manufacturing overhead application. Manufacturing overhead costs for the year:        $787,500 Usage of direct labor hours for the year:               225,000 Beginning Work-in-process, March 1 (Job 57)      $80,000 Beginning...
I have this homework and i have to prepare a case study for it  Develop...
I have this homework and i have to prepare a case study for it  Develop a case study or scenario on a business/economics/related area problem.  Collect and define a set of data on this scenario.  Summarize and analyze the data set by using R-program, or Excel or SPSS.  Apply at least five statistical data description techniques (descriptive measures),  Then solve your case problems by using confidence intervals, determining sample size, hypothesis testing ( single population,...
Given the information below, complete the following requirements: A. Rank the customers by their gross margin...
Given the information below, complete the following requirements: A. Rank the customers by their gross margin as a percent of sales revenue. B. Perform customer profitability analysis by generating an operating income for each customer segment through the use of activity-based costing. C. Rank segments by their respective operating income as a percent of sales. D. If the relative rankings of the segments using operating income as a percent of sales is different from the relative rankings using gross margin...
I have a problem, and I have the answer but I don't know where the solution...
I have a problem, and I have the answer but I don't know where the solution comes from. ( I have to be able to solve these myself so please help me by answering the questions about the problem.) Here is the answer given to me by the professor: What is the density of SF4 vapor at 650 torr and 100 C? 650 torr (1atm/760 Torr)=0.855atm 100C=373K PV=nRT n/v=P/RT= 0.855atm/0.8206l-atm/molek) (373)=0.0279 mole/l M.W. of SF4=108.1 gm/mole Density=mass/volume 0.0279 mole/l(108.1gm/mole) Answer...
I have homework on this but I am not sure how to solve it and which...
I have homework on this but I am not sure how to solve it and which formula to use in excel, can u please help me Rebecca is considering buying a 2019 Genesis G70 costing $37,900 and finds that the retaining values of the vehicle over the next four years are as follows: Percent of the total value retained after 24 months: 71% Percent of the total value retained after 48 months: 53% If her interest rate is 5% compounded...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT