Consider the gear ball. You will, in the next assignment, be asked to program a
ID: 3879093 • Letter: C
Question
Consider the gear ball. You will, in the next assignment, be asked to program a particular style of solver for it. For this assignment, you have some programming and some problem solving. Programming Design and implement data structures for the puzzle itself, produce some (possibly crude) GUI for sanity checks, and write a program to randomize the puzzle. The GUI could be very simple, with each color in the puzzle represented by a letter. Plain text is fine. If you use someone else's code (just for the GUI---the rest must be your own code!), CITE YOUR SOURCE: URL, author, title of link, and dates posted (if known) and read. The randomizer function should take as input the number of moves. To make a move, you need to specify the stationary column, the rotating column, and the direction of rotation. If you held the middle- column steady, the two side-columns will move in opposite directions. If you held the side-column steady, the middle-column will rotate once and the third column will rotate twice. Note that the puzzle returns to its original state after six rotations in the same direction. You should prohibit the randomizer from undoing the last move, and from performing a 6th rotation in a row of the same column in one direction. Problem Solving Come up with at least one heuristic for the puzzle, and explain both the heuristic and why you believe that that heuristic is admissible. A heuristic, in this context, is NOT an algorithm.Explanation / Answer
What is a Randomized Algorithm?
An algorithm that uses random numbers to decide what to do next anywhere in its logic is called Randomized Algorithm..
For example, in Randomized Quick Sort, we use random number to pick the next pivot (or we randomly shuffle the array).
And in Karger’s algorithm, we randomly pick an edge.
How to analyse Randomized Algorithms?
Some randomized algorithms have deterministic time complexity. For example, this implementation of Karger’s algorithm
has time complexity as O(E). Such algorithms are called Monte Carlo Algorithms and are easier to analyse for worst case.
On the other hand, time complexity of other randomized algorithms (other than Las Vegas) is dependent on value of random
variable. Such Randomized algorithms are called Las Vegas Algorithms. These algorithms are typically analysed for expected
worst case. To compute expected time taken in worst case, all possible values of the used random variable needs to be
considered in worst case and time taken by every possible value needs to be evaluated. Average of all evaluated times
is the expected worst case time complexity. Below facts are generally helpful in analysis os such algorithms.
randQuickSort(arr[], low, high)
1. If low >= high, then EXIT.
2. While pivot 'x' is not a Central Pivot.
(i) Choose uniformly at random a number from [low..high].
Let the randomly picked number number be x.
(ii) Count elements in arr[low..high] that are smaller
than arr[x]. Let this count be sc.
(iii) Count elements in arr[low..high] that are greater
than arr[x]. Let this count be gc.
(iv) Let n = (high-low+1). If sc >= n/4 and
gc >= n/4, then x is a central pivot.
3. Partition arr[low..high] around the pivot x.
4.
randQuickSort(arr, low, sc-1)
5.
randQuickSort(arr, high-gc+1, high)