Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the function: int* findMissing(int arr[], int n, int& resArrSize) This function gets an array of integers arr and its logical size n. All elements

Implement the function: int* findMissing(int arr[], int n, int& resArrSize)

This function gets an array of integers arr and its logical size n. All elements in arr are in the range {0, 1, 2, , n}.

Note that since the array contains n numbers taken from a range of size n+1, there must be at least one number that is missing (could be more than one number missing, if there are duplicate values in arr).

When called, it should create and return a new array, that contains all the numbers in range {0, 1, 2, , n} that are not in arr. The function should also update the output parameter, resArrSize, with the logical size of the new array that was created. For example, if arr=[3, 1, 3, 0, 6, 4], after calling findMissing(arr, 6, resArrSize), the function should create and return an array that contains [2, 5], and update the value in resArrSize to be 2.

Implementation requirements:

1. Your function should run in linear time. That is, it should run in 0(theta)(n).

2. Write a main() program that tests this function..

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions