代写EECS 281: Data Structures and Algorithms Fall 2024 PRACTICE MIDTERM EXAM KEY 1代写Web开发

Electrical Engineering & Computer Science

EECS 281: Data Structures and Algorithms

Fall 2024

PRACTICE MIDTERM EXAM

KEY 1

Multiple Choice Portion [60 points]

MULTIPLE CHOICE INSTRUCTIONS:

•  Select only ONE answer per multiple choice question.

•  There are 24 multiple choice questions worth 2.5 points each.

•  Record your choices for all multiple choice questions using the circles in the boxed area next to each question. Use a number 2 pencil, not a pen (so that you may change your answer).  Fill the circle completely. There is no partial credit for multiple-choice questions.  Make sure you bubble in the correct letter. See the example below for how to select your answer.

•  There is no penalty for wrong answers: it is to your benefit to record an answer to each multiple- choice question, even if you’re not sure what the correct answer is.

•  The questions vary in difficulty — try not to spend too much time on any one question. Use your time wisely.

•  When asked about memory complexity, consider all possible sources (stack and heap).

•  The term "heap" as a data structure refers to a binary heap, unless explicitly stated otherwise.

•  The term "binary search tree" refers to a standard implementation that does not self-balance, unless explicitly stated otherwise.

1.   Master Theorem

Which of the following recurrence relations can one solve by applying the Master Theorem?

A)  T(n) = 2/1T(4/n) + Θ(n)

B)  T(n) = T(2/n) + Θ(nlog2 4)

C)  T(n) = 4T(n — 1) + Θ(1)

D)  T(n) = 4T(2/n) + 2T(4/n) + Θ(n2)

E)  None of the above.

2.   Measuring Runtime

Consider the following function:

1       int  func(double  m,  double  n)  {

2                int  c  =  0;

3              while   (m  >  n)  {

4                          m  =  m/2;

5                           for   (int  i  =  1;  i  <  n;  i *=3;) 

6                                      ++c;

7                }  //  while

8

9                return  c;

10        }  //  func

What best characterizes the running time of a call to this function?

A)  O(nlog m)

B)  O( log n)

C)  O((log ) · (log n))

D)  O(mnlog(mn))

E)  O(mn · (log m) · (log n))


3.   Math Foundations

Which of the following is NOT true regarding logarithms?

A)  log2 (n) = O(log3 (n))

B)  log3 (n) = O(log2 (n))

C)  log2 (n!) = O(nlog2 (n))

D)  log2 (n) = Θ(log3 (n))

E)  All of the above are true

4.   Complexity Analysis

Iff(n) = O(g(n)), and f(n) = Ω(h(n)) and f(n), g(n), and h(n) are strictly increasing functions, which of the following MUST be true?

A)  g(n) = O(h(n))

B)  g(n) = Θ(h(n))

C)  g(n) = Ω(h(n))

D)  g(n) = Θ(f(n))

E)  None of the above

5.   Recursion

Consider the following recurrence relation:


T(n) = {c0, n             n= 1

             nT(n - 1) + c, n>1


What is the complexity of T(n)?

A)  Θ(nlog n)

B)  Θ(n2 )

C)  Θ(n3 )

D)  Θ(cn )

E)  Θ(n!)

6.   Queues

What is the best possible space complexity for a function printing out the contents of a std::queue of size n in order, such that the contents and order of the queue are the same before and after the function is called and executed?  This means the auxiliary, or additional, space required to make this occur, not the space taken up by the data that was in the queue to begin with. You can assume that the queue is passed by reference.

A)  O(1)

B)  O(n)

C)  O(n2 )

D)  O(n3 )


7.   Code Analysis

NOTE: Same code as next page, different question

Consider an array data of size n which contains 0s and 1s.  Each element of this array containing 0 appears before all those elements containing 1. For example, [0, 0, 0, 0, 1] is such an array.

1       int  myFunction(int  data[],  int  length)  {

2                  int  mid  =  0,  left  =  0;  int  right  =  length  -  1;

3                  if   (data[0]  ==  1)

4                             return  0;

5                  else  if   (data[length  -  1]  ==  0)

6                             return  length;

7                  else  {

8                             bool  isFound  =  false ;

9                             while   (!isFound)  {

10                                        mid  =  left  +   (right  -  left)  /  2;

11                                        if   (data[mid]  ==  0)

12                                                    left  =  mid  +  1;

13                                        else  {

14                                                   if   (data[mid  -  1]  ==  0)

15                                                               isFound  =  true ;

16                                                   else

17                                                               right  =  mid  -  1; 18                                         }  //  else

19                              }  //  while

20                             return  mid;

21                   }  //  else

22        }  //  myFunction()

In general, what does the function return when it is given such an array?

A)  Number of 0’s in data[]

B)  Number of 1’s in data[]

C)  (Number of 0’s in data[]) + 1

D)  (Number of 1’s in data[]) + 1

E)  (Number of 1’s in data[]) - 1

8.   Complexity of Code

NOTE: Same code as previous page, different question

Consider an array data of size n which contains 0s and 1s.  Each element of this array containing 0 appears before all those elements containing 1. For example, [0, 0, 0, 0, 1] is such an array.

1       int  myFunction(int  data[],  int  length)  {

2                  int  mid  =  0,  left  =  0;  int  right  =  length  -  1;

3                  if   (data[0]  ==  1)

4                             return  0;

5                  else  if   (data[length  -  1]  ==  0)

6                             return  length;

7                  else  {

8                             bool  isFound  =  false ;

9                             while   (!isFound)  {

10                                        mid  =  left  +   (right  -  left)  /  2;

11                                        if   (data[mid]  ==  0)

12                                                    left  =  mid  +  1;

13                                        else  {

14                                                   if   (data[mid  -  1]  ==  0)

15                                                               isFound  =  true ;

16                                                   else

17                                                               right  =  mid  -  1; 18                                         }  //  else

19                              }  //  while

20                             return  mid;

21                   }  //  else

22        }  //  myFunction()

What is the complexity of the above algorithm?

A)  Θ(1)

B)  Θ(log(log n))

C)  Θ(log n)

D)  Θ(n)

E)  Θ(nlog n)

9.   Heaps and Heapsort

Which of the following is TRUE about binary heaps and heapsort?

A)  Finding the maximum element in a min heap tree has a complexity of Θ(log n)

B)  Turning a random set of elements into a heap has a complexity of Θ(log n)

C)  If the priority of one element in a heap changes, fixing the heap requires a minimum of Θ(n) operations

D)  The worst-case time complexity of heapsort is Θ(n2 )

E)  Heapsort can be implemented with O(1) additional space

10.   Binary Heaps

Which of the following represents a valid binary heap?

11.   Heaps

Suppose that we wanted to add a function popRandom() to our priority queues in Project 2.  When implementing it with the binary heap, we could generate a random index, swap values between that index and the last element of the data vector, and call the vector’s pop_back() function.  What else would we have to do to preserve the binary heap property?  Choose the answer with the smallest worst-case complexity.

A)  Call update_priorities().

B)  Call fixDown() followed by fixUp(), both on the random index.

C)  Call fixDown(), starting at the root of the heap.

D)  Call fixUp(), starting at the last element of the heap.

E)  Call exactly one of fixUp() or fixDown(), depending on the values swapped.

12.   Reversing an Array

You are asked to reverse the order of an arbitrary array of length n in constant memory.  Your code skeleton looks like:

1       for   ( . . . )  {

2                    std::swap(array[i],  array[n  -  i  -  1]); 

3        }

What belongs in the for loop header?

A)  for   (size_t  i  =  0;  i  <  n;  ++i)

B)  for   (size_t  i  =  0;  i  <   (n  /  2);  ++i)

C)  for   (size_t  i  =  n;  i  >=  0;  --i)

D)  None of the above


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图