Software Engineering Midterm 2

20 Questions | Total Attempts: 81

SettingsSettingsSettings
Please wait...
Software Engineering Quizzes & Trivia

Quiz to prepare for CS373 Midterm 2


Questions and Answers
  • 1. 
    Define the function arraycopy(), iteratively, such that it mimics    Java's System.arraycopy(). a = [2, 3, 4] b = [2, 3, 4] arraycopy(a, 0, b, 1, 2) assert b == [2, 2, 3] a = [2, 3, 4] arraycopy(a, 0, a, 1, 2) assert a == [2, 2, 3] a = [2, 3, 4] b = [2, 3, 4] arraycopy(a, 1, b, 0, 2) assert b == [3, 4, 4] a = [2, 3, 4] arraycopy(a, 1, a, 0, 2) assert a == [3, 4, 4]
  • 2. 
    #!/usr/bin/env python #What does the following code do? import sys in = sys.stdin.readline() a = in[:-1] p = a[::-1] print a==p
    • A. 

      Checks to see if a and p point to the same memory address.

    • B. 

      Doesn't compile.

    • C. 

      Checks if input is a palindrome (reversed string is the same string).

    • D. 

      Stores the first character in a. Stores the first character from that and stores it in p. Checks to see if their contents are equal.

    • E. 

      Prints true

    • F. 

      Prints false

    • G. 

      Stores the first character in input into a. Stores last character in a into p. Compares

  • 3. 
    """ the set constructor REQUIRES: Select all that apply """
    • A. 

      Only lists, not tuples or frozen sets

    • B. 

      Only tuples, not lists or frozen sets

    • C. 

      Only lists and tuples, not frozen sets

    • D. 

      Any iterable container

    • E. 

      An iterable container with hashable objects

    • F. 

      Mutable objects

    • G. 

      Hashable objects

    • H. 

      Anything

  • 4. 
    """ Given any two sets s1 and s2, Select all that apply: """
    • A. 

      S1|s2 == (s1^s2) | (s1&s2)

    • B. 

      S1^s2 == (s2|s1)-(s1&s2)

    • C. 

      S1-s1 == s1^s1

    • D. 

      S1-s1 == s2^s2

    • E. 

      S1&s2

    • F. 

      S1

    • G. 

      S1&s2

    • H. 

      S1|s2

    • I. 

      S1&s2 = (s1|s2) - (s1^s2)

  • 5. 
    """ What is the output of the following program? """ #!/usr/bin/env python x = [1, 2, 3] y = [4, 5, 6, 7] print [v + w for v in x if v % 2 for w in y if w % 3]
    • A. 

      [8]

    • B. 

      [5,6,8,7,8,10]

    • C. 

      [5,7,9,7]

    • D. 

      [1,3,4,5,7]]

    • E. 

      [2,6]

    • F. 

      [5,7,6,8,8,10]

  • 6. 
    """ What is the output of this program? Or does it cause an error? """ #!/usr/bin/env python a = '\ \ \ abc\ \ \ ' print len(a)
  • 7. 
    """ After the following code, which of the following are valid? Select all that apply. """ a = [1]
    • A. 

      A.append()

    • B. 

      A.append(1)

    • C. 

      A[0]=3

    • D. 

      A.append([1,2,3])

    • E. 

      A.extend(1)

    • F. 

      A.extend([1,2,3])

    • G. 

      A.append([])

  • 8. 
    """ Which of the following are iterable? """
    • A. 

      Range(0,5)

    • B. 

      Range(5)

    • C. 

      List([0,1,2,3,4])

    • D. 

      Set([0,1,2,3,4])

    • E. 

      Dict({1:a})

    • F. 

      "abcde"

    • G. 

      Set([0,1,2,3,4])

    • H. 

      01234

  • 9. 
    Which of the following are hashable? Select all that apply.
    • A. 

      Set([1,2,3])

    • B. 

      Tuple(1,2,3)

    • C. 

      List([1,2,3])

    • D. 

      Frozenset([1,2,3])

    • E. 

      "abc123"

    • F. 

      12345

    • G. 

      A() (where A is a valid class)

  • 10. 
    Which of the following can make a copy of a frozenset f f = frozenset([1,"abc",3.45])
    • A. 

      C = set() c = f.copy

    • B. 

      C = set() c |= f

    • C. 

      C = set(f)

  • 11. 
    What is the output of the following program? [x, y] = z = 2, 3 print x, y, z
  • 12. 
    """ What is the output to the following program? """ def f (x, y, *z) :     return [x, y, z] def g (x, y, **z) :     return [x, y, z] t = (2, 3, 4) print f(*t) d = {"u" : 4, "y" : 3, "x" : 2} print g(**d) d = {"u" : 4, "y" : 3, "v" : 5} print g(2, **d)
  • 13. 
    """ What is the output of the following program? """ s=abCbA print s[4:-6:-2]
  • 14. 
    """What is the output of the following program?""" x = set((1, 2, 3, 5)) y = set([1, 2, 4, 6]) z = (x & y) - (x ^ y) t = (y ^ x) - (y & x) print z print t
  • 15. 
    Which properties of this container are true? (These containers are equivalent) (language Container) c++ vector java ArrayList python list/tuple haskell array  let b = beginning m = middle e = end
    • A. 

      Inserting at b and m are O(n)

    • B. 

      Deleting from b or m are O(n)

    • C. 

      Adding to e is O(n)

    • D. 

      Adding to e is ~O(1)

    • E. 

      Adding to e is O(1)

    • F. 

      Indexing is O(n)

    • G. 

      Indexing is O(1)

    • H. 

      Inserting at b or m are amortized constant

    • I. 

      Inserting at b or m are ~O(1)

  • 16. 
    Which properties of this container are true? (These containers are equivalent) (language Container) c++ deque java Deque python deque haskell n/a  let b = beginning m = middle e = end
    • A. 

      Adding to b and e are O(1)

    • B. 

      Adding to b and e are ~O(1)

    • C. 

      Adding to b and e are O(n)

    • D. 

      Deleting from b and e are O(1)

    • E. 

      Deleting from b and e are ~O(1)

    • F. 

      Deleting from b and e are O(n)

    • G. 

      Indexing is O(1)

    • H. 

      Indexing is O(n)

  • 17. 
    Which properties of this container are true? (These containers are equivalent) (language Container) c++ list java LinkedList python n/a haskell list/tuple Note: assume you already have a pointer to the location you want to insert or remove
    • A. 

      Inserting is O(1)

    • B. 

      Inserting is ~O(1)

    • C. 

      Inserting is O(n)

    • D. 

      Deleting is O(1)

    • E. 

      Deleting is ~O(1)

    • F. 

      Deleting is O(n)

    • G. 

      Indexing is O(1)

    • H. 

      Indexing is ~O(1)

    • I. 

      Indexing is O(log n)

    • J. 

      Indexing is O(n)

  • 18. 
    """ What does the following code output? """ a = [[0,0]]*2 a[0][0] = 1 print a
    • A. 

      [[0,0], [0,0]]

    • B. 

      Doesn't compile or throws an error

    • C. 

      [[1,0], [1,0]]

    • D. 

      [[1,1], [1,1]]

    • E. 

      [[1,0], [0,0]]

  • 19. 
    Suppose l is a list. What does it mean to say if l:
    • A. 

      If the first element is true

    • B. 

      If all elements are true

    • C. 

      If the list is empty

    • D. 

      If the list is not empty

  • 20. 
    """ What is the output to the output of the following code? If more than one error is present, select all that apply """ L = [None]*10 L[0] = 123 L[1] = "abc" L[2] = 2.75 L[3:] = dict({"k":"v"}) print L
    • A. 

      {'k': 'v'}

    • B. 

      Error: can't initialize list with None variables

    • C. 

      [123, 'abc', 2.75, 'k']

    • D. 

      Error: list must be homogeneous (all objects same time)

    • E. 

      Error: can't slice list (L[3:])

    • F. 

      Error: assignment of slice must be of same length

    • G. 

      Error: assignment of slice must be utterable

    • H. 

      [123, 'abc', 2.75, 'v']

    • I. 

      [123, 'abc', 2.75, {'k':'v'}]

    • J. 

      123