Search Algorithm Causing StackOverFlowError?

Apr 29, 2015

I am using what is known as a Depth First Search to solve a maze using my own Stack created class for an assignment. The reason I believe I am getting this error is because my program is never meeting the `finishSpot` condition. I have used the debugger and it looks like it is infinitely stuck at the Point before the `finishSpot`. My logic seems to be mostly correct except until the point where my maze solver tries to finish the maze.

This is a sample maze:

*****
*s* *
* * *
* f*
*****

Here is my Main which uses my created Stack class.

//Creates a Stack and determines the start and endpoints.
public static void solveDFS( char [][] maze ){
LinkedStack stack = new LinkedStack();
Point currentSpot = findPoint( maze,'s' );
Point finishSpot = findPoint( maze, 'f' );
findPath( maze,currentSpot, finishSpot,stack );

[code]....

View Replies


ADVERTISEMENT

Binary Search Algorithm

Mar 24, 2014

I am trying to make a program that compares the 3 different search algorithms(sequential/binary/hashing). I have already made the sequential search algorithm, binary and hashing part of the code.My program OPENS a data file, and then OPENS a key data file. and then searches through them using both. How to go about the binary and hashing search algorithm (in the driver program).

*I have included a zip file with:
-base program
-driver program
-data file
-key data file

View Replies View Related

Search Algorithm Not Reaching End Condition

Apr 29, 2015

I am using what is known as a Depth First Search to solve a maze using my own Stack created class for an assignment. The reason I believe I am getting this error is because my program is never meeting the `finishSpot` condition. I have used the debugger and it looks like it is infinitely stuck at the Point before the `finishSpot`. My logic seems to be mostly correct except until the point where my maze solver tries to finish the maze, so i just need meeting that last condition that is causing my program to crash.

This is a sample maze:

*****
*s* *
* * *
* f*
*****

Here is my Main which uses my created Stack class.

//Creates a Stack and determines the start and endpoints.
public static void solveDFS( char [][] maze ){
LinkedStack stack = new LinkedStack();
Point currentSpot = findPoint( maze,'s' );
Point finishSpot = findPoint( maze, 'f' );
findPath( maze,currentSpot, finishSpot,stack );

[Code] ....

I made a mistake it says my program is crashing which it is not, but simply not meeting the condition.

View Replies View Related

Implementing Search Algorithm To Solve 8 Puzzle

Oct 4, 2014

I have been working on a program that takes in a 2d array (there is a method to convert to 1d as necessary) and uses it as an 8 puzzle, which the program then solves (if it is solvable) using the A* Search algorithm, outputting each solution move. It needs error checkers/traps/exception handlers, and be able to create an 8 puzzle from user input, create an 8 puzzle from file input, and create an 8 puzzle from file input and then output to another file the solution move sequence. I have gotten nearly everything done except for implement the algorithm itself and the methods for handling input from files or output to files (the input/output file methods are a minor problem that I can probably solve fairly easily, I just want to be able to test the a* with the puzzle created from user input first.

I have taken several cracks at it, but I am not really good with Java in this type of situation and this is hurting me a lot. I have put in a method to determine if a puzzle is solvable, but the A* algorithm still eludes me. I understand the concept of the algorithm, you have a heuristic function, a cost function (each move equals 1 in this case), and you add the two together to get f(n), choosing the move that will get you the closest to your goal (best first search basically). here is what I have so far that works:

import java.io.File;
import java.io.IOException;
import java.util.Queue;
import java.util.Scanner;
public class Puzzle {
public static void main(String[] args) throws IOException {

[Code] ....

I have it outputting things to make sure all that works already, I have all the error handlers, but I think that before I can even implement the A*search algorithm, there may be something else I need. Conceptually, I understand I need Nodes, States and Stacks, and Queues (I think, I am not sure about this), but with the way my code has been made so far, I am not sure how to implement those and then implement them with the A* algorithm. What I should do next? I have looked at the code of other uses of A* algorithm(that is how I found out I might need Java data structures like queue and stack and list), but I am not sure exactly where to go to from where I am.

View Replies View Related

Binary Search Algorithm Won't Return Desired Value

May 10, 2014

This was my initial question: I am confused as to why this won't return the desired value. I keep running into an infinite loop or data is returned that I searched.

I still need to work on whether a user enters a search that doesn't exist......that is where I am stuck....

code has been updated......

int low = 0;
int high = subArray.length;
while (low < high) {
System.out.println("You have entered the while loop");
int mid = (low + high) / 2;

[Code] ....

View Replies View Related

How To Save Results / Inputs For A Binary Search Algorithm

Apr 24, 2014

Is there a way that I can save a binary search algorithm to a text file or something, so that it will always contain more information? The reason why I ask this is because I have BST like project which is supposed to act the game Twenty Questions, were it asks a person 20 Q's until it guess the answer. However, although my project does not require you to save stuff to a file, I find it rather very useful and cool if I could do that.So for example it would start out something like this:

Think of an animal and I will guess it.
Does it have legs? YES
Is it a cat? YES
I win! Continue? YES

Think of an animal and I will guess it.
Does it have legs? NO
Is it a snake? YES
I win! Continue? YES

Think of an animal and I will guess it.
Does it have legs? NO
Is it a snake? NO
I give up. What is it? EARTHWORM
Please type a question whose answer is yes for an earthworm and no for a snake.
DOES IT LIVE UNDERGROUND?
Continue? YES

Think of an animal and I will guess it.
Does it have legs? NO
Does it live underground? NO
Is it a snake? NO
I give up. What is it? FISH
Please type a question whose answer is yes for an earthworm and no for a snake.
DOES IT LIVE IN WATER?
Continue? NO
Good-bye.

However, if the user exits the program then everything will be lost and go to waste. So once again, is there a way that I can save all of these inputs to a file or something and then read it in again?

View Replies View Related

Comparing Characters Of A Word To Puzzle Board - Diagonal Search Algorithm

Feb 7, 2015

Coding (must follow pseudocode algorithm provided) for comparing characters of a word to a puzzle board char[][].

I've gotten the horizontal and vertical searches to work, but I'm having a difficult time figuring out how to search diagonally.

Here's the search algorithm format I have to use:

for each guess word
for each letter of the puzzle
for each letter of the guess word
check for diagonal match
if found, add word to list, break to next guess

I'm assuming there should be a +1 horizontal offset after I find the first letter, but every index I've bumped has caused me to screw up my array bounds. I'm missing something.

Here's the algorithm I'm using for diagonal search. This same algorithm worked for vertical search (minus the offset of course)

//diagonal search
for(String word : guessWords) {//for each guess word
 int letterCount = 0;
int index = 0;
for(int j=0; j<grid[index].length; j++) {//for each puzzle letter
 
[Code] ....

View Replies View Related

How To Resolve StackOverFlowError When Using Recursive Method Call

Mar 24, 2014

I have 3 Xml documents that look like this:

model1:
Java Code: <?xml version="1.0" encoding="UTF-8"?>
<model>
<id>1</id>
<nodes>
<id>2</id>
<stencil>TASK</stencil>
</nodes>
<nodes>
<id>3</id>
<stencil>MODEL</stencil>

[Code] ....

After unmarshalling/marshalling in the main class I have created this 3 methods:

Java Code:

public List<Task> extractTasks(Model model) {
List<Task> tasks = new ArrayList<Task>();
for (ModelNodes modelNodes : model.getNodes()) {
if (modelNodes.getStencil().equals("TASK")) {
tasks.add(new Task(modelNodes.getId()));

[Code] ....

When the recursive call to the extractSubModels method is made, I get a **java.lang.StackOverFlowError** ...

View Replies View Related

Array Is Not The Right Size - Causing Errors

Oct 17, 2014

protected void randomise() {
int[] copy = new int[];
// used to indicate if elements have been used
boolean[] used = new boolean[array().length];
Arrays.fill(used,false);
for (int index = 0; index < array().length {

[Code] .....

View Replies View Related

Nested For Loop Causing Program To Crash

Jan 23, 2015

Implementation of the nested for loop. I thought it was going to go smoothly but apparently not.Purpose: This program is meant to print out all the prime numbers up to a certain range using the algorithm Sieve of Eratosthenes.

Update output: Works as expected.

Java Code:

import java.util.Scanner;
import java.util.ArrayList;
public class PrimeFactors
{
static ArrayList<Double> primeList = new ArrayList<>();
static double range = 0;
static double maxPrime = 0;
static double primeTester = 0;

[code]....

View Replies View Related

Switching Security On In WTP Eclipse Plugin Causing Massive Errors

Aug 15, 2014

I am working on an Eclipse based project that uses WTP Eclipse plugin. Since I have switched security on in that plugin (by checking "Enable Security" check box on) I'm having multiple problems. I get a stack of security errors - attached in this post. I also show my java.policy file. Because the of the mass exceptions I list only the top, although I have attached a docx file with full thing.

Here is my java.policy file:

grant codeBase "file:${catalina.base}/wtpwebapps/App/WEB-INF/lib/hibernate-core-4.3.5.Final.jar" {
permission java.util.PropertyPermission "*", "read, write";
};
grant codeBase "file:${catalina.home}/lib/catalina.jar" {
permission java.lang.RuntimePermission "*";

[Code] ....

Exceptions:

15/08/2014 10:12:43 PM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path:
C:Javajdk1.6.0_33in;C:WINDOWSSunJavain;
C:WINDOWSsystem32;C:WINDOWS;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: JTable Cell Renderer Causing Program To Go Black When Minimized

Aug 25, 2014

I'm making a program that selects classes from a database via a jcombo box and then populates a time table with the class times.

I've used a custom cellrenderer that extends DefaultTableCellRenderer to text wrap the information and change the background of the cells.

It works but when i minimize the program it goes all black and if I double click I get a new JTextArea opening up on the timetable and when I minimize the program and go to open it again i get an "Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException" and the cell render seems to be called again even though i haven't rerun the program.

This is the cell renderer that I built

public class TimesTableCellRenderer extends DefaultTableCellRenderer {
private int minHeight = -1;
private final JLabel label = new JLabel();
private final JTextArea textArea = new JTextArea();
public TimesTableCellRenderer(){
super();
textArea.setLineWrap(true);

[Code] ....

View Replies View Related

Ability To Search A Binary Search Tree And Return The Number Of Probes

Sep 1, 2014

I'm trying to build a method that can search a binary search tree for a specific target and then return the number of probes it took to get there. It seems to me that the best way to do this would be a recursive search method and a counter that tracks the number of calls. But I'm struggling with how to implement this. Here's the code I have so far. what works/doesn't work with the method.

// Method to search the tree for a specific name and
// return the number of probes
public T search(BTNode<T> btNode) {

[Code]....

View Replies View Related

Creating Search Method For Binary Search Tree

Apr 22, 2014

I want to create a search method that returns the frequency of a word in the search method.

public class IndexTree {
private class TreeNode {
TreeNode left;
String word;
int frequency;
TreeNode right;

[Code] .....

View Replies View Related

Searching And Sorting Algorithm

Jan 2, 2015

I have a code that is meant to read a file and organize all the names from least to greatest salaries. It also allows the user to enter a name to find from the file, and the program finds the name and displays it. I have two errors, and I will show the error in my code

View Replies View Related

Creation Of Algorithm For Log In With Verification

Feb 7, 2015

I'm making a code for a log in system that allow me to verify if username and psw are correct (using a file txt as refer), and then i will add maybe the possibility to sign up.

The fact is that I want this kind of formatting on the .txt

username psw
username psw
username psw

...etc

So I have to read the lines and split to the " " and compare the insert data and the read data.

Here is my code, it star but give me this error when i insert any word

XML Code:

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at prova.main(prova.java:20) mh_sh_highlight_all('xml'); Java Code: import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class prova {
public static void main(String[] args) throws FileNotFoundException {

[Code] .....

View Replies View Related

Difference Between Algorithm And Programming

Feb 21, 2014

What is difference between algorithm and programming?How to develope algorithm knowledge?

View Replies View Related

Text-to-image Algorithm

Oct 4, 2014

Encryptor

Java Code:

Private Sub cmdDeleteMessage_Click()
If txtMessage.Text = "" Then
a = MsgBox("No message to delete!", vbInformation, "")
Else: If MsgBox("Do you want to create a new message?", vbYesNo, "New") = vbNo Then Exit Sub
txtMessage.Text = ""
Pic.Picture = LoadPicture()

[Code] .....

Is these codes of the Block cipher encryptor for text-to-image algorithm (B-TTIE algorithm) by Abusukhon 2013? If not, how to make it the same with B-TTIE algorithm?

View Replies View Related

How To Create Genetic Algorithm

May 23, 2015

how to create a genetic algorithm.I made this class that Is supposed to Generate the chromes or Possible solutions of the program. Im pretty sure It doesn't have any syntax error and I went over the logic a couple time yet Im getting a NumberFormatException Exception Error. What this error means nor why am I getting it. Here's my code:

/* Contains the genes or possible solutions to the problem
*/
public class Genes
{
/* Each element is a binary number that corresponds to index number they have been assigned to, these are the possible genes
* The last 4 elements in the array represent + - * / correspondingly
*/
private String[] encodedNumbers = {"0000", "0001", "0010", "0011","0100", "0101", "0110","0111","1000","1001","1010","1011","1100","1101"};

[code]...

View Replies View Related

Tic Tac Toe Game - Minimax Algorithm

Jan 4, 2014

I have been trying to create an algorithm for the computer in my Tic-Tac-Toe game? So I searched for some good ones, and found about this confusing but effective algorithm, at least if you get it working, called Minimax. I tried implementing it into my game. Let's say it was easier said than done. Sometimes I think it's working, but sometimes it doesn't work at all. How do I get my algorithm working? What the variables BEST_SCORE_COMPUTER and BEST_SCORE_PLAYER in my code should have as starting values.

Java Code:

import java.util.Scanner;
public class TicTacToe{
private static char BOARD[] = {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}; // This is the main board itself.
private static int ROWS[][] = {{0, 1, 2}, {3, 4, 5}, {6, 7, 8}, {0, 3, 6}, {1, 4, 7}, {2, 5, 8}, {0, 4, 8}, {2, 4, 6}}; // These are all the rows one can win by filling.
private static int SCORE, BEST_MOVE_COMPUTER, BEST_SCORE_COMPUTER = -1, BEST_SCORE_PLAYER = 1; // These variables speak for themselves.
private static byte TURN = 1; // 1 means player's turn, and 2 means computer's turn.

[Code] .....

View Replies View Related

Algorithm That Processes Numbers

May 7, 2014

I have a set of numbers within a text file.

2 6
1 4 4 1

When the program reads these numbers it will start with the first line. It reads 2, this is the number of times the program should loop through the numbers of the second line. Next it reads 6, this is the number that the sum of numbers on line 2 cannot go beyond, it must equal 6 or be less than.

Next it goes to line 2 and processes the numbers, 2 is less than 6 so it gets processed, so is 4 and when added to 2 it equals 6. This passes the rules therefore gets processed and added together and put in a variable. Once 2 and 4 has been processed it gets put at the back of the number queue, so the numbers look like 1 1 2 4.

With one loop done there is only one left, so it processes the next sum of numbers 1 1 2 as these equal 4 and pass the rule. So these get added together and and put to the back of the queue, 4 1 1 2. But all the loops are finished and the sum of the last loop is added on to the sum of the previous loop. 6 + 4 = 10.

What I need the algorithm to do is print the sum of this whole process when it reads these numbers from a file. I am able to read the numbers from a text file but not sure where to proceed from there.

Also the set of numbers vary, for example the next 2 lines of numbers could be,

10 7
3 1 1 1 4 4

View Replies View Related

Enable MD2 Algorithm Only For A Particular Place And Not For Whole JVM

Jun 6, 2014

Is it possible to enable & disable "jdk.certpath.disabledAlgorithms" property programmatically. I want to remove all disabled Algorithms for some time and later I will enable it.

Or is it possible to enable only for a particular place & not in a JVM level. I want that Algorithm need to be enabled for a piece of code, but I don't want it to the remaining part of the application.

View Replies View Related

Genetic Algorithm Programming

Oct 13, 2014

I am looking to program a simple genetic algorithm in Java but where to start.

" In a computer language of your choice, implement a simple genetic algorithm (GA). That is, write code for a generational GA which uses a binary encoding, tournament selection, single-point crossover and bit-wise mutation" ....

View Replies View Related

Pseudocode For Quicksort Algorithm

May 6, 2015

I have been given this Pseudocode for the Quicksort algorithm:

quicksort(a[], p, r)
if r>p then
j=partition(a[], p, r)
quicksort(a[], p, j-1)
quicksort(a[], j+1, r)

[code]....

I was wondering why:

- why the condition left < right needs to be true for the while loop in the function Partition
- what the while loop does in the function Partition

View Replies View Related

Checker Game With Minimax Algorithm

Apr 12, 2015

I have a checker game already and I am trying to make an AI opponent even if not so Intelligent as long as it can move chips on its own until the game is over.

View Replies View Related

Sudoku Solver Backtracking Algorithm

Dec 5, 2014

It's about a backtracking algorithm trying to solve a sudoku, represented by an array of integer arrays. For testing matters, the start field is empty.

static boolean solve(int[][] field, int i, int j) {
if (filled(field)) {
return legal(field);
} else {
for (int k = 1; k <= 9; k++) {
field[i][j] = k;

[Code] ....

View Replies View Related







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