wednesday - ECE 190 Exam 3 Wednesday, April 13th, 2011...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
ECE 190 Exam 3 Wednesday, April 13th, 2011 Problem 1 (5 points): Warmup Problem 2 (20 points): Problem Solving Problem 3 (15 points): File I/O Problem 4 (10 points): Debugging Problem 5 (15 points): Function Activation Records Be sure your exam booklet has 11 pages. This is a closed book exam. You are allowed three handwritten 8.5 x 11” sheets of notes. Absolutely no interaction between students is allowed. Be sure to clearly indicate any assumptions that you make. Don’t panic, and good luck! 1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Warmup (5 points) In this assignment, you are asked to implement a function to project a vector onto another vector in n-dimensional space. The function accepts two vectors, vec1 and normalized vector vec2 , and the number of dimensions, n , and stores the computed projection of vec1 onto vec2 into an output vector, proj : void projection ( f l o a t vec1 [ ] , f l o a t vec2 [ ] , f l o a t proj [ ] , int n ) ; To determine the projection of vec1 onto vec2 , recall the formulas given in MP4: proj = dot product * vec 2 where dot product = ( vec 1[0] * vec 2[0] + vec 1[1] * vec 2[1] + ... + vec 1[ n - 1] * vec 2[ n - 1]) Getting Started Invoke the ’ece190’ script Execute ’cd mp’ Execute ’ls’ to verify that mp.c and Makefile are present To compile the code, simply type ’make’. To run the code, simply type ’make test’ and input the necessary information. Specifics To receive any credit for this problem, the code must compile. You are not allowed to use any functions from the standard math library. 2
Background image of page 2
Problem Solving (20 points) In this problem, you will implement a critical piece of quick sort and fast rank algorithms. This piece, called partition , moves array elements less than the pivot value to the left side of the array and elements greater that or equal to the pivot to the right side of the array. Algorithm One way to implement partition algorithm is to maintain a ”high” index and a ”low” index. Initially, the high index starts at the end of the array and the low index starts at the beginning of the array. Increase the low index until it indexes an element greater that the pivot and decrease the high index until it indexes an element less than the pivot. If the low index exceeds the high index, all elements must have been already swapped. Otherwise, swap the elements pointed by the low and high indexes and continue searching for another pair of elements to swap. Implementation requirements You are required to implement the following function that implements the above algorithm: int partition ( int sz , f l o a t pivot , f l o a t array [ ] ) ; The function should accept 3 arguments: number of elements in the array, sz , pivot value, pivot , and array to be re-arranged, array . The function should return two results: array re-arranged in place of the input array and
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

wednesday - ECE 190 Exam 3 Wednesday, April 13th, 2011...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online