Question

In: Computer Science

This problem should be solved using the DrRacket software in the Racket/Scheme language. Consider two techniques...

This problem should be solved using the DrRacket software in the Racket/Scheme language.

Consider two techniques for representing a graph as Scheme lists. We can represent a directed graph as a list of edges. We call this representation an el-graph (i.e. edge-list graph). An edge is itself a list of length two such that the first element is a symbol denoting the source of the edge and the second element is a symbol denoting the target of the edge. Note that an edge is a list (not just a pair). For example, the following is a graph: '((x y) (y z) (x z)). We can also represent a graph similar to an adjacency matrix. We call this representation an x-graph (i.e. matrix-graph). In this case, a graph is a list of adjacencies where an adjacency is a list of length two such that the first element is a node (a symbol) and the second element is a list of the targets of that node. For example, the following is a graph: '((x (y z)) (y (z)) (z ())).

- Write function (el-graph->x-graph g), that accepts an el-graph g and returns an x-graph of g.

- Write function (x-graph->el-graph g), that accepts an x-graph g and returns an el-graph of g.

Solutions

Expert Solution

(define (el-graph->x-graph g)
   (cond ((null? g) '())
       ; case to handle (z ())
       ((null? (cadar g)) '())
       ; case to handle (y (z))
       ((null? (cdadar g)) (cons (list (caar g) (caadar g)) (el-graph->x-graph (cdr g))))
       ; case to handle (x (y z))
       (else (cons (list (caar g) (caadar g)) (el-graph->x-graph (cons (list (caar g) (cdadar g)) (cdr g)))))
   )
)

; (el-graph->x-graph '((x (y z)) (y (z)) (z ())))


Related Solutions

This problem should be solved using the DrRacket software in Racket/Scheme language. Write a function (merge-sorter...
This problem should be solved using the DrRacket software in Racket/Scheme language. Write a function (merge-sorter L1) that takes list-of-integers L1 and returns all elements of L1 in sorted order. You must use a merge-sort technique that, in the recursive case, a) splits L1 into two approximately-equal-length lists, b) sorts those lists, and then c) merges the lists to obtain the result. See the following examples for clarificaton. (merge-sorter '(3 1 5 4 2) ---> (1 2 3 4 5)...
Please use the Scheme programming language with Dr. Racket to solve a and b below. (Use...
Please use the Scheme programming language with Dr. Racket to solve a and b below. (Use Scheme and not Python) Write before–in–list?, which takes a list and two elements of the list. It should return #t if the second argument appears in the list argument before the third argument: > (before–in–list? '(back in the ussr) 'in 'ussr) #T > (before–in–list? '(back in the ussr) 'the 'back) #F The procedure should also return #f if either of the supposed elements doesn't...
THIS PROBLEM NEEDS TO BE SOLVED ONLY USING EXCEL SOFTWARE! 1. Use the following data set...
THIS PROBLEM NEEDS TO BE SOLVED ONLY USING EXCEL SOFTWARE! 1. Use the following data set to answer the following: ew dbh e 23.5 e 43.5 e 6.6 e 11.5 e 17.2 e 38.7 e 2.3 e 31.5 e 10.5 e 23.7 e 13.8 e 5.2 e 31.5 e 22.1 e 6.7 e 2.6 e 6.3 e 51.1 e 5.4 e 9 e 43 e 8.7 e 22.8 e 2.9 e 22.3 e 43.8 e 48.1 e 46.5 e 39.8...
Write a simple Calculator program using Scheme programming language. It should be able to do following...
Write a simple Calculator program using Scheme programming language. It should be able to do following operations: "+", "-", " * *, "/". the format when using the calculator function should be (calculator(operand1 operation operand2)) -> (calculator(2 + 5)) should give the output of 7.
Scheme Programming - Racket R5RS Longest Non-Decreasing Subsequence You will write two Scheme functions that compute...
Scheme Programming - Racket R5RS Longest Non-Decreasing Subsequence You will write two Scheme functions that compute a longest non-decreasing subsequence from a list of numbers. For example, if you type > (lis '(1 2 3 2 4 1 2)) you might get (1 2 3 4) Note that there may be more than one longest non-decreasing subsequence. In the above example, your program might also find (1 2 2 4) or (1 2 2 2). You should concentrate first on...
Racket/Scheme language [15p] create-mapping A map data structure is described as either a set of key-value...
Racket/Scheme language [15p] create-mapping A map data structure is described as either a set of key-value pairs or a set of keys and a set of values whose relation is described by a function with a one-to-one mapping from keys to values. Write a function, create-mapping, which takes a list of symbols (keys) and a list of any type of Scheme values (vals) and returns a function that takes one symbol argument (the key) and returns the corresponding value. The...
problem that can be solved by one or more of gene manipulation techniques for example PCR
problem that can be solved by one or more of gene manipulation techniques for example PCR
I want this to be solved using R studio or R software, please. Here is the...
I want this to be solved using R studio or R software, please. Here is the example: The data in stat4_prob5 present the performance of a chemical process as a function of sever controllable process variables. (a) Fit a multiple regression modelrelating CO2product (y) to total solvent (x1) and hydrogen consumption (x2) and report the fitted regression line. (b) Find a point estimatefor the variance term σ2. (c) Construct the ANOVA tableand test for the significance of the regression using...
How to create a divide function in (Dr Racket) programming language without using the built in...
How to create a divide function in (Dr Racket) programming language without using the built in function " / " ?
Write functions for each of the following problems. Each problem should be solved by writing a...
Write functions for each of the following problems. Each problem should be solved by writing a recursive function. Your final program should not have any loops in it. (a) Write a function that uses recursion to raise a number to a power. The function should take two arguments, the number to be raised to the power (floating point) and the power (a non-negative int). (10 Points) (b) Write a boolean function named isMember that takes two arguments: an array of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT