├── cycle0.txt ├── data0.txt ├── data1.txt ├── Unix ├── data0.txt ├── data1.txt ├── cycle0.txt ├── data0_rev.txt ├── data0_easy.txt └── slides.txt ├── data0_rev.txt ├── data0_easy.txt ├── .gitattributes ├── Project23.exe ├── slides.txt ├── Grading_Criteria.txt ├── Project23.cpp ├── runSolution.html └── README.md /cycle0.txt: -------------------------------------------------------------------------------- 1 | c100 c200 2 | c300 c200 c100 3 | c200 c100 -------------------------------------------------------------------------------- /data0.txt: -------------------------------------------------------------------------------- 1 | c100 2 | c300 c200 c100 3 | c200 c100 4 | -------------------------------------------------------------------------------- /data1.txt: -------------------------------------------------------------------------------- 1 | c100 2 | c300 c100 c200 3 | c200 c100 4 | -------------------------------------------------------------------------------- /Unix/data0.txt: -------------------------------------------------------------------------------- 1 | c100 2 | c300 c200 c100 3 | c200 c100 4 | -------------------------------------------------------------------------------- /Unix/data1.txt: -------------------------------------------------------------------------------- 1 | c100 2 | c300 c100 c200 3 | c200 c100 4 | -------------------------------------------------------------------------------- /data0_rev.txt: -------------------------------------------------------------------------------- 1 | c300 c200 c100 2 | c200 c100 3 | c100 4 | -------------------------------------------------------------------------------- /Unix/cycle0.txt: -------------------------------------------------------------------------------- 1 | c100 c200 2 | c300 c200 c100 3 | c200 c100 4 | -------------------------------------------------------------------------------- /Unix/data0_rev.txt: -------------------------------------------------------------------------------- 1 | c300 c200 c100 2 | c200 c100 3 | c100 4 | -------------------------------------------------------------------------------- /data0_easy.txt: -------------------------------------------------------------------------------- 1 | 1 c100 2 | 3 c300 c100 c200 3 | 2 c200 c100 4 | -------------------------------------------------------------------------------- /Unix/data0_easy.txt: -------------------------------------------------------------------------------- 1 | 1 c100 2 | 3 c300 c100 c200 3 | 2 c200 c100 4 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Project23.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fazeelkhalid/graph-real-time-problems/HEAD/Project23.exe -------------------------------------------------------------------------------- /slides.txt: -------------------------------------------------------------------------------- 1 | CSE1000 2 | CSE1001 CSE1000 CSE1004 3 | CSE1002 CSE1006 4 | CSE1003 CSE1002 CSE1006 5 | CSE1004 6 | CSE1005 CSE1004 CSE1000 CSE1001 CSE1002 7 | CSE1006 8 | -------------------------------------------------------------------------------- /Unix/slides.txt: -------------------------------------------------------------------------------- 1 | CSE1000 2 | CSE1001 CSE1000 CSE1004 3 | CSE1002 CSE1006 4 | CSE1003 CSE1002 CSE1006 5 | CSE1004 6 | CSE1005 CSE1004 CSE1000 CSE1001 CSE1002 7 | CSE1006 8 | -------------------------------------------------------------------------------- /Grading_Criteria.txt: -------------------------------------------------------------------------------- 1 | Grading criteria - Graphs (courses listed in topological order) 2 | 3 | 15 pts - Code correctly reads from the posted files. 4 | All 15 points will be lost if the 'easy' files are used (the ones that have the number of words at the beginning of each line - see details about this in the homework text). 5 | 6 | 10 pts - Correct mapping vertex number to course name is printed 7 | 25 pts - Correct edge information is created and printed (as either an adjacency matrix or adjacency list). The direction of each edge must be correct. Note that you do not need to draw an edge. The direction is inferred from your printing of the adjacency matrix or adjacency list. 8 | 9 | 10 pts - program correctly identifies if there is a cycle and prints a message about that and it does NOT attempt to print the courses in topological order. 10 | 11 | 20 pts - Courses are printed in correct topological order. It must show both the COURSE (e.g. c100 below) and the VERTEX number (e.g. vertex 0 below). 12 | " 13 | 1. - c100 (corresponds to graph vertex 0) 14 | 2. - c200 (corresponds to graph vertex 2) 15 | 3. - c300 (corresponds to graph vertex 1) 16 | " 17 | 18 | 6 pts - Test case that covers a special case is provided and a brief and clear explanation of what special case it is (e.g. why is it special). 19 | 20 | 14 pts - No Valgring errors. If any memory-related error is reported (including invalid read or invalid write) all points are lost. If "conditional jump depends on uninitilized variable" errors are present but no other memory related errors, 10 out of the 14 points will be lost. 21 | -------------------------------------------------------------------------------- /Project23.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | struct Graph 6 | { 7 | int numOfRows; 8 | int **matrix; 9 | }; 10 | 11 | typedef struct Graph Graph; 12 | 13 | int check(char ***allNodes, char *filename) 14 | { 15 | char ch; 16 | FILE *file; 17 | file = fopen(filename, "r"); // read mode 18 | 19 | if (file == NULL) 20 | { 21 | printf("Error .\n"); 22 | exit(EXIT_FAILURE); 23 | } 24 | 25 | char array[70]; 26 | char *subarray; 27 | int count = 0; 28 | int i = 0; 29 | // Determine the number of nodes 30 | while (!feof(file)) 31 | { 32 | fgets(array, 70, file); 33 | count++; 34 | } 35 | 36 | fseek(file, 0, SEEK_SET); 37 | 38 | *allNodes = (char **)malloc(count * sizeof(char)); 39 | while (i < count) 40 | { 41 | (*allNodes)[i] = (char *)malloc(sizeof(char) * 31); 42 | if ((*allNodes)[i] == NULL) 43 | printf("ERROR OUT OF MEMORY\n"); 44 | strcpy((*allNodes)[i], ""); 45 | 46 | i++; 47 | } 48 | 49 | int n = 0; 50 | // Get the string representation of all the nodes and store it in str_nodes for future references 51 | while (!feof(file)) 52 | { 53 | fgets(array, 1001, file); 54 | subarray = strtok(array, " \n"); 55 | //printf("After tikenize %s \n",); 56 | 57 | strcpy((*allNodes)[n], subarray); 58 | subarray = strtok(NULL, "\n"); 59 | n++; 60 | } 61 | fclose(file); 62 | return count; 63 | } 64 | 65 | int **NewMatrix(int nodes) 66 | { 67 | 68 | int **mat = (int **)malloc(sizeof(int *) * nodes); 69 | int i = 0; 70 | while (i < nodes) 71 | { 72 | mat[i] = (int *)malloc(sizeof(int) * nodes); 73 | i++; 74 | } 75 | return mat; 76 | } 77 | 78 | void createMatrix(char ***nodes, int count, char *filename) 79 | { 80 | char ch; 81 | FILE *file; 82 | file = fopen(filename, "r"); // read mode 83 | 84 | if (file == NULL) 85 | { 86 | perror("Error while opening the file.\n"); 87 | exit(EXIT_FAILURE); 88 | } 89 | char array[70]; 90 | char *subarray; 91 | 92 | *nodes = (char **)malloc(count * count * sizeof(char)); 93 | 94 | int n = 0; 95 | char *newsubarray; 96 | int i = 0; 97 | while (!feof(file)) 98 | { 99 | fgets(array, 1001, file); 100 | newsubarray = strtok(array, " "); 101 | while (newsubarray != NULL) 102 | { 103 | strcpy((*nodes)[n], newsubarray); 104 | newsubarray = strtok(NULL, " "); 105 | } 106 | n++; 107 | //n1=0; 108 | i++; 109 | } 110 | 111 | //printf("After tikenize %s \n", newsubarray[1]); 112 | fclose(file); 113 | //return newsubarray; 114 | //printf("After tikenize %s \n", newsubarray); 115 | } 116 | 117 | void readFile(Graph **g, char **str_nodes, int count, char *filename) 118 | { 119 | FILE *fp = fopen(filename, "r"); 120 | char line[1001]; 121 | char *subarray; 122 | int i = 0; 123 | while (!feof(fp)) 124 | { 125 | fgets(line, 1001, fp); 126 | subarray = strtok(line, " \n"); 127 | while (subarray != NULL) 128 | { 129 | if (strcmp(str_nodes[i], subarray) != 0) 130 | { 131 | 132 | int j = 0; 133 | //printf("VAlue of j is %d \n",j); 134 | int z = 0; 135 | while (z < count) 136 | { 137 | if (strcmp(str_nodes[z], subarray) == 0) 138 | j = z; 139 | z++; 140 | } 141 | 142 | (*g)->matrix[j][i] = 1; 143 | //add_edge(&(*g), j, i); 144 | } 145 | subarray = strtok(NULL, " \n"); 146 | } 147 | i++; 148 | } 149 | 150 | fclose(fp); 151 | } 152 | 153 | int main() 154 | { 155 | printf("Enter name of a file you wish to see\n"); 156 | char filename[100]; 157 | scanf("%s", filename); 158 | char **str_nodes; 159 | 160 | int numOfNodes = check(&str_nodes, filename); 161 | printf("Total Numbers of nodes are: %d", numOfNodes); 162 | 163 | //Create and Initialize a graph struct 164 | Graph *graph; 165 | graph = (Graph *)malloc(sizeof(Graph)); 166 | graph->numOfRows = numOfNodes; 167 | graph->matrix = NewMatrix(graph->numOfRows); 168 | 169 | int i = 0; 170 | while (i < numOfNodes) 171 | { 172 | int j = 0; 173 | while (j < numOfNodes) 174 | { 175 | graph->matrix[i][j] = 0; 176 | j++; 177 | } 178 | i++; 179 | } 180 | 181 | //Populate Graph 182 | readFile(&graph, str_nodes, numOfNodes, filename); 183 | 184 | //Print matrix 185 | printf("\n\n"); 186 | printf(" Matrix Are: \n"); 187 | printf(" "); 188 | i = 0; 189 | while (i < graph->numOfRows) 190 | { 191 | printf("%d ", i); 192 | i++; 193 | } 194 | printf("\n"); 195 | i = 0; 196 | while (i < graph->numOfRows) 197 | { 198 | printf(" %d ", i); 199 | int j = 0; 200 | while (j < graph->numOfRows) 201 | { 202 | printf(" %d", (graph->matrix)[i][j]); 203 | j++; 204 | } 205 | printf("\n"); 206 | i++; 207 | } 208 | 209 | //free memory 210 | i = 0; 211 | while (i < numOfNodes) 212 | free(str_nodes[i++]); 213 | free(str_nodes); 214 | i = 0; 215 | while (i < graph->numOfRows) 216 | { 217 | free(graph->matrix[i]); 218 | i++; 219 | } 220 | free(graph->matrix); 221 | 222 | return 0; 223 | } -------------------------------------------------------------------------------- /runSolution.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | runSolution 5 | 6 | 7 | 8 | In all the sample runs below the the user input is just the file name. 9 | 10 |

-------------Sample run showing execution when file not found.

11 |

 12 | gcc -g -std=c99 courses_graph.c
 13 | valgrind --leak-check=full ./a.out
 14 | ==25615== Memcheck, a memory error detector
 15 | ==25615== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
 16 | ==25615== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
 17 | ==25615== Command: ./a.out
 18 | ==25615==
 19 | 
 20 | This program will read, from a file, a list of courses and their prerequisites and will print the list in which to take cousres.
 21 | Enter filename: badName
 22 | Could not open file badName. Exit
 23 | 
 24 | Failed to read from file. Program will terminate.
 25 | 
 26 | ==25615==
 27 | ==25615== HEAP SUMMARY:
 28 | ==25615==     in use at exit: 0 bytes in 0 blocks
 29 | ==25615==   total heap usage: 1 allocs, 1 frees, 568 bytes allocated
 30 | ==25615==
 31 | ==25615== All heap blocks were freed -- no leaks are possible
 32 | ==25615==
 33 | ==25615== For counts of detected and suppressed errors, rerun with: -v
 34 | ==25615== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
 35 | 
36 | 37 | 38 | 39 |

-------------Sample run when there is a cycle in the graph.

40 |
valgrind --leak-check=full ./a.out
 41 | ==27653== Memcheck, a memory error detector
 42 | ==27653== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
 43 | ==27653== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
 44 | ==27653== Command: ./a.out
 45 | ==27653==
 46 | 
 47 | This program will read, from a file, a list of courses and their prerequisites and will print the list in which to take cousres.
 48 | Enter filename: cycle0.txt
 49 | Number of vertices in built graph:  N = 3
 50 | Vertex - coursename correspondence
 51 | 0 - c100
 52 | 1 - c300
 53 | 2 - c200
 54 | 
 55 | Adjacency matrix:
 56 |     |   0   1   2
 57 | -----------------
 58 |    0|   0   1   1
 59 |    1|   0   0   0
 60 |    2|   1   1   0
 61 | 
 62 | 
 63 | There was at least one cycle. There is no possible ordering of the courses.
 64 | 
 65 | ==27653==
 66 | ==27653== HEAP SUMMARY:
 67 | ==27653==     in use at exit: 0 bytes in 0 blocks
 68 | ==27653==   total heap usage: 9 allocs, 9 frees, 745 bytes allocated
 69 | ==27653==
 70 | ==27653== All heap blocks were freed -- no leaks are possible
 71 | ==27653==
 72 | ==27653== For counts of detected and suppressed errors, rerun with: -v
 73 | ==27653== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
 74 | 
 75 | 
76 | 77 |

-------------Sample run when there is no cycle in the graph.

78 |
valgrind --leak-check=full ./a.out
 79 | ==27818== Memcheck, a memory error detector
 80 | ==27818== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
 81 | ==27818== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
 82 | ==27818== Command: ./a.out
 83 | ==27818==
 84 | 
 85 | This program will read, from a file, a list of courses and their prerequisites and will print the list in which to take cousres.
 86 | Enter filename: data0.txt
 87 | Number of vertices in built graph:  N = 3
 88 | Vertex - coursename correspondence
 89 | 0 - c100
 90 | 1 - c300
 91 | 2 - c200
 92 | 
 93 | Adjacency matrix:
 94 |     |   0   1   2
 95 | -----------------
 96 |    0|   0   1   1
 97 |    1|   0   0   0
 98 |    2|   0   1   0
 99 | 
100 | 
101 | Order in which to take courses:
102 | 1. - c100 (corresponds to graph vertex 0)
103 | 2. - c200 (corresponds to graph vertex 2)
104 | 3. - c300 (corresponds to graph vertex 1)
105 | 
106 | ==27818==
107 | ==27818== HEAP SUMMARY:
108 | ==27818==     in use at exit: 0 bytes in 0 blocks
109 | ==27818==   total heap usage: 9 allocs, 9 frees, 745 bytes allocated
110 | ==27818==
111 | ==27818== All heap blocks were freed -- no leaks are possible
112 | ==27818==
113 | ==27818== For counts of detected and suppressed errors, rerun with: -v
114 | ==27818== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
115 | 
116 | 117 | 118 |

-------------Sample run for same courses as in data0.txt, but given in a different order in the file (data0_rev.txt).

119 |
valgrind --leak-check=full ./a.out
120 | ==5170== Memcheck, a memory error detector
121 | ==5170== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
122 | ==5170== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
123 | ==5170== Command: ./a.out
124 | ==5170==
125 | 
126 | This program will read, from a file, a list of courses and their prerequisites and will print the list in which to take cousres.
127 | Enter filename: data0_rev.txt
128 | Number of vertices in built graph:  N = 3
129 | Vertex - coursename correspondence
130 | 0 - c300
131 | 1 - c200
132 | 2 - c100
133 | 
134 | Adjacency matrix:
135 |     |   0   1   2
136 | -----------------
137 |    0|   0   0   0
138 |    1|   1   0   0
139 |    2|   1   1   0
140 | 
141 | 
142 | Order in which to take courses:
143 | 1. - c100 (corresponds to graph vertex 2)
144 | 2. - c200 (corresponds to graph vertex 1)
145 | 3. - c300 (corresponds to graph vertex 0)
146 | 
147 | ==5170==
148 | ==5170== HEAP SUMMARY:
149 | ==5170==     in use at exit: 0 bytes in 0 blocks
150 | ==5170==   total heap usage: 9 allocs, 9 frees, 745 bytes allocated
151 | ==5170==
152 | ==5170== All heap blocks were freed -- no leaks are possible
153 | ==5170==
154 | ==5170== For counts of detected and suppressed errors, rerun with: -v
155 | ==5170== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
156 | 
157 | 158 |

-------------Sample run for the graph on the slide for topological sorting.

159 | Note that the program produced the same start and finish time and the same vertex order (6,4,2,3,0,1,5). For grading and correctness checking, make sure you have the same mapping between course names and vertex numbers as shown in this sample run. 160 | 161 | 162 |
valgrind --leak-check=full ./a.out
163 | ==26380== Memcheck, a memory error detector
164 | ==26380== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
165 | ==26380== Using Valgrind-3.5.0 and LibVEX; rerun with -h for copyright info
166 | ==26380== Command: ./a.out
167 | ==26380==
168 | 
169 | This program will read, from a file, a list of courses and their prerequisites and will print the list in which to take cousres.
170 | Enter filename: slides.txt
171 | Number of vertices in built graph:  N = 7
172 | Vertex - coursename correspondence
173 | 0 - CSE1000
174 | 1 - CSE1001
175 | 2 - CSE1002
176 | 3 - CSE1003
177 | 4 - CSE1004
178 | 5 - CSE1005
179 | 6 - CSE1006
180 | 
181 | Adjacency matrix:
182 |     |   0   1   2   3   4   5   6
183 | ---------------------------------
184 |    0|   0   1   0   0   0   1   0
185 |    1|   0   0   0   0   0   1   0
186 |    2|   0   0   0   1   0   1   0
187 |    3|   0   0   0   0   0   0   0
188 |    4|   0   1   0   0   0   1   0
189 |    5|   0   0   0   0   0   0   0
190 |    6|   0   0   1   1   0   0   0
191 | 
192 | 
193 | Order in which to take courses:
194 | 1. - CSE1006 (corresponds to graph vertex 6)
195 | 2. - CSE1004 (corresponds to graph vertex 4)
196 | 3. - CSE1002 (corresponds to graph vertex 2)
197 | 4. - CSE1003 (corresponds to graph vertex 3)
198 | 5. - CSE1000 (corresponds to graph vertex 0)
199 | 6. - CSE1001 (corresponds to graph vertex 1)
200 | 7. - CSE1005 (corresponds to graph vertex 5)
201 | 
202 | ==26380==
203 | ==26380== HEAP SUMMARY:
204 | ==26380==     in use at exit: 0 bytes in 0 blocks
205 | ==26380==   total heap usage: 17 allocs, 17 frees, 1,093 bytes allocated
206 | ==26380==
207 | ==26380== All heap blocks were freed -- no leaks are possible
208 | ==26380==
209 | ==26380== For counts of detected and suppressed errors, rerun with: -v
210 | ==26380== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 4 from 4)
211 | 
212 | 213 | 214 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # graph-real-time-problems 2 | Points: 100 Topics: Graphs, topological sort, freedom to decide how to represent data and organize code (while still reading in a graph and performing topological sort) PLAGIARISM/COLLUSION: You should not read any code (solution) that directly solves this problem (e.g. implements DFS, topological sorting or other component needed for the homework). The graph representation provided on the Code page (which you are allowed to use in your solution) and the pseudocode and algorithm discussed in class provide all the information needed. If anything is unclear in the provided materials check with us. You can read materials on how to read from a file, or read a Unix file or how to tokenize a line of code, BUT not in a sample code that deals with graphs or this specific problem. E.g. you can read tutorials about these topics, but not a solution to this problem (or a problem very similar to it). You should not share your code with any classmate or read another classmate's code. Part 1: Main program requirements (100 pts) Given a list of courses and their prerequisites, compute the order in which courses must be taken so that when taking a courses, all its prerequisites have already been taken. All the files that the program would read from are in Unix format (they have the Unix EOL). Provided files: ● Grading Criteria ● cycle0.txt ● data0.txt ● data0_rev.txt ● data1.txt - like data0.txt but the order of the prerequisite courses is modified on line 2. ● slides.txt (graph image) - courses given in such a way that they produce the same graph as in the image. (The last digit in the course number is the same as the vertex corresponding to it in the drawn graph. You can also see this in the vertex-to-course name correspondence in the sample run for this file.) ● run.html● data0_easy.txt - If you cannot handle the above file format, this is an easier file format that you can use, but there will be 15 points lost in this case. More details about this situation are given in Part 3. ● Unix.zip - zipped folder with all data files. ● For your reference: EOL_Mac_Unix_Windows.png - EOL symbols for Unix/Mac/Windows Specifications: 1. You can use structs, macros, typedef. 2. All the code must be in C (not C++, or any other language) 3. Global or static variables are NOT allowed. The exception is using macros to define constants for the size limits (e.g. instead of using 30 for the max course name size). E.g. #define MAX_ARRAY_LENGTH 20 4. You can use static memory (on the frame stack) or dynamic memory. (Do not confuse static memory with static variables.) 5. The program must read from the user a filename. The filename (as given by the user) will include the extension, but NOT the path. E.g.: data0.txt 6. You can open and close the file however many times you want. 7. File format: 1. Unix file. It will have the Unix EOL (end-of-line). 2. Size limits: 1. The file name will be at most 30 characters. 2. A course name will be at most 30 characters 3. A line in the file will be at most 1000 characters. 3. The file ends with an empty new line. 4. Each line (except for the last empty line) has one or more course names. 5. Each course name is a single word (without any spaces). E.g. CSE1310 (with no space between CSE and 1310). 6. There is no empty space at the end of the line. 7. There is exactly one empty space between any two consecutive courses on the same line. (You do not need to worry about having tabs or more than one empty space between 2 courses.) The first course name on each line is the course being described and the following courses are the prerequisites for it. E.g. CSE2315 CSE1310 MATH1426 ENGL13018. The first line describes course CSE2315 and it indicates that CSE2315 has 2 prerequisite courses, namely: CSE1310 and MATH1426. The second line describes course ENG1301 and it indicates that ENG1301 has no prerequisites. 9. You can assume that there is exactly one line for every course, even for those that do not have prerequisites (see ENGL1301 above). Therefore you can count the number of lines in the file to get the total number of courses. 10.The courses are not given in any specific order in the file. 8. You must create a directed graph corresponding to the data in the file. 1. The graph will have as many vertices as different courses listed in the file. 2. You can represent the vertices and edges however you want. 3. You do NOT have to use a graph struct. If you can do all the work with just the 2D table (the adjacency matrix) that is fine. You HAVE TO implement the topological sorting covered in class (as this assignment is on Graphs), but you can organize, represent and store the data however you want. 4. For the edges, you can use either the adjacency matrix representation or the adjacency list. If you use the adjacency list, keep the nodes in the list sorted in increasing order. 5. For each course that has prerequisites, there is an edge, from each prerequisite to that course. Thus the direction of the edge indicates the dependency. The actual edge will be between the vertices in the graph corresponding to these courses. E.g. file data0.txt has: c100 c300 c200 c100 c200 c100 Meaning: c100-----> c200 \ | \ | \ | \ | \ | \ | V V c300(The above drawing is provided here to give a picture of how the data in the file should be interpreted and the graph that represents this data. Your program should *NOT* print this drawing. See the sample run for expected program output.) From this data you should create the correspondence: vertex 0 - c100 vertex 1 - c300 vertex 2 - c200 and you can represent the graph using adjacency matrix (the row and column indexes are provided for convenience): | 0 1 2 ----------------- 0| 0 1 1 1| 0 0 0 2| 0 1 0 e.g. E[0][1] is 1 because vertex 0 corresponds to c100 and vertex 1 corresponds to c300 and c300 has c100 as a prerequisite. Notice that E[1][0] is not 1. If you use the adjacency list representation, then you can print the adjacency list. The list must be sorted in increasing order (e.g. see the list for 0). It should show the corresponding node numbers. E.g. for the above example the adjacency list will be: 0: 1, 2, 1: 2: 1, 6. 7. In order for the output to look the same for everyone, use the correspondence given here: vertex 0 for the course on the first line, vertex 1 for the course on the second line, etc. 1. Print the courses in topological sorted order. This should be done using the DFS (Depth First Search) algorithm that we covered in class and the topological sorting based on DFS discussed in class. There is no topological order if there is a cycle in the graph; in this case print an error message. If in DFV-visit when looking at the (u,v) edge, if the color of v is GRAY then there is a cycle in the graph (and therefore topological sorting is not possible). See the Lecture on topological sorting (You can find the date based on the table on the Scans page and then watch the video from that day. I have also updated the pseudocodein the slides to show that. Refresh the slides and check the date on the first page. If it is 11/26/2020, then you have the most recent version.) 8. (6 points) create and submit 1 test file. It must cover a special case. Indicate what special case you are covering (e.g. no course has any prerequisite). At the top of the file indicate what makes it a special case. Save this file as special.txt. It should be in Unix EOL format. Part 2: Suggestions for improvements (not for grade) 1. CSE Advisors also are mindful and point out to students the "longest path through the degree". That is longest chain of course prerequisites (e.g. CSE1310 ---> CSE1320 --> CSE3318 -->...) as this gives a lower bound on the number of semesters needed until graduation. Can you calculate for each course the LONGEST chain ending with it? E.g. in the above example, there are 2 chains ending with c300 (size 2: just c100-->c300, size 3: c100-->c200-->c300) and you want to show longest path 3 for c300. Can you calculate this number for each course? 2. Allow the user the enter a list of courses taken so far (from the user or from file) and print a list of the courses they can take (they have all the prerequisites for). 3. Ask the user to enter a desired number of courses per semester and suggest a schedule (by semester). Part 3: Implementation suggestions 1. Reading from file: (15 points) For each line in the file, the code can extract the first course and the prerequisites for it. If you cannot process each line in the file correctly, you can use a modified input file that shows on each line, the number of courses, but you would lose the 15 points dedicated to line processing. If your program works with the "easy files", in order to make it easy for the TAs to know which file to provide, please name your C program courses_graph_easy.c. Here is the modification shown for a new example. Instead of c100 c300 c200 c100 c200 the file would have: 1 c1003 c300 c200 c100 1 c200 1. that way the first data on each line is a number that tells how many courses (strings) follow after it on that line. Everything is separated by exactly one space. All the other specifications are the same as for the original file (empty line at the end, no space at the end of any line, length of words, etc). Here is data0_easy.txt Make a direct correspondence between vertex numbers and course names. E.g. the **first** course name on the first line corresponds to vertex 0, the **first** course name on the second line corresponds to vertex 1, etc... 2. 3. The vertex numbers are used to refer to vertices. 4. In order to add an edge in the graph you will need to find the vertex number corresponding to a given course name. E.g. find that c300 corresponds to vertex 1 and c200 corresponds to vertex 2. Now you can set E[2][1] to be 1. (With the adjacency list, add node 1 in the adjacency list for 2 keeping the list sorted.) To help with this, write a function that takes as arguments the list/array of [unique] course names and one course name and returns the index of that course in the list. You can use that index as the vertex number. (This is similar to the indexOf method in Java.) 5. To see all the non-printable characters that may be in a file, find an editor that shows them. E.g. in Notepad++ : open the file, go to View -> Show symbol -> Show all characters. YOU SHOULD TRY THIS! In general, not necessarily for this homework, if you make the text editor show the white spaces, you will know if what you see as 4 empty spaces comes from 4 spaces or from one tab or show other hidden characters. This can help when you tokenize. E.g. here I am using Notepad++ to see the EOL for files saved with Unix/Mac/Windows EOL (see the CR/LF/CRLF at the end of each line): EOL_Mac_Unix_Windows.png How to submit Submit courses_graph.c (or courses_graph_easy.c) and special.txt (the special test case you created) in Canvas . (For courses_graph_easy.c you can submit the "easy" files that you created.)Your program should be named courses_graph.c if it reads from the normal/original files. If instead it reads from the 'easy' files, name it courses_graph_easy.c As stated on the course syllabus, programs must be in C, and must run on omega.uta.edu or the VM. IMPORTANT: Pay close attention to all specifications on this page, including file names and submission format. Even in cases where your answers are correct, points will be taken off liberally for non-compliance with the instructions given on this page (such as wrong file names, wrong compression format for the submitted code, and so on). The reason is that non-compliance with the instructions makes the grading process significantly (and unnecessarily) more time consuming. Contact the instructor or TA if you have any questions 3 | --------------------------------------------------------------------------------