Question

In: Computer Science

Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data...

Language: Java or C (NO OTHER LANGUAGE)

Do NOT use Java library implementations of the data structures (queues, lists, STs, hashtables etc.)

Have a unit test implemented in main(). And comment every code.

Show examples from the executions.

Assume that the edges defined by the vertex pairs in the data base are one-way.

Question: Write a program that can answer if there is a path between any to vertices.
For the vertex pairs use this as your input example:

AL FL
AL GA
AL MS
AL TN
AR LA
AR MO
AR MS
AR OK
AR TN
AR TX
AZ CA

To the comment: what do you mean with year? There is no year

Solutions

Expert Solution

The following code assumes there is a class called graph with parametes vertex and adjacency list (array not any other data structure).

int isthereEdge(String src, String dst)

    {

        String[] temp = new String[somenum];

        boolean visit[] = new boolean[v];

        

        String[] queue = new String[somenum];

        visit[s]=true;

        queue.add(src);

        while (queue.size()!=0)

        {

            String n;

            i = adj[src].listIterator();

            while (i.hasNext())

            {

                n = i.next();

                if (n==dst)

                    return 1;

                

                if (!visit[n])

                {

                    visit[n] = true;

                    queue.add(n);

                }

            }

        }

        return 0;

    }

Public static void main(String args[])

{

int ans = isthereEdge(source, destination);

if (ans)

{

System.out.println("exists");

}

else

{

System.out.println("Not exists");

}

}


Related Solutions

Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data structures (queues, lists, STs, hashtables etc.) Have a unit test implemented in main(). And comment every code. Show examples from the executions. Assume that the edges defined by the vertex pairs are two-way. Question: First step: write a program based on DFS which can answer questions of the type: "Find the a path from X to Y" Which should result in a list of...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data...
Language: Java or C (NO OTHER LANGUAGE) Do NOT use Java library implementations of the data structures (queues, lists, STs, hashtables etc.) Have a unit test implemented in main(). And comment every code. Show examples from the executions. Question: First step: write a program based on DFS which can answer questions of the type: "Find the a path from X to Y" Which should result in a list of vertices traversed from X to Y if there is a path....
Programming Language Required: C Write a multithreaded program in C (not c++) using the pthread library...
Programming Language Required: C Write a multithreaded program in C (not c++) using the pthread library and dynamic memory(malloc) that multiplies two matrices together. The numbers in the matrices must be read in from a text file. The program should also check if the two matrices are capable of being multiplied together. The amount of threads used has to be dynamic. The user should be able to choose how many threads they wish to use using the command line. Finally,...
JAVA PROGRAMMING LANGUAGE Suppose a library is processing an input file containing the titles of books...
JAVA PROGRAMMING LANGUAGE Suppose a library is processing an input file containing the titles of books in order to identify duplicates. Write a program that reads all of the titles from an input file called bookTitles.inp and writes them to an output file called duplicateTitles.out. When complete, the output file should contain all titles that are duplicated in the input file. Note that the duplicate titles should be written once, even though the input file may contain same titles multiple...
Problem 2 [6pt] In early implementations of Fortran language, a compiler may choose to use static...
Problem 2 [6pt] In early implementations of Fortran language, a compiler may choose to use static allocation (i.e., allocation in the static area) for local variables and parameters, effectively arranging for the variables of different invocations to share the same locations, and thereby avoiding any run-time overhead for creation and destruction of stack frames. However, such implementation changes the meaning of recursive function calls. Write down a simple example and explain how its meaning changes under the “Fortran” semantics as...
Write this program in C++ language. Use the concept of structures. DO NOT use vectors. Q...
Write this program in C++ language. Use the concept of structures. DO NOT use vectors. Q (4) Create a structure called time. Its three members, all type int, should be called hours, minutes, and seconds. Write a program that prompts the user to enter a time value in hours, minutes, and seconds. This should be in 12:59:59 format. This entire input should be assigned first to a string variable. Then the string should be tokenized thereby assigning the 1st token...
this is data structures with C++ language, please do "#1 & a" separately and please send...
this is data structures with C++ language, please do "#1 & a" separately and please send me copyable file 1. Write a program that allows the user to enter the last names of the candidates in a local election and the votes received by each candidate. The program should then output each candidate's name, votes received by that candidate, and the percentage of the total votes received by the candidate. Assume a user enters a candidate's name only once and...
Please use C language and use link list to do this program. This program should ask...
Please use C language and use link list to do this program. This program should ask user to enter two fraction polynomials. Then user chocie if he want add it or multiple it. I need you please to test it to see if it work with these two fraction polynomials 1-  Left Poly Pointer: 1/1x2 + 3/4x + 5/12 2-Right Poly Pointer: 1/1x4 – 3/7x2 + 4/9x + 2/11 AND AFTER ADDING 3- Resulting Poly Pointer: 1/1x4 + 4/7x2 + 43/36x...
Translate the following C code into M4K assembly language. You do not have to use the...
Translate the following C code into M4K assembly language. You do not have to use the frame pointer, just use $sp if you need to use the stack. You do not have to show the stack initialization nor stack cleanup. If you need a specific value for an address, just make an assumption. int A; main() { int B = 5; B = A+B }; // main //Disassembly starts here !main() { //stack and frame pointer init // you do...
C# language. Answer in a discussion format. What is a loop? When do you use a...
C# language. Answer in a discussion format. What is a loop? When do you use a loop versus a selection statement? What are some examples when an infinite loop is appropriate? Describe one of the following three types of loops supported in C#: while loop for loop do loop (or do-while loop) Describe the steps necessary to make a while loop end correctly: Explain the difference between incrementing and decrementing loop control variables. Explain the benefits of using both pretest...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT