Two ascending arrays A = [2, 5, 9] and B = [1, 5, 8] are merged by repeatedly comparing their first unconsumed elements. Equal values are taken from A first, and remaining elements are copied after one array is exhausted. How many element-to-element comparisons are made?
Informatics
Question · Medium
Which graph traversal algorithm correctly finds the shortest path (minimum number of edges) from a start vertex to all other vertices in an unweighted graph?
Question · Easy
For n = 20304, an algorithm starts s = 0 and repeatedly executes s = 10*s + n mod 10, then n = n div 10, until n = 0. Here div is integer division. What is the final value of s?
Euclid's algorithm starts with a = 252 and b = 198. While b is nonzero, it executes r = a mod b, a = b, b = r. How many executions of the loop body occur, and what is the final a?
In the classic N-Queens backtracking problem, two queens at positions (r1, c1) and (r2, c2) attack each other diagonally if and only if:
A rooted tree with vertices 1 through 7 is represented by the parent vector [0, 1, 1, 2, 2, 4, 6], where 0 marks the root. What is the path from vertex 7 to the root, including both endpoints?
In graph theory, how many edges does any tree with V vertices contain?
According to Euler's theorem, an undirected connected graph contains an Eulerian Circuit (a closed walk visiting every edge exactly once) if and only if:
Under what condition does Counting Sort achieve linear time complexity O(n)?
A rooted tree on vertices 1 through 8 has parent vector [0, 1, 1, 2, 2, 3, 6, 6]. Which set consists exactly of its leaves?
For nonnegative integers, define F(n) = 0 when n = 0 and F(n) = F(n div 10) + n mod 10 otherwise. What are F(5073) and the total number of calls, including the initial call and the base-case call?
A simple undirected graph has vertices {1, 2, 3, 4, 5} and edges {1-2, 1-3, 2-3, 3-4, 4-5}. After vertex 3 and all its incident edges are deleted, how many connected components remain?
How many total permutations exist for a sequence of n distinct elements?
Given an array sorted in ascending order, which two-pointer strategy finds if two elements sum to a given target T in O(n) time?
In graph theory, what is the maximum number of edges in a simple undirected graph with V vertices?
An algorithm sets n = 360, d = 2 and c = 0. While n > 1, if n mod d = 0 it divides n by d and increments c; otherwise it increments d. What are the final values of c and d?
An algorithm sets s = 0. For i from 1 through 4, it sets j = i and repeatedly increments s and replaces j by j - 2 while j > 0. What is the final value of s?
Binary search looks for 21 in the 1-indexed array [2, 5, 8, 12, 16, 21, 27, 33, 40]. It starts with l = 1 and r = 9, uses m = (l + r) div 2, and after a mismatch excludes position m. How many array-element comparisons occur before success?
If x1, x2, x3 are the roots of the cubic equation x^3 - 3x + 1 = 0, what is the value of x1^3 + x2^3 + x3^3?
Mathematics
Question · Hard
In the finite cyclic group (Z12, +), what is the order of the subgroup generated by the element hat(4)?
How many invertible elements (units) exist in the ring (Z20, +, *)?
What is the value of the limit L = lim (x -> 0) (sin(x) - x) / x^3?
What is the area of the region bounded by the curve y = x * ln(x), the x-axis, and the vertical line x = e?
A 1-indexed sorted array is [2, 2, 3, 3, 3, 5]. An algorithm sets j = 1, then for i from 2 through 6, if a[i] != a[j], it increments j and assigns a[j] = a[i]. What are the final j and the first j array elements?
A recursive function returns n when n <= 1 and otherwise returns F(n - 1) + F(n - 2), without memoization. What are F(5) and the total number of calls made while evaluating it, including the initial call and every base-case call?
Backtracking generates all binary strings of length 5 containing exactly two 1s, with no adjacent 1s and with the first and last positions not both equal to 1. How many complete strings are accepted?
What is the value of the limit L = lim (n -> infinity) (1/n) * sum_(k=1)^n sqrt(k / n)?
How many functions f: {1, 2, 3} -> {A, B, C, D} are strictly injective (one-to-one)?
What is the derivative of f(x) = x^3 * ln(x) for x > 0?
A directed graph has vertices 1 through 6 and arcs 1->2, 2->1, 2->3, 3->4, 4->3, 4->5, 5->6 and 6->5. What is the minimum number of arcs that must be added to make it strongly connected?
What is the value of the definite integral I = integral from 0 to pi/2 of (sin(x) / (sin(x) + cos(x))) dx?
What is the modular multiplicative inverse of 5 modulo 13 (the integer x in {0, 1, ..., 12} such that 5*x = 1 (mod 13))?
In the binomial expansion of (1 + 2x)^6, what is the coefficient of x^4?
What is the value of the limit L = lim (x -> 0) (1 - sqrt(cos(x))) / x^2?
According to De Moivre's formula, what is the value of (cos(pi/6) + i*sin(pi/6))^6?
In Cartesian coordinates, A = (1, 2), B = (-1, 0) and C = (3, 2). What is the foot of the perpendicular from A to the line BC?
How many derangements D_4 (permutations of {1, 2, 3, 4} with no fixed point, so pi(i) != i for all i) exist?
What is the area of the triangle in R^2 with vertices at A(0, 0), B(3, 1), and C(1, 4)?
What is the equation of the slant (oblique) asymptote of f(x) = x^3 / (x^2 - 1) as x -> infinity?
If r is a root of multiplicity k >= 2 of a real polynomial P(X), which condition must hold for P'(X)?
For the matrix with rows [4, 1, 7], [2, 6, 3] and [5, 0, 8], an algorithm first finds the minimum in each row, then returns the maximum of those three minima. What value does it return?
What is the value of the limit L = lim (x -> infinity) x * [ln(x + 1) - ln(x)]?
In C++, void f(int &x, int y) executes x = x + y; then y = x - y; then x = x + y. If a = 3 and b = 5 before f(a, b), what are a and b afterward?
What is the value of the definite integral I = integral from 0 to 1 of (1 / (1 + e^x)) dx?
What is the number of solutions to the equation x^2 = 1 in the ring (Z8, +, *)?
In probability, if an urn contains 3 red balls and 7 blue balls, what is the probability of drawing 2 red balls when drawing 2 balls at once without replacement?
What is the value of the determinant of the 3x3 cyclic matrix C = | 1 2 3 | / | 3 1 2 | / | 2 3 1 |?
What is the limit L = lim (x -> 0) (tan(3x) - sin(3x)) / x^3?
That is everything here.