{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

SYSC2002_2005_Fall

# SYSC2002_2005_Fall - Question 1(6 marks Here is a recursive...

This preview shows pages 1–3. Sign up to view the full content.

Question 1 (6 marks) Here is a recursive definition of a binomial coefficient : If n and k are integers, is undefined if n < 0; binCoeff(n,k) = 0 if k < 0 or k > n; and = binCoeff(n, k-1)*(n-k+1)/k, otherwise Write a recursive function that calculates the binomial coefficient given any integers n and k . Your function must be recursive. No marks will be awarded for an iterative solution. Question 2 (16 marks) (a) A prototypes for a function called insertNoDups() is shown below: int *insertNoDups(int arr[], int size, int capacity, int elem int& newSize, int& newCapacity); Parameter arr is an array of integers in which the elements are stored in ascending order . Parameter size is the number of integers stored in the array. Parameter capacity is the capacity of the array. The capacity can be equal to or greater than size , but will never be less than size . Parameter elem is the value that we want to insert into the array, but only if it is not a duplicate of an element that is already in the array. If elem is not in the array, it is inserted into the array such that the elements remain in ascending order. The function can dynamically allocate a new array, but it should do this only if necessary. If elem is already in the array (i.e., if it is a duplicate of an integer that is in the array), the array is not changed. The function returns a pointer to the sorted array. (Note that this may be a pointer to the original array, or a pointer to a new array that was allocated by the function.) Parameter newSize is used to return the size of this array. Parameter newCapacity is used to return the capacity of this array. Write the insertNoDups() function. (9 marks) (b) A prototype for a function called sortAndRemoveDups() is shown below: int *sortAndRemoveDups( int array[], int size, int& newSize ); Parameter array is unsorted array of integers. This array may contain duplicate elements. Parameter size is the number of elements in this array. The function returns a new, dynamically allocated array, that is a sorted (in ascending order) version of the original array with all duplicate elements removed . Parameter newSize is used to return the size of the new array. This function cannot change the unsorted array that is passed to it. Write the sortAndRemoveDups() function. Your function must call the insertNoDups() function you wrote for part (a) (7 marks). Question 3 (20 marks) Recall from Assignment 6 that an n -degree integer polynomial is a mathematical expression of the form i n i i n n x a x a x a x a a x P = = + + + + = 0 2 2 1 0 ... ) ( where each term's coefficient a i is a constant integer, and each term's exponent i is an integer greater

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
SYSC 2002 A & B Fall 2005 Final Exam Page 2 of 5 than or equal to 0. A polynomial's degree is the value of the largest exponent in the polynomial. For
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 5

SYSC2002_2005_Fall - Question 1(6 marks Here is a recursive...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online