yohandi
A recent graduate with a strong interest in algorithms and data structures.

Algorithm and Data Structure Class Header Collection

Unlike the previous blogs, this space is dedicated purely to my algorithm and data structure class headers. This ongoing project is an extension of my old archive, which can be found here. Pretty much I will keep updating both the old archive and this showcase every time I make a new class header.

Dijkstra

An implemented Dijkstra's algorithm in the form of a class. This class is designed with the intention of simplicity for its user when constructing a Dijkstra's algorithm

The class is recommended for C++11 or later.

Constructor

SyntaxComplexityDescription
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Initializes a new empty graph of size
KaTeX can only parse string typed expression
.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Initializes a new empty graph of size
KaTeX can only parse string typed expression
.

Methods

SyntaxComplexityDescription
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Adds an edge between node
KaTeX can only parse string typed expression
and
KaTeX can only parse string typed expression
with a weight
KaTeX can only parse string typed expression
.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Returns a vector of distances between the
KaTeX can only parse string typed expression
and all nodes.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Returns the infinite value.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Returns the zero value.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Resizes the current graph size to
KaTeX can only parse string typed expression
.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Sets an infinite value.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Sets a zero value.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Returns the number of nodes in class.

dijkstra.hpp:

#ifndef DIJKSTRA_HPP
#define DIJKSTRA_HPP

#include <assert.h>

...

demo.cpp:

// Problem link: https://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_1_A

#include <assert.h>

#include <iostream>
...

Disjoint-Set Data Structure

An implemented Disjoint-set data structure in the form of a class. This class is designed with the intention of simplicity for its user when constructing the data structure.

The class is recommended for C++11 or later.

Constructor

SyntaxComplexityDescription
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Initializes a new disjoint-set data structure of size
KaTeX can only parse string typed expression
.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Initializes a new disjoint-set data structure of size
KaTeX can only parse string typed expression
.

Methods

SyntaxComplexityDescription
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Returns a vector of nodes that are connected to node
KaTeX can only parse string typed expression
(excluding the node
KaTeX can only parse string typed expression
itself).
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Returns the representation of the group where node
KaTeX can only parse string typed expression
belongs.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Returns a boolean value indicating the connectivity between node
KaTeX can only parse string typed expression
and
KaTeX can only parse string typed expression
.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Merges groups where node
KaTeX can only parse string typed expression
and
KaTeX can only parse string typed expression
respectively belong and returns the representation.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Resizes the current data structure size to
KaTeX can only parse string typed expression
(
KaTeX can only parse string typed expression
should be larger than the current size).
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Sets node
KaTeX can only parse string typed expression
as the parent of node
KaTeX can only parse string typed expression
.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Returns the size of the data structure.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Returns the number of nodes that are connected to node
KaTeX can only parse string typed expression
(including the node
KaTeX can only parse string typed expression
itself).

dsu.hpp:

#ifndef DSU_HPP
#define DSU_HPP

#include <assert.h>

...

demo.cpp:

#include <iostream>

#include "dsu.hpp"

using namespace std;
...

Fenwick Tree

An implemented Fenwick tree data structure in the form of a class. This class is designed with the intention of simplicity for its user when constructing the data structure.

The class is recommended for C++11 or later.

Constructor

SyntaxComplexityDescription
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Initializes a new fenwick tree data structure of size
KaTeX can only parse string typed expression
.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Initializes a new fenwick tree data structure of size
KaTeX can only parse string typed expression
.

Methods

SyntaxComplexityDescription
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Adds
KaTeX can only parse string typed expression
to
KaTeX can only parse string typed expression
.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Clears the current data structure.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Returns the zero value.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Resizes the current data structure size to
KaTeX can only parse string typed expression
.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Sets a zero value.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Returns the size of data structure.
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Returns a sum of
KaTeX can only parse string typed expression

fenwick_tree.hpp:

#ifndef FENWICK_TREE_HPP
#define FENWICK_TREE_HPP

#include <assert.h>

...

demo.cpp:

#include <iostream>

#include "fenwick_tree.hpp"
using namespace std;

...

Sparse Table

An implemented sparse table data structure in the form of a class. This class is designed with the intention of simplicity for its user when constructing the data structure.

The class is recommended for C++11 or later.

Constructor

SyntaxComplexityDescription
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Initializes a new sparse table data structure from the given vector
KaTeX can only parse string typed expression
.

Methods

SyntaxComplexityDescription
KaTeX can only parse string typed expression
KaTeX can only parse string typed expression
Returns
KaTeX can only parse string typed expression
)

sparse_table.hpp:

#ifndef SPARSE_TABLE_HPP
#define SPARSE_TABLE_HPP

#include <assert.h>
#include <math.h>
...

demo.cpp:

#include <iostream>

#include "sparse_table.hpp"

using namespace std;
...