0% found this document useful (0 votes)
19 views2 pages

Set 4 Assignment

The document contains pseudo code to find missing numbers in an array of consecutive positive numbers and to find the smallest positive integer that cannot be represented as a sum of numbers in a given array. It includes example inputs and outputs and code to solve both problems.

Uploaded by

rohit bahirat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views2 pages

Set 4 Assignment

The document contains pseudo code to find missing numbers in an array of consecutive positive numbers and to find the smallest positive integer that cannot be represented as a sum of numbers in a given array. It includes example inputs and outputs and code to solve both problems.

Uploaded by

rohit bahirat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Pseudo code:

SET 4:
1. Given an array of positive consecutive numbers, with some numbers missing. Write a
program to find those missing numbers.
Example:
find_missing([1, 2, 3, 4, 6, 8, 10]) → should return {5, 7, 9}
find_missing([88, 90, 91, 92, 93, 96, 97, 98, 100, 101]) → should return {89, 94, 95, 99}
2. class Program
3. {
4.
5. static void printMissingElements(int[] arr, int N)
6.
7. {
8.
9.
10. int diff = arr[0] - 0;
11.
12. for (int i = 0; i < N; i++)
13. {
14.
15. if (arr[i] - i != diff)
16. {
17.
18.
19. while (diff < arr[i] - i)
20. {
21. Console.Write(i + diff + " ");
22. diff++;
23. }
24. }
25. }
26. }
27.
28.
29. static void Main()
30. {
31.
32.
33. int[] arr1 = { 1, 2, 3, 4, 6, 8, 10 };
34.
35. int N1 = arr1.Length;
36.
37.
38. printMissingElements(arr1, N1);
39.
40. Console.WriteLine();
41.
42. int[] arr2 = { 88, 90, 91, 92, 93, 96, 97, 98, 100, 101 };
43.
44. int N2 = arr2.Length;
45.
46.
47. printMissingElements(arr2, N2);
48.
}}}
49. Console.ReadLine();

50. Find the smallest positive integer value that cannot be represented as sum of any subset of a
given array?
Examples:
1. Input: {1, 3, 6, 10, 11, 15};
Output: 2
2. Input: {1, 1, 1, 1};
Output: 5
3. Input: {1, 1, 3, 4};
Output: 10
4. Input: {1, 2, 5, 10, 20, 40};
Output: 4

class Program
{
static int findSmallest(int[] arr, int n)
{

int res = 1;

for (int i = 0; i < n &&


arr[i] <= res; i++)
res = res + arr[i];

return res;
}

static void Main(string[] args)


{
int[] arr1 = {1,3,6,10,11,15 };
int n1 = arr1.Length;
Console.WriteLine(findSmallest(arr1, n1));
int[] arr2 = {1,1,1,1 };
int n2 = arr2.Length;
Console.WriteLine(findSmallest(arr2, n2));
int[] arr3 = { 1, 1, 3, 4 };
int n3 = arr3.Length;
Console.WriteLine(findSmallest(arr3, n3));
int[] arr4 = { 1,2,5,10,20,40 };
int n4 = arr4.Length;
Console.WriteLine(findSmallest(arr4, n4));

Console.ReadLine();

}
}

You might also like