# Notes - Imperative Programming TT23, Misc

> Source: https://ollybritton.com/notes/uni/prelims/tt23/ip/misc/ · Updated: 2024-07-07 · Tags: uni, notes

- [Course - Imperative Programming III TT23](https://ollybritton.com/notes/uni/prelims/tt23/ip/imperative-programming-iii/)

### Flashcards
What are the two types of `Option` in Scala?::
```scala
Some(x) // or,
None
```

What does the `Seq` collection implement in Scala?::
An iterator that is indexable.

Give a fully annotated (pre-conditions, post-conditions, and invariants) binary search algorithm.::
```scala
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

---
Olly Britton — https://ollybritton.com. Machine-readable index: https://ollybritton.com/llms.txt
