lab 7: challenge problemsEN47/COMP9, Fall 2009 overviewIn today's lab, you will choose one of the three "challenge problems" below. This is an opportunity to apply your knowledge to an unfamiliar scenario, in which the terms of a problem are not necessarily well-defined. challenge 1: binary searchThis problem is very similar to Lab 6. Given an array of integers sorted in
ascending order, your program should allow the user to search through the
sorted array. Your program interaction should look something like that of Lab
6, however, instead of linear search, you should implement binary
search. Below is an outline of the recursive binary search algorithm. The
algorithm looks for a target in a a pre-sorted array
int binary_search(int A[], int low, int hi, int target)
mid = (low + hi) / 2
IF (low is greater than hi)
RETURN -1 // Base case. Target was not found.
ELSE IF (value at mid equals target)
RETURN mid
ELSE IF (value at mid is greater than target)
RETURN binary_search ( A, low, mid - 1, target )
ELSE // value at mid is less than target
RETURN binary_search ( A, mid + 1, hi, target )
To start this program, you may want to copy all of your files from Lab 6 to a new directory. You can use your bubble sort function to sort the array. You may use the LEDA functions to visualize the steps in your search algorithm, but this is not required. When you are satisfied with your program, submit it using provide comp9 lab7binary lab7.cpp (Substitute the name of your file for challenge 2: fractalsConsider this fractal pattern below, which is composed of asterisks and spaces.
*
* *
*
* * * *
*
* *
*
* * * * * * * *
*
* *
*
* * * *
*
* *
*
Write a program that uses recursion to generate patterns such as this. Your program should take as input the length of the longest line in the pattern (this should be a power of 2 greater than 0). Think about how the pattern is a fractal. (You may like to read more about fractals online.) Can you find two smaller versions of the pattern within the large pattern? When you are satisfied with your program, submit it using provide comp9 lab7fractal lab7.cpp (Substitute the name of your file for challenge 3: towers of hanoi
The objective of the puzzle is to move the entire stack to another peg, while obeying the following rules:
The website linked above outlines one recursive approach to solving this problem. Write a program that asks the user to enter the initial number of disks, then prints the list of moves required to solve the puzzle. Each move should be of the form "Move the disk from peg 1 to peg 3". You are welcome to consult books and the web to find algorithm outlines, however you must write your own solution and cite any references used. When you are satisfied with your program, submit it using provide comp9 lab7hanoi lab7.cpp (Substitute the name of your file for |