Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions data_structures/morrisinorder.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include <iostream>
#include <queue>

/**************************
/**
@author shrutisheoran
**************************/
*/

using namespace std;

Expand Down
24 changes: 12 additions & 12 deletions dynamic_programming/partition_problem.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/******************************************************************************
/**
* @file
* @brief Implementation of the [Partition
* Problem](https://en.wikipedia.org/wiki/Partition_problem )
Expand Down Expand Up @@ -26,31 +26,31 @@
*
* @author [Lajat Manekar](https://github.com/Lazeeez)
*
*******************************************************************************/
*/
#include <cassert> /// for assert
#include <cstdint> /// for std::uint64_t
#include <iostream> /// for IO Operations
#include <numeric> /// for std::accumulate
#include <vector> /// for std::vector
/******************************************************************************
/**
* @namespace dp
* @brief Dynamic programming algorithms
*******************************************************************************/
*/
namespace dp {

/******************************************************************************
/**
* @namespace partitionProblem
* @brief Partition problem algorithm
*******************************************************************************/
*/
namespace partitionProblem {

/******************************************************************************
/**
* @brief Returns true if arr can be partitioned in two subsets of equal sum,
* otherwise false
* @param arr vector containing elements
* @param size Size of the vector.
* @returns @param bool whether the vector can be partitioned or not.
*******************************************************************************/
*/
bool findPartiion(const std::vector<uint64_t> &arr, uint64_t size) {
uint64_t sum = std::accumulate(arr.begin(), arr.end(),
0); // Calculate sum of all elements
Expand Down Expand Up @@ -82,10 +82,10 @@ bool findPartiion(const std::vector<uint64_t> &arr, uint64_t size) {
} // namespace partitionProblem
} // namespace dp

/*******************************************************************************
/**
* @brief Self-test implementations
* @returns void
*******************************************************************************/
*/
static void test() {
std::vector<uint64_t> arr = {{1, 3, 3, 2, 3, 2}};
uint64_t n = arr.size();
Expand All @@ -96,10 +96,10 @@ static void test() {
std::cout << "Passed!" << std::endl;
}

/*******************************************************************************
/**
* @brief Main function
* @returns 0 on exit
*******************************************************************************/
*/
int main() {
test(); // run self-test implementations
return 0;
Expand Down
12 changes: 6 additions & 6 deletions geometry/graham_scan_algorithm.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/******************************************************************************
/**
* @file
* @brief Implementation of the [Convex
* Hull](https://en.wikipedia.org/wiki/Convex_hull) implementation using [Graham
Expand Down Expand Up @@ -37,17 +37,17 @@
*
* @author [Lajat Manekar](https://github.com/Lazeeez)
*
*******************************************************************************/
*/
#include <cassert> /// for std::assert
#include <iostream> /// for IO Operations
#include <vector> /// for std::vector

#include "./graham_scan_functions.hpp" /// for all the functions used

/*******************************************************************************
/**
* @brief Self-test implementations
* @returns void
*******************************************************************************/
*/
static void test() {
std::vector<geometry::grahamscan::Point> points = {
{0, 3}, {1, 1}, {2, 2}, {4, 4}, {0, 0}, {1, 2}, {3, 1}, {3, 3}};
Expand All @@ -66,10 +66,10 @@ static void test() {
std::cout << "passed!" << std::endl;
}

/*******************************************************************************
/**
* @brief Main function
* @returns 0 on exit
*******************************************************************************/
*/
int main() {
test(); // run self-test implementations
return 0;
Expand Down
36 changes: 18 additions & 18 deletions geometry/graham_scan_functions.hpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/******************************************************************************
/**
* @file
* @brief Implementation of the [Convex
* Hull](https://en.wikipedia.org/wiki/Convex_hull) implementation using [Graham
Expand Down Expand Up @@ -37,30 +37,30 @@
*
* @author [Lajat Manekar](https://github.com/Lazeeez)
*
*******************************************************************************/
*/
#include <algorithm> /// for std::swap
#include <cstdint>
#include <cstdlib> /// for mathematics and datatype conversion
#include <iostream> /// for IO operations
#include <stack> /// for std::stack
#include <vector> /// for std::vector

/******************************************************************************
/**
* @namespace geometry
* @brief geometric algorithms
*******************************************************************************/
*/
namespace geometry {

/******************************************************************************
/**
* @namespace graham scan
* @brief convex hull algorithm
*******************************************************************************/
*/
namespace grahamscan {

/******************************************************************************
/**
* @struct Point
* @brief for X and Y co-ordinates of the co-ordinate.
*******************************************************************************/
*/
struct Point {
int x, y;
};
Expand All @@ -70,11 +70,11 @@ struct Point {

Point p0;

/******************************************************************************
/**
* @brief A utility function to find next to top in a stack.
* @param S Stack to be used for the process.
* @returns Co-ordinates of the Point <int, int> below the top of the stack
*******************************************************************************/
*/
Point nextToTop(std::stack<Point> *S) {
Point p = S->top();
S->pop();
Expand All @@ -83,24 +83,24 @@ Point nextToTop(std::stack<Point> *S) {
return res;
}

/******************************************************************************
/**
* @brief A utility function to return square of distance between p1 and p2.
* @param p1 Co-ordinates of Point 1 <int, int>.
* @param p2 Co-ordinates of Point 2 <int, int>.
* @returns square of the distance between p1 and p2.
*******************************************************************************/
*/
int distSq(Point p1, Point p2) {
return (p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y);
}

/******************************************************************************
/**
* @brief To find orientation of ordered triplet (p, q, r).
* @param p Co-ordinates of Point p <int, int>.
* @param q Co-ordinates of Point q <int, int>.
* @param r Co-ordinates of Point r <int, int>.
* @returns 0 --> p, q and r are collinear, 1 --> Clockwise,
* 2 --> Counterclockwise
*******************************************************************************/
*/
int orientation(Point p, Point q, Point r) {
int val = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);

Expand All @@ -110,13 +110,13 @@ int orientation(Point p, Point q, Point r) {
return (val > 0) ? 1 : 2; // clock or counter-clock wise
}

/******************************************************************************
/**
* @brief A function used by library function qsort() to sort an array of
* points with respect to the first point
* @param vp1 Co-ordinates of Point 1 <int, int>.
* @param vp2 Co-ordinates of Point 2 <int, int>.
* @returns -1 if Point 1 sorts before Point 2, 1 otherwise.
*******************************************************************************/
*/
int compare(const void *vp1, const void *vp2) {
auto *p1 = static_cast<const Point *>(vp1);
auto *p2 = static_cast<const Point *>(vp2);
Expand All @@ -130,12 +130,12 @@ int compare(const void *vp1, const void *vp2) {
return (o == 2) ? -1 : 1;
}

/******************************************************************************
/**
* @brief Prints convex hull of a set of n points.
* @param points vector of Point<int, int> with co-ordinates.
* @param size Size of the vector.
* @returns vector of the Points forming the convex hull.
*******************************************************************************/
*/
std::vector<Point> convexHull(std::vector<Point> points, uint64_t size) {
// Find the bottom-most point
int ymin = points[0].y, min = 0;
Expand Down
6 changes: 3 additions & 3 deletions numerical_methods/durand_kerner_roots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* \param[in] coeffs coefficients of the polynomial
* \param[in] x point at which to evaluate the polynomial
* \returns \f$f(x)\f$
**/
*/
std::complex<double> poly_function(const std::valarray<double> &coeffs,
std::complex<double> x) {
double real = 0.f, imag = 0.f;
Expand Down Expand Up @@ -272,15 +272,15 @@ void test2() {
<< "\n";
}

/***
/**
* Main function.
* The comandline input arguments are taken as coeffiecients of a
*polynomial. For example, this command
* ```sh
* ./durand_kerner_roots 1 0 -4
* ```
* will find roots of the polynomial \f$1\cdot x^2 + 0\cdot x^1 + (-4)=0\f$
**/
*/
int main(int argc, char **argv) {
/* initialize random seed: */
std::srand(std::time(nullptr));
Expand Down
41 changes: 19 additions & 22 deletions search/binary_search.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/******************************************************************************
/**
* @file
* @brief [Binary search
* algorithm](https://en.wikipedia.org/wiki/Binary_search_algorithm)
Expand Down Expand Up @@ -33,31 +33,30 @@
*
* @author [Lajat Manekar](https://github.com/Lazeeez)
* @author Unknown author
*******************************************************************************/

*/
#include <algorithm> /// for std::sort function
#include <cassert> /// for std::assert
#include <cstdint>
#include <iostream> /// for IO operations
#include <vector> /// for std::vector
/******************************************************************************
/**
* @namespace search
* @brief Searching algorithms
*******************************************************************************/
*/
namespace search {

/******************************************************************************
/**
* @namespace binary_search
* @brief Binary search searching algorihm
*******************************************************************************/
*/
namespace binary_search {

/******************************************************************************
/**
* @brief The main function which implements binary search
* @param arr vector to be searched in
* @param val value to be searched
* @returns @param int index of val in vector arr
*******************************************************************************/
*/
uint64_t binarySearch(std::vector<uint64_t> arr, uint64_t val) {
uint64_t low = 0; // set the lowest point of the vector.
uint64_t high = arr.size() - 1; // set the highest point of the vector.
Expand All @@ -67,11 +66,9 @@ uint64_t binarySearch(std::vector<uint64_t> arr, uint64_t val) {

if (val == arr[m]) {
return m;
} /****************************************************
* if pivot point is the val, return it,
* else check if val is greater or smaller than pivot value
* and set the next pivot point accordingly.
****************************************************/
} /* if pivot point is the val, return it,
else check if val is greater or smaller than pivot value
and set the next pivot point accordingly. */
else if (val < arr[m]) {
high = m - 1;
} else {
Expand All @@ -85,10 +82,10 @@ uint64_t binarySearch(std::vector<uint64_t> arr, uint64_t val) {

} // namespace search

/*******************************************************************************
/**
* @brief Self-test implementation #1
* @returns void
*******************************************************************************/
*/
static void test1() {
// testcase #1
// array = [1,3,5,7,9,8,6,4,2] , Value = 4
Expand All @@ -103,10 +100,10 @@ static void test1() {
std::cout << "Passed!" << std::endl;
}

/*******************************************************************************
/**
* @brief Self-test implementation #2
* @returns void
*******************************************************************************/
*/
void test2() {
// testcase #2
// array = [1,23,25,4,2] , Value = 25
Expand All @@ -120,10 +117,10 @@ void test2() {
std::cout << "Passed!" << std::endl;
}

/*******************************************************************************
/**
* @brief Self-test implementation #3
* @returns void
*******************************************************************************/
*/
void test3() {
// testcase #3
// array = [1,31,231,12,12,2,5,51,21,23,12,3] , Value = 5
Expand All @@ -137,10 +134,10 @@ void test3() {
std::cout << "Passed!" << std::endl;
}

/*******************************************************************************
/**
* @brief Main function
* @returns 0 on exit
*******************************************************************************/
*/
int main() {
test1(); // run self-test implementation #1
test2(); // run self-test implementation #2
Expand Down
Loading
Loading