CS1121401 - Section I A NOTE Problem 1 is given both in...

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

View Full Document Right Arrow Icon
Section I - A 1 NOTE! Problem 1 is given both in pseudocode (page 1) and in C (page 2). Choose whichever one you wish. (1, 20%) (Pseudocode) Given the following array of numbers and algorithm, answer the questions below. Assume that the global array T[1. .n] is correctly declared and contains the values shown. Array T 2 7 3 8 4 7 5 1 position 1 2 3 4 5 6 7 8 procedure R(a : integer) i, j, x, y, z : integer; x 0; y 0; z 0; for i 1 to n do for j (i+1) to n do if (T[i] > T[j]) then if (z < a) then z z + j; endif y T[i]; T[i] T[j]; T[j] y; x x + 1; endif endfor endfor endprocedure a) Show the array T after the procedure was called with R(10) ? Array T 1 2 3 4 5 7 7 8 position 1 2 3 4 5 6 7 8 This is a sorting algorithm arranging the values in ascending order by array position. A[I]<=A[j] if and only if I <= J b) What value will the following variables contain right before the procedure terminates? x 12 z 11 c) What is the purpose of variable x (in general) while the procedure R is executing? The variable x counts the number of times the values of A[i] and A[j] are swapped or exchanged.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Section I - A 2 (1, 20%) (C code) Given the following array of numbers and algorithm, answer the questions below. Assume that the integer array T[1. .n] of size n is correctly declared and contains the values shown. Array T
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/21/2011 for the course COP 3330 taught by Professor Staff during the Spring '08 term at University of Central Florida.

Page1 / 5

CS1121401 - Section I A NOTE Problem 1 is given both in...

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

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