代做EECS 376 Foundations of Computer Science Midterm Exam, Winter 2024调试C/C++语言

EECS 376 Midterm Exam, Winter 2024

Multiple Choice:  Select the one correct option.

For each of the problems in this section, select the one correct option. Each one is worth 5 points; no partial credit is given.

1.  Select the language (over the input alphabet Σ = {0, 1}) that the following TM decides, if any.  Here qa is the accept state and qr  is the reject state.

 

⃝  0* (01)*

⃝  0* 10(0|1)*

⃝  0(10)*

⃝  00* (10)*

⃝  This Turing machine doesn’t decide any language.

2.  Let A, B, C be (not necessarily distinct) languages for which (A ∩ B) ≤T  C.

Then A ≤T  C holds for ⃝  all / ⃝  some (but not all) / ⃝  no such languages A, B, and C.

3.  Consider the following algorithm:

1:  function FUNC376(A[1,..., n])

2:         if n = 1 then

3:                return 1

4:         else

5:                a = FUNC376(A[1, . . . , 2n/7])

6:               b = FUNC376(A[2n/7, . . . , 4n/7])

7:               c = FUNC376(A[4n/7, . . . , 6n/7])

8:              d = GET203HELP(A[1,..., n])

9:                return min(a, b, c, d)

Suppose that GET203HELP has running time O(n3/2) on an array of n elements. Select the tightest asymptotic bound that necessarily holds for the running time of FUNC376(A[1,..., n]), as a function of n.

  O(n3/2)

  O(nlog2/7 3 )

  O(nlog7/2 3 )

  O(n3/2 log n)

  O(n7/2)

Multiple Choice:  Select all valid options.

For each of the problems in this section, select all valid options; this could be all of them, none of them, or something in between. For each option, a correct (non-)selection is worth one point. In addition, for each problem you will earn one additional point  (for a total of five) if all four of your (non-)selections are correct.

1.  Select all the decidable languages.

⃝  L0  = {(⟨M⟩, x) : Turing machine M is encoded using more than 376 bits}

⃝  L1  = {(⟨M⟩, x) : M is a Turing machine that does not accept x}

⃝  L2  = {(⟨M⟩, x) : M is a Turing machine that accepts x within 12 steps}

⃝  L3  = ∅

2.  Select all the true statements.

⃝  If L1  and L2  are undecidable languages then L1  ∪ L2  is undecidable.

⃝  If L1  and L2  are undecidable languages then L1  ∩ L2  is undecidable.

⃝  If L1  and L2  are decidable languages then L1  ∪ L2  is decidable.

⃝  If L is an undecidable language then the complement of L is undecidable.

3.  Select all the uncountable sets.

⃝  The set of rational numbers.

⃝  {⟨M⟩ : M is a Turing machine that decides some language} .

⃝  The power set (i.e., the set of all subsets) of the integers.

⃝  The set of real numbers between 0 and 1.

4.  Select all the true statements about shortest paths in a weighted directed graph G = (V, E), where edge weights may be negative, and s, u, v, w ∈ V denote vertices.

⃝  If p is a shortest path from u to v, and p′  is a shortest path from v to w, then p followed by p is a shortest path from u to w.

⃝  If the edges have distinct weights, then there is a unique shortest path between any two vertices in G.

⃝  If a shortest path from s to u with  exactly i  edges  has total length d, and there is an edge (u, v) ∈ E of weight zero, then a shortest path from s to v with  exactly i + 1  edges  also has total length d.

⃝  If a shortest path from u to w goes through v, then the u-to-v segment of that path is a shortest path from u to v.

5.  Let G = (V, E) be a connected, undirected graph in which all the edges have different weights, and let T be the unique minimum spanning tree of G. Let S ⊂ V be an arbitrary subset of vertices where S ≠ V and S ≠ ∅, and let ∂(S) ⊆ E denote the subset of edges that each have one endpoint in S and the other endpoint not in S.

Select all the true statements.

⃝  The smallest-weight edge in ∂(S) must be in T.

⃝  In any cycle C of G, the smallest-weight edge must be in T.

⃝  The largest-weight edge in ∂(S) cannot be in T.

⃝  In any cycle C of G, the largest-weight edge cannot be in T.

Short Answer (8 points each)

1.  Let U = {1,..., n}  for some given positive integer n.  We are also given subsets S1 , S2,..., Sm   ⊆  U , where each element of U belongs to at least one of the Si.  We want to select the  minimum  number of these subsets so that their union equals U, i.e., every element of U is in at least one of the selected subsets.

Consider the following greedy algorithm: repeatedly select one of the Si  that has the  largest number of elements that are not in  any selected subset so far  (breaking ties arbitrarily), until the union of the selected subsets is U.

(a)  Give an explicit value of n ≤ 8 and subsets Si  for which the greedy algorithm’s output can be incorrect, i.e., it does not select a minimum number of subsets.  (You will give a justification in the next part.) Your solution must have n ≤ 8 to receive any credit.

(b)  For the values you gave in the previous part,  give  a  valid  sequence  of subsets  that  the algorithm may select, and state a solution that uses fewer subsets.

2.  Draw a DFA  using five or  fewer states that decides the following language over the alphabet Σ = {3, 7, 6}:

L = {x ∈ Σ*  : x has an even number of 3s, an odd number of 7s, and ends with a 6}  .

Your solution must have five or fewer states to receive any credit.

3.  A string y is a prefix  of a string x = x1 x2 ··· xℓ  if y = x1 x2 ··· xi  for some 0 ≤ i ≤ `.  For example, for the string abcdef, the strings abc, abcdef, and the empty string " are some of its prefixes.  (The empty string has only itself as a prefix.) Notice that a string of length ` has exactly ` + 1 prefixes.

Define

L = {(⟨M⟩;x;k) : M is a Turing machine that halts on exactly  k prefixes of x} .

Below is some incomplete pseudocode of a Turing reduction H from LHALT  to L.  (Recall that LHALT  = {(⟨M⟩;x) : M is a Turing machine that halts on x}.)

Fill in the two missing parts of the pseudocode to make it a correct reduction; do not give any analysis. Recall that a Turing reduction may call its oracle more than once.

1:  Let A be an oracle (“black box”) that decides L.

2:  function H(M;x) // Turing machine that decides LHALT  given access to A

3:         let ` = |x|  // `  0 is the length of x

4:         for k = 0; 1;...;` + 1 do

5:                if                                                                             then

6:                      h ←  k // h is the number of prefixes of x that M halts on

7:         if h = 0 then

8:                return “reject”

9:         if x = " then

10:                return “accept”

11:        let x′  = x1 ··· x - 1  // x′  is all but the last symbol of x

12:         return                                                                             

4.  Consider the following algorithm.

1:  A[1; . . . ; 376] is an array of integers in strictly  increasing order: A[i] < A[j] for all 1  i < j  376.

2:  function Mystery(x;y) // x and y are arbitrary integers

3:         if x  0 or y  0 then

4:                return 1

5:         i ←  AskUser(1; 100) // ask the user for an integer that must be in the range [1; 100]

6:         j  AskUser(1; 100) // same as above

7:         x  x + A[i]

8:         y  y  A[i + j]

9:        return Mystery(y;x)

State a potential function that can be used to prove that this algorithm terminates for any input integers x;y and any valid sequence of user inputs.  Briefly justify (in about two sentences) why this is a valid potential function, and why it implies that the algorithm terminates.

Long Answer (14 Points Each)

1.  A string made up of letters from A–T can be encoded as a string of digits from 0–9 using the following mapping: A → 0, B → 1, . . . , S → 18, T → 19. Given a string C[1,..., n] made up of digits from 0-9, we wish to determine the number of ways it can be “decoded,” i.e., the number of strings made up of letters from A–T that are encoded as C.

For example, there are exactly four ways to decode the string 010194: ABABJE, ABATE, AKBJE, and AKTE. For 0 ≤ i ≤ n, let d[i] be the number of decodings of C[1,..., i] (which is the empty string for i = 0).

(a)  Give, with justification, a correct recurrence and base case(s) for d[i].

(b)  Fill in the following table for the string C = 1110117101.  Your answer will be graded for correctness based on the definition of d[i], regardless of your recurrence.

2.  Consider the following tiling problem: for some n ≥ 2 that is a power of two, we want to tile an n-by-n grid of unit squares using “L-shaped” tiles that are made up of three unit squares each. However, there is one  designated unit square in the grid that should remain uncovered. The rest should be covered by tiles, without any overlap and with every tile contained entirely within the grid. The tiles may be oriented arbitrarily.

See the diagram below for a small example of a four-by-four grid and the shape of the tile.  The uncovered square is marked by a circle, and the thick right angles show the orientations of the tiles in a valid tiling.

It is not immediately obvious that there is a valid tiling for any power-of-two n and desired uncovered square; indeed, certain approaches for placing tiles may “get stuck” in unsolvable configurations. In this problem you will develop and analyze an algorithm that works in all cases.

(a)  Below is an incomplete algorithm for this problem, whose missing parts you will provide. The input is a square n-by-n grid where n ≥ 2 is a power of two, and (the location of) a designated unit square to leave uncovered. The algorithm places tiles accordingly on the grid; this is its “output.”

1. Base case  (if n = 2):  [MISSING PART #1]

2. Recursive case  (if n > 2):

(a)  Designate three additional unit squares, different from the given one, to leave uncovered for now, so that:

i. they can be covered by a single tile, and

ii. each of the four n/2-by-n/2 quadrants  (upper left, lower right, etc.) of the grid has exactly one square to leave uncovered.

Specifically, choose the three squares as follows:  [MISSING PART #2]

(b)  [MISSING PART #3]

(c)  Place a tile to cover the three squares that were chosen in Step 2a.

Provide the three missing parts to make the algorithm correct.  (You will justify correctness and analyze running time in the subsequent parts.)

(b)  In about 3–5 sentences, justify the correctness of the algorithm, as you completed it in the previous part. A formal proof by induction is not required.

(c)  Let T(n) denote the running time of the algorithm as a function of the side length n. The cost to place a tile at a specified location, with a specified orientation, is O(1).

Derive, with brief justification, an asymptotic recurrence and closed-form solution for T(n); for full credit, both should be the tightest possible.

3.  The following problem was on the final exam in W24 because (advanced) Turing reduction was covered after the midterm. It is included here for practice.

Prove that the language

LExactFour  = {⟨M⟩ : M is a TM that accepts exactly four distinct inputs}

is undecidable, by reduction from either LACC  or Lε-HALT . Recall that their definitions are

LACC  = {(⟨M⟩, x) : M is a Turing machine that accepts x} ,

Lε-HALT  = {⟨M⟩ : M is a Turing machine that halts on ε} .

 


热门主题

课程名

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
站长地图