[an error occurred while processing this directive]

## cs150: Notes 13

#### Notes

Big-Oh: upper bound. A function g is in O (f) iff there are positive constants c and n0 such that g(n) ≤ cf(n) for all n ≥ n0.

Ω: lower bound. A function g is in Ω (f) iff there are positive constants c and n0 such that g(n) ≥ cf(n) for all n ≥ n0.

Θ: tight bound. A function g is in Θ (f) iff g is in O(f) and g is in Ω(f).

Why are these operators useful for understanding the cost of evaluating procedures?

#### Best-First Sort

```(define (sort lst cf)
(if (null? lst) lst
(let ((best (find-best lst cf)))
(cons best (sort (delete lst best) cf)))))

(define (find-best lst cf)
(if (= 1 (length lst)) (car lst)
(pick-better cf (car lst) (find-best (cdr lst) cf))))
```

#### Insertion Sort

```(define (insertsort cf lst)
(if (null? lst) null
(insertone cf (car lst) (insertsort cf (cdr lst)))))

(define (insertone cf el lst)
(if (null? lst) (list el)
(if (cf el (car lst)) (cons el lst)
(cons (car lst) (insertone cf el (cdr lst))))))
```