Notes - Imperative Programming TT23, Misc
Flashcards
What are the two types of Option
in Scala?
Option
in Scala?Some(x) // or,
None
What does the Seq
collection implement in Scala?
Seq
collection implement in Scala?An iterator that is indexable.
Give a fully annotated (pre-conditions, post-conditions, and invariants) binary search algorithm.
def search(a: Array[Int], x: Int) {
val N = a.size
var i = 0; var j = N;
while(i < j) {
val m = (i + j)/2
if (A(m) < x) { i = m+1 } else { j = m }
}
}
// Pre: a is sorted
// Post: A[0..i) < x <= A[i..N)
// Inv: 0 <= i <= j <= N, A[0..i] < x <= A[j..N]
What is the CRC method for designing a class?
- Class name
- Responsibilities
- Collaborators