Click or drag to resize
SparseVector Class

The SparseVector class represents a D-dimensional mathematical vector. Vectors are mutable: their values can be changed after they are created. It includes methods for addition, subtraction, dot product, scalar product, unit vector, and Euclidean norm.

The implementation is a symbol table of indices and values for which the vector coordinates are nonzero. This makes it efficient when most of the vector coordindates are zero. See also for an immutable (dense) vector data type.

Inheritance Hierarchy
SystemObject
  Algs4NetSparseVector

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class SparseVector

The SparseVector type exposes the following members.

Constructors
  NameDescription
Public methodSparseVector
Initializes a d-dimensional zero vector.
Top
Properties
  NameDescription
Public propertyDimension
Returns the dimension of this vector.
Top
Methods
  NameDescription
Public methodDot(Double)
Returns the inner product of this vector with the specified array.
Public methodDot(SparseVector)
Returns the inner product of this vector with the specified vector.
Public methodGet
Returns the ith coordinate of this vector.
Public methodMagnitude
Returns the magnitude of this vector. This is also known as the L2 norm or the Euclidean norm.
Public methodStatic memberMainTest
Demo test the SparseVector data type.
Public methodNnz
Returns the number of nonzero entries in this vector.
Public methodPlus
Returns the sum of this vector and the specified vector.
Public methodPut
Sets the ith coordinate of this vector to the specified value.
Public methodScale
Returns the scalar-vector product of this vector with the specified scalar.
Public methodToString
Returns a string representation of this vector.
(Overrides ObjectToString.)
Top
Remarks

For additional documentation, see Section 3.5 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

This class is a C# port from the original Java class SparseVector implementation by the respective authors.

See Also