Lab Assignment 14


Not Alike

Example
Array : {1, 34, 42, 34, 42, 34}
If we delete all 1s and 42s from the above array : 3 deletes
If we delete all 1s and 34s from the above array : 4 deletes
If we delete all 34s and 42s from the above array : 5 deletes
In each of the above cases we end up with equal numbers in the array. Therefore, minimum required deletes = 3.

int getMinimumDeletes( vector<int> &elements )
{
    // Implement this
}

Expanding obscure vocabulary

Example
Array : { ‘a’, ‘b’ }, k = 3
Output
aaa
aab
aba
abb
baa
bab
bba
bbb

void printAllStrings( vector<char> &letters, int k )
{
    // Print all possible strings
}

Subset Problem

Example:
If S = {1,2,3}

Then the output should be:
[]
[1]
[1,2]
[1,2,3]
[1,3]
[2]
[2,3]
[3]

void printAllSubsets( vector<int> &elements )
{
    // Print all the subsets of the given array
}

Tower of Hanoi

Description

Constraints

You can also see the animation of the puzzle:
Fibonacci solve
Source: Wikipedia

Example:

Let us suppose there are 2 disks and the rods are:

Disk 1: From A to C
Disk 2: From A to B
Disk 3: From C to B

void towerOfHanoi(int num_of_disks, string from_rod, string to_rod, string aux_rod){
// Print required series of moves to solve the puzzle
}