#graph adjacency matrix c code
Explore tagged Tumblr posts
Text
Write a C Program for Creation of Adjacency Matrix
Creation of Adjacency Matrix Write a C Program for Creation of Adjacency Matrix. Here’s simple Program for adjacency matrix representation of graph in data structure in C Programming Language. Adjacency Matrix: Adjacency Matrix is a 2D array of size V x V where V is the number of vertices in a graph. Let the 2D array be adj[][], a slot adj[i][j] = 1 indicates that there is an edge from vertex i…
View On WordPress
#adjacency list implementation of graph in c#adjacency list representation of directed graph#adjacency matrix#adjacency matrix example#adjacency matrix graph program in c#adjacency matrix representation#adjacency matrix representation of graph#adjacency matrix representation of graph in c#adjacency matrix representation of graph in c program#adjacency matrix representation of graph in data structure#c data structures#c graph programs#C program to create graph using adjacency matrix method#C Program to Represent Graph Using Adjacency Matrix#graph adjacency matrix c code
0 notes
Text
R Packages worth a look
Blyth-Still-Casella Exact Binomial Confidence Intervals (BlythStillCasellaCI) Computes Blyth-Still-Casella exact binomial confidence intervals based on a refining procedure proposed by George Casella (1986) . Genome-Wide Structural Equation Modeling (gwsem) Melds genome-wide association tests with structural equation modeling (SEM) using ‘OpenMx’. This package contains low-level C/C++ code to rapidly read genetic data encoded in U.K. Biobank or ‘plink’ formats. Prebuilt modeling options include one and two factor models. Alternately, analyses may utilize arbitrary, user-provided SEMs. See Verhulst, Maes, & Neale (2017) for details. An updated manuscript is in preparation. Food Network Inference and Visualization (foodingraph) Displays a weighted undirected food graph from an adjacency matrix. Can perform confidence-interval bootstrap inference with mutual information or maximal information coefficient. Based on my Master 1 internship at the Bordeaux Population Health center. References : Reshef et al. (2011) , Meyer et al. (2008) , Liu et al. (2016) . Varying Coefficients (varycoef) Gives maximum likelihood estimation (MLE) method to estimate and predict spatially varying coefficient (SVC) Models. It supports covariance tapering by Furrer et al. (2006) to allow MLE on large data. An Extension of the Taylor Diagram to Two-Dimensional Vector Data (SailoR) A new diagram for the verification of vector variables (wind, current, etc) generated by multiple models against a set of observations is presented in this package. It has been designed as a generalization of the Taylor diagram to two dimensional quantities. It is based on the analysis of the two-dimensional structure of the mean squared error matrix between model and observations. The matrix is divided into the part corresponding to the relative rotation and the bias of the empirical orthogonal functions of the data. The full set of diagnostics produced by the analysis of the errors between model and observational vector datasets comprises the errors in the means, the analysis of the total variance of both datasets, the rotation matrix corresponding to the principal components in observation and model, the angle of rotation of model-derived empirical orthogonal functions respect to the ones from observations, the standard deviation of model and observations, the root mean squared error between both datasets and the squared two-dimensional correlation coefficient. See the output of function UVError() in this package. http://bit.ly/3bch6ED
0 notes
Text
R Packages worth a look
Blyth-Still-Casella Exact Binomial Confidence Intervals (BlythStillCasellaCI) Computes Blyth-Still-Casella exact binomial confidence intervals based on a refining procedure proposed by George Casella (1986) . Genome-Wide Structural Equation Modeling (gwsem) Melds genome-wide association tests with structural equation modeling (SEM) using ‘OpenMx’. This package contains low-level C/C++ code to rapidly read genetic data encoded in U.K. Biobank or ‘plink’ formats. Prebuilt modeling options include one and two factor models. Alternately, analyses may utilize arbitrary, user-provided SEMs. See Verhulst, Maes, & Neale (2017) for details. An updated manuscript is in preparation. Food Network Inference and Visualization (foodingraph) Displays a weighted undirected food graph from an adjacency matrix. Can perform confidence-interval bootstrap inference with mutual information or maximal information coefficient. Based on my Master 1 internship at the Bordeaux Population Health center. References : Reshef et al. (2011) , Meyer et al. (2008) , Liu et al. (2016) . Varying Coefficients (varycoef) Gives maximum likelihood estimation (MLE) method to estimate and predict spatially varying coefficient (SVC) Models. It supports covariance tapering by Furrer et al. (2006) to allow MLE on large data. An Extension of the Taylor Diagram to Two-Dimensional Vector Data (SailoR) A new diagram for the verification of vector variables (wind, current, etc) generated by multiple models against a set of observations is presented in this package. It has been designed as a generalization of the Taylor diagram to two dimensional quantities. It is based on the analysis of the two-dimensional structure of the mean squared error matrix between model and observations. The matrix is divided into the part corresponding to the relative rotation and the bias of the empirical orthogonal functions of the data. The full set of diagnostics produced by the analysis of the errors between model and observational vector datasets comprises the errors in the means, the analysis of the total variance of both datasets, the rotation matrix corresponding to the principal components in observation and model, the angle of rotation of model-derived empirical orthogonal functions respect to the ones from observations, the standard deviation of model and observations, the root mean squared error between both datasets and the squared two-dimensional correlation coefficient. See the output of function UVError() in this package. http://bit.ly/2vxp7DN
0 notes
Text
CSCI203/CSCI803 ASSIGNMENT 3 Solved
This assignment involves an extension to the single source - single destination shortest path problem.
The Program
Your program should: Open the text file “ass3.txt”. (Note: “ass3.txt” should be a hardcoded as a constant.) Read a graph from the file. Find the shortest path between the start and goal vertices specified in the file. Print out the vertices on the path, in order from start to goal. Print out the length of this path and the total number of vertices visited. Devise a strategy for determining the second shortest path between the vertices. Find the second shortest path between the start and goal vertices specified in the file. Print out the vertices on the path, in order from start to goal. Print out the length of this path and the total number of vertices visited. Optimize your shortest and second shortest path algorithms to improve their performance. The data files are constructed as follows: Two integers: nVertices and nEdges, the number of vertices and edges in the graph. nVertices triples consisting of the label and the x- and y-coordinates of each vertex. nEdges triples consisting of the labels of the start and end vertices of each edge, along with its weight. Note: the weight associated with an edge will be greater than or equal to the Euclidean distance between its start and end vertices as determined by their coordinates. Two labels, the indicating the start and goal vertices for which the paths are required. A proposed solution to the second shortest path problem is as follows: For each edge ei on the shortest path: Find the shortest path on (V, E – {ei}). // shortest path without edge ei The shortest of these is the second shortest path.
Questions
Think about this! Is this proposed solution correct always? What if we require that the second shortest path be longer than the shortest path? What if the graph contains cycles? What if the graph is undirected? Explain your answers. If necessary explain how you might modify the proposed algorithm to address any issues that you identify. Note: you may implement either the proposed solution or any modification you develop. You are not required to implement a modified proposal if you do not wish to do so.
Step-1 (Week-10 demo, 2 marks)
For step 1, you should read the data file into adjacency lists, or an adjacency matrix, and print on the screen the first 5 vertices and the vertices they are connected to together with their weights. e.g.: a: c(35) d(27) e(48) b: d(35) g(27) c: b(125) e(20) f(56) h(31) . . . Note: The data shown above is for format purposes only.
Step-2 (Discovering the Shortest Path) (2 marks)
For step 2, you should implement Dijkstra's algorithm and find the shortest path between the start and goal vertices specified in the input file. Print out the vertices on the path (in order from start to goal), the length of this path and the total number of nodes visited by the algorithm to discover the shortest path.
Step-3 (Discovering the Second Shortest Path) (4 marks)
For step 3, you should devise a strategy for determining the second shortest path between the start and goal vertices specified in the file and implement your solution. Print out the vertices on the path (in order from start to goal), the length of this path and the total number of nodes visited by the algorithm to discover the second shortest path.
Step-4 (Optimisation) (2 marks)
For step 4, implement the A* algorithm and repeat Step-2 and Step-3. Print the same information to show the improved performance.
Step-5 (Report) (2 marks)
In a comment block at the bottom of your program (no more than 30 lines of text) list the data structures used by your program and describe your solution to the second shortest path problem. Also, provide answer to the questions. For this step, marks will be awarded based on accuracy and correctness. Compilation: All programs submitted must compile and run on banshee: C: gcc ass2.c C++: g++ ass2.cpp Java: javac ass2.java Python: python ass2.py Programs which do not compile on banshee with the above commands will receive zero marks. It is your responsibility to ensure that your program compiles and runs correctly. Marking Guide: Marks will be awarded for the appropriate use of data structures and the efficiency of the program at processing the input and producing the correct output. Marks may be deducted for untidy or poorly designed code. Appropriate comments should be provided where needed. There will be a deduction of up to 4 marks for using STL, or equivalent libraries, rather than coding the data structures and algorithms yourself. You may use string or String type for storing words or text, if you wish. All coding and comments must be your own work. Submission: Assignments should be typed into a single text file named "ass2.ext" where "ext" is the appropriate file extension for the chosen language. You should run your program and copy and paste the output into a text file named: "output.txt" Submit your files via the submit program on banshee:
submit -u user -c csci203 -a 3 ass3.ext output.txt
- where user is your unix userid and ext is the extn of your code file. Late assignment submissions without granted extension will be marked but the points awarded will be reduced by 1 mark for each day late. Assignments will not be accepted if more than five days late. An extension of time for the assignment submission may be granted in certain circumstances. Any request for an extension of the submission deadline must be made via SOLS before the submission deadline. Supporting documentation should accompany the request for any extension. Read the full article
0 notes
Text
FIT1045 Algorithms and programming in Python, S2 Assignment 1 Solved
Objectives
The objectives of this assignment are: To demonstrate the ability to implement algorithms using basic data structures and operations on them. To gain experience in designing an algorithm for a given problem description and implementing that algorithm in Python.
Submission Procedure
Save your files into a zip file called yourStudentID yourFirstName yourLastName.zip Submit your zip file containing your solution to Moodle. Your assignment will not be accepted unless it is a readable zip file. Important Note: Please ensure that you have read and understood the university’s policies on plagiarism and collusion available at http://www.monash.edu.au/students/policies/academic-integrity.html. You will be required to agree to these policies when you submit your assignment. A common mistake students make is to use Google to find solutions to the questions. Once you have seen a solution it is often difficult to come up with your own version. The best way to avoid making this mistake is to avoid using Google. You have been given all the tools you need in workshops. If you find you are stuck, feel free to ask for assistance on Moodle, ensuring that you do not post your code. Marks: This assignment will be marked both by the correctness of your code and by an interview with your lab demonstrator, to assess your understanding. This means that although the quality of your code (commenting, decomposition, good variable names etc.) will not be marked directly, it will help to write clean code so that it is easier for you to understand and explain. This assignment has a total of 12 marks and contributes to 10% of your final mark. For each day an assignment is late, the maximum achievable mark is reduced by 10% of the total. For example, if the assignment is late by 3 days (including weekends), the highest achievable mark is 70% of 12, which is 8.4. Assignments submitted 7 days after the due date will normally not be accepted. Detailed marking guides can be found at the end of each task. Marks are subtracted when you are unable to explain your code via a code walk-through in the assessment interview. Readable code is the basis of a convincing code walk-through.
Task 1: Strings (3.5 Marks)
Create a Python module called strings.py. Within this module implement the following three tasks. For this module you may not use the Python sequence method s.count(x). You may not import any other libraries or modules.
Part A: Code Breaker (1 Mark)
Write a function decode(string, n) that takes in an encoded message as a string and returns the decoded message. Input: a string string and a positive integer n. Output: the decoded string. The string is decoded by discarding the first n characters from the input string, keeping the next n characters, discarding the next n characters, and so on, until the input string is exhausted. There is no guarantee at which point in the decoding (keep or discard) the string will be exhausted. There is no guarantee that the length of string will be a multiple of n. Examples Calling decode(‘#P#y#t#h#o#n#’, 1) returns ‘Python’. Calling decode(‘AxYLet1x3’s T74codaa7e!’, 3) returns ‘Let’s code!’.
Part B: Pattern Finder (1 Mark)
Write a function pattern count(string, pat) that counts how many times a pattern occurs within a text. Input: a string string and a non-empty string pat, both comprising both upper and lower case alphanumeric and non-alphanumeric characters. Output: an integer count of the number of times pat occurs within string. The count is case sensitive. (See Example c.) Examples Calling pattern count(‘bcabcabca’, ‘abc’) returns 2. Calling pattern count(‘aaaa’, ‘aa’) returns 3. Calling pattern count(‘A long time ago in a galaxy far, far away...’, ‘a’) returns 8. Calling pattern count(‘If you must blink, do it now.’, ‘code’) returns 0.
Part C: Palindromes (1.5 Marks)
A palindrome is a word, phrase, or sequence that reads the same backwards as forwards. Write a function palindrome(string) that determines whether or not a given string is a palindrome. In order to receive full marks, the function must determine whether the alphanumerical characters create a palindrome (see Examples). Input: a string string comprising both upper and lower case alphanumeric and non-alphanumeric characters. Output: a boolean, True if the string when converted to lower case alphanumeric characters is a palindrome; otherwise False. Examples Calling palindrome(‘RacecaR’) returns True because ‘RacecaR’ reads the same backwards as forwards. Calling palindrome(‘66racecar77’) returns False because ‘66racecar77’ does not read the same backwards as forwards. Calling palindrome(‘Racecar’) returns True because ‘racecar’ reads the same backwards as forwards. Calling palindrome(‘Madam, I’m Adam’) returns True because ‘madamimadam’ reads the same backwards as forwards. Calling palindrome(‘#4Satire: Veritas4’) returns True because ‘4satireveritas4’ reads the same backwards as forwards.
Marking Guide (total 3.5 marks)
Marks are given for the correct behavior of the different functions: 1 mark for decode. 1 mark for pattern count. 5 marks if palindrome can correctly identify that a string with no processing is a palindrome (see Examples a and b), 1.5 marks if palindrome can correctly identify that a string when converted to lower case alphanumeric characters is a palindrome (see Examples c, d, and e).
Task 2: Friends (4.5 Marks)
You have been employed by Monash to analyse friendship groups on campus. Individuals have been allocated a number between 0 and the number of people on campus (minus one), and their friendships have been recorded as edges between numbered vertices. We assume friendships are always bi-directional. Monash has implemented this graph in a Python-readable format as both an adjacency matrix and an adjacency list. Create a Python module called friends.py. Within this module implement the following three tasks. Ensure you follow the inputs for each function correctly - one function takes an adjacency list, two functions take an adjacency matrix. You may not import any other libraries or modules.
Part A: Popular (1.5 Marks)
Write a function popular(graph list, n) that returns a list of people who have at least n friends. Each person is identified by the number of their vertex. Input: a nested list graph list that represents a graph as an adjacency list, that models the friendships at Monash; and a non-negative integer n. Output: a list of integers, where each integer is a person with at least n friends. If no person has at least n friends, return an empty list. The list may be in any order. Examples clayton_list = , , , , ] The example graph clayton list is provided for illustrative purpose. Your implemented function must be able to handle arbitrary graphs in list form. Calling popular(clayton list,2) returns . Calling popular(clayton list,3) returns . Calling popular(clayton list,0) returns .
Part B: Friend of a Friend (1.5 Marks)
Write a function foaf(graph matrix, person1, person2) that determines whether two people have exactly one degree of separation: that is, whether two (distinct) people are not friends, but have at least one friend in common. Input: a nested list graph matrix that represents a graph as an adjacency matrix, that models the friendships at Monash; an integer person1, and an integer person2, where 0 ≤person1, person2< number of people on campus, and person16= person2. Output: a boolean, True if the two people are not friends and they have at least one friend in common; otherwise False. Examples clayton_matrix = , , , , ] The example graph clayton matrix is provided for illustrative purpose. Your implemented function must be able to handle arbitrary graphs in matrix form. Calling foaf(clayton matrix,0,4) returns True as 0 and 4 are both friends with 2. Calling foaf(clayton matrix,0,3) returns False as 0 and 3 are friends directly. Calling foaf(clayton matrix,1,4) returns False as 1 and 4 have no friends in common.
Part C: Society (1.5 Marks)
Write a function society(graph matrix, person) that determines whether a person has two friends who are also friends with each other. Input: a nested list graph matrix that represents a graph as an adjacency matrix, that models the friendships at Monash; and an integer person, where 0 ≤person< number of people on campus. Output: a boolean, True if person has at least two friends who are also friends with each other; otherwise False. Examples Calling society(clayton matrix,0) returns True as 1 and 3 are both friends with 0. Calling society(clayton matrix,2) returns False as 2 is friends with 0 and 4, but 0 and 4 are not friends with each other.
Marking Guide (total 4.5 marks)
Marks are given for the correct behavior of the different functions: 5 marks for popular. 5 marks for foaf. 5 marks for society.
Task 3: Cards (4 Marks)
A friend of yours is developing a prototype for a website on which people can play poker. They have contacted you to help them implement some of the project’s backend: specifically, they would like some help telling what kind of hand a player has played. You have agreed to implement four functions to assist them. In the backend, your friend has decided to represent cards as tuples comprising an integer and a string: (rank, suit). For example, the seven of clubs would be represented as (7, ‘C’). As this is a prototype, your friend has told you that no face cards will be used (that is, rank is always an integer, where 2 ≤ rank ≤ 10, unless otherwise specified). There are four suits, with the following string representations: clubs: ‘C’, diamonds: ‘D’, hearts: ‘H’, spades: ‘S’. As this is poker, which is only played with one deck of cards, there will never be duplicates, and each hand will contain exactly five cards. Create a Python module called cards.py. Within this module implement the following four tasks. For this module you may not use the Python inbuilt function sorted() or the Python method list.sort(). You may not import any other libraries or modules.
Part A: Suits (1 Mark)
Write a function suits(hand) that sorts a given hand into the four suits. As there is no standard ranking of suits in poker, we will order alphabetically: clubs, diamonds, hearts, spades. Input: a list hand containing five cards. Output: a nested list containing four lists of cards, with each internal list corresponding to a suit. If there are no cards of that suit in the hand, the internal list for that suit is empty. Cards may be in any order within their suit-list.
Part B: Flush (1 Mark)
Write a function flush(hand) that determines whether a given hand is a flush. In poker, a flush is a hand that contains five cards of the same suit. Input: a list hand containing five cards. Output: a boolean, True if all five cards in hand are the same suit, False if not.
Part C: Straight (2 Marks)
Write a function straight(hand) that determines whether a given hand is a straight. In poker, a straight is a hand that contains five cards of sequential rank. The cards may be of different suits. Your friend has asked you an additional favour: they would like to use this function in various other games they may implement in the future, so instead of checking for a five-card straight, they would like you to check for an n card straight, where n is the number of cards in the hand. Like in poker, the cards may be of different suits. Input: a list hand containing at least three cards, where each card may have a rank of some number greater than zero. Output: a boolean, True if the ranks of the cards in hand may be ordered into an unbroken sequence with no rank duplicated, False if not.
Examples
Calling suits() returns , , , ]. As there are multiple clubs, the clubs cards may be in any order within their internal list. Calling flush() returns True. Calling flush() returns False. Calling straight() returns True. Calling straight() returns False. Calling straight() returns False. Calling straight() returns True as the ranks of the cards form an unbroken sequence, , with no rank duplicated.
Marking Guide (total 4 marks)
Marks are given for the correct behavior of the different functions: 1 mark for suits. 1 mark for flush. 1 mark for straight if it is able to handle a normal poker five-card hand with card ranks between 2 and 10 inclusive (see Examples d, e, and f); 2 marks for straight if it is able to handle an arbitrarily large hand with arbitrary ranks (see Example g). The functions may return True or False at your discretion for instances where person1 is person2. This case will not be marked. Read the full article
0 notes