Friday, January 19th, 2024

If opportunity doesn't knock, build a door.

— Milton Berle

MUS106 Lecture 5

  • Elvis Presley’s popularity and live performance capability outgrew Sun Records’ financial capability six months after Blackboard Jungle’s debut (Sam Phillips couldn’t even pay Elvis’s royalties)—Sam Phillips sold Elvis’s contract to RCA for $35,000 in 1955. Elvis hired Colonel Tom Parker as agent.
  • ”Elvis the Pelvis”: nickname given by the press (?) to condemn against his appeal to teenage girls.
    • June 1956, Milton Berle Show
  • Elvis got drafted in 1957, and chose to enlist into the military to serve in Germany (and shaved his iconic hair) instead of the entertainment corps. This helped recasting him in a patriotic light.
  • Elvis released some gospel records, which he wanted to do for a long time.
  • Elvis: a song stylist (never writes his own music)
  • Aloha from Hawaii was broadcasted through globally linked satellite broadcast; 1 billion people were estimated to have watched it (25% of global population)

ECS122A quiz 2 study guide problems

Q1

Code analysis, like quiz1 or hw1 or any class code analysis

See ECS122A problem set 1 and ECS122A quiz 1

Q2

Solve via recurrence tree, and confirm via substitution.

1)

layers

  • subproblems, each with operations
  • subproblems, each with operations

The tree height is , so we have . To ease proving, we can add a lower order term

To confirm via substitution

2)

layers

  • subproblems, each with operations
  • subproblems, each with operations

Runtime increases drastically in the leaves, overpowering the work done to split & combine solutions (), so we have .

To make it easier to prove, we can add a lower order term. Confirm via substitution:

3)

  • subproblems each with operations
  • subproblems each with operations

The work in leaves / higher tree depths decreases drastically, so we can safely disregard them. The overall runtime is therefore , the work taken to split & merge solutions, which came from .

Confirm via substitution:

Solve for :

Q3

Design & analyze the run-time of your algorithms

1) Write pseudocode that lists the subsets of an array of ints.

// Assuming all elements are unique
// Assuming duplicate subsets are OK
int[][] subsets_of(int[] arr) {
    int[] result = [[]];
    for (i from 1 to arr.length ^ 2) {
        int[] current = []
        for (j from 0 to arr.length) {
            if (if j-th bit of i is 1)
                current.add(arr[j])
        }
        result.add(current)
    }
    return result;
}
  • Outer loop: It takes to iterate through the number of possible subsets. The loop counter i also happen to encode which elements are in the current subset.
  • Inner loop: It takes time / time to add the elements encoded in i into the current subset.
  • Combined, the algorithm takes time.

2): Write psuedocode that finds the smallest number of an array of ints.

skipped

3): Write psudedocode that lists all possible substring of a string S.

skipped

4): Given you have two sorted lists, write pseudocode that returns a new merged sorted list

int[] merge_sorted(int[] a, int[] b) {
    int i = 0, j = 0;
    int[] result = [];
    while (i < a.length or j < b.length) {
        if (i == a.length) {
            result.add(b[j]);
            j++;
            continue;
        } else if (j == b.length) {
            result.add(a[i]);
            i++;
            continue;
        } else if (a[i] < b[j]) {
            result.add(a[i]);
            i++;
            continue
        } else {
            result.add(b[j]);
            j++;
            continue
        }
    }
    return result;
}

runtime. The loop iterates through both arrays exactly once, so the runtime is the sum of lengths of the two arrays.