# 15BG_Test1_Answers - CIS 15BG 1 Test 1 Answers Chapters 8 9...

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

CIS 15BG Test 1 Answers: Chapters 8, 9, 10, 11 1. Functions, loops, logical expressions, arithmetic expressions (A). 54321, the reversed value of n, is returned from the function. (B) 3 is returned from the function; 3 represents the index of the smallest element in the list. 2. (A). One Dimensional Arrays – Sorting: Both selection and bubble sorts exchange elements. The insertion sort does not. Explain how the insertion sort rearranges the data without exchanges. It is based on shifting the elements in the sorted part of the array to make room for the current element to be inserted. “In each pass, the first element of the unsorted sub-list is picked up and transferred into the sorted sub-list by inserting it at the appropriate place. When it locates the correct position, therefore, the data have already been moved right one position, and the current location is empty. So, the sort simply places the saved element in its proper location” (B). One Dimensional Arrays – Searching: Given the following fragment of code, circle the errors and correct them (Hint: there are 5 errors) // Prototype Declarations int binSearch( float ary[], int size, float target, int* locn); // Local Definitions float list[100] = {5, 5, 8, 9, 10, 10, 25 , 90, 50, 60}; int size = 10; float target = 25; int* locn; // int locn; int found; // Statements // a calling statement for binary search found = binSearch( ary[], size, target, locn); found = binSearch( list , size, target, locn); 1. ary not defined in main 2. no [] when passing an array to a function (in the actual parameters’ list) 3. local definition section in main(): locn not a pointer 4. calling statement, the last argument must be an address 5. list is not sorted 1

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

View Full Document
CIS 15BG Test 1 Answers: Chapters 8, 9, 10, 11 3.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}