{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

18-07mar29arrays

18-07mar29arrays - CS100J 29 March 2007 Arrays searching...

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CS100J 29 March 2007 Arrays: searching & sorting. Reading: 8.5 Why did I get a Christmas Card on Halloween? Searching and sorting algorithms are on the course website. Decimal 00 01 02 03 04 05 06 07 08 09 10 Octal 00 01 02 03 04 05 06 07 10 11 12 Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 Decimal 11 12 13 14 15 16 17 18 19 20 21 Octal 13 14 15 16 17 20 21 22 23 24 25 Binary 01011 01100 01101 01110 01111 10000 10001 10010 10011 10100 10101 Decimal 22 23 24 25 26 27 28 29 30 31 32 Octal 26 27 30 31 32 33 34 35 36 37 40 Binary 010110 010111 011000 011001 011010 011011 011100 011101 011110 011111 100000
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 Decimal 5482: 5*10 3 + 4*10 2 + 8*10 1 + 2*10 0 Octal 3726: 3*8 3 + 7*8 2 + 2*8 1 + 6*10 0 Binary 1011: 1*2 3 + 0*2 2 + 1*2 1 + 1*2 0 /** = a string that contains the binary representation of n. Precondition: n >= 0 */ public static String binary( int n) { if (n <= 1) return “” + n; return binary(n/2) + (n%2); }
Image of page 2
3 Getting an invariant as picture: Combine pre- and post-condition ? 0 n pre: reds whites blues 0 n post: reds whites ? blues 0 h k j n inv: ? 0 n pre: x is the min of this 0 n post: x is the min of this ? 0 k n inv: Dutch national flag Finding the minimum value of an array
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 • Linear search. Vague spec.: find first occurrence of v in b[h..k-1].
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}