2018 05 Summer Final Exam Form A.docx - Name:_ GT Username...

This preview shows page 1 - 6 out of 20 pages.

Name:___________________________________________________GT Username (gburdell3, etc.):_______________________________Assigned Section:___________CS 1371Final ExamForm A-Check the board at the front of the room for any updates/clarifications during the exam.-You may not use the MATLAB string class-All logical values should be denotedtrueorfalseNOT 0 or 1-An appendix containing useful information is attached to the back of the exam. If you tear it off,please reattach the sheet after the exam is over.-No credit will be given for comments, but if they are useful for you, feel free to use them.-If there is a problem that you cannot figure out, skip it and move on. Be mindful ofrecommended times and how much each question is worth. Each question has multiple parts.-If you run out of room, you may request extra paper for coding.-You have 2 hours and 50 minutes. Good luck!Problem 1_____/20Problem 2_____/25Problem 3_____/20Problem 4_____/20Problem 5_____/20Problem 6_____/20Problem 7_____/30Problem 8_____/25Problem 9_____/20Total_____/200I pledge that I have neither given nor received help on this exam:___________________________________________________________________SignatureDate
Problem 1. Answer the following short answer questions. (20 points)a.Explain what it means to say an algorithm is O(n). (5 points)b.Is an O(1) algorithm necessarily always faster than an O(n) algorithm? Why or why not? (5points)For parts b-c, consider the following function.1function vec = strangeSort(vec)2n = length(vec);3for j=1:n-14for i=1:n-15if vec(i)>vec(i+1);6temp=vec(i);7vec(i)=vec(i+1);8vec(i+1)=temp;9end10end11end12endc.What sorting algorithm does this function perform? (3 points)
d.What is the big O of the above algorithm? (2 points)e.On the lines below, write down the sequence of steps thatmerge sortwould take in sortingthe vector. (5 points)[14, 7, 0, 29, 5, 1, 3, 10]____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
Problem 2. Answer the following questions about recursion. (25 points)a.Identify the three pillars of recursion. (6 points)
b.The following function is defined in thefib.mfile in your current folder.
The following lines of code are run in the Command Window.>> n = 4;>> fib4 = fib(n);How many times will each of the following function calls be made? (8 points)
c.The following call to fib will error. What is the error, and why did it error? (5 points)

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 20 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
Stallworth
Tags
Metropolitana di Napoli, Source lines of code, Jack Sparrow

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture