I'm working on a recursive Ackermann function in Java. I am getting an error at may recursive line, 23.
return Ack(m - 1, Ack(m, n - 1));
Thanks so much if ... |
Does anyone know the logic behind creating a recursive function to generate all combinations of capitals in a given word? I'm trying to do this in Java... For exmaple, give it ... |
Similar to this: http://stackoverflow.com/questions/426878/is-there-any-way-to-do-n-level-nested-loops-in-java
I want to create a recursive function, which generates N nested loops, where the indicies depend on the depth of the loop. So basically, I want to ... |
I would like to go from one number to another. For example if I started at 6 and my goal was 10 I want a function that on every pass would ... |
I am trying to design a function that essentially does as follows:
String s = "BLAH";
store the following to an array:
blah
lah
bah
blh
bla
bl
ba
bh
ah
al
So basically what I did there was subtract each letter from it ... |
I profiled my code and found that my program spent roughly 85% of the time executing this particular recursive function. The function aims to calculate the probability of reaching a set ... |
the following java code is executed in the console window in DR.java IDE.
i have the following two problems please help me friends.
- Is it possible to make password masking ?? i ...
|
|
Does every recursive function have an equivalent for loop? (Both achieve the same result).
I have this recursive function:
private static boolean recur(String word, int length) {
if(length == 1 ...
|
public class For {
public static void main(String[] args){
for(int i=2; i<=1024; i *= 2){
...
|
The function below accepts an integer n and returns the sum of the first n reciprocals.
sum(2) should return 1.5
Here is what I have:
public double sum(int n) {
...
|
Trying to figure out the best place to put a try catch statement when a recursive call is placed. The factorial computation is done with long datatype. Expecting an exception to ... |
I am new to programming hence unable to figure out this simple code.
What I don't understand in the following code is onCreate() is being called by onCreate() itself, yet setContentView() ie ... |
the problem with the code you gave as an example, is that the value of N will never be 0 or 1 and because of this, your value of N is ... |
There's nothing wrong with recursive algorithms per se. They tend to be shorter, and look more elegant when implemented, although that can be deceiving. One example are the Fibonacci numbers. They are usually defined recursively, and very easy to implement that way. But the recursive approach has exponential complexity, while it's easy to implement an iterative approach that has linear complexity. ... |
Many mathematical functions like factorial and fibonacci progressions and many algorithms like quicksort and depth-first-search are defined recursively, so it's natural to write recursive code when efficency is not an issue. You can always convert these programs into conventional loops to save CPU cycles and memory, but any such translation can introduce subtle errors if you're not careful. |
Hi guys, What is the best way of doing recursive functions - or maybe I should rephrase that - what's the best way of repeating something recursively. The reason I ask is because I have a function that recurses and it hits a stack overflow and it got me thinking that recursive functions were perhaps not the best technique. Any help ... |
I wonder why lecturers pose such awful questions. Perhaps they are trying to discredit the recursive approach while teaching it, by using algorithms which don't benefit from recursion. Descending a filesystem is a better example (especially if you have hardlinks to deal with). Think about what you do when you process a list by hand, e.g., 10 coins from your pocket. ... |
Work this with pencil and paper first and see how it goes. 1 .-------. 2 5 .---. .---. 3 4 6 7 What are the rules to visit in order? Something like: 1 Go left as long as you can 2 Go back to the last place you haven't gone right yet 3 Go right 4 Repeat from 1 First make ... |
Hi All , Here i posted simple recursive function..but i wonder about its output.. ----------------------------------------------------------------- public class Java extends Java1 { void myMethod( int counter) { if(counter == 0){ System.err.println("couter is zero"); return; }else { System.out.println("hello" + counter); myMethod(--counter); System.out.println("%%"+counter); return; } } public static void main(String[] args) { Java ja=new Java(); ja.myMethod(5); } } ------------------------------------------------------ output: ------------------------------------------------------ hello5 hello4 hello3 ... |
I want to create a function to do this: "1" "1 2 1" "1 2 1 3 1 2 1" "1 2 1 3 1 2 1 4 1 2 1 3 1 2 1" this is the "Ruler" problem, but I cant figure out how to put it in a recursive function, I am new to recursion so any help ... |
I cant understand how the out put for the following program comes. class test{ public static void main(String [] arg){ myMethod(4); System.out.println("bottom"); } static void myMethod( int counter) { if(counter == 0){ System.out.println("counter ==0"); return; } else { System.out.println("hello" + counter); myMethod(--counter); System.out.println("bye"+counter); return; } } } Output: hello4 hello3 hello2 hello1 counter ==0 bye0 bye1 bye2 bye3 bottom I can ... |
|
|
Hi, I am a first year student studying Computing for Business. I have some coursework set with three questions. I am currently stuck on the last question.7 I AM USING BLUEJ My task is: A builder wishes to build a (three-dimensional) pyramid. Each layer is comprised of square blocks. The top layer comprises a single block, the next layer comprises four ... |
I want to create a program to evaluate math expressions. First, the expression has to be split into small sections of strings while the split string contains a single value. A class is created that takes the whole expression as a string. And its recursive functions should check whether the selected string contains more than a single value. If then, they ... |
To do this you need: 1) A way to map a single digit (9) to a word (nine) 2) A way to parse single digits out of the number (9 out of 987) 3) To understand how recursive functions work. I suggest skipping that part and making a non-recursive method that does what you want. Then if you need to, you ... |
So youre just trying to find the values in Pascals Triangle? http://mathworld.wolfram.com/PascalsTriangle.html Use BigInteger instead of any other numbers. Factorials get restrictively huge almost immediately. Example: 13! is too big to store in an int. I posted the code to this problem here before so do a search. This should be easy to write. Start with a short compilable example and ... |
I'm sorry for having to ask for homework help - I'm badly stuck on this! Can someone give me a kick in the right direction with this? need a recursive function with a single positive int parameter n. the function should write (2^n - 1) integers and should be in the following pattern... n = 1, Output: 1 n = 2, ... |
Hi iam new to java .i need help on the recursive algorithm ..I have a hashmap where value is a array list for eg: key value a -> b ,c,d,e,f b -> i,j,k,l,m d -> f,p,q i -> u,w,x v -> z,l r -> 1,2,3,4 t -> ma,ku,sa input to the program is "a" i need to look whether ... |
|
|
I'm sorry it wasn't clear. I'll try to explain better: I have a recursive method that creates permutations on a grid like: A0000 B0000 C0000 D0000 0A000 0B000 0C000 0D000 [...] AA000 AB000 AC000 AD000 [...] DDDDA DDDDB DDDDC DDDDD Except there are some rules like A can only be used twice, so while BBB00 is acceptable, AA00A is not. I ... |
|
|
|
|
I'd suggest using not using a tree structure here. What you want is a flat associative table keyed on URL, with the parent URL in the data. You have a queue of URLs to be scanned, your program just keeps taking to top URL off the queue, checking you haven't already put it in your database and, if not, finding all ... |
Hi Sorry. 1) Well the code is OK and running. 2) Yes, I am using a debugger. 3) I am not using System.out.... 4) It appears that the recursion is NOT running all over the tree. It is going down the first leaf and ends. for example if I have a root folder: A and under there are two sub folders ... |
I am trying to do a recursive function, but when I do it I am getting this error java.sql.SQLException: Operation not allowed after ResultSet closed at com.mysql.jdbc.ResultSet.checkClosed(ResultSet.java:618) at com.mysql.jdbc.ResultSet.next(ResultSet.java:6043) at org.iiscian.common.Test.display(Test.java:15) at org.iiscian.common.Test.display(Test.java:20) at org.iiscian.common.Test.main(Test.java:36) Here is the program. package org.iiscian.common; import java.sql.*; import java.util.*; class Test { //System.out.println(parent); void display(int parent, int level,Statement stmt ) { try { ResultSet rs ... |
I am trying to make a recursion function that adds up all the integers from an array. The array size is X and I want to add up the first X digits. Everytime I tried to program it, the stack overflows. Can someone help me fix this problem? [case] public static int sum(int[] N){ if (N.length > 0) return (N[N.length-1] + ... |
I am trying to make a recursion function that adds up all the integers from an array. The array size is X and I want to add up the first X digits. Everytime I tried to program it, the stack overflows. Can someone help me fix this problem? public static int sum(int[] N){ if (N.length > 0) return (N[N.length-1] + N[sum(N)-2]); ... |