UVic Competitive Programming
From an address in memory to merge sort
This is deliberately ordered. Everything tonight is built from the thing before it: arrays are memory with arithmetic, linked lists are pointers, hash tables are arrays plus a function, stacks and queues are either one, and merge sort is recursion wearing a costume.
If a block feels obvious, sit with it anyway. The gaps show up later as bugs, not as confusion.
&x takes the address. *p follows it, to read or to write.i lives at base + i × size, so indexing is arithmetic, not searching. O(1).T(n) = 2T(n/2) + O(n) resolves to O(n log n), which is the next slide.merge_sort(a):
if len(a) <= 1: return a
m = len(a) // 2
L = merge_sort(a[:m])
R = merge_sort(a[m:])
return merge(L, R)
Attempt first · then we talk
* once you already hold the node † at the permitted end only
Sorting. Selection sort is Θ(n²) comparisons with at most n−1 swaps. Merge sort is O(n log n) always, stable, with O(n) extra space.
A linked list or a hash table, in whatever language you write in, without looking anything up. An hour, and it exposes every gap at once.
Not "I did not get it". The specific line where you stalled. That sentence is what makes a walkthrough on Friday worth sitting through.
Friday is the coached session. Professor Ibrahim works through the set on the board and answers the questions collected during the week.
Patterns built on tonight: two pointers, sliding window, binary search, and the monotonic stack. All of them assume this material.
Tuesday and Friday, 6:00 to 7:30 PM. Both nights run in teams of three.