Directed Graph Cycle Detection

Jan 4, 2015

I have some problem checking if a directed graph has a cycle or not. So I have a given rooted directed graph, and find if there at least one existing cycle.

For example, I have to input the Root Node, followed by a number of nodes, the nodes in the graph, number of edges, and the adjacency list representing the edges. Each entry in the adjacency list contains a pair of nodes. The ordering of the nodes in the pair represents the direction of the edge. An entry A, B means that there is an edge from A to B. Nodes in each pair is separated by a space. One input per line.

And the output should display whether the directed graph has a cycle or not.

Sample input:

A //Root Node
6 //Number of Nodes
A //Nodes in Graph
B
C
D
E
F
6 //Number of edges
A B //Adjacency list representing the edges
B C
C D
C F
F E
E B

Output:
Cycle!

Graph Representation:

Based on the illustration above, the graph has one cycle. The cycle exists in nodes B, C, F and E.

View Replies


ADVERTISEMENT

Cycle Through Database Entries Alphabetically

Aug 6, 2014

I have a database of peoples names linked up to a from to enter a new employee.The form has a previous and next button that should cycle through the employees alphabetically.What im doing the cycle by now is ID which isnt in alphabetical order and just goes by the order they where entered in.

Is there any way to cycle through alphabetically instead? Is running a query each time the next/previous button is pressed the correct way or should it just grab all the names in the array. Theres probably 150 names.

View Replies View Related

JButton On GUI - Cycle Through To Next Image In ArrayList

May 1, 2014

So basically I have an arraylist (names) filled with images.

Now I have a JButton on my GUI and when I click my 'next' button, it's supposed to cycle through to the next image in the arraylist. With this code I am only using it to actually see if it will set the new image, but I keep getting errors thrown at me when im trying to define the new image to be set

String shield = "C:\Documents and Settings\derek\Desktop\shields\" + names.get(1);
imgico = new ImageIcon(shield);
img.setIcon(imgico);

The error i'm getting is:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at newmay1.makegui$myhandle.actionPerformed(makegui.java:66)

Along with a ton more lines of red text, and i've tried many different ways of doing this.

Even when I simply just output to the console each item in my arraylist, it comes out perfectly as a string.

View Replies View Related

ESP Game - Cycle Through Colors After Each Guess Entered

Dec 16, 2014

I'm writing an ESP game code for class. The problem is i cant get it to cycle through the colors after each guess is entered. It stays fixed on the original random number generated.

import java.util.Random;
import java.util.Scanner;
public class Final1 {
String colorInput, computerColor;
int computerNum, right, wrong;

[Code] ....

This repeats 10x but the color never changes from the initial random chosen.

View Replies View Related

EJB / EE :: Life Cycle Call Back Methods

Apr 17, 2014

Life Cycle Call back methods(init(), destroy(),...) are not transactional by default and expecting this in coming EJB releases (EJB 3.x / EJB 4.x). I was expecting next EJB release along with Java 8, but it stays at 3.2

View Replies View Related

Object Motion Detection

Mar 25, 2014

Any examples for object detection or motion detection program..

View Replies View Related

Face Detection On Camera?

Sep 3, 2014

I want to do face detection on the camera.

View Replies View Related

Faulty Mouse Point Detection?

May 26, 2014

So I'm making buttons for a game I'm making. The graphics work, at least to the extent that I don't have to fix them yet. However, click detection is a bit iffy. For example pressing where the black line is in the first picture below, triggers a response. Now obviously that point is not on the button. I have tested the buttons bounding box by drawing a rectangle around it, using it's getBounds() method (which is also used for click detection) and it draws a perfect rectangle around it. So then I tested the mouse click points and it turns out that even though the button is placed at y = 100, at the black line, the mouse point is also equal to 100... Now, why that is happening, especially because, if I place the button in the top left corner, the mouse detection correctly detects the top pixels and there is no offset...

View Replies View Related

Object Collision Detection - Character Freezes

Dec 2, 2014

I don't understand why when I collide into my objects my character freezes. Such as if I collide into collision() I can go left and right but, not up and if I collide into collision2() I freeze in all places but, if I collide into the bounds I made I can still go in all directions without problems. The xa and ya are still being set to 0.

package com.questkings.game;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;

[Code] .....

View Replies View Related

Pong Game - Y Axis Collision Detection

Jan 28, 2014

I have made a "Pong" game and how to check if the ball has hit the top or the bottom of a paddle, however I do know how to check if it has hit the left or right side:

Java Code:

if((BALL.getX() >= LEFT_BAT.getX() && BALL.getX() <= LEFT_BAT.getX() + LEFT_BAT.getWidth()
&& BALL.getY() >= LEFT_BAT.getY() && BALL.getY() <= LEFT_BAT.getY() + LEFT_BAT.getHeight())
&& (BALL.getX() >= RIGHT_BAT.getX() && BALL.getX() <= RIGHT_BAT.getX() + RIGHT_BAT.getWidth()
&& BALL.getY() >= RIGHT_BAT.getY() && BALL.getY() <= RIGHT_BAT.getY() + RIGHT_BAT.getHeight())){
BALL.increaseDX();
BALL.setDX(-BALL.getDX());
} mh_sh_highlight_all('java');

It seems as though I would use the same code for checking the top or bottom.

View Replies View Related

Video Game - Collision Detection Class?

Apr 30, 2014

I use eclipse as my IDE. I have decided to make my own video game and somebody had sent me a class that could be used for collision detection. The problem with the collision detection class was that it made a box around an object and if something else had touched the object, the collision detection would work. My problem with this class is what happens when i want to use circles? I cant have a box drawn around it. Then it wouldn't work as i would want. Is there a pixel perfect collision detection class out there I can use? It'll be useful in my journey to become successful in computer science! By the way this is in the java language.

View Replies View Related

Space Invaders Game - Collision Detection

Apr 19, 2014

I'm working on a space invaders game and I'm having problems with collision detection. My main issue is I'm having problems getting what the y value of the "missile" is as it goes up towards the top of the game. I have tried for many hours and tried to look at other people's space invaders game in an attempt to figure out how to figure out my problem. Also I'm not sure if I have the code for my collision detection in the correct spot. Right now I have the code in the keyPressed method. Below is the code for the main and missle classes ...

import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Iterator;

[Code] ....

View Replies View Related

Servlets :: Feature Detection - Determine Browser Type

Apr 22, 2014

I need to be able to detect IE 9, IE 10, IE 11 and the latest from Firefox and Chrome. The old method using the user-agent string is unreliable and not recommended. There is a different approach called, "Feature Detection". But I need to know what features to test to determine the browser. I can write it myself, or if there is a handy dandy API using feature detection already written that would be OK too.

View Replies View Related

Collision Detection Using Rectangles - Player Sometimes Passes Through The Tiles

May 19, 2014

I have already tried every possible way for removing this bug but all failed. The problem is that sometimes my player passes through the map tiles, i mean, the algorithm is like -- if not colliding, move in required direction; else if colliding, move in opposite direction. But sometimes the second condition fails i dont understand why.

private void movement(){
left=bindObject.getLeft();
right=bindObject.getRight();
up=bindObject.getUp();
down=bindObject.getDown();
bindObject.setColliding(colliding);

[Code] .....

Where bindObject is a class which contains key bindings of following keys:-

left arrow key (when pressed) , left arrow key (when released),
right arrow key (when pressed), right arrow key (when released),
up arrow key (when pressed), up arrow key (when released),
down arrow key (when pressed), down arrow key (when released)

View Replies View Related

How To Plot Graph

Nov 13, 2014

I am new to java. I wana create a java program that can plot a graph for that I've already written this:

/ x axis would be the ,,elemszam" from 0 to 599;
y axis would be ,,resz_xy"
double sum_xy=0;
double g=10000.0;
double z_xy;
double xy=0;

[Code]...

--- Update ---

Actually i'm using netbeans...

--- Update ---

and the datas are coming from a text file...

View Replies View Related

In And Out Degree Of A Graph

May 2, 2014

I have this code for reading a text file and printing out information about the graph, the program works perfectly but I need to figure out the in degree and out degree of the graph if it is an directed graph. So my question is how would I go about implementing that? I know what in degree and out degree does but in terms of the code I'm not so sure, so I'm thinking if the case of vertex 0,1 the first vertex comes before the second vertex so that would in an in degree right? But how would I do that?

graphs.txt
6,1
0,2 0,4 1,4 1,5 2,1 2,3 2,5 3,2 3,4 4,1 4,5 5,1 5,3 5,2

import java.io.File;
import java.util.Scanner;
 public class Vertices {
public static void main(String[] args) throws Exception {
@SuppressWarnings("resource")

[Code] ....

View Replies View Related

Generate Bar Graph From Data

May 22, 2014

I need to generate a bar chart given the data that is in main. The relative performance of each sorting algorithm with respect to time, number of comparisons, and number of swaps for each data set (e.g., 50,000 –400,000 random integers). Each algorithm will have 5 bars corresponding to the 5 data sets. The height of these bars will depend on the performance of the algorithm for that data set.

I know how to write a bar with normal values like integers but for this I'm not sure because the values for instance comparisons and swaps are not given they are calculated. I just need to know what steps to go about doing that, you can even express them in pseudocode or even just explaining it I don't need the code, I think. Here is the main

public class Main {
public static void main(String[] args){
int t= 50000;
int t2=100000;
int t3=200000;
int t4=300000;
int t5=400000;

[Code] .....

View Replies View Related

Adjacency List Graph

May 4, 2014

I'm trying to read a text file of a graph and print information about the graph including the order and size of the graph, rather it is a directed or undirected graph, if it is directed the in and out degree, and the and a list of all vertices for which it is adjacent. The problem is the adjacency list is just printing out the list of vertices instead of the adjacency list. Is there something in my code that is problematic? Also I'm unsure of how to go about the in and out degree

"graphs.txt"
6,1
0,2 0,4 1,4 1,5 2,1 2,3 2,5 3,2 3,4 4,1 4,5 5,1 5,3 5,2
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner; 
public class AdjList {
private Node first; // beginning of list

[Code

View Replies View Related

Java Graph - Cannot Find Symbols

Feb 27, 2015

I am taking an algorithm class and i am having some problems trying to get this program to work.The file name is Graph.java

package graphs;
import java.util.HashSet;
import java.util.ArrayList;
public abstract class Graph

[code]....

View Replies View Related

Graph In Java - How To Draw Curve

Apr 8, 2014

If I have a function for example y=x^2

How can I draw the curve?

View Replies View Related

Swing/AWT/SWT :: Graph Plotting In Java

May 22, 2014

What are the different options available to plot graphs in Java other than JFreechart API?

View Replies View Related

Each Bar In Graph Will Represent Value Of Each Element Of Array

Nov 5, 2014

So I have an array which holds 19 elements, each element represents a value of 'income'. I'm trying to code the graph so that each bar will represent the value of each element of the array (income). I have been given the code ' for (int Bar = 0; Bar < array of values.length; bar++);' however i'm unsure if this is how to do it, or what to add to this code to make it work.

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

Reading A Text File For A Graph?

May 2, 2014

I'm trying to print the number of vertices in a text file on a graph which is the first integer in the file and then the type of graph is an undirected graph for a 0 or a 1 for a directed graph. Right now I'm just trying to print the number of vertices which is a 6 in the text file.

Here's the text file:

6,1
0,2 0,4 1,4 1,5 2,1 2,3 2,5 3,2 3,4 4,1 4,5 5,1 5,3 5,2
Im getting the following error:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 6, Size: 0
at java.util.ArrayList.rangeCheckForAdd(Unknown Source)
at java.util.ArrayList.add(Unknown Source)
at Vertices.main(Vertices.java:21)

Then I need to know how to go about reading the next line in the file, do you read it with the nextLine and put it into an arrayList or do I read each index in the graph?

public class Vertices
{
public static void main(String[] args) throws Exception
{
Scanner inFile = new Scanner(new File("graphs.txt"));
// Read the number of vertices
String line = inFile.nextLine();
ArrayList<Integer> list=new ArrayList<Integer>();
String[] data=line.split("[\,]");
int numberofvertices=Integer.parseInt(data[0]);
int typeOfGraph=Integer.parseInt(data[1]);
list.add(numberofvertices,typeOfGraph);
System.out.println("The number of vertices is " + numberofvertices);
}
}

View Replies View Related

Function That Returns The Panel Of The Graph

Jun 9, 2014

Before I created the data file are the points of x and y I created a model class that represents the graph. I have a problem with making a function that returns the panel of the graph.

Attached File(s)

 data.cvs.txt (726bytes)
Number of downloads: 12
 chart.txt (3.72K)
Number of downloads: 10

View Replies View Related

Control Flow Graph In Jframe

Apr 23, 2014

Java code to build control flow graph of any user program in jframe...

View Replies View Related







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