5. gayle in/gaylemcdgayle 5
z
Gayle Laakmann McDowell
What
is NOT
expected
To know the answers
To solve immediately
To code perfectly
(It’snice.Itjustdoesn’t
happen*.)
*Okayfine.Ithappenedonce,in2000+hiringpackets.
6. gayle in/gaylemcdgayle 6
z
Gayle Laakmann McDowell
What
IS
expected
Be excitedabout hard problems
Drive!
Keep trying when stuck
More than just “correct”
Pay attention to me!
Write real code
Showmehowyouthink!
13. gayle in/gaylemcdgayle 13Gayle Laakmann McDowell
step
Draw an Example
INTERSECTION SIZE: Find #
elementsin common between
two sorted, distinct arrays:
14. gayle in/gaylemcdgayleGayle Laakmann McDowell 14
Ex:Intersection ofTwo Sorted Arrays
Most people draw somethinglike this:
[1, 12, 15, 19]
[2, 12, 13, 20]
Toosmall
Toospecial-case-y
• same size, one commonelement, same index
30. gayle in/gaylemcdgayleGayle Laakmann McDowell 30
find abbcd in
b a b c d b a e f d b b a c b d d f a e
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
31. Gayle Laakmann McDowell 31gayle in/gaylemcdgayle
(C)Do it yourself
Findpermutationsof swithinb
s = abbcd
b =
Findthem!
… now how didyou actuallydoit?
b a b c d b a e f d b b a c b d d f a e
32. Gayle Laakmann McDowell 32gayle in/gaylemcdgayle
Techniquesto Develop Algorithms
BUD
Space and Time
Do It Yourself
39. gayle in/gaylemcdgayle 39Gayle Laakmann McDowell
step
Testing
FIRST Analyze
What’s it doing? Why?
Anything that looks weird?
Errorhot spots
THEN use test cases
Small test cases
Edge cases
Biggertest cases
BUT…
Test code, notalgorithm
Think as you test
Think before you fix