First, here is my code for the O(n):
import java.util.*;
public class BigO{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter a number: ");
String userInput = in.nextLine();
int mNum = Integer.parseInt(userInput);
int y = new BigO().linear(mNum);
System.out.println(y);
}
//O(n) - Linear
public int linear(int n) {
int sum = 0;
for (int j = 0; j < n; j++) {
sum++;
System.out.print(sum + " ");
}
return sum;
}
I apologize if this is a dumb question because I haven't done big-O notation for a long time and I want to make sure, but for whatever that I have above, is it a Bottom-Up or Top-Down calculation? If it's neither, how can I approach for either one of them (or both)? Please let me know. Thanks.
UPDATE: Alright, nevermind, I've asked some of my friends who are in my class as well as the professor and he written down our problem incorrectly. He corrected it and meant to say we were suppose to use this type of O(n) time algorithm for the recursive fibonacci. Sorry about that lol.