Implementation of a function based on a recursive definition [closed] - java

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I am studying for a test and i came across this question. I am Computer science and business administration student. I am a little confused on the question. Not sure if our prof wants us to write the java program of the question below
Implement the function Q (a chaotic sequence generator based on the following recursive definition
Q(N) =
N if N < 3
Q(N-Q(N-1)) + Q(N-Q(N-2)) if N>=3

A simple Java implementation :
public int q(int n){
if(n < 3) return n;
return q(n-q(n-1)) + q(n-q(n-2))
}

Related

How to write double number shorter in java? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have part of the code:
public void CollectorOrPocrushka(double output) {
if (output <= 0.4999999999999999999999)
System.out.println("покришка");
if (output > 0.5 && output <= 1.0)
System.out.println("колектор");
}
Can I write float number 0.4999999999999999999999 shorter?
Something like that:
0.49F
0.49e^10
If your question is about to simplify the first if condition and your goal is to check if the output is less than or equal 0.4999999999999999999999, you can easily write
if(output < 0.5)
System.out.println("покришка");

Java Array.sort algo explanation [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
How to understand the implementation of algorithm behind Arrays.sort(int[]).
The sort function inside Arrays class - the logic is decided based on
paramArrayOfInt>7
paramArrayOfInt > 40
Why these specific breakpoint where paramArrayOfInt is the int array variable.
The sorting algorithm for Arrays.sort(int[] a) is a tuned quicksort.
Ref: https://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html#sort(int[])
Read this article: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.14.8162&rep=rep1&type=pdf for understanding the Quick-sort used in Array.sort() by JON L. BENTLEY & M. DOUGLAS McILROY
In Java 7 pivot dual quick-sort algorithm is used for Arrays.sort(int[] a) i.e. refer this: What's the difference of dual pivot quick sort and quick sort?

What is the equivalent Java code of this MATLAB code? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
What is the equivalent Java code of this MATLAB code: ran = sign(rand-0.5)?
Is it randomly assigned either 1 or -1 to ran? Should I used a Pseudo random number generator that generates randomly 1 or -1?
Random rand = new Random(key);
ran = rand.nextInt(1);
double ran = Math.signum(Math.random() - 0.5);
The variable ran will contain +1, -1 or sometimes 0.

how to calculate the time complexity for the following code? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
For (int i=1; i <=n;i/=2){
System.out.println(i);
}
For the time complexity about the above coding, is ot log (n)?
Thanks!
If n > 0: It's time complexity is O(∞) because the loop will never end
If n <= 0: It's time complexity is O(1)
because the loop will not be executed

Its not coming out of the loop [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Hi in the below code mandatoryCount = 0 and it should be increased when an image is selected but its found to be always 1 and i cant exit the loop can any one help me. Here if mandatoryCount = 0 or mandatoryCount>=imageTypeMandatory.length. It must come out of loop. But this code is working if i comment the mandatory count ==0. I cannot find the exact error.
if (dataOne.getCount() >= 1) {
mandatoryCount=0;
dataOne.moveToFirst();
while(!dataOne.isAfterLast()){
for(int iCopy=0;iCopy<imageTypeMandatory.length;iCopy++){ if(imageTypeMandatory[iCopy].trim().equalsIgnoreCase(dataOne.getString(0).trim())){
mandatoryCount++; imageTypeMandatoryCopy[iCopy]="";
}}
dataOne.moveToNext();
}
The logic is testing the moveFirst/moveNext.
if (dataOne.moveToFirst()) {
do {
for(int iCopy=0;iCopy<imageTypeMandatory.length;iCopy++){
if(imageTypeMandatory[iCopy].trim().equalsIgnoreCase(dataOne.getString(0).trim())){
mandatoryCount++;
imageTypeMandatoryCopy[iCopy]="";
}
}
} while(dataOne.moveToNext());
}

Categories