Place this object method inside the concrete class. Its precondition is the representation invariant; its postcondition is that the abstract data type state is unchanged and its left-to-right contents have been printed in bracket notation followed by a newline:
def display: Unit = {
  print("[")
  var i = 0
  while (i < size) {
    if (i > 0) print(", ")
    print(a(slot(i)))
    i += 1
  }
  println("]")
}
Assume ordinary sequential execution and successful output. The loop invariant is , unchanged representation, and output consisting of [ followed by precisely the first abstract values, separated by commas and spaces. The loop variant decreases. At exit the closing bracket completes the required display, including [] for emptiness. This takes output operations and constant space.
Only the list header is present: h.next eq h, h.prev eq h, and h.index is the dimension. This represents every coordinate as zero, including the unique zero-dimensional vector when the dimension is zero. The header is never treated as a nonzero coordinate.
Use an immutable index and mutable value and links:
class Node(var value: Double, val index: Int,
           var prev: Node = null, var next: Node = null)
For the sparse linked vector representation, a header h has h.index >= 0, records that vector's dimension, and lies on a finite circular linked list. Every ordinary linked list node has an index in [0,h.index), a nonzero finite value, and a unique index; indices increase strictly from h.next to h.prev. For every reachable linked list node, including h, p.next.prev eq p and p.prev.next eq p. The abstraction function fills unspecified coordinates with zero. The header's value has no meaning. Finite real coordinates are assumed throughout; infinities and NaN are not ordinary real number coordinates for a mathematical inner product.
Use exponentiation by squaring, retaining the unprocessed exponent in k:
def eaBinary(n: Int): Double = {
  require(n > 0)
  var base = 1.0 + 1.0 / n.toDouble
  var k = n
  var result = 1.0
  while (k > 0) {
    if ((k & 1) != 0) result *= base
    k = k / 2
    if (k > 0) base *= base
  }
  result
}
Writing , the loop invariant is and . If the old exponent is , , multiplying the accumulator by and replacing the remaining power by preserves the invariant. When , the unused squaring may be omitted. The nonnegative integer k is a loop variant, since for . At exit the remaining power is one, giving . There are iterations, at most one accumulator multiplication and one squaring per iteration, hence multiplications and constant space.
Keep a running product of the fixed base. In particular, 1.0/n uses floating-point arithmetic, avoiding the truncation that integer division would introduce:
def eaLinear(n: Int): Double = {
  require(n > 0)
  val base = 1.0 + 1.0 / n.toDouble
  var k = 0
  var result = 1.0
  while (k < n) {
    result *= base
    k += 1
  }
  result
}
The loop invariant is and . Initially the empty product is one. Multiplication by base and incrementing k preserve the invariant. The loop variant decreases by one. On exit , so the result is , with exactly multiplications and time complexity. With Double, the operational result is the rounded recurrence, rather than an exact real power; this distinction applies to the next two power computations too.
Maintain two spanning trees whose sorted edge sequences share a prefix, initially of length zero. At the next position, select whichever next edge has smaller weight, breaking equal-weight ties arbitrarily. Keep that tree unchanged and apply spanning-tree prefix exchange from part (i) to the other tree. Both trees now have a common prefix one edge longer; one tree's sorted weight vector is unchanged and the other's cannot increase coordinatewise.
Repeat for positions. The final trees have all their edges in common, so they are one tree . Throughout, the sorted weight vector of never exceeds its original vector from , and that of never exceeds its original vector from . Consequently their common final vector satisfies at every position.
This proves the required existence without assuming either original tree was minimum. More generally, a minimum spanning tree has a coordinatewise minimum spanning-tree weight vector: after restricting the graph to edges of weight at most any threshold, a maximum forest contains at least as many edges as the corresponding portion of every other spanning tree. This threshold viewpoint explains why an optimum can simultaneously dominate every sorted coordinate, rather than merely having a smaller total weight.
The displayed reference to index makes the nontrivial case ; at the trees already agree and no further edge exists. Write and . If , its weight is at least the first nonprefix weight and at most that weight by hypothesis. Thus it ties for the next position, and simply ordering this tie with first gives the result.
Otherwise add to . The resulting fundamental cycle contains an edge : if its whole path lay in , then would already contain a cycle. Every edge of , including , has weight at least . Set .
This is a spanning tree and still contains . Its sorted order can begin with the specified prefix and then , because all remaining edges have weight at least and each prefix weight is at most . Replacing one entry of a multiset by a no-larger entry cannot increase any sorted order statistic: for every threshold, the number of entries below or equal to it cannot decrease. Hence for every . Ties may be ordered as needed; the paper prescribes nondecreasing weights, not an immutable global tie-break rule. This is spanning-tree prefix exchange.
True. Delete ; the resulting two connected components define a cut of a graph. If a crossing edge had , the exchange would be a spanning tree of smaller total weight, contradicting the minimum spanning tree assumption. Thus is a light edge crossing a cut for this fundamental cut. It need not be uniquely light.
True. A tree has exactly one path between any two vertices. For , that path between the endpoints of , together with , is a fundamental cycle. Every cycle in must contain , since itself is acyclic; deleting from such a cycle leaves that same unique path. Therefore the cycle is unique. Minimality of the spanning tree's weight is not needed for this assertion.
The minimum spanning tree cut property, in its safe-edge form, says: if an edge set is contained in some minimum spanning tree, a cut of a graph respects , and is a light edge crossing a cut, then is contained in some minimum spanning tree.
Choose an MST containing . If , nothing changes. Otherwise adding creates its unique fundamental cycle. The path in between the endpoints of must cross the chosen cut; take such an edge . Since the cut respects , . Since is light, . The exchange is a spanning tree containing , with total weight no greater than that of . Minimality of forces equal optimum weight, proving the claim. Equal edge weights cause no difficulty: “safe” means belonging to some compatible optimum, not to every optimum.
A cut of a graph is a partition into two nonempty vertex sets. An edge crosses it when its endpoints lie on opposite sides. An edge set respecting a cut contains no crossing edge. A light edge crossing a cut has minimum weight among all crossing edges; there can be several tied light edges. These definitions concern the graph's weighted edges, independently of any particular spanning tree.
Replace breadth-first search by Dijkstra's algorithm from , using the positive edge weights to compute . The strongly connected components, the condensation graph and the reverse-topological order propagation are unchanged, because reachability ignores weights. Only the label assigned to a reachable vertex changes.
With a binary heap, the total time is , including the linear component-processing stages. More specialized priority queues give their corresponding shortest-path bounds. The proof still compares the precomputed distances from ; it must not add the weight of a path from to the candidate, which would optimize a different quantity.
First run breadth-first search from to compute each distance . All are finite by hypothesis. Next compute the strongly connected components and their condensation graph . For every component , initialize a representative minimizing over . Process components in reverse topological order, using
Break equal-distance ties consistently, for example by fixed vertex index. Return for every .
Every vertex of one strongly connected component reaches every other; every reachable different component is reached through some first outgoing edge of . Since is a directed acyclic graph, reverse topological order has already solved every successor. Induction over that order proves that the representative minimizes over all reachable vertices. This is minimum reachable label propagation.
All stages take time and space with explicit adjacency lists. Retaining parallel component edges is harmless: they can be scanned once each without sorting or deduplication. Reachability here includes the length-zero path, so ; this standard convention also makes the requested answer meaningful at a sink.
False for directed distance. Take four vertices . Put both directed edges between every distinct pair in , and add and . Every vertex has out-degree two, satisfying , and there are no self-loops. Nevertheless no directed path leads from any of to , so the claimed finite upper bound on graph distance fails.
If “connected” means weakly connected, that portion does follow: a weak component of size gives each of its vertices out-degree at most , so each component would have size at least , making two components impossible. It does not imply a strongly connected directed graph. Thus either the strong-connectivity interpretation fails outright or the weak interpretation leaves the distance assertion false; the complete claim is false in either case.
False. Let the directed edges be , , and . Start depth-first search at and explore its neighbor before . Then
The directed path exists and , but and are siblings in the discovery tree. An existing path may leave the current recursive branch via a gray ancestor and only later enter a different branch. The usual white-path condition would need all vertices of a suitable path to be white when is discovered; that condition is absent here.
Figure 1.
A directed path crosses from an earlier DFS branch to a later branch through the root; node labels give discovery and finishing times
. Details.
False. Use only the directed edge , but choose first in the outer loop of depth-first search. It finishes before a second discovery tree starts at : , , , . The edge supplies the required directed path and , yet . A path to an already black vertex need not put the two vertices into one discovery tree.
False. Take two vertices with both directed edges, and start depth-first search at . The timestamps are , , , . There is an edge, hence a directed path, from to , but . Reaching a gray ancestor does not make the ancestor finish first.
For , use largest-denomination-first greedy algorithm steps: for , take coins and replace the residual amount by . A target is representable exactly when it is divisible by , because the smallest denomination is , not one.
To prove optimality whenever the target is representable, observe that an optimum can have fewer than coins of every denomination with : replacing such coins by one coin preserves value and reduces the count by . After all such carrying, the coefficients of are the unique base- digits of , while the coefficient of is the remaining quotient. Largest-first division produces exactly these coefficients. The greedy coin count is optimal, and can be computed with quotient/remainder operations without listing every coin.
For , distinct denominations permit only ; then all coins have value one and the answer is . This handles the printed positive-integer condition without silently assuming .
For the minimum coin change recurrence, initialize and use
where the minimum over no feasible predecessor is and . Removing the last coin of an optimal representation proves the lower bound; appending the corresponding coin to an optimal predecessor proves attainability. is the minimum number of coins, obtained in time and space. Store one minimizing coin per amount if the actual coins are wanted.
Use a Boolean dynamic programming state for whether amount can be made exactly. Initialize and, for , compute
An empty disjunction is false. Any nonempty representation ends in some coin; removing it gives one of the displayed predecessor states, and adding it back proves the converse. Return . This takes time and space for positive integer denominations and nonnegative integer target , with unlimited coins of each type.

Pinned article: Introduction to the OurBigBook Project

Welcome to the OurBigBook Project! Our goal is to create the perfect publishing platform for STEM subjects, and get university-level students to write the best free STEM tutorials ever.
Everyone is welcome to create an account and play with the site: ourbigbook.com/go/register. We belive that students themselves can write amazing tutorials, but teachers are welcome too. You can write about anything you want, it doesn't have to be STEM or even educational. Silly test content is very welcome and you won't be penalized in any way. Just keep it legal!
We have two killer features:
  1. topics: topics group articles by different users with the same title, e.g. here is the topic for the "Fundamental Theorem of Calculus" ourbigbook.com/go/topic/fundamental-theorem-of-calculus
    Articles of different users are sorted by upvote within each article page. This feature is a bit like:
    • a Wikipedia where each user can have their own version of each article
    • a Q&A website like Stack Overflow, where multiple people can give their views on a given topic, and the best ones are sorted by upvote. Except you don't need to wait for someone to ask first, and any topic goes, no matter how narrow or broad
    This feature makes it possible for readers to find better explanations of any topic created by other writers. And it allows writers to create an explanation in a place that readers might actually find it.
    Figure 1.
    Screenshot of the "Derivative" topic page
    . View it live at: ourbigbook.com/go/topic/derivative
  2. local editing: you can store all your personal knowledge base content locally in a plaintext markup format that can be edited locally and published either:
    This way you can be sure that even if OurBigBook.com were to go down one day (which we have no plans to do as it is quite cheap to host!), your content will still be perfectly readable as a static site.
    Figure 5. . You can also edit articles on the Web editor without installing anything locally.
    Video 3.
    Edit locally and publish demo
    . Source. This shows editing OurBigBook Markup and publishing it using the Visual Studio Code extension.
  3. https://raw.githubusercontent.com/ourbigbook/ourbigbook-media/master/feature/x/hilbert-space-arrow.png
  4. Infinitely deep tables of contents:
    Figure 6.
    Dynamic article tree with infinitely deep table of contents
    .
    Descendant pages can also show up as toplevel e.g.: ourbigbook.com/cirosantilli/chordate-subclade
All our software is open source and hosted at: github.com/ourbigbook/ourbigbook
Further documentation can be found at: docs.ourbigbook.com
Feel free to reach our to us for any help or suggestions: docs.ourbigbook.com/#contact