Question 7

image

  • I got this wrong because I didn’t realize that this will prevent an ArrayIndexOutOfBoundsException from being thrown if target does not appear in data, however if target is at element 0, -1 will be returned instead of 0 as intended.
  • Answer B is correct because the seqSearchRecHelper recursive method does not work as intended when target does not appear in data. In this case, when last becomes -1, the method will throw an ArrayIndexOutOfBoundsException in the first if statement after line 1. To prevent this, we should add a check to see if last is less than 0 and if it is, return -1 as expected.
  • I can watch 10.1 Daily Videos #1 and #2 to learn these skills.

Question 18

image

  • I got this wrong because I was not sure if this would be the return value if k started at 0.
  • Answer C is correct because the value of the loop control variable k starts at 1 and is incremented by 2 as long as it is less than input.length. In this case, input is assigned “computer”, so input.length is 8. The values of k are 1, 3, 5, 7, and then when k is 9, the loop terminates. The statement input.substring (k, k + 1) will return the value of input at index k. The values that are added to output in order are “o”, “p”, “t”, and “r”. The value “optr” is returned.
  • Resources : 2.7: Daily Video 1 (Skill 2.C), 2.7: Daily Video 2 (Skill 3.A), 2.7: Daily Video 3, 4.3: Daily Video 1 (Skill 2.C), 4.3: Daily Video 2 (Skill 3.C), 4.3: Daily Video 3 (Skill 3.C)

Question 22

image

  • This was an accidental error not from lack of knowledge but just cause I thought it was super easy.
  • Answer B is correct because De Morgan’s Law states that !(p && q) is equivalent to !p   !q. By applying De Morgan’s Law to this expression, we negate the first expression !(!(a !=b)) and the second expression !(b >7) to form !(!(a != b))   !(b > 7). In the first expression the two consecutive not operators (!) cancel each other out giving us (a != b). In the second expression, the opposite of > is <= giving us (b <= 7). The equivalent expression is (a != b)   (b <= 7).
  • Resources: 3.6: Daily Video 1, 3.6: Daily Video 2