Skip to content

Instantly share code, notes, and snippets.

View greatsharma's full-sized avatar
🏠
Working from home

Gaurav Sharma greatsharma

🏠
Working from home
View GitHub Profile
@greatsharma
greatsharma / graph.cpp
Last active August 28, 2020 05:59
Adjacency Graph in C++
#include <iostream>
#include <conio.h>
#include <queue>
#include <stack>
#define INFINITY 10000
#define WHITE 0 // Not discovered
#define GREY 1 // Discovered
#define BLACK 2 // Done
@greatsharma
greatsharma / particle_swarm_optimization.cpp
Created April 8, 2019 07:30
This is a simple c++ program on particle swarm optimization, this pso optimizes a sphere function and can optimize other functions by defining those functions appropriately.
#include <iostream>
#include <time.h>
#define INFINITY 100000.0
using namespace std;
class PSOTestFunction
{
public:
/**
@greatsharma
greatsharma / heapSort.cpp
Last active April 26, 2019 10:21
A simple c++ program to sort an array using heap sort algorithm with the help of max-heap data structure. Here the indexing starts from 0.
/*
Name: Heap Sort
Author: Gaurav Sharma
Date: 26-04-19 15:02
Description: A simple c++ program to sort an array using heap sort algorithm with the help of max-heap data structure.
Here the indexing starts from 0.
*/
#include <iostream>
#include <math.h>
#include <time.h>
@greatsharma
greatsharma / countSort.cpp
Created April 26, 2019 11:53
A simple c++ program to sort an array using count sort algorithm.
/*
Name: Count Sort
Author: Gaurav Sharma
Date: 26-04-19 17:19
Description: A simple c++ program to sort an array using count sort algorithm. If range is linear with array size than this
algorithm runs in linear time.
*/
#include <iostream>
#include <time.h>
@greatsharma
greatsharma / subsetSum.cpp
Last active April 27, 2019 14:04
A simple c++ program to find a subset from a set of positive numbers whose combined sum is exactly equal to given sum using DP. Here subsetSum() calculates a DP table, displayTable displays the table and getSubset prints the subset if exists using bracktracking.
/*
Name: Subset problem
Author: Gaurav Sharma
Date: 27-04-19 16:57
Description: A simple c++ program to find a subset from a set of positive numbers whose combined sum is exactly equal to
given sum using DP. Here subsetSum() calculates a DP table, displayTable displays the table and getSubset prints the
subset if exists using bracktracking.
*/
#include <iostream>
#include <conio.h>
@greatsharma
greatsharma / RBT.cpp
Created April 28, 2019 13:40
Red black tree using c++ with support of insert and delete operations.
/*
Name: RED BLACK TREE
Author: Gaurav Sharma
Date: 28-04-19 19:09
Description: A simple c++ program to create a red black tree with insert and delete operations.
*/
#include <iostream>
#include <conio.h>
#define RED 1
@greatsharma
greatsharma / bubbleSort.cpp
Last active April 29, 2019 09:44
A simple c++ program to sort an array using bubble sort algorithm.
/*
Name: Bubble Sort
Author: Gaurav Sharma
Date: 28-04-19 17:29
Description: A simple c++ program to sort an array using bubble sort algorithm.
*/
#include <iostream>
#include <conio.h>
#include <time.h>
@greatsharma
greatsharma / insertionSort.cpp
Last active April 29, 2019 09:47
A simple c++ program to sort an array using insertion sort algorithm.
/*
Name: Insertion Sort
Author: Gaurav Sharma
Date: 26-04-19 17:31
Description: A simple c++ program to sort an array using insertion sort algorithm.
*/
#include <iostream>
#include <conio.h>
#include <time.h>
@greatsharma
greatsharma / selectionSort.cpp
Last active April 29, 2019 09:46
A simple c++ program to sort an array using Selection sort algorithm.
/*
Name: Selection Sort
Author: Gaurav Sharma
Date: 26-04-19 17:35
Description: A simple c++ program to sort an array using Selection sort algorithm.
*/
#include <iostream>
#include <conio.h>
#include <time.h>
@greatsharma
greatsharma / quickSort.cpp
Last active April 29, 2019 09:56
A simple c++ program to sort an array using Quick sort algorithm.
/*
Name: Quick Sort
Author: Gaurav Sharma
Date: 27-04-19 18:01
Description: A simple c++ program to sort an array using Quick sort algorithm.
*/
#include <iostream>
#include <conio.h>
#include <time.h>