Lecture 21, CS 302-6, October 21
i. Why? Some people still haven’t taken it
i. 10pm Monday-pairs must be registered
i. Try to think of a small test case that you know the answer to
ii. “If we have A ants, a map B, tunnelAttractivenesses C, pheromone evaporation coefficient D, pheromone strength coefficient E, and run for F iterations, what should be the shortest route”
iii. Suggestion: 1 ant, 1 iteration, set constants to 1, use a simple map
i. This is a little like setting String to “”, integer to 0, etc.
ii. Example:
1. int[] test=null ;
iii. Null is a key word – basically says don’t point anywhere in memory
iv. Note – we’ll get index out of bounds errors if we try to use test (for instance, call print(test[1]). But we can pass it as a parameter, return it, and check if it is null (test==null or test!=null)
i. But it is good to know
i. Elegant/simple/concise solutions to complicated problems – sometimes (almost) the only solution
ii. Also one of the most confusing topics in CS
i. Recursive case
1. Case in which the method calls itself
ii. Base case
1. Case that terminates – does not call itself
2. Often (but not always) something like:
a. When length is 0
b. When value is 0
i. Factorials.java
i. Definition – all possible orders of the letters in the word
ii. Idea – pick a letter, stick it in front. You have n-1 letters left. Pick a letter from that, stick it in front. Etc. Do this for each possible selection.