























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
An in-depth exploration of decision trees, recursive algorithms, and their applications in computer science. The concepts of structural and non-structural recursion, recursively defined structures, and the importance of dividing and conquering in problem-solving. Examples of binary search and merge sort, explaining their workings and the benefits of using recursion in these algorithms.
Typology: Lecture notes
1 / 31
This page cannot be seen from the preview
Don't miss anything!
























2
Friday, October 15, 2010 6:26 PM
Inductive step: a new question has yes and no branches that are decision trees. Application: the classic game of "animals".
Decision trees Friday, October 15, 2010 5:53 PM
Friday, October 15, 2010 5:54 PM
Friday, October 15, 2010 5:58 PM
["Is it a mammal?", "horse", "fish"]; Step 1: Distinguish between a horse and a fish Step 2: Distinguish between a horse and a pig. ["Is it rideable", "horse", "pig"] Step 3: Combine the above into one "tree": ["Is it a mammal?", ["Is it rideable", "horse", "pig"], "fish"] This is a recursively defined array structure. Step 4: distinguish between a fish and a lizard: ["Does it live in the desert?", "lizard", "fish"] Step 5: combine steps 3 and 4: ["Is it rideable?", "horse", "pig"] ["Does it live in the desert?", "lizard", "fish"] [ "Is it a mammal?", ] We can continue this as long as we want, refining lower levels. Building a decision tree Friday, October 15, 2010 5:59 PM
Friday, October 15, 2010 6:39 PM
Friday, October 15, 2010 2:28 PM
searching for an item among n sorted things => searching n/2 things. Binary search: Serial version: my $found = &FALSE; my $low = 0; my $high = @words-1; while ($high-$low>1) { my $mid = ($high + $low) /2; if ($word gt $words[$mid]) { $low=$mid; } elsif ($word lt $words[$mid]) { $high=$mid; } else { $found=&TRUE; last; } } if ($found) { print "'$word' is in the dictionary\n"; } else { print "'$word' is not in the dictionary\n"; } Pasted from Example: binary search Friday, October 15, 2010 2:33 PM
Pasted from
Friday, October 15, 2010 5:48 PM
sub sorter { my $thing = shift; my $length = @$thing; if ($length==0) { return []; } elsif ($length==1) { return [$thing->[0]]; } else { my $size = @$thing; my $mid = int($size/2); my $bot = [@$thing[0..$mid-1]]; my $top = [@$thing[$mid..$size-1]]; my $sbot = &sorter($bot); my $stop = &sorter($top); return &merge($sbot,$stop) ; } } my $out = &sorter([1,6,3,2,9,1,203,40,20]); Pasted from Example: merge sort Friday, October 08, 2010 1:49 PM
Merging two (sorted) arrays Sunday, October 10, 2010 4:42 PM
Monday, October 18, 2010 3:26 PM