Tutor profile: Jefferson K.
Subject: Python Programming
In Python for loops can be iterated over either a list or a unique Python construct known as a generator. What are some limitations to using a generator? What are some advantages?
A generator computes the value to be returned by the iterator at the moment it is asked for. As a consequence generators can only be used once per instance, and cannot be indexed at specific values (except by iterating to said value). However, generators don’t need to store all yielded values in memory, which can offer significant performance benefits and allows for infinite sets to be represented.
Subject: Java Programming
When would you use the ‘synchronized’ keyword in Java?
The synchronized keyword can be used in a method declaration or as a code block in order to acquire the lock of the instance the declared method (or method containing the code block) is being called on. By acquiring this lock, the JVM ensures that only one execution of a synchronized method or code block can be executed on any given instance concurrently. This is useful when multiple threads need to share and mutate the same instance of an object, typically for I/O and data stores.
Suppose you were scrolling through Census data and picked a surveyed individual at random. You are unaware of the individual’s profession, but judging by the data-set, you determine they must be either a CEO or a farmer. Upon learning that the selected individual earned an annual income of greater than $300,000 a year; which job would you guess they held, and why?
Many consider the above average salary to be an indicator of the selected individual being a CEO; after all, such a salary is more common among CEOs than farmers. However, this line of thinking entirely ignores our prior knowledge on the general odds of *any* randomly selected individual being a farmer rather than a CEO (~20:1). A Bayesian approach would take the total number of high earning CEOs and divide it by the total number of high earners who are either CEOs or farmers. In doing so, this method takes into account the greater raw number of farmers.