Consider an array consisting of the following sequence: 1,2,3,4,5,…..,n.
Suppose a number in the sequence is missing.
a) Write the mathematical process to find the missing number, i.e. some equation.
b) What is the time complexity of finding the missing number in the sequence?
Answers
Answer :-
a) the mathematical process to find the missing number, i.e. some equation
public class Fibonacci {
public static void main(seq.[] args) {
int n = n, t1 = 2, t2 = 3;
System.out.print("First " + n + " terms: ");
for (int i = 1; i <= n; ++i)
{
System.out.print(t1 + " + ");
int sum = t1 + t2;
t1 = t2;
t2 = sum; } }}
b.) the time complexity of finding the missing number in the sequence
public class Fibonacci {
public static void main(String[] args) {
int n, t1 =1 , t2 = 2;
System.out.print("Upto " + n + ": ");
while (t1 <= n)
{
System.out.print(t1 + " + ");
int sum = t1 + t2;
t1 = t2;
t2 = sum,; }
Answer:
a) The mathematical process to find the missing number, i.e. some equation
Public class Fibonacci {
Public static void main (seq.[] args) {
Int n = n, t1 = 2, t2 = 3;
System.out.print ("First” + n + " terms: ");
For (int i = 1; i <= n; ++i)
{
System.out.print (t1 + “+ ");
Int sum = t1 + t2;
t1 = t2;
t2 = sum ;}}}
b.) the time complexity of finding the missing number in the sequence
Public class Fibonacci {
Public static void main (String [] args) {
Int n, t1 =1, t2 = 2;
System.out.print ("Upto" + n + ": ");
While (t1 <= n)
{
System.out.print (t1 + "+");
Int sum = t1 + t2;
t1 = t2;
t2 = sum, ;}