Algorithmic Prep
- For the actual event, we had a series of practices online and also in person in order to rehearse for the Algorhythmic and to put up our best performance.
At School:
-
We continued to plan together, generating new ideas and working to better the performance and assigning duties to everyone and refining the script to its best versions
-
We would meet as frequent as possible with typically meeting during lunch and office hours and figuring out discrepencies and other things such as timings
-
We also tried to make sure to practice more with everyone who wasn’t able to make it to the meetings and keep them up to date with the new things we added and new steps
-
We also worked around the media account and tried to generate many different viewers as well as serve as a way to ensure that people who missed out on the meetings and rehearsals could look to the account and see how everything is progressing
Link for social media account: @flower_mergers
Some images of planning and rehearsals:
Algorhytmic Code Prep (All Sorts)
import java.util.*;
public class Algorhytmic {
public static class Collectable implements Comparable<Collectable> {
int number;
String name;
String classroom;
public Collectable(int number, String name, String classroom) {
this.number = number;
this.name = name;
this.classroom = classroom;
}
@Override
public int compareTo(Collectable other) {
return this.name.compareToIgnoreCase(other.name);
}
@Override
public String toString() {
return "{\"number\":" + number + ", \"name\":\"" + name + "\", \"classroom\":\"" + classroom + "\"}";
}
}
static class FlowerGroup {
ArrayList<Collectable> members;
public FlowerGroup(ArrayList<Collectable> members) {
this.members = members;
}
// Bubble Sort, O(n^2) time complexity
public void bubbleSort() {
int n = members.size(); // takes the number of objects in the members arrayList
for (int i = 0; i < n - 1; i++) { // controls the number of passes
for (int j = 0; j < n - i - 1; j++) { // iterates over each pair
if (members.get(j).compareTo(members.get(j + 1)) > 0) { // compares j with j+1
Collectable temp = members.get(j); // swaps the elements if out of order
members.set(j, members.get(j + 1));
members.set(j + 1, temp);
}
}
}
}
// Merge Sort, O(n log n) time complexity
public void mergeSort() {
mergeSortHelper(0, members.size() - 1); // calls the helper method
}
private void mergeSortHelper(int low, int high) { // method that divides the arrays into smaller sub arrays
if (low < high) {
int mid = low + (high - low) / 2;
mergeSortHelper(low, mid);
mergeSortHelper(mid + 1, high);
merge(low, mid, high); // merges the sub-arrays
}
}
private void merge(int low, int mid, int high) { // takes all the 3 different sub arrays
ArrayList<Collectable> temp = new ArrayList<>(members); // array list to hold values
int i = low, j = mid + 1, k = low; // index variables where k is merged list
while (i <= mid && j <= high) {
if (temp.get(i).compareTo(temp.get(j)) <= 0) { // compares low with high if hih is less, merges and increases the position of i
members.set(k, temp.get(i));
i++;
} else {
members.set(k, temp.get(j)); // compares low with high if it is more, merges and increases the position of j
j++;
}
k++; // k's position is incremented regardless
}
while (i <= mid) { // this conditional exists to moving all the remaining elements to the main members list
members.set(k, temp.get(i));
k++;
i++;
}
}
// Selection Sort,
public void selectionSort() {
int n = members.size(); // size of the list
for (int i = 0; i < n - 1; i++) { // loop for each element
int minIndex = i; // assume the minimum is the first unsorted element
for (int j = i + 1; j < n; j++) { // iterate through the rest of the list
if (members.get(j).compareTo(members.get(minIndex)) < 0) { // check if we found a smaller element
minIndex = j; // update the index of the smallest element
}
}
Collectable temp = members.get(minIndex); // swap the smallest with the current element
members.set(minIndex, members.get(i));
members.set(i, temp);
}
}
// Quick Sort
public void quickSort() {
quickSortHelper(0, members.size() - 1); // calls the helper method to split members into sub arrays
}
private void quickSortHelper(int low, int high) {
if (low < high) {
int pi = partition(low, high);
quickSortHelper(low, pi - 1); // recursive call on left sub-array to divide it even further
quickSortHelper(pi + 1, high); // recursive call on right sub-array to divide it even further
}
}
private int partition(int low, int high) {
Collectable pivot = members.get(high); // choose pivot as last element
int i = low - 1; // index of smaller element
for (int j = low; j < high; j++) {
if (members.get(j).compareTo(pivot) < 0) { // conditional to order the lower values before the pivot and the higher ones after pivot
i++; // increment index of smaller element
Collectable temp = members.get(i);
members.set(i, members.get(j));
members.set(j, temp);
}
}
Collectable temp = members.get(i + 1);
members.set(i + 1, members.get(high));
members.set(high, temp);
return i + 1; // return the index for the partitioning
}
// Insertion Sort
public void insertionSort() {
int n = members.size();
for (int i = 1; i < n; ++i) {
Collectable key = members.get(i);
int j = i - 1;
while (j >= 0 && members.get(j).compareTo(key) > 0) {
members.set(j + 1, members.get(j));
j = j - 1;
}
members.set(j + 1, key);
}
}
@Override
public String toString() {
StringBuilder result = new StringBuilder("[");
for (int i = 0; i < members.size(); i++) {
result.append(members.get(i).toString());
if (i < members.size() - 1) {
result.append(", ");
}
}
result.append("]");
return result.toString();
}
}
public static void main(String[] args) { // setting up tester data
ArrayList<Collectable> members = new ArrayList<>();
members.add(new Collectable(1, "Alara", "CSP"));
members.add(new Collectable(2, "Abigail", "CSP"));
members.add(new Collectable(3, "Aditi", "CSP"));
members.add(new Collectable(4, "Yuri", "CSA"));
members.add(new Collectable(5, "Aditya", "CSA"));
members.add(new Collectable(6, "Jishnu", "CSA"));
members.add(new Collectable(7, "Ethan T", "CSA"));
members.add(new Collectable(8, "Alex", "CSA"));
members.add(new Collectable(9, "Tanvi", "CSP"));
members.add(new Collectable(10, "James", "CSA"));
members.add(new Collectable(11, "Anthony", "CSA"));
members.add(new Collectable(12, "Emaad", "CSA"));
members.add(new Collectable(13, "Tay", "CSA"));
members.add(new Collectable(13, "Krishiv", "CSA"));
members.add(new Collectable(14, "David", "CSA"));
FlowerGroup flowerGroup = new FlowerGroup(members);
// Before Sorting
System.out.println("\nBefore Sorting:");
System.out.println(flowerGroup.toString());
// Bubble Sort
flowerGroup.bubbleSort();
System.out.println("\nAfter Bubble Sort:");
System.out.println(flowerGroup.toString());
// Merge Sort
flowerGroup.mergeSort();
System.out.println("\nAfter Merge Sort:");
System.out.println(flowerGroup.toString());
// Selection Sort
flowerGroup.selectionSort();
System.out.println("\nAfter Selection Sort:");
System.out.println(flowerGroup.toString());
// Quick Sort
flowerGroup.quickSort();
System.out.println("\nAfter Quick Sort:");
System.out.println(flowerGroup.toString());
// Insertion Sort
flowerGroup.insertionSort();
System.out.println("\nAfter Insertion Sort:");
System.out.println(flowerGroup.toString());
}
}
Algorhytmic.main(null)
Before Sorting:
[{"number":1, "name":"Alara", "classroom":"CSP"}, {"number":2, "name":"Abigail", "classroom":"CSP"}, {"number":3, "name":"Aditi", "classroom":"CSP"}, {"number":4, "name":"Yuri", "classroom":"CSA"}, {"number":5, "name":"Aditya", "classroom":"CSA"}, {"number":6, "name":"Jishnu", "classroom":"CSA"}, {"number":7, "name":"Ethan T", "classroom":"CSA"}, {"number":8, "name":"Alex", "classroom":"CSA"}, {"number":9, "name":"Tanvi", "classroom":"CSP"}, {"number":10, "name":"James", "classroom":"CSA"}, {"number":11, "name":"Anthony", "classroom":"CSA"}, {"number":12, "name":"Emaad", "classroom":"CSA"}, {"number":13, "name":"Tay", "classroom":"CSA"}, {"number":13, "name":"Krishiv", "classroom":"CSA"}, {"number":14, "name":"David", "classroom":"CSA"}]
After Bubble Sort:
[{"number":2, "name":"Abigail", "classroom":"CSP"}, {"number":3, "name":"Aditi", "classroom":"CSP"}, {"number":5, "name":"Aditya", "classroom":"CSA"}, {"number":1, "name":"Alara", "classroom":"CSP"}, {"number":8, "name":"Alex", "classroom":"CSA"}, {"number":11, "name":"Anthony", "classroom":"CSA"}, {"number":14, "name":"David", "classroom":"CSA"}, {"number":12, "name":"Emaad", "classroom":"CSA"}, {"number":7, "name":"Ethan T", "classroom":"CSA"}, {"number":10, "name":"James", "classroom":"CSA"}, {"number":6, "name":"Jishnu", "classroom":"CSA"}, {"number":13, "name":"Krishiv", "classroom":"CSA"}, {"number":9, "name":"Tanvi", "classroom":"CSP"}, {"number":13, "name":"Tay", "classroom":"CSA"}, {"number":4, "name":"Yuri", "classroom":"CSA"}]
After Merge Sort:
[{"number":2, "name":"Abigail", "classroom":"CSP"}, {"number":3, "name":"Aditi", "classroom":"CSP"}, {"number":5, "name":"Aditya", "classroom":"CSA"}, {"number":1, "name":"Alara", "classroom":"CSP"}, {"number":8, "name":"Alex", "classroom":"CSA"}, {"number":11, "name":"Anthony", "classroom":"CSA"}, {"number":14, "name":"David", "classroom":"CSA"}, {"number":12, "name":"Emaad", "classroom":"CSA"}, {"number":7, "name":"Ethan T", "classroom":"CSA"}, {"number":10, "name":"James", "classroom":"CSA"}, {"number":6, "name":"Jishnu", "classroom":"CSA"}, {"number":13, "name":"Krishiv", "classroom":"CSA"}, {"number":9, "name":"Tanvi", "classroom":"CSP"}, {"number":13, "name":"Tay", "classroom":"CSA"}, {"number":4, "name":"Yuri", "classroom":"CSA"}]
After Selection Sort:
[{"number":2, "name":"Abigail", "classroom":"CSP"}, {"number":3, "name":"Aditi", "classroom":"CSP"}, {"number":5, "name":"Aditya", "classroom":"CSA"}, {"number":1, "name":"Alara", "classroom":"CSP"}, {"number":8, "name":"Alex", "classroom":"CSA"}, {"number":11, "name":"Anthony", "classroom":"CSA"}, {"number":14, "name":"David", "classroom":"CSA"}, {"number":12, "name":"Emaad", "classroom":"CSA"}, {"number":7, "name":"Ethan T", "classroom":"CSA"}, {"number":10, "name":"James", "classroom":"CSA"}, {"number":6, "name":"Jishnu", "classroom":"CSA"}, {"number":13, "name":"Krishiv", "classroom":"CSA"}, {"number":9, "name":"Tanvi", "classroom":"CSP"}, {"number":13, "name":"Tay", "classroom":"CSA"}, {"number":4, "name":"Yuri", "classroom":"CSA"}]
After Quick Sort:
[{"number":2, "name":"Abigail", "classroom":"CSP"}, {"number":3, "name":"Aditi", "classroom":"CSP"}, {"number":5, "name":"Aditya", "classroom":"CSA"}, {"number":1, "name":"Alara", "classroom":"CSP"}, {"number":8, "name":"Alex", "classroom":"CSA"}, {"number":11, "name":"Anthony", "classroom":"CSA"}, {"number":14, "name":"David", "classroom":"CSA"}, {"number":12, "name":"Emaad", "classroom":"CSA"}, {"number":7, "name":"Ethan T", "classroom":"CSA"}, {"number":10, "name":"James", "classroom":"CSA"}, {"number":6, "name":"Jishnu", "classroom":"CSA"}, {"number":13, "name":"Krishiv", "classroom":"CSA"}, {"number":9, "name":"Tanvi", "classroom":"CSP"}, {"number":13, "name":"Tay", "classroom":"CSA"}, {"number":4, "name":"Yuri", "classroom":"CSA"}]
After Insertion Sort:
[{"number":2, "name":"Abigail", "classroom":"CSP"}, {"number":3, "name":"Aditi", "classroom":"CSP"}, {"number":5, "name":"Aditya", "classroom":"CSA"}, {"number":1, "name":"Alara", "classroom":"CSP"}, {"number":8, "name":"Alex", "classroom":"CSA"}, {"number":11, "name":"Anthony", "classroom":"CSA"}, {"number":14, "name":"David", "classroom":"CSA"}, {"number":12, "name":"Emaad", "classroom":"CSA"}, {"number":7, "name":"Ethan T", "classroom":"CSA"}, {"number":10, "name":"James", "classroom":"CSA"}, {"number":6, "name":"Jishnu", "classroom":"CSA"}, {"number":13, "name":"Krishiv", "classroom":"CSA"}, {"number":9, "name":"Tanvi", "classroom":"CSP"}, {"number":13, "name":"Tay", "classroom":"CSA"}, {"number":4, "name":"Yuri", "classroom":"CSA"}]