Finding Number Of Paths Between Two Nodes

May 5, 2015

Is it possible to find the number of paths between two nodes in a directed graph using an adjacency matrix? I know how to find all said paths of a given length by using matrix exponentiation, but I don't know how to find all the paths. The professor didn't note it in the assignment but I assume she meant all simple paths because this is a cyclic graph, so there's a potentially infinite number of paths.

I'm thinking I should use matrix exponentiation to find the number of paths of lengths 1 to n-1, where n is the number of nodes in the graph. Then add the number of paths for each length together. Would this work?

View Replies


ADVERTISEMENT

Number Of Paths Coordinate System

Oct 18, 2014

I've been pondering about this algorithm for about a week but I'm still not able to write a "fast" working method/algorithm to solve the Number-of-paths-exercise we were given in my class />

So here's the task:
Write an efficient java program "Paths" which solves the following task:

- Read input n ∈ N and give output a(n) which is the number of paths from (0,0) to (n,0)
it is not allowed to go over the diagonal (m,m) and also not below the x-axis (m,0)

Here are the allowed steps:
u = (1,1), U = (1,4), d = (1,−1), D = (1,−4) and H = (1,0)
steps are performed in a two-dimensional-coordinate-system!

View Replies View Related

Finding Nth Number In Fibonacci Sequence

Oct 30, 2014

I have to find where in the fibonacci sequence a at number belongs, using a if or while loop.

Example

>55 is a Fibonacci number whose order in the sequence is 11
>35 is not a Fibonacci number. However, it lies between Fibonacci numbers 34 (order: 10) and 55 (order: 11)

import java.util.Scanner;
public class While {
public static void main(String[] args) {
System.out.println("Welcome to the Fibonacci Sequence Detector");
Scanner in = new Scanner(System.in);

[Code] .....

View Replies View Related

Finding Array Index Number Through For Loop

Jan 29, 2014

int[] a = new int[7];
a[0] = 0;
a[1] = 10;
a[2] = 256;
a[3] = 57;
a[4] = 33;
a[5] = -154;
a[6] = 168;

[code]....

What program needs to find is the most biggest number. It does the job, but another task of the program is to find the index of that number . The second loop should do just that, but for some reason, as the loop goes further, it passes through the if statement even though answer "a[i]" is not equal to "answer". The idea is that if a[i] and answer are equal, the "i" should represent the index number.

View Replies View Related

No Compiler Errors / Finds Largest Number In Array But Not Finding Smallest

Oct 19, 2014

A java program to print 10 random numbers between 512 and 1024 and then finds the smallest and biggest numbers from the list using only one loop

class BSLab4d {
public static void main (String[] args){
int[] nums = new int[10];
int largest = nums[0];
int x = 0;
int smallest = nums[0];
int y = 0;
 
[code]....

View Replies View Related

Building Linked List Whose Nodes Data Is The Sum Of Nodes Of Other List

May 1, 2014

public void add(int d){
listNode l = new listNode (d, null);
l.next = first;
first= l;

public list Sum2List (list l1, list l2){
//variables
int sum;

[Code] .....

But I have a problem in my first listNode where it ll be pointing to null, thus in the sum2List method the program checks the while condition into false and doesn't go through the loop.

View Replies View Related

Displaying All Paths In A Tree

Nov 20, 2014

I know what the tree data structure is, how it works, etc., but I need to design a method that will sequentially print out all the paths in the tree (i.e. for each node).

The method as provided is

private static String getAllPaths(final BinaryNodeInterface<Character> root) { }

Now the string that must be returned needs to be of the format:

root.getData() + " " + path + "
"
root.getData()[1] + " " + path[1] + "
"
etc.

The pseudocode I was thinking of doing was something along the lines of:

paths
if(root.getData() = null) return paths;
path = ?; // absolutely no clue what to do here
paths += root.getData() + " " + path + "
";
if(root.hasLeftChild()) {
newPath += "0";
paths += begin recursion;
}
if(root.hasRightChild()) {
newPath += "1";
paths += begin recursion;
}
return paths;

Problems:

(1) I don't know how to determine "path" before the left and right children check (the root node's path is "", the first left node's path is "0", the first right node's path is "1", pattern continues with left being "0" and right being "1").
(2) I don't know where to put newlines precisely.
(3) I'm not sure how to get the print layout precisely as it is supposed to be. At most I've been able to just get the last number in the sequence (i.e. if it was supposed to be "1000", I could get "0".

I am working with the pseudocode formulation, especially in regards to the logic and formatting. I think once I have an understanding of what is going on, I can solve it. And yes, I've gone through a couple pseudocode rewrites (a few hours worth) and haven't gotten anywhere which is slightly unnerving.

View Replies View Related

Can't Get Relative Paths To Work

Apr 25, 2014

I can't get Relative paths to work. I have created the class.dat file and I can't get java to recognize it. I am using Eclipse as an IDE. Was wondering if I could get Eclipse to recognize it. I tried with a .txt file as well and couldn't get that to work.

import java.io.*;
public class ReadBytes
{
public static void main(String[] args)
{
try
{
FileInputStream file = new FileInputStream("class.dat");

[Code] .....

View Replies View Related

How To Print All Paths Of Cyclic Graph

Sep 14, 2014

I print a path like below with iteration. It is redundant as you see. How can I remove the redundant path? im using arrayList .

1. [0, 1]
2. [0, 1, 2]
3. [0, 1, 3]
4. [0, 1, 3, 4]

View Replies View Related

File Paths In Eclipse / Jgrasp

May 1, 2014

So I downloaded jgrasp and eclipse on a new computer and am trying to figure out how their filing/path system works.In eclipse I created a new project under which I've imported all my files for my comp sci class, so they're all under this one project which is my only project. I attached a pic of what my eclipse workspace looks like. In this project folder is a file I'm trying to run.

I keep getting an error saying "editor" does not contain a main type.When I change my class name to the project folder I end up getting an option to run the program as an applet or an application, but either one I choose I get the same error message. In the bottom it gives me a warning saying

DescriptionResourcePathLocationType
Build path specifies execution environment CDC-1.1/Foundation-1.1. There are no JREs installed in the workspace that are strictly compatible with this environment. CS1050AssignmentsBuild pathJRE System Library Problem

I tried running the program in jgrasp and got this error

----jGRASP wedge2 error: command "javac" not found.
---- This command must be in the current working directory or
---- on the current system PATH or jGRASP PATH to use this function.
---- System + jGRASP PATH is "C:UsersQudrat.MommandiDocuments;C:Windowssystem32;C:Program Files (x86)InteliCLS Client;C:Progra

[code]...

I have the JDK installed in program files, I have the correct versions of eclipse and Jgrasp, and have uninstalled / reinstalled the JDK/Jgrasp/Eclipse so I don't know what the problem is?

View Replies View Related

Drawing Interactive Paths In JavaFx 8?

Aug 6, 2014

I am trying to make a GUI that allows the user to input the NumberLink puzzle (through mouse action events), and then, displays the puzzle in a grid with features to draw a path, and undo it. This is almost exactly the same functionality as in Numberlink on Nikoli

1. In my project, I have a Stage in which a setup scene prompts user for rows and columns (to take size of puzzle),

2. Then, it generates an empty grid (I'm thinking of using a GridPane here), and the user clicks the squares to enter the numbers into the square. this phase isnt a problem if I use text fields and mouse listeners and store info in a grid... the next phase is what I'm stuck at... unless I know exactly how to do that, I cant make progress...

3. In the third stage, I have to display the numbers to the user just like on the Nikoli site (the highlighting number pairs on mouse hover is a necessary feature too, which I think I can handle with CSS).. and the user should draw paths between the numbers, just as on that site ( I thought VLineTo and HLineTo classes would be suitable.. but I'm not sure, and cant find any alternatives) .....

So with this in mind, I made FXML based dummy gui layouts to test if my ideas work... And I cant get the GridPane to have lines drawing atop it (meaning, I cant place Line objects like HLine on top of the grid panes).... is there any other way to do what I need to do ? I also thought of making canvases in a grid (each square is its own canvas)

How I can implement a user inputted path drawing ??

View Replies View Related

List All Possible Paths From Point A To B Using Recursion?

Apr 12, 2014

From a two-dimensional grid 5x5 that looks like this:

(0,0)(0,1)(0,2)(0,3)(0,4)
(1,0)(1,1)(1,2)(1,3)(1,4)
(2,0)(2,1)(2,2)(2,3)(2,4)
(3,0)(3,1)(3,2)(3,3)(3,4)
(4,0)(4,1)(4,2)(4,3)(4,4)

We have Starting point that is (3,0) and an ending point is (1,3). We can only move up and right to get to the ending point by using recursion. We have to list all possible paths from (3,0) to (1,3)

Example: paths:(3,0)(2,0)(1,0)(1,1)(1,2)(1,3)
(3,0)(2,0)(2,1)(1,1)(1,2)(1,3)
etc...

I was able to get from (3,0) to (1,3) but how to list the other paths. This is my code so far

public class Program7 {
public static void main(String[] args){

int size = 5;

int x1 = 3;
int y1 = 0;
int x2 = 1;
int y2 = 3;

System.out.println(x1+" "+y1);
System.out.println(x2+" "+y2);

int [][] path = new int[size][size];
grid(path,x1,y1,x2,y2);

[code].....

View Replies View Related

How To List All Possible Paths From Point A To B By Using Recursion

Apr 12, 2014

From a two-dimensional grid 5x5 that looks like this:

(0,0)(0,1)(0,2)(0,3)(0,4)
(1,0)(1,1)(1,2)(1,3)(1,4)
(2,0)(2,1)(2,2)(2,3)(2,4)
(3,0)(3,1)(3,2)(3,3)(3,4)
(4,0)(4,1)(4,2)(4,3)(4,4)

We have Starting point that is (3,0) and an ending point is (1,3). We can only move up and right to get to the ending point by using recursion. We have to list all possible paths from (3,0) to (1,3)

Example: paths:(3,0)(2,0)(1,0)(1,1)(1,2)(1,3)
(3,0)(2,0)(2,1)(1,1)(1,2)(1,3)
etc...

I was able to get from (3,0) to (1,3) but how to list the other paths. This is my code so far

public class Program7 {
public static void main(String[] args){
int size = 5;
int x1 = 3;
int y1 = 0;
int x2 = 1;
int y2 = 3;
System.out.println(x1+" "+y1);
System.out.println(x2+" "+y2);

[Code] ....

View Replies View Related

Method Get In Type Paths Is Not Applicable For Argument

Jun 4, 2014

I am using Oracle Java 8 in Eclipse working on both Ubuntu and OSX. I have this code:

Java Code:

private static String getConfigDir(){
Path configDir = Paths.get(homeDir(), homeConfig(), appName());
return configDir.toString();

[code]...

But for the method get() of Paths, I get this error in eclipse.The method get(String, String[]) in the type Paths is not applicable for the argument..Yet on the Oracle documentation site, it uses a similar example:

Path p5 = Paths.get(System.getProperty("user.home"),"logs", "foo.log");

View Replies View Related

Managing Class Paths On Different Operating Systems

Jun 5, 2014

I use git as my SCM and I use both Ubuntu and Mac OSX. The home directory of the two operating systems are different and there lies the problem. When I commit the .classpath to version control, it looks something like this:

Java Code:

<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="/Users/MyUser/Documents/github/Gateway/GDGateway/java-json.jar"/>
<classpathentry kind="lib" path="/Users/MyUser/Documents/github/Gateway/GDGateway/postgresql-9.3-1101.jdbc41.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath> mh_sh_highlight_all('java');

Now when I update my project on Ubuntu. I have to change the build path again because it is referencing paths on OSX. And this goes back and forth. Rather than remove this file from git with .gitignore, I'd prefer to use a global environment variable like as follows:

Java Code:

<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="$HOME/Documents/github/Gateway/GDGateway/java-json.jar"/>
<classpathentry kind="lib" path="$HOME/Documents/github/Gateway/GDGateway/postgresql-9.3-1101.jdbc41.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath> mh_sh_highlight_all('java');

Is this possible?

View Replies View Related

Create Compound Shapes / Paths In JavaFX?

Apr 28, 2015

Is there some way to create compound shapes/paths in JavaFX?

For the record I'm not implying the use of the methods intersect, subtract, or union. These produce other shapes. A compound shape/path is one that has a knockout of some sort. For instance, a circle within a circle, such as in a 2d donut shape. Alternatives do not include a circle with a thick stroke nor an overlayed circle with the background color. Specifically, JavaFX supports the FillRule, in the case of the Path object. However, there doesn't appear to be an "add" method as there was in the Area shape in Swing.

View Replies View Related

Java Servlet :: Storing Images In Folder And Their Relative Paths In MySQL Database

Nov 16, 2012

I am developing an web application with servlets and jsp. I have an issue to store images. I am storing images in folder and their relative path's in mysql database.

When I retrieve path from database then using <IMG> tag i have displayed image like:

     out.println("<td><img src="+user.getPlaceImage()+" width='70' height='50' /></td>");

It is working fine with internet explorer but not working (that is Not displaying image) in chrome/mozilla.

How to display that image in all browsers....

View Replies View Related

Inserting / Linking Nodes At The End?

Mar 15, 2015

having trouble trying to understand the insertion and removal of Nodes.

I have to insert a new node at the end of the linked nodes, if i insert by terminal : 1, 2, 3. The printed nodes are going to be in the same order, 1,2, 3.

I have done the exercise, but it only prints the last node created and i dont know where its the problem. We did it before with "insert at the beginning", may be the problem is with the print() method in SimpleList.java, but i dont know how to print "backwards".

This is the code:

Node.java

public class Node {
public int infoNodo;
public Node next;
}
SimpleList.java
public class SimpleList {
private Node head;

[code]....

View Replies View Related

Display GUI By Using Graphical Nodes?

Feb 8, 2014

I need to calculate id=hash(number) xor id.id is string and number is random number.

My problem is how to convert my string ex='hello' into equivalent integer,so that i can do xor.

I have client and server program. I need to display a gui by using graphical nodes.

View Replies View Related

JavaFX 2.0 :: Using CSS Sub-structure On Own Nodes

May 26, 2014

I have noticed that you can style JavaFX controls using their sub-structure.

E.g. to style the label in a table column header to be left justified I can do this :
 
.table-view .column-header-background .label {    -fx-alignment: center-left ;  } 
 
How can I style my own nodes/controls doing this? Basically it amounts to asking how the selectors like ".column-header-background" are associated with sub-structures of my Java control/node objects. So suppose I have something like
 
.fancy-node .fred .label { ... }
 
How does JavaFX associate fancy-node and fred with something in my implementation of a Node/Control?

View Replies View Related

How Do All Nodes Continue To Occupy Memory

Dec 30, 2014

I had a question about data structures. For the insert method of a linked list, the 'node' object is declared in the insert method. So doesn't the 'node' get destroyed as soon as the closing brace of the insert method is encountered? How do all the nodes continue to occupy memory?

View Replies View Related

ArrayList To Make A List Of Nodes

May 3, 2014

import java.io.*;
import java.util.ArrayList;
public class SpiltList
{
private class node
{
int number;
node next;

[code]....

I am using an ArrayList to make a list of nodes. I cannot seem to find documentation on how to call the nodes, just find how to get int and strings from a list.

View Replies View Related

Sorting Linked Lists Via Consecutive Nodes

Feb 13, 2014

I have the following code that supposed to perfrom sorting on the linked list using method sort in order usind node concept of Linked List but seems to give inlogic results. the following code tests only the values lower than the first value but i can't manage to sort the data higher than the first entered value;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

import java.util.*;
public class ListNode<T extends Comparable> {
ListNode<T> nextNode;
T data;
public ListNode(T item)

[Code] .....

View Replies View Related

Assign Values To Nodes Read From XML Using Java?

Apr 13, 2014

i am trying to assign unique values to nodes read from XML file.. eg: consider this XML file:
 
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description> ...Strong Belgian waffles...</description>
<calories>650</calories>

[code]....

now assigning these nodes "a unique value" has to be done following the LSDX labelling pattern i.e:

To the document element we first give an “a”.As there is no parent node for the document element, we assign “0” at the front of that “a” . “0a” is the unique code for the document element (breakfast_menu). For the children nodes of “0a”, we continue with the next level of the XML tree which is “1” then the code of its parent node which is “a” and a concatenation “.” . We then add a letter “b” for the first child, letter “c” for the second child, “d” for the third child and so on.Unique codes for children nodes of “0a” shall be “1a.b”, “1a.c”, “1a.d”, etc.Hence foe the above given XML the mapping would look something like this:

0a breakfast_menu
1a.b food
2ab.b name
2ab.c price
2ab.d description
2ab.e calories
2ab.f chef
3abf.b chef1
3abf.c chef2
1a.c food
2ac.b name
2ac.c price
2ac.d description
2ac.e calories
2ac.f chef
3acf.b chef1
3acf.c chef2

For more samples about LSDX labelling : 1.) Section 3.1 LSDX Labelling on this link: [URL]

2.) Fig 3 on page 1189 on this link:[URL]

right now i am using SAX parser to read xml and get the nodes in their hierarchical order..now the problem is that i have to assign these specific value to their respective nodes using java.

View Replies View Related

Servlets :: How To Exchange Data In Different Nodes In Same Cluster

Jul 21, 2014

What is better and easier approach for exchanging data (in my case list of objects) between servlets in different nodes in same cluster? I thought about RMI or just direct url servlet call. But it seems that I'm missing something here.

My problem is the following:

I have to create some kind of diagnostic storage for each cluster member. It will collect all information and errors during application work.

And If I need to check application status I do web request and it will show me that these servers (cluster members) are okay and that node has an issue.

I'm using spring and tomcat.

View Replies View Related

Printing Nodes Of Words That Does Not Exist In Dictionary

Jan 21, 2015

The task is

-getting words from dictionary text file and inserting them into a hash table - DONE
-getting words from a usertext file and inserting them into a red-black tree - STUCK
-after that i need to see if there is nodes of words that dosen't exist in the dictionary and print if so

kinda like a spelling checker

OK so the main code that hold the reading and storing part of dictionary and inserting to hash table

import java.io.FileReader;
import java.util.*;
import java.util.Arrays;
import java.io.File;
import java.io.BufferedReader;
import java.util.ArrayList;

[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved