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
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
1
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
Hindi,
4 months ago
Math,
4 months ago
Social Sciences,
9 months ago
English,
9 months ago
Social Sciences,
1 year ago