Computer Science, asked by hahaha3bar, 7 months ago

Consider an array consisting of the following sequence: 1,2,3,4,5,…..,n. Suppose a number in the sequence is missing. (1)Write the mathematical process to find the missing number, i.e. some equation. (2)What is the time complexity of finding the missing number in the sequence? DESIGN & ANALYSIS OF ALGORITHM

Answers

Answered by Anonymous
2

Explanation:

Consider an array consisting of the following sequence: 1,2,3,4,5,…..,n. Suppose a number in the sequence is missing. (1)Write the mathematical process to find the missing number, i.e. some equation. (2)What is the time complexity of finding the missing number in the sequence? DESIGN & ANALYSIS OF ALGORITHM

Answered by Anonymous
1

Answer:

\huge{\underline{\underline{\mathbb{\</strong><strong>o</strong><strong>r</strong><strong>a</strong><strong>n</strong><strong>g</strong><strong>e</strong><strong>{Answer:-}}}}}

Approach: The length of the array is n-1. So the sum of all n elements, i.e sum of numbers from 1 to n can be calculated using the formula n*(n+1)/2. Now find the sum of all the elements in the array and subtract it from the sum of first n natural numbers, it will be the value of the missing element.

Similar questions