AI Program Knowledge
AI Knowledge
Sample Questions
- The below function attempts to format an integer, using commas as a thousands separator. Which test case would fail, indicating a bug?
choice
- assert format(0) == ‘0’
- assert format(100000) == ‘100,000’
- assert format(1000) == ‘1,000’
- assert format(100) == ‘100’
- The below code implements the sieve of Eratosthenes algorithm for finding prime numbers. What is wrong with it?
- It eventually raises a stack overflow error
- It only sieves even numbers
- It never terminates when called
- It doesn’t output the first prime number
- Assume there is an ORM with typical methods on its query object: all, count, exists, and first. Which code snippet has the most efficient query usage to determine if any matching row objects satisfy a predicate? Assume the and operator short-circuits.
- query.first() is not None and any(predicate(row) for row in query.all())
- query.count() and any(predicate(row) for row in query.all())
- query.exists() and any(predicate(row) for row in query.all())
- any(predicate(row) for row in query.all())
- Which of the following algorithms is most suitable for binary classification?
- Simplex
- Linear regression
- Logistic regression
- K-means
- What is the problem with executing the below SQL string?
- It has invalid syntax
- It does not quote its parameter
- It may be vulnerable to an injection
- It does not support integer ids
- All of the below are common examples of probabilistic Monte-Carlo algorithms, with one-sided error and deterministic running time, except which one?
- randomized quicksort
- edge contraction to find a minimum cut in a graph
- bloom filters
- primality tests
- The below code uses multiple inheritance to implement geometries. Fill in the missing line of code
- super().init(side, 90)
- super(Square, self).init(side, 90)
- super(Rectangle, self).init(side, side)
- super(Rhombus, self).init(side, side)
- When overwriting an existing file, what is a reason to first write to a temporary named file, and then use the system to rename it to the destination?
- To guarantee atomicity of the data written to the destination
- To save disk space
- To increase write performance
- To prevent permissions errors in opening the destination file
- Given an array of hash sets, the task is to find the intersection of all the sets. Which implementation is both correct and the fastest asymptotically?
- return sets.fold(sets.minBy({it.size})?:setOf()){r,s->r.intersect(s)}
- return sets.fold(setOf()){r,s->r.intersect(s)}
- return sets.fold(sets[0]){r,s->r.intersect(s)}
- return sets.reduce{r,s->r.intersect(s)}
- Which of the following best describes the output of an “embedding”?
- A sparse,high-dimensional vector
- A basis vector
- A one-hot vector
- A dense,low-dimensional vector