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

Info icon This 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.
Image of page 1

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

View Full Document Right 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.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern