Warning This class is being recorded. At least I think it is. It’s probably also being transcribed.
Approximate overview
Academic
Cultural
Peer
Wellness
Misc
Comparator.compare(x,y) returns a negative integer if x < y,
zero if x == y, and a positive integer if x > y. Don’t count on
the negative and positive integers returning -1/1.lo and hi or lb and ub) to keep track of
subvectors. That often permits us to avoid copying subvectors.large than I do), make sure that you also modify the state
drawings.See examples/quicksort/Quicksort.java.
Without looking at your notes, come up with an invariant for the main loop of partition.
private static <T> int partition(T[] vals, Comparator<? super T> order, int lb, int ub)
+-------+---+--------+---------------+----------+-------+
| | p | <= p | unprocessed | > p | |
+-------+---+--------+---------------+----------+-------+
| | | | | |
0 lb lb+1 small large ub length
pivot
Let’s translate that to code.
private static <T> int partition(T[] vals, Comparator<? super T> order, int lb, int ub) {
// If the subvector is small enough, return
// Initialize small and large
// Pick the pivot and put at the front
// Until the unprocessed section is empty
while (...) {
// Advance small, if possible
// Otherwise, retreat large, if possible
// Otherwise, swap the leftmost unprocessed element (a large value)
// with the rightmost unprocessed element (a small value) and
// advance small and retreat large.
} // while
// Put the pivot at the end of the small section.
}
Checking math
+---+---+---+
| | | |
+---+---+---+
lb=1
ub=2
lb=2
ub=2
Why did we swap small-1 with the pivot, rather than small.
+-------+---+--------+----------+-------+
| | p | <= p | > p | |
+-------+---+--------+----------+-------+
| | | | | |
0 lb lb+1 small ub length
pivot large
Answer: The thing at index small is large, as counter-intuitive as that sounds.
Will we have enough courses to cover demand?
I think so. Let’s do a back-of-the-envelope calculation.
80 majors in the class of 2025, 60 majors in the class of 2024, 50 students in the class of 2026 in the two CSC-207’s = demand for 190 seats. (This ignores the students going abroad, the seniors who need two courses, the mid-year graduates; as I said, it’s a “back of the envelope” calculation.)
1 section of 211 (24) + 2 sections of 301 (20 each) + 2 sections of 324 (20 each) + 2 sections of 341 (20 each) + 2 sections of 395 (20 each) = 184 seats.
What happens if the second 395 isn’t approved before registration?
Complex stuff that Sam doesn’t understand. “It’s above my pay grade.”
This seems unfair to people with two majors, both of which are competitive.
I agree.
What value do you suggest we take as the median in Quicksort?
I’m a fan of grabbing a few values and taking the median of those values.
One option: Three random values.
Another option: First, middle, and last.
Have you tried ChatGPTsort yet?
Nope. Soon.
Can we get more efficient than merge sort?
Not asymptotically with arbitrary data.
But in practice, using wall clock time, yes.
For particular kinds of data, there are more efficient sorting algorithms. Example: I know the contents of my array are 1..100, each value appearing once. Can I sort quickly? Yes. O(n).
Is Quicksort quicker than merge sort?
We’ll see in the competition. Or you can run experiments yourself.
Can I use multithreading?
No.
https://www.acm.org/code-of-ethics
TPS questions!
Modified from https://ethics.acm.org/code-of-ethics/using-the-code/case-dark-ux-patterns/. (Please don’t look there for analysis.)
The change request Stewart received was simple enough: replace the web site’s rounded rectangle buttons with arrows and adjust the color palette to one that mixes red and green text. But when Stewart looked at the prototype, he found it confusing. The left arrow suggested that the web site would go back to a previous page or cancel some action; instead, this arrow replaced the button for accepting the company’s default product. The right arrow, on the other hand, upgraded the user to the more expensive category; it also silently added a protection warranty without asking for confirmation. Stewart suggested to his manager that this confusing design would probably trick users into more expensive options that they didn’t want. The response was that these were the changes requested by the client.
Shortly after the updates were released into their production system, Stewart’s team was invited to a celebration. As a result of these changes, revenues at their client had increased significantly over the previous quarter. At the celebration, Stewart overheard some of the client’s managers discussing the small increase for refunds by users who claimed that they didn’t want the protection plan, but there weren’t many. One manager noted several complaints from visually impaired users, who noted that the mixture of red and green text obscured important disclaimers about the product. “So what you’re saying, then, is that the changes worked as planned,” quipped one of the managers.
TPS: What should Stewart do (or have done)?
Modified from https://ethics.acm.org/code-of-ethics/using-the-code/case-malware-disruption/. Please don’t read the analysis.
Rogue Services advertised its web hosting services as “cheap, guaranteed uptime, no matter what.” While some of Rogue’s clients were independent web-based retailers, the majority were focused on malware and spam. Several botnets used Rogue’s reliability guarantees to protect their command-and-control servers from take-down attempts. Spam and other fraudulent services leveraged Rogue for continuous delivery. Corrupted advertisements often linked to code hosted on Rogue to exploit browser vulnerabilities to infect machines with ransomware.
Despite repeated requests from major ISPs and international organizations, Rogue refused to intervene with these services, citing their “no matter what” pledge to their customers. Furthermore, international pressure from other governments failed to induce national-level intervention, as Rogue was based in a country whose laws did not adequately proscribe such hosting activities.
Ultimately, Rogue was forcibly taken offline through a coordinated effort from multiple security vendors working with several government organizations. This effort consisted of a targeted worm that spread through Rogue’s network. This denial-of-service attack successfully took Rogue’s machines offline, destroying much of the data stored with the ISP in the process. All of Rogue’s clients were affected. No other ISPs reported any impact from the worm, as it included mechanisms to limit its spread. As a result of this action, spam and botnet traffic immediately dropped significantly. In addition, new infections of several forms of ransomware ceased.
TPS: Was the response appropriate? Ethical? What principles would permit the security vendors and government organizations to write such software.
Read the first five paragraphs of https://ethics.acm.org/code-of-ethics/using-the-code/case-accessibility-in-software-development/. The last paragraph you read should be the one that starts “Nevertheless,the product owner was being pressured to launch the new version despite the accessibility defects.”
TPS: ….