Full Code of srbcheema1/Algo_Ds for AI

master d69ddbb67cd8 cached
253 files
367.4 KB
120.1k tokens
1001 symbols
1 requests
Download .txt
Showing preview only (428K chars total). Download the full file or copy to clipboard to get everything.
Repository: srbcheema1/Algo_Ds
Branch: master
Commit: d69ddbb67cd8
Files: 253
Total size: 367.4 KB

Directory structure:
gitextract_r3ies5y1/

├── .gitignore
├── BST/
│   ├── BinarySearchTree.java
│   ├── Delete.c
│   ├── Height.c
│   ├── Insert & Search.cpp
│   ├── MinMax_8.c
│   ├── checkbst
│   ├── createBST.cpp
│   ├── lca.cpp
│   └── spiraltransversal.c
├── Backtrack/
│   ├── NQueen.cpp
│   ├── Rat_Maze_Recurssion_Backtracking.c
│   ├── nqueen_allsol.py
│   └── permutations_of_string.cpp
├── CONTRIBUTING.md
├── Competitive Programming Challenges/
│   └── C:C++/
│       ├── HackerEarth:CodeForces/
│       │   ├── buy_max_with_given_money.cpp
│       │   ├── median searching efficientalgo.cpp
│       │   ├── ques/
│       │   │   └── volcano.cpp
│       │   ├── ques-beat_the_clock/
│       │   │   └── spiral_matrix.cpp
│       │   ├── ques-l1/
│       │   │   ├── codeforces_426_2.cpp
│       │   │   ├── positions.cpp
│       │   │   └── snake/
│       │   │       ├── snake.cpp
│       │   │       └── wrong_snake.cpp
│       │   └── searchmat.cpp
│       └── Patterns/
│           ├── pattern1.cpp
│           ├── pattern2.cpp
│           ├── pattern3.cpp
│           ├── pattern4.cpp
│           ├── pattern6.cpp
│           └── pattern7.cpp
├── Conversions/
│   └── C:C++/
│       └── binary2octal.c
├── Data Structures/
│   ├── C:C++/
│   │   ├── Applications/
│   │   │   ├── Evaluating Postfix Expression.c
│   │   │   ├── Infix to Postfix.c
│   │   │   ├── balance parenthesis.cpp
│   │   │   └── stack_and_its_implementation.c
│   │   ├── Graph/
│   │   │   ├── FloydWarshall.cpp
│   │   │   ├── adjacency_list.hpp
│   │   │   ├── adjacency_matrix.hpp
│   │   │   ├── bfs_dfs/
│   │   │   │   ├── bfs/
│   │   │   │   │   ├── BFS.java
│   │   │   │   │   └── bfs.Py
│   │   │   │   └── ques/
│   │   │   │       ├── graph_connected_components.cpp
│   │   │   │       └── tbbfs.cpp
│   │   │   ├── dijakstra/
│   │   │   │   ├── Dijkstra.java
│   │   │   │   ├── dist_from_source.cpp
│   │   │   │   ├── dist_from_source_oops.cpp
│   │   │   │   └── ques/
│   │   │   │       ├── min_path.cpp
│   │   │   │       └── qgrid_11.cpp
│   │   │   ├── shortest_paths.hpp
│   │   │   ├── topological_sort.hpp
│   │   │   └── tree/
│   │   │       └── binarySearchTree/
│   │   │           └── bsTree.cpp
│   │   ├── Linked List/
│   │   │   ├── Circular_LL.c
│   │   │   ├── Circular_ll.cpp
│   │   │   ├── Doubly LL.c
│   │   │   ├── Insertion_Deletion_SinglyLL.c
│   │   │   ├── Queue using LinkedList.cpp
│   │   │   ├── Queue_using_linkedlist.c
│   │   │   ├── Reverse_SinglyLL.c
│   │   │   ├── all_operations_of_Doubly_ll.cpp
│   │   │   ├── concatinate.c
│   │   │   ├── doubly circular.c
│   │   │   ├── doubly linked list.c
│   │   │   ├── linked_list.c
│   │   │   ├── ordered_linked.c
│   │   │   ├── reverse.cpp
│   │   │   ├── stackLinkedList.cpp
│   │   │   └── stack_Linked_List.c
│   │   ├── Stack/
│   │   │   ├── Balanced_Brackets.cpp
│   │   │   ├── Reverse_Queue.cpp
│   │   │   ├── Stack_as_linked_list.cpp
│   │   │   ├── largestRectangleHistogram.cpp
│   │   │   ├── nextgreaterelement
│   │   │   └── stack.hpp
│   │   ├── Trees/
│   │   │   ├── segment_tree/
│   │   │   │   ├── segment_tree.cpp
│   │   │   │   └── segment_trees_lazy.cpp.cpp
│   │   │   └── tree/
│   │   │       ├── Fenwick_tree.cpp
│   │   │       ├── bst.hpp
│   │   │       ├── segment_tree.hpp
│   │   │       ├── tree.hpp
│   │   │       └── trie.cpp
│   │   └── queue/
│   │       └── queue.hpp
│   ├── Java/
│   │   └── Stack/
│   │       └── Stack.java
│   └── Python/
│       ├── Graphs/
│       │   ├── Graph.py
│       │   └── dfs.py
│       ├── Linked List/
│       │   └── singly_linked_list.py
│       ├── Queue/
│       │   └── Queue.py
│       ├── Stack/
│       │   └── stack.py
│       └── Trees/
│           └── m-coloring-problem.py
├── Dynamic Programing/
│   ├── Dynamic_fibonacci.py
│   ├── Edit Distance.Py
│   ├── Knapsack.py
│   ├── Memoized Cut Rod.Py
│   ├── Word_Wrap.Py
│   └── longest_increasing_subsequence.cpp
├── Mathematical Challenges/
│   ├── C:C++/
│   │   ├── Fibonacci/
│   │   │   └── Fibonacci Test.cpp
│   │   ├── Square Root Decomposition/
│   │   │   └── MO's Algorithm/
│   │   │       └── MOAlgo.cpp
│   │   ├── armstrong_number/
│   │   │   ├── C/
│   │   │   │   └── armstrong.c
│   │   │   └── README.md
│   │   ├── convexHull/
│   │   │   └── ConvexHullScan.cpp
│   │   ├── factorial/
│   │   │   └── factorial.c
│   │   ├── fibbinacci/
│   │   │   └── fibbinacci.c
│   │   ├── gcd/
│   │   │   ├── extended_gcd.cpp
│   │   │   ├── gcd.cpp
│   │   │   └── mod_inverse.cpp
│   │   ├── largestoutof3/
│   │   │   └── largestoutof3.c
│   │   ├── mathpuzzle.c/
│   │   │   └── matchstick game
│   │   ├── multiplication/
│   │   │   └── multiply 2 numbers greater than 10^6.cpp
│   │   ├── power/
│   │   │   ├── modular_exponention.cpp
│   │   │   ├── ques/
│   │   │   │   └── summation.cpp
│   │   │   └── two_pow.cpp
│   │   ├── powerset/
│   │   │   └── PowerSet.java
│   │   ├── prime/
│   │   │   ├── PrimeCheck.py
│   │   │   ├── PrimeToNumber.py
│   │   │   ├── prime.c
│   │   │   └── sieveOferatosthenes.cpp
│   │   ├── prime number tricks/
│   │   │   └── List all primes.cpp
│   │   └── ques/
│   │       └── cpcrc1c.cpp
│   └── python/
│       ├── pernicious_prime/
│       │   └── pernicious.py
│       └── sieve_of_eratoshthenes.py
├── Patterns/
│   ├── pattern10.cpp
│   ├── pattern11.cpp
│   ├── pattern12.cpp
│   ├── pattern13.cpp
│   ├── pattern14.cpp
│   ├── pattern15.cpp
│   ├── pattern16.cpp
│   ├── pattern8.cpp
│   └── pattern9.cpp
├── README.md
├── STL C++/
│   ├── STACK_with_Application/
│   │   ├── Evaluating Postfix Expression.c
│   │   ├── Infix to Postfix.c
│   │   ├── balance parenthesis.cpp
│   │   └── stack_and_its_implementation.c
│   ├── sorting_a_vector.cpp
│   ├── stack/
│   │   ├── Stack.java
│   │   ├── largestRectangleHistogram.cpp
│   │   └── stack.hpp
│   ├── using_map.cpp
│   └── using_set.cpp
├── STRUCTURE.md
├── Searching Algorithms/
│   ├── Bogo_sort.cpp
│   ├── C:C++/
│   │   ├── Binary_Search.cpp
│   │   ├── Binary_search.cpp
│   │   ├── Interpolation Search
│   │   ├── Interpolation_search.cpp
│   │   ├── Jump_Search.cpp
│   │   ├── Liear_search.cpp
│   │   ├── MEDIAN_SEARCH.cpp
│   │   ├── Selection_sort.cpp
│   │   ├── Ternary_search.cpp
│   │   ├── b_search.cpp
│   │   ├── fibonacci_search.cpp
│   │   ├── seaching algorithms [rename]/
│   │   │   ├── binary_search.cpp
│   │   │   ├── binary_search_extras/
│   │   │   │   ├── position_in_sorted_array/
│   │   │   │   │   ├── eq_less_than.cpp
│   │   │   │   │   ├── first_occurance.cpp
│   │   │   │   │   ├── just_less_than_num.cpp
│   │   │   │   │   └── position_in_sorted_array.cpp
│   │   │   │   └── ques/
│   │   │   │       └── aggrcow.cpp
│   │   │   ├── jump_search.cpp
│   │   │   └── linear.cpp
│   │   ├── ternarySearch.cpp
│   │   └── ternary_search.c
│   ├── Java/
│   │   ├── TODO
│   │   ├── algos/
│   │   │   ├── BinarySearch.java
│   │   │   └── LinearSearch.java
│   │   └── driving.java
│   └── Python/
│       ├── binarysearch.py
│       └── bst.py
├── Segment Trees/
│   ├── ADA/
│   │   ├── README.md
│   │   └── segmentree.adb
│   ├── C++/
│   │   ├── RangeMinimumQuery.cpp
│   │   └── SumInGivenRange.cpp
│   └── Java/
│       ├── SegementTree.java
│       └── SegementTreeLazyPropagation.java
├── Sorting Algorithms/
│   ├── C:C++/
│   │   ├── Counting_Sort.cpp
│   │   ├── Insertion_sort.cpp
│   │   ├── Merge_sort.cpp
│   │   ├── QuickSort.c
│   │   ├── Quick_sort.cpp
│   │   ├── Radix_sort.cpp
│   │   ├── bubblesort.c
│   │   ├── bubblesort.cpp
│   │   ├── bucketsort.c
│   │   ├── heapSort.c
│   │   ├── insertion.hpp
│   │   ├── merge.hpp
│   │   ├── quick.hpp
│   │   ├── quick_sort.c
│   │   ├── radix.hpp
│   │   ├── selectionsort.c
│   │   ├── shell_sort.h
│   │   ├── slow.cpp
│   │   └── sorting_a_vector.cpp
│   ├── Java/
│   │   ├── Countsort.java
│   │   ├── HeapSort.java
│   │   └── MergeSort.java
│   ├── Javascript/
│   │   └── bubblesort.js
│   ├── Python/
│   │   ├── QuickSort.py
│   │   ├── bogosort.py
│   │   ├── bubblesort.py
│   │   ├── cocktailsort.py
│   │   ├── insertionsort.py
│   │   ├── mergesort.py
│   │   ├── quicksort.py
│   │   └── topological_sort.py
│   └── sleep sort.c
├── String Manipulation/
│   ├── C:C++/
│   │   ├── String_algo/
│   │   │   ├── KMP.cpp
│   │   │   ├── SUFFIX-ARRAY.cpp
│   │   │   └── z_algorithm.cpp
│   │   └── tokens/
│   │       ├── token_break.cpp
│   │       └── word_break.cpp
│   └── Python/
│       └── LCS.py
├── backtrack/
│   └── sudoku/
│       ├── code2.cpp
│       └── sudoku.cpp
├── binary_tree/
│   └── binarytree.java
├── btree.cpp
├── cryptography/
│   ├── Python/
│   │   └── porta.py
│   └── des/
│       └── java/
│           ├── Converter.java
│           ├── DES.java
│           ├── IO.java
│           └── Main.java
├── dfs.cpp
├── disjoint_set/
│   └── disjoint_set.hpp
├── divide_and_conquer/
│   ├── maximum_sub_array.cpp
│   └── strassen.cpp
├── dp/
│   ├── 0-1knapsack.cpp
│   ├── Digit_dp.cpp
│   ├── coinchange.cpp
│   ├── editDistance.cpp
│   ├── eggdropping.cpp
│   ├── kadane.cpp
│   ├── lcs.cpp
│   ├── lis.cpp
│   └── mcm.cpp
├── euler_totent_function
├── genome_sort.py
├── graph/
│   ├── Kosaraju_algorithm
│   └── bfs_dfs/
│       ├── bfs/
│       │   ├── BFS.cpp
│       │   ├── BFS.py
│       │   └── bfs.cpp
│       └── dfs/
│           ├── DFS.cpp
│           └── DFS.java
├── heap/
│   ├── heap.hpp
│   └── min_heap.cpp
├── os/
│   └── scheduling/
│       ├── fcfs.cpp
│       ├── os_priority.cpp
│       ├── os_roundrobin.cpp
│       ├── os_sjf.cpp
│       ├── os_srtf.cpp
│       └── readme.txt
├── shellsort.c
├── sieve_of_eratoshthenes.cpp
├── square_root_decomposition
└── travelling_salesman_problem

================================================
FILE CONTENTS
================================================

================================================
FILE: .gitignore
================================================
build*/

# ----------- C++ ------------------
# Prerequisites
*.d

# Compiled Object files
*.slo
*.lo
*.o
*.obj

# Precompiled Headers
*.gch
*.pch

# Compiled Dynamic libraries
*.so
*.dylib
*.dll

# Fortran module files
*.mod
*.smod

# Compiled Static libraries
*.lai
*.la
*.a
*.lib

# Executables
*.exe
*.out
*.app

# ----------- CMake ------------------
CMakeCache.txt
CMakeFiles
CMakeScripts
Testing
Makefile
cmake_install.cmake
install_manifest.txt
compile_commands.json
CTestTestfile.cmake

# files to check the functionality
check_*.cpp

.DS_STORE


================================================
FILE: BST/BinarySearchTree.java
================================================
/*
* @author Nikunj Khokhar
*/
public class BinarySearchTree {


    class Node {
        int key;
        Node left, right;

        public Node(int item) {
            key = item;
            left = right = null;
        }
    }


    Node root;


    BinarySearchTree() {
        this.root = null;
    }


    void insert(int key) {
        root = insertRec(root, key);
    }


    Node insertRec(Node root, int key) {


        if (root == null) {
            root = new Node(key);
            return root;
        }


        if (key < root.key)
            root.left = insertRec(root.left, key);
        else if (key > root.key)
            root.right = insertRec(root.right, key);


        return root;
    }


    void inorder()  {
        inorderRec(root);
    }


    void inorderRec(Node root) {
        if (root != null) {
            inorderRec(root.left);
            System.out.println(root.key);
            inorderRec(root.right);
        }
    }



    void preorder()  {
        preorderRec(root);
    }


    void preorderRec(Node root) {
        if (root != null) {
            System.out.println(root.key);
            preorderRec(root.left);
            preorderRec(root.right);
        }
    }



    void postorder()  {
        postorderRec(root);
    }


    void postorderRec(Node root) {
        if (root != null) {

            postorderRec(root.left);
            postorderRec(root.right);
            System.out.println(root.key);
        }
    }


}

public class Main {
    public static void main(String args[])
    {
        BinarySearchTree tree = new BinarySearchTree();
        tree.insert(50);
        tree.insert( 30);
        tree.insert( 20);
        tree.insert( 40);
        tree.insert( 70);
        tree.insert( 60);
        tree.insert(80);


        System.out.println("Inorder traversal of the given tree : ");
        tree.inorder();
        System.out.print("\n\n");


        System.out.println("Postorder traversal of the given tree : ");
        tree.postorder();
        System.out.print("\n\n");

        
        System.out.println("Preorder traversal of the given tree : ");
        tree.preorder();
    }
}


================================================
FILE: BST/Delete.c
================================================
#include<stdio.h>
#include<stdlib.h>

struct tree{
		int data;
		struct tree *left;
		struct tree *right;
}*root=NULL,*newn;

struct tree* create(int n)
{
	newn=(struct tree*)malloc(sizeof(struct tree));
	newn->data=n;
	newn->left=NULL;
	newn->right=NULL;
	return newn;
}

struct tree* ins(struct tree*r,int dat)
{
	if(r==NULL)
		return create(dat);
	if(dat < r->data)
		r->left=ins(r->left,dat);
	else if(dat > r->data)
		r->right=ins(r->right,dat);
	return r;
}

int max=-10000,min=10000;

void preorder(struct tree* n)
{
	if(n==NULL)
		return;
	else
	{
	preorder(n->left);
	preorder(n->right);
	printf("Deleting Node:%d\n",n->data);
	free(n);
	}
}
int flag=0;

void main()
{
	int choice=1,t,ne, exit;
	printf("Enter Root Node:\n");
	scanf("%d",&ne);
	root=ins(root,ne);
	while(choice!=0)
	{
		printf("Enter Value:\n");
		scanf("%d",&t);
		ins(root,t);
		printf("Want to Continue the tree:1 or 0...?\n");
		scanf("%d",&choice);
	}
	preorder(root);
	scanf("%d", exit);
}


================================================
FILE: BST/Height.c
================================================
#include<stdio.h>
#include<stdlib.h>

struct tree{
		int data;
		struct tree* left;
		struct tree* right;
};

struct tree* create(int dat)
{
	struct tree* n=(struct tree*)malloc(sizeof(struct tree));
	n->data=dat;
	n->left=NULL;
	n->right=NULL;
	return n;
}

int height(struct tree* n)
{
	int l,r;
	if(n==NULL)
		return 0;
	else
	{
		l=height(n->left);
		r=height(n->right);
		if(l>r)
			return(l+1);
		else
			return (r+1);
	}
}

int count=0;

int node(struct tree* n)
{
	if(n==NULL)
		return count;
	else
	{
		node(n->left);
		node(n->right);
		count++;
	}
	
}

void main()
{
	struct tree* root;
	int ans, exit;
	root=create(30);
	ans=height(root);
	printf("Height of tree after first insertion: %d\n",ans);
	root->left=create(20);
	root->right=create(40);
	root->left->left=create(60);
	ans=height(root);
	printf("Height of given tree: %d\n",ans);
	ans=node(root);
	printf("No. of nodes: %d\n",ans);
	scanf("%d", exit);
}


================================================
FILE: BST/Insert & Search.cpp
================================================
/******************************************
*    AUTHOR         :   VIVEK SHAH        *
*    INSTITUTION    :   NIT SURAT         *
******************************************/

#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ll long long int
#define mod 1000000007
#define rep(i,a,b) for (ll i = a; i<b; ++i)

using namespace std;

struct node
{
	int data;
	struct node* left;
	struct node* right;
};

struct node* getNode(int data){
	struct node* tmp = new node();
	tmp->data = data;
	tmp->left = NULL;
	tmp->right = NULL;
	return tmp;
}

struct node* insert(struct node* root,int data){
	if (root==NULL)
	{
		root = getNode(data);
	}
	else if (data <= root->data)
	{
		root->left = insert(root->left,data); 
	}
	else{
		root->right = insert(root->right,data);
	}
	return root;
}

int search(struct node* root, int data){
	if (root==NULL)
	{
		return 0;
	}
	else if (root->data = data)
	{
		return 1;
	}
	else if (data<=root->data)
	{
		return search(root->left,data);
	}
	else{
		return search(root->right,data);
	}
}

int main()
{
	boost;
	struct node* root = NULL;
	root = insert(root,15);
	root = insert(root,10);
	root = insert(root,20);
	if(search(root,15)){
		cout<<"Found";
	}
	else cout<<"Not Found";
	return 0;
}

================================================
FILE: BST/MinMax_8.c
================================================
#include<stdio.h>
#include<stdlib.h>
struct tree{
		int data;
		struct tree *left;
		struct tree *right;
}*root=NULL,*newn;
struct tree* create(int n)
{
	newn=(struct tree*)malloc(sizeof(struct tree));
	newn->data=n;
	newn->left=NULL;
	newn->right=NULL;
	return newn;
}
struct tree* ins(struct tree*r,int dat)
{
	if(r==NULL)
		return create(dat);
	if(dat < r->data)
		r->left=ins(r->left,dat);
	else if(dat > r->data)
		r->right=ins(r->right,dat);
	return r;
}
int max=-10000,min=10000;
void Preo(struct tree* n)
{
	if(n==NULL)
		return;
	if(n->data>max)
		max=n->data;
	if(n->data<min)
		min=n->data;
	//printf("%d ",n->data);
	Preo(n->left);
	Preo(n->right);
}
void main()
{
	int choice=1,t,ne, exit;
	printf("Enter Root Node:\n");
	scanf("%d",&ne);
	root=ins(root,ne);
	while(choice!=0)
	{
		printf("Enter Data:\n");
		scanf("%d",&t);
		ins(root,t);
		printf("Want to Continue the tree:1 or 0...?\n");
		scanf("%d",&choice);
	}
	Preo(root);
	printf("Minimum:%d\n",min);
	printf("Maximum:%d\n",max);
	scanf("%d", exit);
}


================================================
FILE: BST/checkbst
================================================
/ C++ program to check if a given tree is BST.
#include <bits/stdc++.h>
using namespace std;
 
/* A binary tree node has data, pointer to
   left child and a pointer to right child */
struct Node
{
    int data;
    struct Node* left, *right;
};
 
// Returns true if given tree is BST.
bool isBST(Node* root, Node* l=NULL, Node* r=NULL)
{
    // Base condition
    if (root == NULL)
        return true;
 
    // if left node exist that check it has
    // correct data or not
    if (l != NULL and root->data < l->data)
        return false;
 
    // if right node exist that check it has
    // correct data or not
    if (r != NULL and root->data > r->data)
        return false;
 
    // check recursively for every node.
    return isBST(root->left, l, root) and
           isBST(root->right, root, r);
}
 
/* Helper function that allocates a new node with the
   given data and NULL left and right pointers. */
struct Node* newNode(int data)
{
    struct Node* node = new Node;
    node->data = data;
    node->left = node->right = NULL;
    return (node);
}
 
/* Driver program to test above functions*/
int main()
{
    struct Node *root = newNode(3);
    root->left        = newNode(2);
    root->right       = newNode(5);
    root->left->left  = newNode(1);
    root->left->right = newNode(4);
 
    if (isBST(root))
        cout << "Is BST";
    else
        cout << "Not a BST";
 
    return 0;
}


================================================
FILE: BST/createBST.cpp
================================================
#include<stdio.h>
#include<stdlib.h>
 
typedef struct BST
{
    int data;
    struct BST *left;
    struct BST *right;
}node;
 
node *create();
void insert(node *,node *);
void preorder(node *);
 
int main()
{
    char ch;
    node *root=NULL,*temp;
    
    do
    {
        temp=create();
        if(root==NULL)
            root=temp;
        else    
            insert(root,temp);
            
        printf("nDo you want to enter more(y/n)?");
        getchar();
        scanf("%c",&ch);
    }while(ch=='y'|ch=='Y');
    
    printf("nPreorder Traversal: ");
    preorder(root);
    return 0;
}
 
node *create()
{
    node *temp;
    printf("nEnter data:");
    temp=(node*)malloc(sizeof(node));
    scanf("%d",&temp->data);
    temp->left=temp->right=NULL;
    return temp;
}
 
void insert(node *root,node *temp)
{
    if(temp->data<root->data)
    {
        if(root->left!=NULL)
            insert(root->left,temp);
        else
            root->left=temp;
    }
    
    if(temp->data>root->data)
    {
        if(root->right!=NULL)
            insert(root->right,temp);
        else
            root->right=temp;
    }
}
 
void preorder(node *root)
{
    if(root!=NULL)
    {
        printf("%d ",root->data);
        preorder(root->left);
        preorder(root->right);
    }
}


================================================
FILE: BST/lca.cpp
================================================
/*
	Author: Pritish Thakkar
	Codechef : joe001
	Blog : http://sleepincode.blogspot.com
*/

/// SUMMARY: 
/// The lowest common ancestor between two nodes n1 
/// and n2 is defined as the lowest node in BST that 
/// has both n1 and n2 as descendants (where we allow
/// a node to be a descendant of itself).

// This contains almost all headers required during 
// competitive programming contests, and that's why used
// by every best coder out there..
#include<bits/stdc++.h>

using namespace std;

// Structure if a node in BST
struct node{
	int data;
	struct node* left;
	struct node* right;
};

// Returns a new whenever required
struct node* getNode(int data){
	struct node* tmp = new node();
	tmp->data = data;
	tmp->left = NULL;
	tmp->right = NULL;
	return tmp;
}

// Function to insert the elements in a BST
struct node* insert(struct node* root,int data){
	if (root==NULL)
	{
		root = getNode(data);
	}
	else if (data <= root->data)
	{
		root->left = insert(root->left,data); 
	}
	else{
		root->right = insert(root->right,data);
	}
	return root;
}


// Returns the value of LCA node.
int lca(node* root, int val1, int val2){
	// If boths values are smaller than current node value
	// it means LCA is present in left subtree.
	if(root->data > val1 && root->data > val2){
		return lca(root->left, val1, val2);
	}

	// If boths values are greater than current node value
	// it means LCA is present in right subtree.
	if(root->data < val1 && root->data < val2){
		return lca(root->right, val1, val2);
	}

	// Now, one is in left subtree and other in right subtree
	// return current node value.
	return root->data;
}

int main(){
	struct node* root = NULL;
	
	// Inserting the values in the BST
	root = insert(root,15);
	root = insert(root,10);
	root = insert(root,20);
	root = insert(root,16);
	root = insert(root,17);
	root = insert(root,12);

	cout << lca(root, 12, 17) << endl;

	// OUTPUT : 15
}

================================================
FILE: BST/spiraltransversal.c
================================================
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include<malloc.h>
//structure of node
struct node{
int data;
struct node* left;
struct node* right;
};
struct node* root;
//insertion into bst
struct node* insert(struct node *rootptr,int data)
{
    if(rootptr==NULL)
    {
        rootptr=(struct node*)malloc(sizeof(struct node));
        rootptr->data=data;
        rootptr->left=NULL;
        rootptr->right=NULL;
        return;
    }
    else if(data<=rootptr->data)
    {
        rootptr->left=insert(rootptr->left,data);
    }
    else if(data>= rootptr->data)
    {
        rootptr->right=insert(rootptr->right,data);
    }
    return rootptr;
}
//inorder transversal of tree
void inorder(struct node* rootptr)
{
    if(rootptr==NULL)
    return;
    inorder(rootptr->left);
    printf("%d ",rootptr->data);
    inorder(rootptr->right);
}
//to print a level of tree
void printGivenLevel(struct node* root, int level, int ltr)
{
    if(root == NULL)
        return;
    if(level == 1)
        printf("%d ", root->data);
    else if (level > 1)
    {
        if(ltr)
        {
            printGivenLevel(root->left, level-1, ltr);
            printGivenLevel(root->right, level-1, ltr);
        }
        else
        {
            printGivenLevel(root->right, level-1, ltr);
            printGivenLevel(root->left, level-1, ltr);
        }
    }
}
//to find height of tree
int height(struct node* node)
{
    if (node==NULL)
        return 0;
    else
    {

        int lheight = height(node->left);//to find height of left subtree
        int rheight = height(node->right);//to find height of right subtree


        if (lheight > rheight)
            return(lheight+1);
        else return(rheight+1);
    }
}
//for spiral transversal of tree
void printSpiral(struct node* root)
{
    int h = height(root);
    int i;

    /*ltr -> Left to Right. If this variable is set,
      then the given level is traverseed from left to right. */
    bool ltr = false;
    for(i=1; i<=h; i++)
    {
        printGivenLevel(root, i, ltr);

        /*Revert ltr to traverse next level in opposite order*/
        ltr = !ltr;
    }
}

main()
{
    root=NULL;
    int n,data;
    while(1)
   {
    printf("1.insert\n2.display\n3.Spiral Order traversal\n4.exit\nenter choice\n");
    scanf("%d",&n);
    switch(n)
    {
        case 1: printf("enter data");
                scanf("%d",&data);
                root=insert(root,data);
                break;
        case 2:inorder(root);
                break;
        case 3:printf("Spiral Order traversal of binary tree is \n");
                printSpiral(root);

        case 4:return;
    }
   }
}


================================================
FILE: Backtrack/NQueen.cpp
================================================
#include <iostream>
using namespace std;

bool isSafe(char board[][100], int row, int column, int n){
	
	//check that whole row should not have a queen
	for(int i=0; i<n; i++){
		if(board[row][i] == 'Q')
			return false;
	}

	//check that whole column should not have a queen
	for(int i=0; i<n; i++){
		if(board[i][column] == 'Q')
			return false;
	}

	//check that left diagonal to the current cell should not have queen
	int p=row, q=column;
	while(p>=0 && q>=0){
		if(board[p][q] == 'Q')
			return false;
		p--; q--;
	}

	//check that right diagonal to the current cell should not have queen
	p=row; q=column;
	while(p>=0 && q<=n-1){
		if(board[p][q] == 'Q')
			return false;
		p--; q++;
	}

	return true;
}

bool nqueen(char board[][100], int n, int i=0){
	if(i == n){
		//board is filled with the n-queens, just print the board
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				cout << board[i][j] << " ";
			}
			cout << endl;
		}
		return true;
	}

	for(int j=0; j<n; j++){
		if(isSafe(board, i, j, n)){ //check that cell is safe or not
			board[i][j] = 'Q'; //if it's safe, then place a queen at that cell
			if(nqueen(board, n, i+1)) //now searching place for queen in next row
				return true;
			board[i][j] = '.'; //since, not safe, so again mark that cell with '.'
		}
	}
	return false;
}

int main(){
	int n;
	cin >> n;

	char board[100][100];
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			board[i][j] = '.';
		}
	}

	if(!nqueen(board, n))
		cout << "No state possible!";

	return 0;
}

================================================
FILE: Backtrack/Rat_Maze_Recurssion_Backtracking.c
================================================
#include<stdio.h>
#define N 4

void display(int sol[N][N])
{
	int i,j;
	for(i=0;i<N;i++)
	{
		for(j=0;j<N;j++)
			printf("%d ",sol[i][j]);
		printf("\n");
	}
}


int issafe(int maze[N][N],int x,int y)
{
	if((x>=0 && x<4) && (y>=0 && y<3) && maze[x][y]==1)
		return 1;
	else
		return 0;
}

int solvemaze(int maze[N][N],int x,int y,int sol[N][N])
{
	if(x==N-1 && y==N-1)
	{
		sol[x][y]=1;
		return 1;
	}
	
		if(issafe(maze,x,y)==1)
		{
			sol[x][y]=1;
			
			if(solvemaze(maze,x+1,y,sol)==1)
				return 1;
			
			if(solvemaze(maze,x,y+1,sol)==1)
				return 1;
			
			sol[x][y]=0;
			return 0;
		}
	return 0;
}

void solve(int maze[N][N])
{
	int sol[N][N]={{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};
	if(solvemaze(maze,0,0,sol)==0)
	{
		printf("No Solution possible\n");
	}
	else
	{
		display(sol);
	}
}
void main()
{
	int maze[N][N]={{1,0,0,0},{1,1,0,1},{0,1,0,0},{1,1,1,1}};
	solve(maze);
}


================================================
FILE: Backtrack/nqueen_allsol.py
================================================
def initialize(board,n):
    keys=['queen','row','col','pdiag','sdiag']
    for i in keys:
        board[i]={}
    for i in range(n):
        board['queen'][i]=-1
        board['row'][i]=0
        board['col'][i]=0
    for i in range(-(n-1),n):
        board['pdiag'][i]=0
    for i in range(0,2*n-1):
        board['sdiag'][i]=0

def placequeen(r,board,n):
    return True

def printboard(board,n):
    for row in board['queen'].keys():
        print('(',row,',',board['queen'][row],')',end=' ')
    print('')

def isfree(i,j,board):
    return (board['row'][i]==0 and board['col'][j]==0 and board['pdiag'][j-i]==0 and board['sdiag'][j+i]==0)

def addqueen(i,j,board):
    board['queen'][i]=j
    board['row'][i]=1
    board['col'][j]=1
    board['pdiag'][j-i]=1
    board['sdiag'][j+i]=1

def undoqueen(i,j,board):
    board['queen'][i]=-1
    board['row'][i]=0
    board['col'][j]=0
    board['pdiag'][j-i]=0
    board['sdiag'][j+i]=0

def placequeen(i,board,n):
    for j in range(n):
        if isfree(i,j,board):
            addqueen(i,j,board)
            if i==n-1:
                printboard(board,n)
            else:
                extend=placequeen(i+1,board,n)
            undoqueen(i,j,board)
   
#main
n=int(input('Enter the number of queens:'))
board={}
initialize(board,n)
placequeen(0,board,n)


================================================
FILE: Backtrack/permutations_of_string.cpp
================================================
// Solution for printing all the permutations of a string.
#include<bits/stdc++.h>

/* Function to swap values at two pointers */
void swap(char *x, char *y)
{
    char temp;
    temp = *x;
    *x = *y;
    *y = temp;
}

/* Function to print permutations of string
   This function takes three parameters:
   1. String
   2. Starting index of the string
   3. Ending index of the string. */
void permute(char *a, int l, int r)
{
    int i;
    if (l == r)
        cout<<a;
    else
    {
        for (i = l; i <= r; i++)
        {
            swap((a+l), (a+i));
            permute(a, l+1, r);
            swap((a+l), (a+i)); //backtrack
        }
    }
}

int main()
{
    char str[] = "ABC";
    int n = strlen(str);
    permute(str, 0, n-1);
    return 0;
}
/*Output
ABC
ACB
BAC
BCA
CBA
CAB*/


================================================
FILE: CONTRIBUTING.md
================================================
<h1>Contributing Guidelines for Algo_Ds</h1>

<p>Thanks for taking the time to contribute to this project. Before making PRs, please note the following:</p>

<h3>A few norms you should follow</h3>
  <ul>
    <li>Proper intendation is must!</li>
    <li>Include ample comments so that code is understandable and easy to follow.</li>
    <li>Mention the complexity of a function in a comment.</li>
      <ul>
        <li>Time complexity : </li>
        <li>Space complexity : </li>
      </ul>
    <li>Place your code in right directory.</li>
    <li>Give your files names that are relevant and meaningful.</li>
  </ul>

<h4>You may add your solved questions on spoj, codechef, interviewbit, hackerearth, hackerrank and codeforces.</h4>
  <ul>
    <li>First line of your code must begin with a comment mentioning the link of the question</li>
    <li>Place the solutions in seperate folder "ques" in relevant directory</li>
  </ul>

<h4>DESCRIPTION.md</h4>
  <p>If not already present, you are free to create a DESCRIPTION.md file in a folder: </p>
  <ul>
    <li>Please write a brief description of your algorithm in DESCRIPTION.md file</li>
    <li>Suggestions of things to include in DESCRIPTION.md file:</li>
      <ul>
        <li>Description of algorithm</li>
        <li>Time and space complexity of algorithm</li>
        <li>Links to your favourite online questions solvable by that algorithm</li>
          <ui>
            <li>You may also provide solution to related questions in "ques" folder in the same directory.</li>
            <li>Also, mention link of solution (if available) along with the question link.</li>
          </ui>
      </ul>
  </ul>

<h4>Best Practices for opening a Pull Request</h4>
<ul>
  <li>Give the PR a meaningful name.</li>
  <li>For e.g. 'Fixes #(issue-number): PR name, fixing the particular bug' (without commas)</li>
  <li>There should be always 1 commit for 1 PR.</li>
  <li>If there are more than 1 commit in a PR, squash them.</li>
  <li>Pull Request details should be descriptive.</li>
  <li>Commit message should meaningful.</li>
</ul>

<h4>please have a look at <a href="https://github.com/srbcheema1/Algo_Ds/blob/master/STRUCTURE.md">STRUCTURE.md</a> for file structure</h4>


================================================
FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/buy_max_with_given_money.cpp
================================================
//https://www.hackerrank.com/contests/gs-codesprint/challenges/buy-maximum-stock////i///////i/s
#include<bits/stdc++.h>

#define F0(i,t) for(int i=0; i<t; i++)
#define F1(i,t) for(int i=1; i<=t; i++)
#define Si(x) scanf("%d",&x)
#define Si2(x,y) scanf("%d %d",&x,&y)
#define Sl(x) scanf("%lld",&x)
#define Sl2(x,y) scanf("%lld %lld",&x,&y)
#define dout if(debugg)cout<<" "

   /* * * * * * * * * * * * * * * * * * * * * * * *
    *                                             *
    *            _/_/_/            _/             *
    *         _/        _/  _/_/  _/_/_/          *
    *          _/_/    _/_/      _/    _/         *
    *             _/  _/        _/    _/          *
    *      _/_/_/    _/        _/_/_/             * 
    *                                             *
    * * * * * * * * * * * * * * * * * * * * * * * */

using namespace std;

typedef unsigned long long int ulli;
typedef unsigned int ui;
typedef pair<lli,lli> mp;

int debugg = 0;

bool sort_fxn(mp a,mp b){
    return a.second < b.second;
}

/*
 * return maximum number of elements we can buy...
 * we can buy max i elements at i day
 * vector a is 0 based
 * a[i] contains price of that elem
 * k = max amount to be spent
 */
ulli buyMaximumProducts(ulli n, ulli k, vector <ulli> a) {
    vector<mp > vec(n);
    for(int i=0;i<n;i++)
        vec[i]=mp(i+1,a[i]);
    sort(vec.begin(),vec.end(),sort_fxn);

    ulli amount = k;
    ulli bought = 0;
    ulli buy;
    for(int i=0;i<n;i++){
        buy = min(vec[i].first,amount/vec[i].second);
        bought += buy;
        amount -= buy*vec[i].second;
        if(vec[i].second > amount) break;
    }
    return bought;
}

int main() {
    ulli n,k;
    cin >> n;
    vector<ulli> arr(n);

    for(ulli i = 0; i < n; i++)
       cin >> arr[i];

    ulli k;
    cin >> k;

    ulli result = buyMaximumProducts(n, k, arr);
    cout << result << endl;
}
// a code by srbcheema1


================================================
FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/median searching efficientalgo.cpp
================================================
#include<iostream>
#include<vector>
#include<algorithm>
#include<array>
using namespace std;
int median(int *a,int s,int r,int k);
int pivot(int *a,int s,int r);
int main()
{
int *a;
int n;
cin>>n;
a=new int[n];
for(int i=0;i<n;i++)
{
cin>>a[i];

}
int k;
cin>>k;
int x=median(a,0,n-1,k);
cout<<"kth smallest element is\n"<<x;
return 0;

}
int median(int *a,int s,int r,int k)
{
int p=pivot(a,s,r);
int v1[r+1],v2[r+1],v3[r+1];
int s1=0,s2=0,s3=0;
int r=0,v=0,t=0;
for(int i=0;i<r+1;i++)
{
if(a[i]<p)
{
v1[r]=a[i];
cout<<v1[i]<<" ";
s1++;
r++;
cout<<s1;
}
else if(a[i]==p)
{
v2[v]=a[i];
s2++;v++;
}
else{
v3[t]=a[i];
s3++;t++;
}
}



if(s1>k)
{
median(v1,s,s1-1,k);

}
else if(s1+s2>k)
{
return p;
}
else{
median(v3,s1+s2-1,r,k-s1-s2);
}
}

int pivot(int *a,int s,int r)
{
    int t;
    if((r+1)%5==0)
    {
        t=(r+1)/5;
    }
   else{
       t=((r+1)/5)+1;
   }
int b[t][5];

int p;
int k=0;
for(int i=0;i<t;i++)
{
for(int j=0;j<5;j++)
{
b[i][j]=a[k];
k++;
}
}

for(int i=0;i<t;i++)
{
  int *q=*(b+i);
  int *w=(*(b+i)+5);
sort(q,w);
}
p=b[t/2-1][2];
cout<<p<<endl;
return p;

}


================================================
FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques/volcano.cpp
================================================
//https://www.hackerrank.com/contests/university-codesprint-3/challenges/erupting-volcanoes
#include<bits/stdc++.h>

#define F0(i,t) for(int i=0; i<t; i++)
#define F1(i,t) for(int i=1; i<=t; i++)
#define Si(x) scanf("%d",&x)
#define Si2(x,y) scanf("%d %d",&x,&y)
#define Sl(x) scanf("%lld",&x)
#define Sl2(x,y) scanf("%lld %lld",&x,&y)
#define dout if(debugg)cout<<" "

   /* * * * * * * * * * * * * * * * * * * * * * * *
    *                                             *
    *            _/_/_/            _/             *
    *         _/        _/  _/_/  _/_/_/          *
    *          _/_/    _/_/      _/    _/         *
    *             _/  _/        _/    _/          *
    *      _/_/_/    _/        _/_/_/             * 
    *                                             *
    * * * * * * * * * * * * * * * * * * * * * * * */

using namespace std;

typedef unsigned long long int ulli;
typedef unsigned int ui;
typedef pair<int,int> mp;
typedef vector<vector<int> > matrix;

struct elem{
    int x;
    int y;
    int w;
    elem(int x,int y,int w){
        this->x = x;
        this->y = y;
        this->w = w;
    }
};

int debugg = 0;

void fill(int x,int y,int w,int n,matrix& mat,matrix& filled){

    queue<elem> q;
    q.push(elem(x,y,w));
        
    while(!q.empty()){
        elem temp = q.front();
        x = temp.x; y = temp.y; w = temp.w;
        q.pop();

        if(x<0 || y<0 || x>=n || y>=n || w<=0 )continue;
        if(filled[x][y]==1) continue;

        filled[x][y]=1;
        mat[x][y] += w;

        q.push(elem(x+1,y,w-1));
        q.push(elem(x,y+1,w-1));
        q.push(elem(x-1,y,w-1));
        q.push(elem(x,y-1,w-1));
        
        q.push(elem(x-1,y+1,w-1));
        q.push(elem(x-1,y-1,w-1));
        q.push(elem(x+1,y+1,w-1));
        q.push(elem(x+1,y-1,w-1));
    }
}

int main(){
	int t=1;
    ios_base::sync_with_stdio(0);cin.tie(0);
	while(t--){
        int n,m,x,y,w,maxx=0;
        cin>>n>>m;
        matrix mat(n,vector<int>(n,0));

        while(m--){
            cin>>x>>y>>w; 
            matrix filled(n,vector<int>(n,0));
            fill(x,y,w,n,mat,filled);
        }

        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(mat[i][j] >maxx){
                    maxx=mat[i][j];
                }
            }
        }
        cout<<maxx<<endl;
	}
}
// a code by srbcheema1


================================================
FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques-beat_the_clock/spiral_matrix.cpp
================================================
#include<bits/stdc++.h>

#define F0(i,t) for(int i=0; i<t; i++)
#define F1(i,t) for(int i=1; i<=t; i++)
#define Si(x) scanf("%d",&x)
#define Si2(x,y) scanf("%d %d",&x,&y)
#define Sl(x) scanf("%lld",&x)
#define Sl2(x,y) scanf("%lld %lld",&x,&y)
#define dout if(debugg)cout<<" "

   /* * * * * * * * * * * * * * * * * * * * * * * *
    *                                             *
    *            _/_/_/            _/             *
    *         _/        _/  _/_/  _/_/_/          *
    *          _/_/    _/_/      _/    _/         *
    *             _/  _/        _/    _/          *
    *      _/_/_/    _/        _/_/_/             * 
    *                                             *
    * * * * * * * * * * * * * * * * * * * * * * * */

using namespace std;

typedef unsigned long long int ulli;
typedef unsigned int ui;
typedef pair<int,int> mp;

int debugg = 0;

/*
 * func to return matrix in a vector such that it is unfolded 
 * vec is vector of vectors containing the matrix
 * m and n are dimentions
 */
vector<int> func(vector<vector<int> > vec,int m,int n){
    vector<int> ans;
    int l=0,r=n-1,u=0,d=m-1;
    int row=0;int col=0;

    while(true){
        if(l>r || u>d) break;
        for(int i=l;i<=r;i++){//     >>>
            dout<<"> ";
            ans.push_back(vec[row][i]);
        }
        col = r;
        u = u+1;
        if(l>r || u>d) break;
        for(int i=u;i<=d;i++){//     V
            dout<<"V ";
            ans.push_back(vec[i][col]);
        }
        row = d;
        r = r-1;
        if(l>r || u>d) break;
        for(int i=r;i>=l;i--){//   <<<
            dout<<"< ";
            ans.push_back(vec[row][i]);
        }
        col=l;
        d = d-1;
        if(l>r || u>d) break;
        for(int i=d;i>=u;i--){//  ^
            dout<<"^ ";
            ans.push_back(vec[i][col]);
        }
        row = u;
        l = l+1;
        if(l>r || u>d) break;
    }
    return ans;
}

int main(){
	int t=1,n,m,temp;
    ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>t;
	while(t--){
        cin>>m>>n;
        vector<vector<int> > vec(m);
        for(int i=0;i<m;i++)
            for(int j=0;j<n;j++){
                cin>>temp;
                vec[i].push_back(temp); 
            }

        vector<int> ans = func(vec,m,n);
        for(int i=0;i<ans.size();i++)
            cout<<ans[i]<<" ";
        cout<<endl;
	}
}
// a code by srbcheema1


================================================
FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques-l1/codeforces_426_2.cpp
================================================
//http://codeforces.com/problemset/problem/834/B
#include<bits/stdc++.h>

using namespace std;

int main(){
    int g,k;
    int start[27];
    int last[27];
    
    cin>>g>>k;
    string str;
    cin>>str;

    int alot=0,free=0,gate=0;
    memset(start,-1,sizeof(start));
    memset(last,-1,sizeof(last));
    for(int i=0;i<g;i++){
        gate=str[i]-'A'+1;

        if(start[gate]==-1)start[gate]=i;

        last[gate]=i;
    }

    for(int i=0;i<g;i++){
        gate=str[i]-'A'+1;

        if(start[gate]==i){
            if(free==0){
                alot++;
            }
            else{
                free--;
                alot++;
            }
        }
        if(last[gate]==i){
            alot--;
            free++;
        }
    }
    if(free>k) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


================================================
FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques-l1/positions.cpp
================================================
//https://www.hackerearth.com/problem/algorithm/attack-on-daleks/
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n;
    long long int sum;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin>>n;
    int arr1[n],arr2[n];
    for(int i=0;i<n;i++)
        cin>>arr1[i];
        
    for(int i=0;i<n;i++)
        cin>>arr2[i];

    sort(arr1,arr1+n);
    sort(arr2,arr2+n);
    sum=0;
    for(int i=0;i<n;i++){
        sum+=abs(arr2[i]-arr1[i]);
    }
    cout<<sum<<endl;
}


================================================
FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques-l1/snake/snake.cpp
================================================
//https://www.hackerrank.com/contests/university-codesprint-3/challenges/the-snake-vs-the-wind
#include<bits/stdc++.h>

#define F0(i,t) for(int i=0; i<t; i++)
#define F1(i,t) for(int i=1; i<=t; i++)
#define Si(x) scanf("%d",&x)
#define Si2(x,y) scanf("%d %d",&x,&y)
#define Sl(x) scanf("%lld",&x)
#define Sl2(x,y) scanf("%lld %lld",&x,&y)
#define dout if(debugg)cout<<" "

   /* * * * * * * * * * * * * * * * * * * * * * * *
    *                                             *
    *            _/_/_/            _/             *
    *         _/        _/  _/_/  _/_/_/          *
    *          _/_/    _/_/      _/    _/         *
    *             _/  _/        _/    _/          *
    *      _/_/_/    _/        _/_/_/             * 
    *                                             *
    * * * * * * * * * * * * * * * * * * * * * * * */

using namespace std;

typedef unsigned long long int ulli;
typedef unsigned int ui;
typedef pair<int,int> mp;
typedef vector<vector<int> > matrix;

int debugg = 0;

void fill(matrix& mat,int x,int y,int d,int n){
    int num=1;
    if(d==1){//^
        while(true){
            mat[x][y]=num;
            num++;
            if(x-1>=0 && mat[x-1][y]==0){
                x = x-1;
            }
            else if(y-1>=0 && mat[x][y-1]==0){
                y=y-1;
            }
            else if(y+1<n && mat[x][y+1]==0){
                y=y+1;
            }
            else if(x+1<n && mat[x+1][y]==0){
                x=x+1; 
            }
            else{
                break;
            }
        } 
    }
    if(d==2){//v
        while(true){
            mat[x][y]=num;
            num++;
            if(x+1<n && mat[x+1][y]==0){
                x = x+1;
            }
            else if(y-1>=0 && mat[x][y-1]==0){
                y=y-1;
            }
            else if(y+1<n && mat[x][y+1]==0){
                y=y+1;
            }
            else if(x-1>=0 && mat[x-1][y]==0){
                x=x-1; 
            }
            else{
                break;
            }
        }
    }
    if(d==3){//>
        while(true){
            mat[x][y]=num;
            num++;
            if(y+1<n && mat[x][y+1]==0){
                y=y+1;
            }
            else if(x-1>=0 && mat[x-1][y]==0){
                x = x-1;
            }
            else if(x+1<n && mat[x+1][y]==0){
                x=x+1; 
            }
            else if(y-1>=0 && mat[x][y-1]==0){
                y=y-1;
            }
            else{
                break;
            }
        }
    }
    if(d==4){//<
        while(true){
            mat[x][y]=num;
            num++;
            if(y-1>=0 && mat[x][y-1]==0){
                y=y-1;
            }
            else if(x-1>=0 && mat[x-1][y]==0){
                x = x-1;
            }
            else if(x+1<n && mat[x+1][y]==0){
                x=x+1; 
            }
            else if(y+1<n && mat[x][y+1]==0){
                y=y+1;
            }
            else{
                break;
            }
        }
    }
}

int main(){
	int t=1;
    ios_base::sync_with_stdio(0);cin.tie(0);
	while(t--){
        int n,x,y,d;
        cin>>n;
        string dir;
        cin>>dir>>x>>y;
        
        if(dir[0]=='n')d=1;//^
        if(dir[0]=='s')d=2;//v
        if(dir[0]=='e')d=3;//>
        if(dir[0]=='w')d=4;//<
        
        matrix mat(n,vector<int>(n,0));
        fill(mat,x,y,d,n);

        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++)
                cout<<mat[i][j]<<" ";
            cout<<endl;
        }
	}
}
// a code by srbcheema1


================================================
FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques-l1/snake/wrong_snake.cpp
================================================
//https://www.hackerrank.com/contests/university-codesprint-3/challenges/the-snake-vs-the-wind
#include<bits/stdc++.h>

#define F0(i,t) for(int i=0; i<t; i++)
#define F1(i,t) for(int i=1; i<=t; i++)
#define Si(x) scanf("%d",&x)
#define Si2(x,y) scanf("%d %d",&x,&y)
#define Sl(x) scanf("%lld",&x)
#define Sl2(x,y) scanf("%lld %lld",&x,&y)
#define dout if(debugg)cout<<" "

   /* * * * * * * * * * * * * * * * * * * * * * * *
    *                                             *
    *            _/_/_/            _/             *
    *         _/        _/  _/_/  _/_/_/          *
    *          _/_/    _/_/      _/    _/         *
    *             _/  _/        _/    _/          *
    *      _/_/_/    _/        _/_/_/             * 
    *                                             *
    * * * * * * * * * * * * * * * * * * * * * * * */

using namespace std;

typedef unsigned long long int ulli;
typedef unsigned int ui;
typedef pair<int,int> mp;
typedef vector<vector<int> > matrix;

int debugg = 0;

void movehu(matrix& mat,int x,int y,int num,int n){
    if(y==0)
    for(int i=n-1;i>=0;i--){
        for(int j=0;j<n;j++){
            mat[i][j]=num;
            num++;
        }
        i--;
        if(i<0)break;
        for(int j=n-1;j>=0;j--){
            mat[i][j]=num;
            num++;
        }
    }
    else
    for(int i=n-1;i>=0;i--){
        for(int j=n-1;j>=0;j--){
            mat[i][j]=num;
            num++;
        }
        i--;
        if(i<0)break;
        for(int j=0;j<n;j++){
            mat[i][j]=num;
            num++;
        }
    }
}
void movehd(matrix& mat,int x,int y,int num,int n){
    if(y==0)
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            mat[i][j]=num;
            num++;
        }
        i++;
        if(i>=n)break;
        for(int j=n-1;j>=0;j--){
            mat[i][j]=num;
            num++;
        }
    }
    else
    for(int i=0;i<n;i++){
        for(int j=n-1;j>=0;j--){
            mat[i][j]=num;
            num++;
        }
        i++;
        if(i>=n)break;
        for(int j=0;j<n;j++){
            mat[i][j]=num;
            num++;
        }
    }
}
void movevl(matrix& mat,int x,int y,int num,int n){
    if(x==0)
    for(int j=n-1;j>=0;j--){
        for(int i=0;i<n;i++){
            mat[i][j]=num;
            num++;
        }
        j--;
        if(j<0)break;
        for(int i=n-1;i>=0;i--){
            mat[i][j]=num;
            num++;
        }
    }
    else
    for(int j=n-1;j>=0;j--){
        for(int i=n-1;i>=0;i--){
            mat[i][j]=num;
            num++;
        }
        j--;
        if(j<0)break;
        for(int i=0;i<n;i++){
            mat[i][j]=num;
            num++;
        }
    }
}
void movevr(matrix& mat,int x,int y,int num,int n){
    if(x==0)
    for(int j=0;j<n;j++){
        for(int i=0;i<n;i++){
            mat[i][j]=num;
            num++;
        }
        j++;
        if(j>=n)break;
        for(int i=n-1;i>=0;i--){
            mat[i][j]=num;
            num++;
        }
    }
    else
    for(int j=0;j<n;j++){
        for(int i=n-1;i>=0;i--){
            mat[i][j]=num;
            num++;
        }
        j++;
        if(j>=n)break;
        for(int i=0;i<n;i++){
            mat[i][j]=num;
            num++;
        }
    }
}


void fill(matrix& mat,int x,int y,int d,int n){ 
    if(d==1 || d==2){//n  or s  ... move horizontally
        if(x==n-1){//horizontally up
            movehu(mat,x,y,1,n) ;
        }
        else{//horizontally down
            movehd(mat,x,y,1,n) ;
        }
    }
    else{//e or w ... move vertically
        if(y==n-1){//vertically left
            movevl(mat,x,y,1,n) ; 
        } 
        else{//vertically right
            movevr(mat,x,y,1,n) ;
        }
    }
}

int main(){
	int t=1;
    ios_base::sync_with_stdio(0);cin.tie(0);
	while(t--){
        int n,x,y,d;
        cin>>n;
        string dir;
        cin>>dir>>x>>y;
        
        if(dir[0]=='n')d=1;//^
        if(dir[0]=='s')d=2;//v
        if(dir[0]=='e')d=3;//>
        if(dir[0]=='w')d=4;//<
        
        matrix mat(n,vector<int>(n,0));
        fill(mat,x,y,d,n);

        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++)
                cout<<mat[i][j]<<" ";
            cout<<endl;
        }
	}
}
// a code by srbcheema1


================================================
FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/searchmat.cpp
================================================
// A program to search for an element in a 2D matrix in which each row and coloumn is sorted in ascending order
#include <iostream>
using namespace std;

int main(){
  // Number of test cases
  int test;
  cin >> test;
  while(test--){
    // Number of rows and coloumns in the matrix
    int a, b;
    cin >> a >> b;
    int ar[a][b];
    // Array of arrays to store the values of 2D-Matrix
    for (int i = 0; i < a * b; ++i) {
      cin >> ar[i % a][i % b];
    }
    // Number to be searched for
    int x;
    cin >> x;
    // Start from top right
    int i = 0, j = b - 1;
    while(1){
      // Problem solved if element is found
      if(ar[i][j] == x){
	cout << 1;
	break;
      }
      // Move down if element is less than key
      else if(ar[i][j]<x){
	i++;
      }
      // Move left if element is greater than key
      else if(ar[i][j]>x){
	j--;
      }
      // If element is not found return 0
      // as we reach the bottom-left of the matrix
      // The element was not present
      if(i >= a || j <0){
	cout << 0 << endl;
	break;
      }
    }
  }
  return 0;
}

// Sample test case:
// 1
// 3 3
// 2 6 8
// 3 9 12
// 4 10 13
// 9


================================================
FILE: Competitive Programming Challenges/C:C++/Patterns/pattern1.cpp
================================================
#include <iostream>
using namespace std;

int main(){

	int n;
	cin >> n;

	for( int i = 0; i < n; i++ ){
		for( int j = 0; j < n; j++ ){
			cout << "*";
		}
		cout << endl;
	}
    return 0;

}

/*
5

*****
*****
*****
*****
*/


================================================
FILE: Competitive Programming Challenges/C:C++/Patterns/pattern2.cpp
================================================
#include <iostream>
using namespace std;

int main(){

	int n;
	cin >> n;

	for( int i = 0; i < n; i++ ){
		for( int j = 0; j <= i; j++ ){
			cout << "*";
		}
		cout << endl;
	}

    return 0;

}

/*
5

*
**
***
****
*****
*/


================================================
FILE: Competitive Programming Challenges/C:C++/Patterns/pattern3.cpp
================================================
#include <iostream>
using namespace std;

int main(){

	int n;
	cin >> n;

	for( int i = n; i > 0; i-- ){
		for( int j = 0; j < i; j++ ){
			cout << "*";
		}
		cout << endl;
	}

    return 0;
}

/*
5

*****
****
***
**
*

*/


================================================
FILE: Competitive Programming Challenges/C:C++/Patterns/pattern4.cpp
================================================
#include <iostream>
using namespace std;

int main(){

	int n;
	cin >> n;

	for( int i = 0; i < n; i++ ){
		for( int j = 0; j <= i; j++ ){
			cout << "*";
		}
		cout << endl;
	}

	for( int i = n-1; i > 0; i-- ){
		for( int j = 0; j < i; j++ ){
			cout << "*";
		}
		cout << endl;
	}

    return 0;

}

/*

5

*
**
***
****
*****
****
***
**
*

*/


================================================
FILE: Competitive Programming Challenges/C:C++/Patterns/pattern6.cpp
================================================
#include <iostream>
using namespace std;

int main(){

	int n;
	cin >> n;

	for( int i = 1; i <= n; i++ ){
		for( int j = 1; j <= i; j++ ){
			cout << i;
		}
		cout << endl;
	}

    return 0;
}

/*

5

1
22
333
4444
55555

*/


================================================
FILE: Competitive Programming Challenges/C:C++/Patterns/pattern7.cpp
================================================
#include <iostream>
using namespace std;

int main(){
	int n;
	cin >> n;

	int count = 1;
	for( int i = 0; i < n; i++ ){
		for( int j = 0; j <= i; j++ ){
			cout << count << " ";
			count++;
		}
		cout << endl;
	}
    return 0;

}

/*

5

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

*/


================================================
FILE: Conversions/C:C++/binary2octal.c
================================================
// Binary number to octal number conversion
#include<stdio.h>

//Function that returns the last three digits
int three_digits(int n)
{
    int r, d = 0, p=1;

    for(int i=0; i<3; i++)
    {
        r = n%10;
        d = d + r * p;
        p = p * 10;
        n = n / 10;
    }
    return d;
}

int main(void)
{
    int binary_num, d=0, base=1, remainder, td, res=0, ord=1;

    printf("Enter the binary no: ");
    scanf("%d", &binary_num);

    while(binary_num > 0)
    {
        if(binary_num > 111) //Checking if binary number is greater than three digits
            td = three_digits(binary_num);

        else td = binary_num;

        binary_num = binary_num / 1000;

        d = 0, base =1;

        // Converting the last three digits to decimal
        while(td > 0)
        {
            remainder = td % 10;
            td = td / 10;
            d = d + (base * remainder);
            base = base * 2;
        }

        res = res + d * ord; // Calculating the octal value
        ord = ord * 10;
    }

    printf("\nOctal equivalent is: %d", res);
    return 0;
}


================================================
FILE: Data Structures/C:C++/Applications/Evaluating Postfix Expression.c
================================================
#include <stdio.h>
#include <string.h>
#define MAX 200

int isoperator(char c){
	return (c=='*' || c=='/' || c=='+' || c=='-');
}

struct stack
{
	int top;
	double a[MAX];
}s;

void push(double c){
	s.a[++s.top]=c;
}

double pop(){
	return s.a[s.top--];
}

double perform(double a, double b, char c){
	if (c=='*')
	{
		return a*b;
	}
	else if (c=='+')
	{
		return a+b;
	}
	else if (c=='/')
	{
		return a/b;
	}
	else return a-b;
}

void post_infix(char a[],int l){
	int i;
	for(i=0;i<l;i++){
		if (isoperator(a[i]))
		{
			double sec = pop(); 
			//printf("%f",sec);
			double fir = pop(); 
			//printf("%f",fir);
			double res = perform(fir,sec,a[i]); 
			//printf("%f",res);
			push(res);
		}
		else{
			push(a[i]-'0');
		}
	}
}

int main()
{
	printf("Enter a postfix expression :\n");
	char post[100];
	s.top=-1;
	scanf("%s",post);
	int n=strlen(post);
	post_infix(post,n);
	printf("%f",s.a[s.top]);
	return 0;
}


================================================
FILE: Data Structures/C:C++/Applications/Infix to Postfix.c
================================================
#include<stdio.h>

int j;
struct temp{
	char a[200];
	int top;
};
struct temp s;

void push(char item){
	s.a[++s.top]=item;
}

int isempty(){
	return s.top==-1;
}

char pop(){
	if(!isempty())return s.a[s.top--];
}

int isoperator(char c){
	if(c=='*'||c=='/'|| c=='+'|| c=='-')return 1;
	return 0;
}
int precedence(char c){
	if(c=='+' || c=='-')return 1;
	else if(c=='*' || c=='/')return 2;
	else if(c=='^')return 3;
	return 0;
}
char *infix_postfix(char *p){
	int i;
	j=0;
	char *p1 = (char *)malloc(100*sizeof(char));
	for(i=0;p[i]!='\0';i++){
		//printf("%d\n",j);
		if(isalpha(p[i]) || isdigit(p[i])){
			p1[j++]=p[i];
		}
		else if(isoperator(p[i])){//printf("%c\n",p[i]);
			while(!isempty() && /*s.a[s.top]!='(' &&*/ (precedence(p[i]) <= precedence(s.a[s.top]))){
				p1[j++] = s.a[s.top];
				pop();
			}	
			push(p[i]);
		}
		else if(p[i]=='(')push(p[i]);
		else if(p[i]==')'){
			while(!isempty() && s.a[s.top]!='('){
				p1[j++]=s.a[s.top];
				pop();
			}
			pop();
		}
	}
	while(!isempty()){
		//printf("%c ",s.a[s.top]);
		p1[j++]=s.a[s.top];
		pop();
	}
	//for(i=0;i<j;i++)printf("%c",p[i]);
	return p1;
}

int main(){
	s.top = -1;
	char *p = (char *)malloc(100*sizeof(char));
	while(1){
		printf("Enter expression : \n");
		gets(p);
		char *p1 = infix_postfix(p);
		//infix_postfix(exp);
		int i;
		for(i=0;i<j;i++)printf("%c",p1[i]);
		printf("\n");
	}
	return 0;
}


================================================
FILE: Data Structures/C:C++/Applications/balance parenthesis.cpp
================================================
#include<iostream>
#include<bits/stdc++.h>
#include<string.h>
#include<stack>
using namespace std;

int main(){
	string str;
	printf("Enter a String");
	cin>>str;
	int l = str.length();
	stack <char> s;
	for(int i=0;i<l;i++){
		if(str[i]=='{' || str[i]=='[' || str[i]=='('){
			s.push(str[i]);
		}
		else if(str[i]=='}' || str[i]==']' || str[i]==')'){
			if(s.empty()){
				printf("\nNot Balanced\n");
				return false;
			}
			else{
				if(str[i]=='}' && s.top()=='{'){
					s.pop();
				}
				else if(str[i]==']' && s.top()=='['){
					s.pop();
				}
				else if(str[i]=='(' && s.top()==')'){
					s.pop();
				}
				else{
					printf("\nNot Balanced\n");return false;
				}
			}
		}
	}
	if(s.empty()){
		printf("\nBalanced\n");
	}
	else{
		printf("\nNot Balanced\n");
	}
}


================================================
FILE: Data Structures/C:C++/Applications/stack_and_its_implementation.c
================================================
//Auhor : VIVEK SHAH
/*Performs Push, Pop, Peep and Displays elements of Stack*/


#include<stdio.h>

struct stack{
	char book_name[200][200];
	int book_id[20];
	int book_price[20];
	int top;
};

struct stack *p;
int size;

void push(){
	if((p->top)==size-1){
		printf("Overflow");
		return;
	}
	p->top = p->top +1;
	//printf("p->top = %d",p->top);
	printf("\nEnter elements to be pushed : ");
	printf("\nEnter book name:");
	scanf("%s",p->book_name[p->top]);
	printf("\nEnter book id:");
	scanf("%d",&p->book_id[p->top]);
	printf("\nEnter book price:");
	scanf("%d",&p->book_price[p->top]);
}

void pop(){
	if(p->top==-1){
		printf("Underflow\n");
	}
	else{
		p->top = p->top - 1;
	}
}

void peep(){
	int i= p->top;
		printf("\nBook Name : %s",p->book_name[i]);
		printf("\nBook ID : %d",p->book_id[i]);
		printf("\nBook Price : %d",p->book_price[i]);
		printf("\n");
}

void print(){
	int x = p->top;
	if(x==-1){
		printf("Nothing to be displayed\n");
	}
	int i;
	for(i=0;i<=x;i++){
		printf("\nBook Name : %s",p->book_name[i]);
		printf("\nBook ID : %d",p->book_id[i]);
		printf("\nBook Price : %d",p->book_price[i]);
		printf("\n");
	}	
}

int main(){
	printf("********************************\t\n");
	printf("Enter stack size : ");
	scanf("%d",&size);
	p = (struct stack*)malloc(sizeof(struct stack));
	p->top = -1;
	while(1){
		printf("\n1.Push\n2.Pop\n3.Peep\n4.Display all elements\n5.Exit\n");
		int ch;
		scanf("%d",&ch);
		if(ch==1){
			//p->top = p->top + 1;
			push();
		}
		else if(ch==2){
			pop();
		}
		else if(ch==3){
			peep();
		}
		else if(ch==4){
			print();
		}
		else{
			break;
		}
	}
}


================================================
FILE: Data Structures/C:C++/Graph/FloydWarshall.cpp
================================================
//Floyd Warshall Algorithm for All Pair Shortest Path Problem
#include <bits/stdc++.h>
#define FOR(i,n) for(size_t i=0;i<n;++i)
#define endl '\n'
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;

ll gcd(ll a , ll b){return a==0?b:gcd(b%a,a);}

int main(){
	//Floyd Warshall algorithm for all pair shortest path algorithm
	//NOTE - Vertices in this are from 0 to V-1. For 1 to V, modify the code!!
	//Complexity is O(V*V*V). Thi
	int e,v,a,b,weight, floyd_warshall [1000][1000],i,j,k,temp;
	cin>>v>>e;
	FOR(i,v){
		FOR(j,v)
		{
			if(i!=j)
				floyd_warshall[i][j] = 99999999;
			else floyd_warshall[i][j] = 0;
		}
	}

	FOR(i,e){
		cin>>a>>b>>weight;
		floyd_warshall[a][b] = weight;
	}
	
	FOR(k,v){
		FOR(i,v){
			FOR(j,v){
				temp = floyd_warshall[i][k] + floyd_warshall[k][j];
				if(temp <  floyd_warshall[i][j])
					floyd_warshall[i][j] = temp;
			}
		}
	}
	cout<<floyd_warshall[2][3];
	return 0;
}


================================================
FILE: Data Structures/C:C++/Graph/adjacency_list.hpp
================================================
#include <iostream>
#include <vector>
#include "../queue/queue.hpp"
using namespace std;

template<typename T>
class graph_al {
private:
	int count;
	map< int, vector<T> > connections;
	vector<T> vertices;
	bool *visited;
public:
	graph_al(T vertices[], int count) : count(count), visited(new bool[count]) {
		for(int i=0;i<count;i++){
			this->vertices.push_back(vertices[i]);
		}
	}

	void connect(int i, int j){
		connections[i].push_back(j);
	}

	void connect_both_sides(int i, int j){
		connect(i, j);
		connect(j, i);
	}

	bool contains(vector<int> v, int n){
		return find(v.begin(), v.end(), n) != v.end();
	}

	bool bfs(int i, int j){
		queuemp<int> *q = new queuemp<int>();
		// else, try seraching though the connections
		for(int w=0;w<this->count;w++) visited[w] = false;
		q->push(i);
		visited[i] = true;
		while(q->size){
			int v = q->pop();
			for(int w = 0; w < connections[v].size();w++){
				if(!visited[connections[v][w]]){
					if(connections[v][w] == j) return true;
					q->push(connections[v][w]);
					visited[connections[v][w]] = true;
				}
			}
		}
		return false;
	}

	void dfs(int i){
		for(int j=0;j<connections[i].size();j++){
			if(!visited[connections[i][j]]){
				visited[connections[i][j]] = true;
				dfs(connections[i][j]);
			}
		}
	}

	// check if the vertices at i and j are connected.
	bool connected(int i, int j){
		return bfs(i, j);
	}

	void print_graph(){
		cout << "Printing adjacency list of graph:" << endl;
		for(int i=0;i<count;i++){
			vector<int> v = connections[i];
			cout << "vertices connected to " << i << ":" << endl;
			for(int j=0;j<v.size();j++){
				cout << connections[i][j] << " ";
			}
			cout << endl;
		}
	}

	int connected_components(){
		for(int i=0;i<count;i++) visited[i] = false;
		int components = 0;
		for(int i=0;i<count;i++){
			if(!visited[i]){
				visited[i] = true;
				dfs(i);
				components++;
			}
		}
		return components;
	}
};


================================================
FILE: Data Structures/C:C++/Graph/adjacency_matrix.hpp
================================================
#include <iostream>
#include "../queue/queue.hpp"
using namespace std;

template<typename T>
class graph_am {
private:
	int count;
	bool **connections;
	T *vertices;
	bool *visited;
public:
	graph_am(T vertices[], int count) : count(count), vertices(new T[count]), visited(new bool[count]) {
		connections = new bool*[count];
		for(int i=0;i<count;i++){
			connections[i] = new bool[count];
		}
		for(int i=0;i<count;i++){
			this->vertices[i] = vertices[i];
			for(int j=0;j<count;j++){
				connections[i][j] = (i==j);
			}
		}
	}

	void connect(int i, int j){
		connections[i][j] = true;
	}

	void connect_both_sides(int i, int j){
		connect(i, j);
		connect(j, i);
	}

	bool bfs(int i, int j){
		queuemp<int> *q = new queuemp<int>();
		if(connections[i][j]) return true;
		// else, try seraching though the connections
		for(int w=0;w<this->count;w++) visited[w] = false;
		q->push(i);
		visited[i] = true;
		while(q->size){
			int v = q->pop();
			for(int w = 0; w < this->count; w++){
				if(!visited[w] && connections[v][w]){
					if(w == j) return true;
					q->push(w);
					visited[w] = true;
				}
			}
		}
		return false;
	}

	void dfs(int i){
		for(int j=0;j<count;j++){
			if(!visited[j] && connections[i][j]){
				visited[j] = true;
				dfs(j);
			}
		}
	}

	// check if the vertices at i and j are connected.
	bool connected(int i, int j){
		return bfs(i, j);
	}

	int connected_components(){
		for(int i=0;i<count;i++) visited[i] = false;
		int components = 0;
		for(int i=0;i<count;i++){
			if(!visited[i]){
				dfs(i);
				components++;
			}
		}
		return components;
	}
};


================================================
FILE: Data Structures/C:C++/Graph/bfs_dfs/bfs/BFS.java
================================================
/**
 * Input file example:
 *
 *
 * 8
 * INF 1 1 INF INF INF INF INF
 * 1 INF INF 1 1 INF INF INF
 * 1 INF INF INF INF 1 1 INF
 * INF 1 INF INF INF INF INF INF
 * INF 1 INF INF INF INF INF 1
 * INF INF 1 INF INF INF INF INF
 * INF INF 1 INF INF INF INF INF
 * INF INF INF INF 1 INF INF INF
 * 1
 *
 * First line is number of elements in graph
 * Next n-lines is graph
 * Last line is begin point
 *
 * Output file:
 * 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8
 *
 */

import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.*;

class BFS {

    private static final String INPUT_FILE_PATH = "input.txt";

    private static final String OUTPUT_FILE_PATH = "output.txt";

    private static final int INF = Integer.MAX_VALUE / 2;

    private static int begin;

    public static void main(String[] args) {
        int[][] matrix = readMatrixFromFile();
        List<Integer> way = bfs(matrix);
        printSolution(way);
    }

    private static int[][] readMatrixFromFile() {
        int[][] matrix = null;

        try (Scanner scanner = new Scanner(new FileInputStream(INPUT_FILE_PATH))) {
            int matrixSize = Integer.parseInt(scanner.nextLine());
            matrix = new int[matrixSize][matrixSize];

            for (int row = 0; row < matrixSize; row++) {
                String[] numbers = scanner.nextLine().split(" ");
                for (int col = 0; col < matrixSize; col++) {
                    if (numbers[col].equals("INF")) {
                        matrix[row][col] = INF;
                    } else {
                        matrix[row][col] = Integer.parseInt(numbers[col]);
                    }
                }
            }

            begin = scanner.nextInt() - 1;
        } catch (IOException e) {
            e.printStackTrace();
        }

        return matrix;
    }

    private static List<Integer> bfs(int[][] matrix) {
        boolean[] used = new boolean[matrix.length];
        List<Integer> way = new ArrayList<>();
        Queue<Integer> queue = new LinkedList<>();
        queue.offer(begin);

        while (!queue.isEmpty()) {
            int v = queue.poll();
            used[v] = true;
            way.add(v + 1);

            for (int nv = 0; nv < matrix.length; nv++) {
                if (!used[nv] && matrix[v][nv] != INF) {
                    queue.offer(nv);
                }
            }
        }
        return way;
    }

    private static void printSolution(List<Integer> way) {
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(OUTPUT_FILE_PATH))) {
            writer.write(Integer.toString(way.get(0)));

            for (int i = 1; i < way.size(); i++) {
                writer.write(" -> " + way.get(i));
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}

================================================
FILE: Data Structures/C:C++/Graph/bfs_dfs/bfs/bfs.Py
================================================
# Program to print BFS traversal from a given source
# vertex. BFS(int s) traverses vertices reachable
# from s.
from collections import defaultdict
 
# This class represents a directed graph using adjacency
# list representation
class Graph:
 
    # Constructor
    def __init__(self):
 
        # default dictionary to store graph
        self.graph = defaultdict(list)
 
    # function to add an edge to graph
    def addEdge(self,u,v):
        self.graph[u].append(v)
 
    # Function to print a BFS of graph
    def BFS(self, s):
 
        # Mark all the vertices as not visited
        visited = [False]*(len(self.graph))
 
        # Create a queue for BFS
        queue = []
 
        # Mark the source node as visited and enqueue it
        queue.append(s)
        visited[s] = True
 
        while queue:
 
            # Dequeue a vertex from queue and print it
            s = queue.pop(0)
            print s,
 
            # Get all adjacent vertices of the dequeued
            # vertex s. If a adjacent has not been visited,
            # then mark it visited and enqueue it
            for i in self.graph[s]:
                if visited[i] == False:
                    queue.append(i)
                    visited[i] = True
 
 
# Driver code
# Create a graph given in the above diagram
g = Graph()
g.addEdge(0, 1)
g.addEdge(0, 2)
g.addEdge(1, 2)
g.addEdge(2, 0)
g.addEdge(2, 3)
g.addEdge(3, 3)
 
print "Following is Breadth First Traversal (starting from vertex 2)"
g.BFS(2)
# contributed by   drunk-maester


================================================
FILE: Data Structures/C:C++/Graph/bfs_dfs/ques/graph_connected_components.cpp
================================================
#include <iostream>
#include <vector>
using namespace std;

vector <int> adj[12];
bool visited[12];

void dfs(int s) {
    visited[s] = true;
    for(int i = 0;i < adj[s].size();++i)    {
     if(visited[adj[s][i]] == false)
         dfs(adj[s][i]);
    }
}

void initialize() {
    for(int i = 0;i < 10;++i)
         visited[i] = false;
}

int main() {
    int nodes, edges, x, y, connectedComponents = 0;
    cin >> nodes;                       
    cin >> edges;                       
    for(int i = 0;i < edges;++i) {
     cin >> x >> y;     
     adj[x].push_back(y);               
     adj[y].push_back(x);               
    }
    initialize();                        
    for(int i = 1;i <= nodes;++i) {
     if(visited[i] == false)     {
         dfs(i);
         connectedComponents++;
     }
    }
    cout << "Number of connected components: " << connectedComponents << endl;
    return 0;
}


================================================
FILE: Data Structures/C:C++/Graph/bfs_dfs/ques/tbbfs.cpp
================================================
//http://www.spoj.com/problems/TDBFS/
#include<bits/stdc++.h>
#define dout if(debugg) cout<<" "
using namespace std;

int debugg = 1;
class Node{
    public:
    vector<int> adj;
    int visited; 

    Node(){
        clear();
    }
    void clear(){
        visited = 0;
        adj.clear();
    }
};

void dfs_rec(vector<Node> &node,int a){
    cout<<a<<" ";
    for(auto i : node[a].adj){
        if(node[i].visited==0){
            node[i].visited=1;
            dfs_rec(node,i);
        }
    }
}
void dfs(vector<Node> &node,int a){
    for(auto &i : node){
        i.visited=0;
    }

    node[a].visited=1;
    dfs_rec(node,a);

    cout<<endl;
}

void bfs(vector<Node> &node,int a){
    for(auto &i : node)
        i.visited=0;

    queue<int> q;
    q.push(a);
    node[a].visited=1;

    while(!q.empty()){
        int temp = q.front();
        for(auto i : node[temp].adj){
            if(node[i].visited==0){
                node[i].visited=1;
                q.push(i);
            }
        }
        q.pop();
        cout<<temp<<" ";
    }
    cout<<endl;
}

int main(){
    int t,temp;
    cin>>t;
    for(int x=1; x<=t; x++){
        int n;
        cin>>n;
        vector<Node> node(n+1);

        for(int i=1; i<=n; i++){//insert adj nodes
            int m,faltu;
            cin>>faltu>>m;
            while(m--){
                cin>>temp;
                node[i].adj.push_back(temp); 
            }
        }

        cout<<"graph "<<x<<endl;
        while(true){
            int a,type;
            cin>>a>>type;
            if(a==0)break;

            if(type)
                bfs(node,a);
            else
                dfs(node,a);
        }
    }
}


================================================
FILE: Data Structures/C:C++/Graph/dijakstra/Dijkstra.java
================================================
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

/**
 * Input file example:
 *
 * 6
 * INF 7 9 INF INF 14
 * 7 INF 10 15 INF INF
 * 9 10 INF 11 INF 2
 * INF 15 11 INF 6 INF
 * INF INF INF 6 INF 9
 * 14 INF 2 INF 9 INF
 * 5 1
 *
 * First line is number of elements inn graph
 * Next n-lines is graph
 * Last line is begin and end point
 *
 * Output file:
 * Way from 5 to 1:
 * 5 -> 6 -> 3 -> 1
 * Length: 20
 *
 */
public class Dijkstra {

    private static final String INPUT_FILE_PATH = "input.txt";

    private static final String OUTPUT_FILE_PATH = "output.txt";

    private static final int INF = Integer.MAX_VALUE / 2;

    private static int begin;

    private static int end;

    public static void main(String[] args) {
        int[][] matrix = readMatrixFromFile();
        dijkstra(matrix);
    }

    private static int[][] readMatrixFromFile() {
        int[][] matrix = null;

        try (Scanner scanner = new Scanner(new FileInputStream(INPUT_FILE_PATH))) {
            int matrixSize = Integer.parseInt(scanner.nextLine());
            matrix = new int[matrixSize][matrixSize];

            for (int row = 0; row < matrixSize; row++) {
                String[] numbers = scanner.nextLine().split(" ");
                for (int col = 0; col < matrixSize; col++) {
                    if (numbers[col].equals("INF")) {
                        matrix[row][col] = INF;
                    } else {
                        matrix[row][col] = Integer.parseInt(numbers[col]);
                    }
                }
            }

            begin = scanner.nextInt();
            end = scanner.nextInt();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return matrix;
    }

    private static void dijkstra(int[][] matrix) {
        boolean[] used = new boolean[matrix.length];
        int[] dist = new int[matrix.length];
        int[] way = new int[matrix.length];

        begin -= 1;
        end -= 1;

        Arrays.fill(dist, INF);
        Arrays.fill(way, 0);
        dist[begin] = 0;

        while (true) {
            int v = -1;
            for (int nv = 0; nv < matrix.length; nv++) {
                if (!used[nv] && (v == -1 || dist[nv] < dist[v])) {
                    v = nv;
                }
            }

            if (v == -1) {
                break;
            }

            used[v] = true;

            for (int nv = 0; nv < matrix.length; nv++) {
                if (!used[nv] && matrix[v][nv] + dist[v] < dist[nv]) {
                    dist[nv] = matrix[v][nv] + dist[v];
                    way[nv] = v;
                }
            }
        }

        printSolution(way, dist);
    }

    private static void printSolution(int[] trip, int[] dist) {
        Stack<Integer> stack = new Stack<>();
        StringBuilder answer = new StringBuilder();
        answer.append(String.format("Way from %d to %d:\n", begin + 1, end + 1));

        int lastPoint = end;

        while (lastPoint != begin) {
            stack.push(lastPoint);
            lastPoint = trip[lastPoint];
        }

        answer.append(begin + 1);
        while (!stack.isEmpty()) {
            answer.append(" -> ").append(stack.pop() + 1);
        }

        answer.append(String.format("\nLength: %d\n", dist[end]));

        try (BufferedWriter writer = new BufferedWriter(new FileWriter(OUTPUT_FILE_PATH))) {
            writer.write(answer.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}


================================================
FILE: Data Structures/C:C++/Graph/dijakstra/dist_from_source.cpp
================================================
//https://www.codechef.com/problems/BUG2K17B
#include<bits/stdc++.h>
#define mp pair<int,int>
using namespace std;

int debugg=0;
class Node{
    public:
    int dist;
    vector<pair<int,int> > next;//first contains city index .. second contains distance
    
    void clear(){
        dist=INT_MAX;
        next.clear();
    }
} node[100002];

struct priority_fxn{
    bool operator() (int a,int b){
       return node[a].dist > node[b].dist; 
    }
};
void dijakstra(int source){
    int n,d,temp;
    priority_queue<int,vector<int>,priority_fxn> q;
    
    //init queue
    node[source].dist=0;
    q.push(source);
    
    while(!q.empty()){
        temp=q.top();
        for(auto elem : node[temp].next){
            n=elem.first;
            d=elem.second;
            if(node[n].dist > node[temp].dist + d){
                node[n].dist = node[temp].dist + d;
                q.push(n);
            }    
        }
        q.pop();
    }
}

int main(){
    int t,a,b,c,n,p;
    cin>>t;
    while(t--){
        cin>>n>>p;
        for(int i=1;i<=n;i++)
            node[i].clear();
        while(p--){
            cin>>a>>b>>c;
            node[a].next.push_back(mp(b,c));
            node[b].next.push_back(mp(a,c));
        }
        dijakstra(1);
        if(node[n].dist==INT_MAX)cout<<"NONE"<<endl;
        else
            cout<<node[n].dist<<endl;
    }
}


================================================
FILE: Data Structures/C:C++/Graph/dijakstra/dist_from_source_oops.cpp
================================================
//https://www.codechef.com/APRIL17/problems/CLIQUED
//  only dijastra ques not complete
#include<bits/stdc++.h>
#define ulli long long int
#define ui unsigned int

using namespace std;

class Road{
    public:
    int dist;
    int left;
    int right;
    
    Road(int l,int r,int d){
        left=l;
        right=r;
        dist=d;
    }
};

class Node{
    public:
    ulli dist;
    vector<Road> linked;
    
    Node(){
        dist=LLONG_MAX;
    }
};

typedef pair<int,vector<Node>&> node_info;//stores node index and vector reference

struct priority_fxn{
    bool operator() (node_info a,node_info b){
        return a.second[a.first].dist > b.second[b.first].dist;
    }
};

/*
 * set value of dist in each node relative to root
 * ct ==> vector of Nodes 
 * root ==> source node
 */
void dijakstra(vector<Node> &ct,int root){
    priority_queue<node_info,vector<node_info>,priority_fxn> pq;//priority queue
    int ind;//contains index
    ulli temp_dist;
    
    ct[root].dist=0;
    pq.push(node_info(root,ct));
    
    while(!pq.empty()){
        root = pq.top().first;
        pq.pop();
        
        for(auto elem : ct[root].linked){
            ind = elem.left==root ? elem.right : elem.left;//select other than root
            temp_dist = ct[root].dist + (ulli)elem.dist;//calculate temp_dist 
            
            if(temp_dist < ct[ind].dist){
                ct[ind].dist=temp_dist;
                pq.push(node_info(ind,ct));
            }
        }
    }
}

int main()
{
	int t=1,n,r,s,a,b;
	ulli d;
	cin>>t;
	while(t--)
	{    
	    cin>>n>>r>>s;//num of cities  , roads , source
	    vector<Node> city(n+1,Node());
	    for(int i=1;i<=r;i++){
	        cin>>a>>b>>d;
		    city[a].linked.push_back(Road(a,b,d));
		    city[b].linked.push_back(Road(a,b,d));
	    }
	    
	    dijakstra(city,s);
	    
	    for(int i=1;i<=n;i++){
	        cout<<city[i].dist<<" ";
	    }
	    cout<<endl;
	}
	return 0;
}


================================================
FILE: Data Structures/C:C++/Graph/dijakstra/ques/min_path.cpp
================================================
//https://www.codechef.com/SEPT17/problems/QGRID
#include<bits/stdc++.h>
#define ulli long long int
#define dout if(debugg)cout<<" "
using namespace std;
typedef pair<ulli,ulli> mp; 
typedef pair<mp,ulli> mpp;

int debugg=0;

class Node{
    public:
    ulli dist;
    ulli weight;
    ulli parentx,parenty;
    vector<pair<mp,ulli> > next;
    void clear(){
        weight=0;
        dist=LONG_MAX;
        next.clear();
    }
    Node(){
        clear();
    }
    void setparent(ulli px,ulli py){
        parentx=px;
        parenty=py;
    }
} node[5][100009];
 
struct priority_fxn{
    bool operator() (mp a,mp b){
       return node[a.first][a.second].dist > node[b.first][b.second].dist; 
    }
};
void dijakstra(ulli sx,ulli sy,ulli ex,ulli ey,ulli update){
    priority_queue<mp ,vector<mp >,priority_fxn> q;
    queue<mp> dist_sett;//so that i can again set dist as intmax;
    ulli d,n1,n2;
    mp temp;

    node[sx][sy].dist=0;
    node[sx][sy].setparent(sx,sy);
    q.push(mp(sx,sy));
    dist_sett.push(mp(sx,sy));
   
    while(!q.empty()){
        n1=q.top().first;
        n2=q.top().second;
        if(n1==ex && n2==ey)break;//reached the point
        for(ulli i=0;i<node[n1][n2].next.size();i++){
            temp=node[n1][n2].next[i].first;
            d=node[n1][n2].next[i].second;
            if(node[temp.first][temp.second].dist > node[n1][n2].dist + d){
                node[temp.first][temp.second].dist = node[n1][n2].dist + d;
                node[temp.first][temp.second].setparent(n1,n2);
                dist_sett.push(temp);
                q.push(temp);
            }    
        }
        q.pop();
    }//end while loop

    //set dist back to INT_MAX
    while(!dist_sett.empty()){
        mp elem = dist_sett.front();
        node[elem.first][elem.second].dist=LONG_MAX;
        dist_sett.pop();
        
    }

    int n1_;
    while(n1!=sx || n2!=sy){
       node[n1][n2].weight+=update;
       n1_=node[n1][n2].parentx;
       n2=node[n1][n2].parenty;
       n1=n1_;
       dout<<n1<<" "<<n2<<endl;
    }
    node[n1][n2].weight+=update;
}
 
int main(){
    ulli m,n,q,d,type;
    cin>>m>>n>>q;
    for(ulli i=1;i<m;i++){
        for(ulli j=1;j<=n;j++){
            cin>>d;
            node[i][j].next.push_back(mpp(mp(i+1,j),d));
            node[i+1][j].next.push_back(mpp(mp(i,j),d));
        }
    }
    for(ulli i=1;i<=m;i++){
        for(ulli j=1;j<n;j++){
            cin>>d;
            node[i][j].next.push_back(mpp(mp(i,j+1),d));
            node[i][j+1].next.push_back(mpp(mp(i,j),d));
        }
    }

    ulli sx,sy,ex,ey,update;
    while(q--){
        cin>>type;
        if(type==1){
            cin>>sx>>sy>>ex>>ey>>update;
            dijakstra(sx,sy,ex,ey,update);
        }
        else{
            cin>>sx>>sy;
            cout<<node[sx][sy].weight<<endl;
        }
    }
}


================================================
FILE: Data Structures/C:C++/Graph/dijakstra/ques/qgrid_11.cpp
================================================
#include<bits/stdc++.h>
#define ulli long long int
using namespace std;
typedef pair<ulli,ulli> mp; 
typedef pair<mp,ulli> mpp;
 
 
class Node{
    public:
    ulli dist;
    ulli weight;
    ulli parentx,parenty;
    vector<pair<mp,ulli> > next;
    void clear(){
        weight=0;
        dist=LONG_MAX;
        next.clear();
    }
    Node(){
        clear();
    }
    void setparent(ulli px,ulli py){
        parentx=px;
        parenty=py;
    }
} node[5][100009];
 
struct priority_fxn{
    bool operator() (mp a,mp b){
       return node[a.first][a.second].dist > node[b.first][b.second].dist; 
    }
};
 
void update_weight(ulli l,ulli r,ulli update){
    ulli a = min(r,l);
    ulli b = max(r,l);
    for(ulli i=a;i<=b;i++){
        node[1][i].weight+=update;
    } 
}
void dijakstra(ulli sx,ulli sy,ulli ex,ulli ey,ulli update){
    priority_queue<mp ,vector<mp >,priority_fxn> q;
    queue<mp> dist_sett;//so that i can again set dist as intmax;
    ulli d,n1,n2;
    mp temp;
 
    node[sx][sy].dist=0;
    node[sx][sy].setparent(sx,sy);
    q.push(mp(sx,sy));
    dist_sett.push(mp(sx,sy));
   
    while(!q.empty()){
        n1=q.top().first;
        n2=q.top().second;
        if(n1==ex && n2==ey)break;//reached the point
        for(ulli i=0;i<node[n1][n2].next.size();i++){
            temp=node[n1][n2].next[i].first;
            d=node[n1][n2].next[i].second;
            if(node[temp.first][temp.second].dist > node[n1][n2].dist + d){
                node[temp.first][temp.second].dist = node[n1][n2].dist + d;
                node[temp.first][temp.second].setparent(n1,n2);
                dist_sett.push(temp);
                q.push(temp);
            }    
        }
        q.pop();
    }//end while loop
 
    //set dist back to INT_MAX
    while(!dist_sett.empty()){
        mp elem = dist_sett.front();
        node[elem.first][elem.second].dist=LONG_MAX;
        dist_sett.pop();
    }
 
    int n1_;
    while(n1!=sx || n2!=sy){
       node[n1][n2].weight+=update;
       n1_=node[n1][n2].parentx;
       n2=node[n1][n2].parenty;
       n1=n1_;
    }
    node[n1][n2].weight+=update;
}
 
int main(){
    ulli m,n,q,d,type;
    cin>>m>>n>>q;
    //make graph
    for(ulli i=1;i<m;i++){
        for(ulli j=1;j<=n;j++){
            cin>>d;
            node[i][j].next.push_back(mpp(mp(i+1,j),d));
            node[i+1][j].next.push_back(mpp(mp(i,j),d));
        }
    }
    for(ulli i=1;i<=m;i++){
        for(ulli j=1;j<n;j++){
            cin>>d;
            node[i][j].next.push_back(mpp(mp(i,j+1),d));
            node[i][j+1].next.push_back(mpp(mp(i,j),d));
        }
    }
    //querries
    ulli sx,sy,ex,ey,update;
    while(q--){
        cin>>type;
        if(type==1){
            cin>>sx>>sy>>ex>>ey>>update;
            if(m==1)
                update_weight(sy,ey,update);
            else
                dijakstra(sx,sy,ex,ey,update);
        }
        else{
            cin>>sx>>sy;
            cout<<node[sx][sy].weight<<endl;
        }
    }
}
 


================================================
FILE: Data Structures/C:C++/Graph/shortest_paths.hpp
================================================
#include <vector>
#include <queue>
#include <utility> // for pair, make_pair etc
using namespace std;

/*
 * Shortest path in Unweighted graph 
 */
pair< vector<int>, vector<int> > unweighted_shortest_path(vector< vector<int> > graph, int s){
	vector<int> distance(graph.size(), -1);
	vector<int> path(graph.size());
	queue<int> q;
	int v, w;
	q.push(s);
	distance[s] = 0;

	while(!q.empty()) {
		v = q.front();
		q.pop();
	    for(int k = 0; k < graph[v].size(); k++){
	    	w = graph[v][k];
	    	if(distance[w] == -1){
	    		distance[w] = distance[v] + 1;
	    		path[w] = v;
	    		q.push(w);
	    	}
	    }
	}
	return make_pair(distance, path);
}



================================================
FILE: Data Structures/C:C++/Graph/topological_sort.hpp
================================================
#include <iostream>
#include <vector>
#include <stack>
using namespace std;

// util function
void _ts(int v, bool visited[], stack<int> *st, vector< vector<int> > graph){
	visited[v] = true;

	// go to all verices adjacent to this one
	for(int w=0;w<graph[v].size();w++){
		int new_node = graph[v][w];
		if(!visited[new_node]) _ts(new_node, visited, st, graph);
	}

	st->push(v);
}

stack<int> topological_sort(vector< vector<int> > graph){
	int vertices = graph.size();
	stack<int> st;
	
	// mark all vertices as not visited
	bool *visited = new bool[vertices];
	for(int i=0;i<vertices;i++) visited[i] = false;

	// call helper function to store topological sort
	// starting from all vertices one by one
	for(int i=0;i<vertices;i++){
		if(!visited[i]) _ts(i, visited, &st, graph);
	}

	stack<int> st2;
	st2 = st;

	cout << "Printing graph after topological sort: " << endl;
	while(!st.empty()){
		cout << st.top() << " ";
		st.pop();
	}
	cout << endl;

	return st2;
}

================================================
FILE: Data Structures/C:C++/Graph/tree/binarySearchTree/bsTree.cpp
================================================
// This a program to demonstrate insert in a binary tree through recursion it also keeps count of all child of a node and also deletes nodes by recursion. It is basically a spoj question orderset. 

#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define FOR(i,n) for(int i=0;i<n;i++)
#define REP(i, a, b) for(int i=a;i<=b;i++)
#define FORb(i, n) for(int i=n-1; i>=0; i--)
#define lli long long int
#define ulli unsigned long long int
#define dout if(debug)cout<<" "

int debug = 0;

struct tree{
    int data;
    int childcnt;
    tree *left;
    tree *right;
};

tree *root = NULL;

//This is the 
void insert(tree *curr, tree *node){
    int sum = 0;
    if(node->data < curr->data){

        if(curr -> left == NULL){
            curr -> left = node;
            sum++;
            
        }
        
        else{
            insert(curr -> left, node);
            sum += curr -> left -> childcnt + 1;   
        }
                
        if(curr -> right != NULL){
            sum += curr -> right -> childcnt + 1;
        }
        
        curr -> childcnt = sum;
        return;
    }

    else if(node->data > curr->data){

        if(curr -> right == NULL){
            curr -> right = node;
            sum++;
        }
        
        else{
           insert(curr -> right, node);
           sum += curr -> right -> childcnt + 1;
        }
                
        if(curr -> left != NULL){
            sum += curr -> left -> childcnt + 1;
        }
        
        curr -> childcnt = sum;
        return ;
    }
    
}

tree * minValueNode( tree *curr){
    tree *current= curr;

    while(current -> left != NULL)
        current = current -> left;

    return current;
}

tree* deleteNode(tree *root, int key){
    root -> childcnt--;

    if (root == NULL)
        return root;

    if (key  < root -> data){
        root -> left = deleteNode(root -> left, key);
    }

    else if (key > root -> data){
        root -> right = deleteNode( root -> right, key);
    }

    else{ 

        if (root -> left == NULL){
            tree *temp = root -> right;
            free(root);
            return temp;
        }
        
        else if (root -> right == NULL){
            tree *temp = root -> left;
            free(root);
            return temp;
        }
         
        tree *temp = minValueNode(root -> right);

        root -> data =temp -> data;
        root -> right = deleteNode(root -> right, temp -> data);
    }
    return root;
}

int Kpify(tree *curr, int pos, int target){
    int count = pos + 1;

    if( curr -> left != NULL){
        count += curr -> left -> childcnt + 1;

        if (target < count){
            return Kpify(curr -> left, pos, target); 
        }
    }
    
    if ( target == count )
    {
        return curr -> data;
    }

    else if (target > count )
    {
        return Kpify(curr -> right, count, target);
    }
}

int main(){

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    
    int Q;
    cin >> Q;

    set<int> myset;

    while (Q--){
        char type;
        cin >> type;
        int num;
        set<int> :: iterator its;

        if (type == 'I'){
            cin >> num;

            if (myset.find(num) == myset.end())
                myset.insert(num);

            tree *n =new tree;
            n->left = NULL;
            n->right = NULL;
            n->data = num;
            n->childcnt = 0;    

            if ( root == NULL){
                root = n;
            }
            
            else{
                insert(root, n);
            }
        }
        
        if (type == 'D'){
            cin >> num;
            its = myset.find(num);

            if (its != myset.end()){
                myset.erase(num);
                root = deleteNode(root, num);
            }
        }
        
        if (type == 'C'){
            cin >> num;
            its = myset.lower_bound(num);
            cout << distance(myset.begin(), its) << endl;
        }

        if (type == 'K'){
            cin >> num;

            if (num <= myset.size() ){
                cout << Kpify(root, 0, num) << endl; 
            }

            else
                cout << "invalid" << endl;
        }
    }
	return 0;
}


================================================
FILE: Data Structures/C:C++/Linked List/Circular_LL.c
================================================
/*
	***********************
	Author   : Vivek Shah
	Question : Circular LL
	***********************
*/

#include<stdio.h>
#include<stdlib.h>
#include <string.h>

struct node
{
	char name[100];
	int roll;
	float cgpa;
	struct node* next;
};

struct node* head;
void display();

struct node* getNode(){
	char name[100];
	int roll;
	float cgpa;
	printf("Enter name to be inserted\n");
	printf("Enter Roll to be inserted\n");
	printf("Enter CGPA to be inserted\n");
	scanf("%s",name);
	scanf("%d",&roll);
	scanf("%f",&cgpa);
	struct node* temp = (struct node*)malloc(sizeof(struct node)) ;
	strcpy(temp->name,name);
	temp->roll=roll;
	temp->cgpa=cgpa;
	temp->next=NULL;
	return temp;
}

int countNode(){
	struct node* temp = head;
	int c = 0;

	if (head==NULL)
	{
		return 0;
	}

	do{
		c++;
		temp = temp->next;
	}while(temp!=head);

	return c;
}


void insert_beg(){
	struct node* temp = getNode();
	temp->next = head;

	if (head==NULL)
		temp->next = temp;

	else{
		struct node* tm = head;
		do{
			tm = tm->next;
		}while(tm->next!=head);			//traverse through entire list
		tm->next = temp;
	}
	head = temp;
	display();
}

void insert_btw(){
	printf("Enter the Node no. after wise Node is to be inserted\n");
	int ch;
	scanf("%d",&ch);
	int count = 0;
	if (ch<=0 || ch>countNode())
	{
		printf("INVALID NODE No.\n");
		return;
	}
    else{
	struct node* temp = getNode();
	struct node* tempor = head;

	do{
		count++;
		tempor = tempor->next;
	}while(tempor->next!=head && ch!=count);

	temp->next = tempor->next;
	tempor->next = temp;
    display();
    }
}

void insert_end(){
	struct node* temp = getNode();

	if (head == NULL)
	{
		temp->next = temp;
		head = temp;
	}

	else{
		struct node* t = head;
		do{
			t = t->next;
		}while(t->next!=head);
		t->next = temp;
	}
	temp->next = head;
	display();
}


void delete_beg(){
	if (head==NULL)
	{
		printf("Nothing to Delete\n");
	}
	else{
		struct node* temp = head;
		do{
			temp = temp->next;

		}while(temp->next!=head);
		head = head->next;
		temp->next = head;
	}
}


void delete_btw(){
	printf("Enter the Node no. to be deleted\n");
	int ch;
	scanf("%d",&ch);
	int count = 0;
	if (ch<=0 || ch>countNode())
	{
		printf("INVALID NODE No.\n");
		return;
	}
    else{
    	int c=0;
		struct node* tempor = head;
		do{
			c++;
			tempor = tempor->next;
		}while(tempor->next!=head && c==ch-1);
		if (tempor->next==head && ch==countNode())
		{
			tempor->next=head;
		}
		else{
			tempor->next = tempor->next->next;
		}
	}
}

void delete_end(){
	if (head==NULL)printf("Nothing to Delete\n");
	else if(head->next==NULL)head=NULL;
	else{
		struct node* temp = head;
		do{
			temp = temp->next;
		}while(temp->next->next!=head);
		temp->next = head;
	}
}


void search(){
	int sc;
	printf("Enter a roll no to be Searched\n");
	scanf("%d",&sc);
	if (head==NULL)
	{
		printf("No data to search\n");
		return;
	}
	else{
		struct node* temp = head;
		int f=0;
		do{
			if(temp->roll==sc){f=1;break;}
			temp = temp->next;
		}while(temp!=head);
		if(f==0)printf("No data found\n");
		else{
			printf("FOUND THE DATA\n");
			printf("\n%s\n%d\n%f\n",temp->name,temp->roll,temp->cgpa);
		}
	}
}

void display(){
	if(head==NULL){printf("Nothing to display\n");return;}
	struct node* temp = head;
	do{
		printf("\n************************************************\n");
		printf("Name    : %s\n",temp->name);
		printf("Roll No : %d\n",temp->roll);
		printf("CGPA 	: %f\n",temp->cgpa);
		temp = temp->next;
	}while(temp!=head);
	printf("\n************************************************\n\n");
}

int main()
{
	head = NULL;
	int i,ch;
	while(1){
        printf("1.Insert\n2.Delete\n3.Search\n4.Display\n");
        scanf("%d",&i);
        if (i==1)
        {
            printf("1.Insert Begin\n2.Insert Between\n3.Insert End\n");
            scanf("%d",&ch);
            if (ch==1)
                insert_beg();
            else if (ch==2)
            	insert_btw();
            else if(ch==3)
                insert_end();
            else printf("Invalid Choice\n");

        }
        else if (i==2)
        {
            printf("1.Delete Begin\n2.Delete Between\n3.Delete End\n");
            scanf("%d",&ch);
            if (ch==1)
                delete_beg();
            else if (ch==2)
            	delete_btw();
            else if(ch==3)
                delete_end();
            else printf("Invalid Choice\n");
        }
        else if(i==3){
        	search();
        }

        else if(i==4){
            display();
        }
        else printf("Invalid Choice\n");
	}
	return 0;
}


================================================
FILE: Data Structures/C:C++/Linked List/Circular_ll.cpp
================================================
/*
 * C++ Program to Implement Circular Linked List 
 */
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
/*
 * Node Declaration
 */
struct node
{
    int info;
    struct node *next;
}*last;
 
/*
 * Class Declaration
 */
class circular_llist
{
    public:
        void create_node(int value);
        void add_begin(int value);
        void add_after(int value, int position);
        void delete_element(int value);
        void search_element(int value);
        void display_list();
        void update();
        void sort();
        circular_llist()
        {
            last = NULL;           
        }
};
 
/*
 * Main :contains menu 
 */
int main()
{
    int choice, element, position;
    circular_llist cl;
    while (1)
    {
        cout<<endl<<"---------------------------"<<endl;
        cout<<endl<<"Circular singly linked list"<<endl;
        cout<<endl<<"---------------------------"<<endl;     
        cout<<"1.Create Node"<<endl;
        cout<<"2.Add at beginning"<<endl;
        cout<<"3.Add after"<<endl;
        cout<<"4.Delete"<<endl;
        cout<<"5.Search"<<endl;
        cout<<"6.Display"<<endl;
        cout<<"7.Update"<<endl;
        cout<<"8.Sort"<<endl;
        cout<<"9.Quit"<<endl;
        cout<<"Enter your choice : ";
        cin>>choice;
        switch(choice)
        {
        case 1:
            cout<<"Enter the element: ";
            cin>>element;
            cl.create_node(element);
            cout<<endl;
            break;
        case 2:
            cout<<"Enter the element: ";
            cin>>element;
            cl.add_begin(element);
            cout<<endl;
            break;
        case 3:
            cout<<"Enter the element: ";
            cin>>element;
            cout<<"Insert element after position: ";
            cin>>position;
            cl.add_after(element, position);
            cout<<endl;
            break;
        case 4:
            if (last == NULL)
            {
                cout<<"List is empty, nothing to delete"<<endl;
                break;
            }
            cout<<"Enter the element for deletion: ";
            cin>>element;
            cl.delete_element(element);
            cout<<endl;
            break;
        case 5:
            if (last == NULL)
            {
                cout<<"List Empty!! Can't search"<<endl;
                break;
            }
            cout<<"Enter the element to be searched: ";
            cin>>element;
            cl.search_element(element);
            cout<<endl;
            break;
        case 6:
            cl.display_list();
            break;
        case 7:
            cl.update();
            break;
        case 8:
            cl.sort();
            break;                      
        case 9:
            exit(1);
            break;
        default:
            cout<<"Wrong choice"<<endl;
        }
    }
    return 0;
}
 
/*
 * Create Circular Link List
 */
void circular_llist::create_node(int value)
{
    struct node *temp;
    temp = new(struct node);
    temp->info = value;
    if (last == NULL)
    {
        last = temp;
        temp->next = last;   
    }
    else
    {
        temp->next = last->next; 
        last->next = temp;
        last = temp;
    }
}
 
/*
 * Insertion of element at beginning 
 */
void circular_llist::add_begin(int value)
{
    if (last == NULL)
    {
        cout<<"First Create the list."<<endl;
        return;
    }
    struct node *temp;
    temp = new(struct node);
    temp->info = value;
    temp->next = last->next;
    last->next = temp;
}
 
/*
 * Insertion of element at a particular place 
 */
void circular_llist::add_after(int value, int pos)
{
    if (last == NULL)
    {
        cout<<"First Create the list."<<endl;
        return;
    }
    struct node *temp, *s;
    s = last->next;
    for (int i = 0;i < pos-1;i++)
    {
        s = s->next;
        if (s == last->next)
        {
            cout<<"There are less than ";
            cout<<pos<<" in the list"<<endl;
            return;
        }
    }
    temp = new(struct node);
    temp->next = s->next;
    temp->info = value;
    s->next = temp;
    /*Element inserted at the end*/
    if (s == last)
    { 
        last=temp;
    }
}
 
/*
 * Deletion of element from the list
 */
void circular_llist::delete_element(int value)
{
    struct node *temp, *s;
    s = last->next;
      /* If List has only one element*/
    if (last->next == last && last->info == value)  
    {
        temp = last;
        last = NULL;
        free(temp);
        return;
    }
    if (s->info == value)  /*First Element Deletion*/
    {
        temp = s;
        last->next = s->next;
        free(temp);
        return;
    }
    while (s->next != last)
    {
        /*Deletion of Element in between*/
        if (s->next->info == value)    
        {
            temp = s->next;
            s->next = temp->next;
            free(temp);
            cout<<"Element "<<value;
            cout<<" deleted from the list"<<endl;
            return;
        }
        s = s->next;
    }
    /*Deletion of last element*/
    if (s->next->info == value)    
    {
        temp = s->next;
        s->next = last->next;
        free(temp);		
        last = s;
        return;
    }
    cout<<"Element "<<value<<" not found in the list"<<endl;
}
 
/*
 * Search element in the list 
 */
void circular_llist::search_element(int value)
{
    struct node *s;
    int counter = 0;
    s = last->next;
    while (s != last)
    {
        counter++;
        if (s->info == value)    
        {
            cout<<"Element "<<value; 
            cout<<" found at position "<<counter<<endl;
            return;
        }
        s = s->next;
    }
    if (s->info == value)    
    {
        counter++;             
        cout<<"Element "<<value;
        cout<<" found at position "<<counter<<endl;
        return;
    }
    cout<<"Element "<<value<<" not found in the list"<<endl;
}
 
/*
 * Display Circular Link List 
 */
void circular_llist::display_list()
{
    struct node *s;
    if (last == NULL)
    {
        cout<<"List is empty, nothing to display"<<endl;
        return;
    }
    s = last->next;
    cout<<"Circular Link List: "<<endl;
    while (s != last)
    {
        cout<<s->info<<"->";
        s = s->next;
    }
    cout<<s->info<<endl;
}
 
/*
 * Update Circular Link List 
 */
void circular_llist::update()
{
    int value, pos, i;
    if (last == NULL)
    {
        cout<<"List is empty, nothing to update"<<endl;
        return;
    }
    cout<<"Enter the node position to be updated: ";
    cin>>pos;
    cout<<"Enter the new value: ";
    cin>>value;
    struct node *s;
    s = last->next;
    for (i = 0;i < pos - 1;i++)
    {
        if (s == last)
        {
            cout<<"There are less than "<<pos<<" elements.";
            cout<<endl;
            return;
        }
        s = s->next;
    }
    s->info = value;  
    cout<<"Node Updated"<<endl;
} 
 
/*
 * Sort Circular Link List 
 */
void circular_llist::sort()
{
    struct node *s, *ptr;
    int temp;
    if (last == NULL) 
    {
        cout<<"List is empty, nothing to sort"<<endl;
        return;
    }
    s = last->next;
    while (s != last)
    {
        ptr = s->next;
        while (ptr != last->next)
        {
            if (ptr != last->next)
            {
                if (s->info > ptr->info)
                {
                    temp = s->info;
                    s->info = ptr->info;
                    ptr->info = temp;
                }
            }
            else
            {
                break;
            }
            ptr = ptr->next;    
        }
        s = s->next;         
    }
}


================================================
FILE: Data Structures/C:C++/Linked List/Doubly LL.c
================================================
/*
	***********************
	Author   : Vivek Shah
	Question : Doubly LL
	***********************
*/

#include<stdio.h>
#include<stdlib.h>
#include <string.h>

struct node
{
	char name[100];
	int roll;
	float cgpa;
	struct node* next;
	struct node* pre;
};

struct node* head;
void display();

struct node* getNode(){
	char name[100];
	int roll;
	float cgpa;
	printf("Enter name to be inserted\n");
	printf("Enter Roll to be inserted\n");
	printf("Enter CGPA to be inserted\n");
	scanf("%s",name);
	scanf("%d",&roll);
	scanf("%f",&cgpa);
	struct node* temp = (struct node*)malloc(sizeof(struct node)) ;
	strcpy(temp->name,name);
	temp->roll=roll;
	temp->cgpa=cgpa;
	temp->next = NULL;
	temp->pre = NULL;
	return temp;
}

int countNode(){
	struct node* temp = head;
	int c = 0;

	if (head==NULL)
	{
		return 0;
	}

	while(temp!=NULL){
		c++;
		temp = temp->next;
	}

	return c;
}


void insert_beg(){
	struct node* temp = getNode();
	temp->next = head;
	if(head!=NULL){
		head->pre = temp;
	}
	head = temp;
	display();
}

void insert_btw(){
	printf("Enter the Node no. after wise Node is to be inserted\n");
	int ch;
	scanf("%d",&ch);
	int count = 0;
	if (ch<=0 || ch>countNode())
	{
		printf("INVALID NODE No.\n");
		return;
	}
    else{
		struct node* temp = getNode();
		struct node* t = head;

		while(t!=NULL && t!=ch){
			t=t->next;
		}	
		temp->pre = t;
		temp->next = t->next;
		t->pre->next = temp;
		if(t->next!=NULL)t->next->pre = temp;
	    display();
    }
}

void insert_end(){
	struct node* temp = getNode();

	if (head == NULL)
		head = temp;

	else{
		struct node* t = head;
		while(t->next!=NULL)
			t = t->next;
		t->next = temp;
		temp->pre = NULL;
	}
	display();
}


void delete_beg(){
	if (head==NULL)
	{
		printf("Nothing to Delete\n");
	}
	else{
		head=head->next;
		head->pre=NULL;
	}
}


void delete_btw(){
	printf("Enter the Node no. to be deleted\n");
	int ch;
	scanf("%d",&ch);
	int count = 0;
	if (ch<=0 || ch>countNode())
	{
		printf("INVALID NODE No.\n");
		return;
	}
    else{
    	if(ch==1){
    		head=NULL;
    		return;
		}
    	int c=0;
		struct node* t = head;
		int f=0;
		while(t!=NULL){
			c++;
			if (c==ch)
			{
				f=1;
				break;
			}
			t = t->next;
		}
		if (f==0)
		{
			printf("NOT FOUND\n");
		}
		else if (t->next!=NULL)
		{
			t->pre->next = t->next;
			t->next->pre = t->pre;
		}
		else{
			t->pre->next = NULL;
		}
	}
}

void delete_end(){
	if (head==NULL)printf("Nothing to Delete\n");
	else if(head->next==NULL)head=NULL;
	else{
		struct node* t = head;
		while(t->next->next!=NULL)
			t = t->next;
		t->next=NULL;
	}
}


void search(){
	int sc;
	printf("Enter a roll no to be Searched\n");
	scanf("%d",&sc);
	if (head==NULL)
	{
		printf("No data to search\n");
		return;
	}
	else{
		struct node* temp = head;
		int f=0;
		while(temp!=NULL){
			if(temp->roll==sc){f=1;break;}
			temp = temp->next;
		}
		if(f==0)printf("No data found\n");
		else{
			printf("FOUND THE DATA\n");
			printf("\n%s\n%d\n%f\n",temp->name,temp->roll,temp->cgpa);
		}
	}
}

void display(){
	if(head==NULL){printf("Nothing to display\n");return;}
	struct node* temp = head;
	while(temp!=NULL){
		printf("\n************************************************\n");
		printf("Name    : %s\n",temp->name);
		printf("Roll No : %d\n",temp->roll);
		printf("CGPA 	: %f\n",temp->cgpa);
		temp = temp->next;
	}
	printf("\n************************************************\n\n");
}

int main()
{
	head = NULL;
	int i,ch;
	while(1){
        printf("1.Insert\n2.Delete\n3.Search\n4.Display\n");
        scanf("%d",&i);
        if (i==1)
        {
            printf("1.Insert Begin\n2.Insert Between\n3.Insert End\n");
            scanf("%d",&ch);
            if (ch==1)
                insert_beg();
            else if (ch==2)
            	insert_btw();
            else if(ch==3)
                insert_end();
            else printf("Invalid Choice\n");

        }
        else if (i==2)
        {
            printf("1.Delete Begin\n2.Delete Between\n3.Delete End\n");
            scanf("%d",&ch);
            if (ch==1)
                delete_beg();
            else if (ch==2)
            	delete_btw();
            else if(ch==3)
                delete_end();
            else printf("Invalid Choice\n");
        }
        else if(i==3){
        	search();
        }

        else if(i==4){
            display();
        }
        else printf("Invalid Choice\n");
	}
	return 0;
}


================================================
FILE: Data Structures/C:C++/Linked List/Insertion_Deletion_SinglyLL.c
================================================
#include<stdio.h>

struct node{
	int item;
	struct node* next;
};

struct node* head;

void Insert(){
	struct node* temp;
	temp = (struct node*)malloc(sizeof(struct node));
	int x;
	printf("\nEnter element to be inserted : ");
	scanf("%d",&x);
	printf("\n");
	temp->item = x;
	temp->next = NULL;
	temp->next = head;
	head = temp;
}

void delete(){
	int x;
	if(head==NULL){
		printf("Nothing to be deleted\n");
		return;
	}
	printf("Enter the position to be deleted : ");
	scanf("%d",&x);printf("\n");
	if(head->next==NULL){//only a single element is present
		head=NULL;
		return;
	}	
	struct node* temp;
	temp = head;
	int i;
	for(i=0;i<x-2;i++){
		temp = temp->next;
	}//came to n-1th node
	temp = temp->next->next;
	temp->next = NULL;
}

void Print(){
	struct node* temp = head;
	while(temp!=NULL){
		printf("%d  ",temp->item);
		temp = temp->next;
	}
	printf("\n");
}

int main(){
	head = NULL;
	printf("Enter number of Items : ");
	int n;
	scanf("%d",&n);
	printf("\n");
	int i;
	for(i=0;i<n;i++){
		int ch;
		printf("What would you like to perform:");
		scanf("%d",&ch);
		if(ch==1){
				Insert();
		}
		else if(ch==3){
			Print();
		}
		else if(ch==2){
			delete();
		}	
	}
}


================================================
FILE: Data Structures/C:C++/Linked List/Queue using LinkedList.cpp
================================================
/******************************************
*    AUTHOR         :   VIVEK SHAH        *
*    INSTITUTION    :   NIT SURAT         *
******************************************/

/*Queue - Linked List implementation*/
#include<stdio.h>
#include<stdlib.h>

struct Node {
	int data;
	struct Node* next;
};
// Two glboal variables to store address of front and rear nodes. 
struct Node* front = NULL;
struct Node* rear = NULL;

// To Enqueue an integer
void Enqueue(int x) {
	struct Node* temp = 
		(struct Node*)malloc(sizeof(struct Node));
	temp->data =x; 
	temp->next = NULL;
	if(front == NULL && rear == NULL){
		front = rear = temp;
		return;
	}
	rear->next = temp;
	rear = temp;
}

// To Dequeue an integer.
void Dequeue() {
	struct Node* temp = front;
	if(front == NULL) {
		printf("Queue is Empty\n");
		return;
	}
	if(front == rear) {
		front = rear = NULL;
	}
	else {
		front = front->next;
	}
	free(temp);
}

int Front() {
	if(front == NULL) {
		printf("Queue is empty\n");
		return;
	}
	return front->data;
}

void Print() {
	struct Node* temp = front;
	while(temp != NULL) {
		printf("%d ",temp->data);
		temp = temp->next;
	}
	printf("\n");
}

int main(){
	/* Drive code to test the implementation. */
	// Printing elements in Queue after each Enqueue or Dequeue 
	Enqueue(2); Print(); 
	Enqueue(4); Print();
	Enqueue(6); Print();
	Dequeue();  Print();
	Enqueue(8); Print();
}


================================================
FILE: Data Structures/C:C++/Linked List/Queue_using_linkedlist.c
================================================
#include<stdio.h>

//insert at beginning and remove at the end

struct node{
	int item;
	struct node* next;
};

struct node* head;

void push(){//insert at the beginning
	struct node* ptr = (struct node*)malloc(sizeof(struct node));
	printf("Enter element to be inserted : ");
	scanf("%d",&ptr->item);
	ptr->next = NULL;
	if(head == NULL){
		head = ptr;
		return;
	}
	ptr->next = head;
	head = ptr; 	
}

void pop(){
	struct node* temp = head;
	if(head == NULL){
		printf("Nothing to Pop\n");
		return;
	}
	else if(head->next == NULL){
		head = NULL;
		return;
	}
	while(temp->next->next!=NULL){
		temp = temp->next;
	}	
	
	temp->next = NULL;
}

void display(){
	struct node* temp = head;
	if(temp==NULL){
		printf("Nothing to display\n");
	}
	while(temp!=NULL){
		printf("%d ",temp->item);
		temp = temp->next;
	}
	printf("\n");
}

int main(){
	head = NULL;
	while(1){
		printf("\n1.Push\n2.Pop\n3.Display\nAny other number to Exit\n\n");
		printf("Enter your choice : ");
		int ch;
		scanf("%d",&ch);
		printf("\n");
		if(ch==1){
			push();
		}
		else if(ch==2){
			pop();
		}
		else if(ch==3){
			display();
		}
		else{
			break;
		}
	}
}


================================================
FILE: Data Structures/C:C++/Linked List/Reverse_SinglyLL.c
================================================
#include<stdio.h>

struct node{
	int item;
	struct node* next;
};

struct node* head;

struct node* reverse(){
	struct node* pre;
	struct node* current;
	struct node* post;
	current = head;
	pre = NULL;
	while(current!=NULL){
		post = current->next;
		current->next = pre;
		pre = current;
		current = post; 		
	}
	head = pre;
	return head;
}

void insert(int item,int n){
	struct node* temp;
	temp = (struct node*)malloc(sizeof(struct node));
	temp->item = item;
	temp->next = NULL;
	if(n==1){
		temp->next = head;
		head = temp;
		return;
	}
	struct node* temp1;
	temp1 = head;
	int i;
	for( i = 0;i<n-2;i++){
		temp1 = temp1->next;
	}
	temp->next = temp1->next;
	temp1->next = temp;
}

void print(){
	struct node* temp = head;
	while(temp!=NULL){
		printf("%d ",temp->item);
		temp = temp->next;
	}
	printf("\n");
}

int main(){
	head = NULL;
	insert(8,1);
	insert(51,2);
	insert(21,3);
	print();
	reverse();
	print();
}


================================================
FILE: Data Structures/C:C++/Linked List/all_operations_of_Doubly_ll.cpp
================================================
/*
 * C++ Program to Implement Doubly Linked List 
 */
#include<iostream>
#include<cstdio>
#include<cstdlib>
/*
 * Node Declaration
 */
using namespace std;
struct node
{
    int info;
    struct node *next;
    struct node *prev;
}*start;
 
/*
 Class Declaration 
 */
class double_llist
{
    public:
        void create_list(int value);
        void add_begin(int value);
        void add_after(int value, int position);
        void delete_element(int value);
        void search_element(int value);
        void display_dlist();
        void count();
        void reverse();
        double_llist()
        {
            start = NULL;  
        }
};
 
/*
 * Main: Conatins Menu
 */
int main()
{
    int choice, element, position;
    double_llist dl;
    while (1)
    {
        cout<<endl<<"----------------------------"<<endl;
        cout<<endl<<"Operations on Doubly linked list"<<endl;
        cout<<endl<<"----------------------------"<<endl;         
        cout<<"1.Create Node"<<endl;
        cout<<"2.Add at begining"<<endl;
        cout<<"3.Add after position"<<endl;
        cout<<"4.Delete"<<endl;
        cout<<"5.Display"<<endl;
        cout<<"6.Count"<<endl;
        cout<<"7.Reverse"<<endl;
        cout<<"8.Quit"<<endl;
        cout<<"Enter your choice : ";
        cin>>choice;
        switch ( choice )
        {
        case 1:
            cout<<"Enter the element: ";
            cin>>element;
            dl.create_list(element);
            cout<<endl;
            break;
        case 2:
            cout<<"Enter the element: ";
            cin>>element;
            dl.add_begin(element);
            cout<<endl;
            break;
        case 3:
            cout<<"Enter the element: ";
            cin>>element;
            cout<<"Insert Element after postion: ";
            cin>>position;
            dl.add_after(element, position);
            cout<<endl;
            break;
        case 4:
            if (start == NULL)
            {                      
                cout<<"List empty,nothing to delete"<<endl;   
                break;
            }
            cout<<"Enter the element for deletion: ";
            cin>>element;
            dl.delete_element(element);
            cout<<endl;
            break;
        case 5:
            dl.display_dlist();
            cout<<endl;
            break;
        case 6:
            dl.count();
            break;    
        case 7:
            if (start == NULL)
            {
                cout<<"List empty,nothing to reverse"<<endl;
                break;
            }
            dl.reverse();
            cout<<endl;
            break;
        case 8:
            exit(1);
        default:
            cout<<"Wrong choice"<<endl;
        }
    }
    return 0;
}
 
/*
 * Create Double Link List
 */
void double_llist::create_list(int value)
{
    struct node *s, *temp;
    temp = new(struct node); 
    temp->info = value;
    temp->next = NULL;
    if (start == NULL)
    {
        temp->prev = NULL;
        start = temp;
    }
    else
    {
        s = start;
        while (s->next != NULL)
            s = s->next;
        s->next = temp;
        temp->prev = s;
    }
}
 
/*
 * Insertion at the beginning
 */
void double_llist::add_begin(int value)
{
    if (start == NULL)
    {
        cout<<"First Create the list."<<endl;
        return;
    }
    struct node *temp;
    temp = new(struct node);
    temp->prev = NULL;
    temp->info = value;
    temp->next = start;
    start->prev = temp;
    start = temp;
    cout<<"Element Inserted"<<endl;
}
 
/*
 * Insertion of element at a particular position
 */
void double_llist::add_after(int value, int pos)
{
    if (start == NULL)
    {
        cout<<"First Create the list."<<endl;
        return;
    }
    struct node *tmp, *q;
    int i;
    q = start;
    for (i = 0;i < pos - 1;i++)
    {
        q = q->next;
        if (q == NULL)
        {
            cout<<"There are less than ";
            cout<<pos<<" elements."<<endl;
            return;
        }
    }
    tmp = new(struct node);
    tmp->info = value;
    if (q->next == NULL)
    {
        q->next = tmp;
        tmp->next = NULL;
        tmp->prev = q;      
    }
    else
    {
        tmp->next = q->next;
        tmp->next->prev = tmp;
        q->next = tmp;
        tmp->prev = q;
    }
    cout<<"Element Inserted"<<endl;
}
 
/*
 * Deletion of element from the list
 */
void double_llist::delete_element(int value)
{
    struct node *tmp, *q;
     /*first element deletion*/
    if (start->info == value)
    {
        tmp = start;
        start = start->next;  
        start->prev = NULL;
        cout<<"Element Deleted"<<endl;
        free(tmp);
        return;
    }
    q = start;
    while (q->next->next != NULL)
    {   
        /*Element deleted in between*/
        if (q->next->info == value)  
        {
            tmp = q->next;
            q->next = tmp->next;
            tmp->next->prev = q;
            cout<<"Element Deleted"<<endl;
            free(tmp);
            return;
        }
        q = q->next;
    }
     /*last element deleted*/
    if (q->next->info == value)    
    { 	
        tmp = q->next;
        free(tmp);
        q->next = NULL;
        cout<<"Element Deleted"<<endl;
        return;
    }
    cout<<"Element "<<value<<" not found"<<endl;
}
 
/*
 * Display elements of Doubly Link List
 */
void double_llist::display_dlist()
{
    struct node *q;
    if (start == NULL)
    {
        cout<<"List empty,nothing to display"<<endl;
        return;
    }
    q = start;
    cout<<"The Doubly Link List is :"<<endl;
    while (q != NULL)
    {
        cout<<q->info<<" <-> ";
        q = q->next;
    }
    cout<<"NULL"<<endl;
}
 
/*
 * Number of elements in Doubly Link List
 */
void double_llist::count()
{ 	
    struct node *q = start;
    int cnt = 0;
    while (q != NULL)
    {
        q = q->next;
        cnt++;
    }
    cout<<"Number of elements are: "<<cnt<<endl;
}
 
/*
 * Reverse Doubly Link List
 */
void double_llist::reverse()
{
    struct node *p1, *p2;
    p1 = start;
    p2 = p1->next;
    p1->next = NULL;
    p1->prev = p2;
    while (p2 != NULL)
    {
        p2->prev = p2->next;
        p2->next = p1;
        p1 = p2;
        p2 = p2->prev; 
    }
    start = p1;
    cout<<"List Reversed"<<endl; 
}


================================================
FILE: Data Structures/C:C++/Linked List/concatinate.c
================================================
#include<stdio.h>
#include<conio.h>
#include<malloc.h>
struct node
{
    int data;
    struct node *next;
};
struct node*p=NULL;
struct node*q=NULL;
int j=0,k=0;

struct node* create(struct node*current)
{
  struct node *new_node;
  new_node=(struct node *)malloc(sizeof(struct node));

  printf("\nEnter the data : ");
  scanf("%d",&new_node->data);
  new_node->next=NULL;
  j=j+1;

  if(p==NULL)
  {
    p=new_node;
    current=new_node;
  }
  else
  {
  current->next=new_node;
  current=new_node;
  }
  return current;

}

struct node* create2(struct node*current)
{
  struct node *new_node;
  new_node=(struct node *)malloc(sizeof(struct node));

  printf("\nEnter the data : ");
  scanf("%d",&new_node->data);
  new_node->next=NULL;
  k=k+1;

  if(q==NULL)
  {
    q=new_node;
    current=new_node;
  }
  else
  {
    current->next=new_node;
    current=new_node;
  }
  return current;

}


void display(struct node*start)
{
    struct node *new_node;
    printf("\nThe Linked List : \n");
    new_node=start;
    while(new_node!=NULL)
    {
        printf("%d--->",new_node->data);
        new_node=new_node->next;
    }
    printf("NULL");
}
struct node* sort(struct node*s)
{
    int i;
    struct node *temp;
    for(i=0;i<j+k;i++)
    {
        s=p;
        while(s->next!=NULL)
        {
            if(s->data>s->next->data)
            {
                temp->data=s->data;
                s->data=s->next->data;
                s->next->data=temp->data;
            }
            s=s->next;
        }

   }

}
void con(struct node*p,struct node*q)
{
    while(p->next!=NULL)
    p=p->next;
    p->next=q;
}


main()
{
    int n;
    struct node* current1,*current2;
    current1=NULL;
    current2=NULL;
    while(1)
    {
        printf("1.insert list 1\n2.insert list 2\n3.display list 1\n4.display list 2\n5.sort\n6.display final list\n7.concatinate\n8.exit \nenter choice\n");
        scanf("%d",&n);

    switch(n){
    case 1: current1=create(current1);
            //p=current;
            break;
    case 2: current2=create2(current2);
            //q=current;
            break;
    case 3: display(p);
            break;
    case 4:display(q);
            break;
    case 5:sort(p);
            break;
    case 6: display(p);
            break;
    case 7:con(p,q);
            break;
    case 8: return;
    }
    }
}


================================================
FILE: Data Structures/C:C++/Linked List/doubly circular.c
================================================
/*
	***********************
	Author   : Vivek Shah
	Question : Doubly Circular LL
	***********************
*/

#include<stdio.h>
#include<stdlib.h>
#include <string.h>

struct node
{
	char name[100];
	int roll;
	float cgpa;
	struct node* next;
	struct node* pre;
};

struct node* head;
struct node* last;
void display();

struct node* getNode(){
	char name[100];
	int roll;
	float cgpa;
	printf("Enter name to be inserted\n");
	printf("Enter Roll to be inserted\n");
	printf("Enter CGPA to be inserted\n");
	scanf("%s",name);
	scanf("%d",&roll);
	scanf("%f",&cgpa);
	struct node* temp = (struct node*)malloc(sizeof(struct node)) ;
	strcpy(temp->name,name);
	temp->roll=roll;
	temp->cgpa=cgpa;
	temp->next = NULL;
	temp->pre = NULL;
	return temp;
}

int countNode(){
	struct node* temp = head;
	int c = 0;

	if (head==NULL)
	{
		return 0;
	}

	do{
		c++;
		temp = temp->next;
	}while(temp!=head);

	return c;
}


void insert_beg(){
	struct node* temp = getNode();
	if (head==NULL)
	{
		temp->next=temp;
		temp->pre=temp;
	}
	else{
		temp->next=head;
		head->pre = temp;
		temp->pre = last;
		last->next=temp;
	}
	head = temp;
	last = head->pre;
	/*struct node* temp = getNode();
	temp->next = head;
    struct node* last = head->pre; 
    struct node* new_node = getNode();
    new_node->next = head;
    new_node->pre = last;
    last->next = head->pre = new_node;
    head = new_node;*/
    
	display();
}

void insert_btw(){//problem hai...
	printf("Enter the Node no. after wise Node is to be inserted\n");
	int ch;
	scanf("%d",&ch);
	printf("The total count of nodes is %d",countNode());
	int count = 0;
	if (ch<=0 || ch>countNode())
	{
		printf("INVALID NODE No.\n");
		return;
	}
	
	struct node* temp = getNode();
	struct node* t = head;

	do{
		count++;
		t=t->next;
	}while(t!=head || count!=ch-1);
/*
	printf("The value of count is %d",count);
	printf("\n************************************************\n");
	printf("Name    : %s\n",t->name);
	printf("Roll No : %d\n",t->roll);
	printf("CGPA 	: %f\n",t->cgpa);
*/
	temp->pre = t;
	temp->next = t->next;
	if(t==last){
		temp->next=head;
		last=temp;
	}
	else t->next->pre = temp;
	t->next = temp;
    display();
}

void insert_end(){
	struct node* temp = getNode();

	if (head == NULL){
		temp->next=temp;
		temp->pre=temp;
		head = temp;
		last = head->pre;
	}

	else{
		temp->next=last->next;
		temp->pre = last;
		last->next = temp;
		last = temp;
		last->next = head;
	}
	display();
}


void delete_beg(){
	if (head==NULL)
	{
		printf("Nothing to Delete\n");
	}
	else if (head==last)
	{
		head=NULL;
		last=NULL;
	}
	else{
		head=head->next;
		head->pre=NULL;
		last->next=head;
	}
	display();
}


void delete_btw(){
	printf("Enter the Node no. to be deleted\n");
	int ch;
	scanf("%d",&ch);
	int count = 0;
	if (ch<=0 || ch>countNode())
	{
		printf("INVALID NODE No.\n");
		return;
	}
    else{
    	if(ch==1){
    		head=NULL;
    		last=NULL;
    		return;
		}
    	int c=0;
		struct node* t = head;
		int f=0;
		while(t!=NULL){
			c++;
			if (c==ch)
			{
				f=1;
				break;
			}
			t = t->next;
		}
		if (f==0)
		{
			printf("NOT FOUND\n");
		}
		if (t==last)
		{
			last = last->pre;
			last->next=head;
		}
		else 
		{
			t->pre->next = t->next;
			t->next->pre = t->pre;
		}
	}
	display();
}

void delete_end(){
	if (last==NULL)printf("Nothing to Delete\n");
	else if(head==last){
		head=NULL;
		last=NULL;
	}
	else{
		last = last->pre;
		last->next = head;
	}
	display();
}


void search(){
	int sc;
	printf("Enter a roll no to be Searched\n");
	scanf("%d",&sc);
	if (head==NULL)
	{
		printf("No data to search\n");
		return;
	}
	else{
		struct node* temp = head;
		int f=0;
		do{
			if(temp->roll==sc){f=1;break;}
			temp = temp->next;
		}while(temp!=head);
		if(f==0)printf("No data found\n");
		else{
			printf("FOUND THE DATA\n");
			printf("\n%s\n%d\n%f\n",temp->name,temp->roll,temp->cgpa);
		}
	}
}

void display(){
	if(head==NULL){printf("Nothing to display\n");return;}
	struct node* temp = head;
	do{
		printf("\n************************************************\n");
		printf("Name    : %s\n",temp->name);
		printf("Roll No : %d\n",temp->roll);
		printf("CGPA 	: %f\n",temp->cgpa);
		temp = temp->next;
	}while(temp!=head);
	printf("\n************************************************\n\n");
}

int main()
{
	head = NULL;
	last = NULL;
	int i,ch;
	while(1){
        printf("1.Insert\n2.Delete\n3.Search\n4.Display\n");
        scanf("%d",&i);
        if (i==1)
        {
            printf("1.Insert Begin\n2.Insert Between\n3.Insert End\n");
            scanf("%d",&ch);
            if (ch==1)
                insert_beg();
            else if (ch==2)
            	insert_btw();
            else if(ch==3)
                insert_end();
            else printf("Invalid Choice\n");

        }
        else if (i==2)
        {
            printf("1.Delete Begin\n2.Delete Between\n3.Delete End\n");
            scanf("%d",&ch);
            if (ch==1)
                delete_beg();
            else if (ch==2)
            	delete_btw();
            else if(ch==3)
                delete_end();
            else printf("Invalid Choice\n");
        }
        else if(i==3){
        	search();
        }

        else if(i==4){
            display();
        }
        else printf("Invalid Choice\n");
	}
	return 0;
}


================================================
FILE: Data Structures/C:C++/Linked List/doubly linked list.c
================================================
#include<stdio.h>

struct node{
	int item;
	struct node* pre;
	struct node* next;
};

struct node *head, *ptr;

struct node* getNode(){
	ptr = (struct node*)malloc(sizeof(struct node));
	printf("Enter element to be inserted in Doubly Linked List : ");
	int x;
	scanf("%d",&x);
	ptr->item = x;
	ptr->pre = NULL;
	ptr->next = NULL;
	return ptr;
}

void insert(){
	struct node* ptr = getNode();
	ptr->next = head;
	if(head == NULL){
		head = ptr;
		return;
	}	
	head->pre = ptr;
	head = ptr;
}

void insert1(){
	struct node* ptr = getNode();
	if(head==NULL){
		head = ptr;
		return;
	}
	struct node* temp;
	temp=head;
	while(temp->next!=NULL){
		temp = temp->next;
	}//temp is last element
	
	temp->next = ptr;
	ptr->pre = temp;
	ptr->next = NULL;		
}


void print(){
	struct node* temp;
	temp = head;
	while(temp!=NULL){
		printf("%d ",temp->item);
		temp = temp->next;
	}
}

int main(){
	head = NULL;
	insert();//insert inserts at beginning
	insert();
	insert1();//insert1 inserts at end
	insert1();
	print();
}


================================================
FILE: Data Structures/C:C++/Linked List/linked_list.c
================================================
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
struct node
{
	int roll;
	char name[100];
	float cgpa;
	struct node* next;
};

struct node* head;

struct node* getNode(int roll1,char name1[], float cgpa1){
	struct node* p = (struct node*)malloc(sizeof(struct node));
	p->roll=roll1;
	strcpy(p->name,name1);
	p->cgpa=cgpa1;
	return p;
}

struct node* getLastNode(){
	struct node* temp = head;
	while(temp->next!=NULL)
		temp=temp->next;
	return temp;
}

int countNode(){
	struct node* temp = head;
	int count=0;
	while(temp!=NULL){
		count++;
		temp = temp->next;
	}
	return count;
}

void ins_beg(int roll,char name[], float cgpa){
	struct node* p =getNode(roll,name,cgpa);
	p->next = head;
	head = p;
}

void ins_btw(int roll,char name[], float cgpa,int pos){
	if (pos>0 && pos<=countNode())
	{
		struct node* temp = head;
		int count=0;
		while(count!=(pos-1)){
			temp = temp->next;
		}
		struct node* p = getNode(roll,name,cgpa);
		p->next = temp->next;
		temp->next=p;
	}
	else{
		printf("INVALID POSITIONS\n");
	}
}

void ins_end(int roll,char name[], float cgpa){
	struct node* p =getNode(roll,name,cgpa);
	if (head==NULL)//list is empty
	{
		head=p;
	}
	else{
		struct node* temp = head;
		while(temp->next!=NULL)
			temp=temp->next;
		temp->next = p;
	}
}

void del_beg(){
	if(head==NULL)printf("NOTHING TO BE DELETED\n");
	else{
		head = head->next;	
	}
}

void del_btw(int pos){	
	if (pos>0 && pos<=countNode())
	{
		struct node* temp = head;
		int count=0;
		while(count!=(pos-1)){
			temp = temp->next;
		}			
		temp->next=temp->next->next;
	}
	else{
		printf("INVALID POSITIONS\n");
	}

}

void del_end(){
	if(head==NULL)printf("NOTHING TO BE DELETED\n");
	else if(head->next==NULL)head=NULL;
	else{
		struct node* temp = head;
		while(temp->next->next!=NULL)temp = temp->next;		
		temp->next = NULL;	
	}
}

void search(int roll){
	struct node* temp = head;
	int count=1,flag=0;
	while(temp!=NULL){
		if(temp->roll==roll){
			printf("POSITION at %d\n",count);
			printf("FOLLOWING DATA OF ROLL NO. :\n");	
			printf("ROLL NO. : %d\nNAME : %s\nCGPA : %f\n\n",temp->roll,temp->name,temp->cgpa);
			flag=1;			
			break;
		}
		++count;
		temp = temp->next;
	}
	if(flag==0)printf("NOT FOUND\n");
}

void DISPLAY(){
	struct node* temp = head;
	if(temp==NULL)printf("NOTHING TO DISPLAY\n");
	else{
		while(temp!=NULL){
			printf("ROLL NO: %d\nNAME: %s\nCGPA:%f\n\n",temp->roll,temp->name,temp->cgpa);
			temp=temp->next;
		}
	}
}

int main()
{
	head = NULL;
	while(1){	
		printf("1.INSERT : \n2.DELETE : \n3.SEARCH : \n4.DISPLAY : \n");
		int ch;
		scanf("%d",&ch);
		if (ch==1)
		{
			int ch1;
			printf("1.INSERT at BEGINNING: \n2.INSERT at END: \n3.INSERT at BETWEEN:\n");
			scanf("%d",&ch1);
			int roll;
			char name[100];
			float cgpa;
			printf("Enter UNIQUE ROLL NO. to be inserted\n");
			scanf("%d",&roll);
			printf("Enter NAME to be inserted\n");
			gets(name);
			printf("Enter CGPA to be inerted\n");
			scanf("%f",&cgpa);
			if (ch1==1)
			{
				ins_beg(roll,name,cgpa);
			}
			else if (ch1==2)
			{
				ins_end(roll,name,cgpa);
			}
			else if (ch1==3)
			{
				printf("Enter the POSITION where node is to be inserted\n");
				int k;
				scanf("%d",&k);
				ins_btw(roll,name,cgpa,k);
			}
			else printf("INVALID INPUT\n");
		}
		else if(ch==2){
			int ch1;
			printf("1.DELETE at BEGINNING: \n2.DELETE at END: \n3.DELETE at BETWEEN:\n");
			scanf("%d",&ch1);
			if(ch1==1){
				del_beg();
			}
			else if(ch1==2){
				del_end();
			}
			else if(ch1==3){
				printf("Enter the POSITION at which node is to be DELETED\n");
				int k;
				del_btw(scanf("%d",&k));		
			}
			else printf("INVALID POSITION");

		}
		else if(ch==3){
			int roll;
			printf("Enter UNIQUE ROLL NO. to be searched\n");
			scanf("%d",&roll);
			search(roll);
		}
		else if(ch==4)DISPLAY();
		else {printf("INVALID INPUT\n");break;}
	}
	return 0;
}


================================================
FILE: Data Structures/C:C++/Linked List/ordered_linked.c
================================================
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
struct node
{
	int roll;
	char name[100];
	float cgpa;
	struct node* next;
};

struct node* head;

struct node* getNode(int roll1,char name1[], float cgpa1){
	struct node* p = (struct node*)malloc(sizeof(struct node));
	p->roll=roll1;
	strcpy(p->name,name1);
	p->cgpa=cgpa1;
	p->next=NULL;
	return p;
}

struct node* getLastNode(){
	struct node* temp = head;
	while(temp->next!=NULL)
		temp=temp->next;
	return temp;
}

int countNode(){
	struct node* temp = head;
	int count=0;
	while(temp!=NULL){
		count++;
		temp = temp->next;
	}
	return count;
}

void insert(int roll,char name[], float cgpa){
	struct node* p =getNode(roll,name,cgpa);
	if(head==NULL){
		head = p;	
	}
	else if(head->roll > roll){
		p->next=head;
		head=p;
	}
	else{
		struct node* temp = head;
		struct node* pre = NULL;
		while(temp->roll < roll && temp!=NULL){
			pre = temp;	
			temp=temp->next;
		}	
		p->next = temp;
		pre->next = p;
	}
}
/*void ins_beg(int roll,char name[], float cgpa){
	struct node* p =getNode(roll,name,cgpa);
	p->next = head;
	head = p;
}

void ins_btw(int roll,char name[], float cgpa,int pos){
	if (pos>0 && pos<=countNode())
	{
		struct node* temp = head;
		int count=0;
		while(count!=(pos-1)){
			temp = temp->next;
		}
		struct node* p = getNode(roll,name,cgpa);
		p->next = temp->next;
		temp->next=p;
	}
	else{
		printf("INVALID POSITIONS\n");
	}
}

void ins_end(int roll,char name[], float cgpa){
	struct node* p =getNode(roll,name,cgpa);
	if (head==NULL)//list is empty
	{
		head=p;
	}
	else{
		struct node* temp = head;
		while(temp->next!=NULL)
			temp=temp->next;
		temp->next = p;
	}
}*/

void del_beg(){
	if(head==NULL)printf("NOTHING TO BE DELETED\n");
	else head = head->next;	
}

void del_btw(int pos){	
	if (pos>0 && pos<=countNode())
	{
		struct node* temp = head;
		int count=0;
		while(count!=(pos-1)){
			temp = temp->next;
		}			
		temp->next=temp->next->next;
	}
	else printf("INVALID POSITIONS\n");
}

void del_end(){
	if(head==NULL)printf("NOTHING TO BE DELETED\n");
	else if(head->next==NULL)head=NULL;
	else{
		struct node* temp = head;
		while(temp->next->next!=NULL)temp = temp->next;		
		temp->next = NULL;	
	}
}

void search(int roll){
	struct node* temp = head;
	int count=1,flag=0;
	while(temp!=NULL){
		if(temp->roll==roll){
			printf("POSITION at %d\n",count);
			printf("FOLLOWING DATA OF ROLL NO. :\n");	
			printf("ROLL NO. : %d\nNAME : %s\nCGPA : %f\n\n",temp->roll,temp->name,temp->cgpa);
			flag=1;			
			break;
		}
		temp = temp->next;
		++count;
	}
	if(flag==0)printf("NOT FOUND\n");
}

void DISPLAY(){
	struct node* temp = head;
	if(temp==NULL)printf("NOTHING TO DISPLAY\n");
	else{
		while(temp!=NULL){
			printf("ROLL NO: %d\nNAME: %s\nCGPA:%f\n\n",temp->roll,temp->name,temp->cgpa);
			temp=temp->next;
		}
	}
}

int main()
{
	head = NULL;
	while(1){	
		printf("1.INSERT : \n2.DELETE : \n3.SEARCH : \n4.DISPLAY : \n");
		int ch;
		scanf("%d",&ch);
		if (ch==1)
		{
			int roll;
			char name[100];
			float cgpa;
			printf("Enter ROLL NO. to be inserted\n");
			scanf("%d",&roll);
			printf("Enter NAME to be inserted\n");
			gets(name);
			printf("Enter CGPA to be inerted\n");
			scanf("%f",&cgpa);
			insert(roll,name,cgpa);
		}
		else if(ch==2){
			int ch1;
			printf("1.DELETE at BEGINNING: \n2.DELETE at END: \n3.DELETE at BETWEEN:\n");
			scanf("%d",&ch1);
			if(ch1==1){
				del_beg();
			}
			else if(ch1==2){
				del_end();
			}
			else if(ch1==3){
				printf("Enter the POSITION at which node is to be DELETED\n");
				int k;
				del_btw(scanf("%d",&k));		
			}
			else printf("INVALID INPUT");

		}
		else if(ch==3){
			int roll;
			printf("Enter ROLL NO. to be searched\n");
			scanf("%d",&roll);
			search(roll);
		}
		else if(ch==4)DISPLAY();
		else {printf("INVALID INPUT\n");break;}
	}
	return 0;
}


================================================
FILE: Data Structures/C:C++/Linked List/reverse.cpp
================================================
#include<iostream>
#include<malloc.h>
using namespace std;
//structure of node
struct node
{
    int data;
    struct node *next;
}*start=NULL;
//function to create linked list
struct node* create(struct node*current)
{
  struct node *new_node;//pointer to node
  new_node=(struct node *)malloc(sizeof(struct node));

  cout<<"\nEnter the data : ";
  cin>>new_node->data;
  new_node->next=NULL;

  if(start==NULL)//to check if the root node is null or not
  {
    start=new_node;
    current=new_node;
  }
  else
  {
    current->next=new_node;
    current=new_node;
  }
  return current;

}
//function to display linked list
void display()
{
    struct node *new_node;
    cout<<"\nThe Linked List : "<<endl;
    new_node=start;
    while(new_node!=NULL)//condition to point to the last node
    {
        cout<<new_node->data<<"--->";
        new_node=new_node->next;
    }
    cout<<"NULL"<<endl;
}
//function to reverse linked list
void reverse()
{
    struct node *prev,*curr,*nextt;//prev for pointing to previous node,curr for pointing to current node,nextt for pointing to next node
    curr=start;//pointing to the root node
    prev=NULL;
    while(curr!=NULL)
    {
        nextt=curr->next;
        curr->next=prev;
        prev=curr;
        curr=nextt;


    }
    start=prev;
    display();
}
int main()
{
    int n;
    struct node*current;
    current=NULL;
    while(1)
    {
        cout<<"1.to insert\n2.display\n3.reverse\n4.exit\nenter choice"<<endl;
        cin>>n;

        switch(n)
        {
            case 1: current=create(current);//passing current pointer to create function
                    break;
            case 2: display();
                    break;
            case 3:reverse();
                    break;
            case 4: return 0;
        }
    }
    return 0;
}


================================================
FILE: Data Structures/C:C++/Linked List/stackLinkedList.cpp
================================================
#include<bits/stdc++.h>

struct node{
	int item;
	struct node* next;
};

struct node* head;
int size;

void insertathead(){
	struct node* ptr;
	ptr = (struct node*)malloc(sizeof(struct node));
	printf("Enter data : ");
	scanf("%d",&ptr->item);
	printf("\n");
	ptr->next = NULL;
	if(head == NULL){
		head = ptr;
		return;
	}
	ptr->next = head;
	head = ptr;
}

void pop(){
	if(head==NULL){
		printf("UnderFlow\n");
		return;
	}
	if(head->next == NULL){
		head=NULL;
		return;
	}
	struct node* temp;
	temp = head;
	head = head->next;
	temp->next = NULL;
}
void print(){
	struct node* temp;
	temp = head;
	printf("List : ");
	while(temp!=NULL){
		printf("%d ",temp->item);
		temp = temp->next;
	}
	printf("\n");
}

int main(){
	head=NULL;
	printf("Enter the size of array\n");
	scanf("%d",&size);
	while(1){
		printf("Enter choice\n1.Insert\n2.Pop\n3.Print\n");
		int ch;
		scanf("%d",&ch);
		if(ch==1){
		insertathead();
		}
		else if(ch==2){
			pop();	
		}
		else if(ch==3){
			print();
		}
	}
}


================================================
FILE: Data Structures/C:C++/Linked List/stack_Linked_List.c
================================================
/*Implementation of stack using linked list */

/*Stack is a LIFO (Last In Fast Out Data Structure */

/*
 * push operation 	O(1)
 * pop operation	O(1)
 * top operation	O(1)
 * isEmpty operation 	O(1)
*/

#include <stdio.h>
#include <stdlib.h>
struct node{
	int item;
	struct node* next;
};

struct stack{
	struct node *tos;
};

typedef struct node node;
typedef struct stack stack;

/*Function to create stack*/
stack* createStack(){
	stack *temp=(stack*)malloc(sizeof(stack));
	temp->tos=NULL;
	return temp;
}


/*Function to push in a stack */
void push(stack *s,int data){
	node *temp=(node*)malloc(sizeof(node));
	/*checking if the memory was allocated to temp*/
	if(temp==NULL){
		printf("OVERFLOW\n");
		exit(0);
	}
	temp->item=data;
	if(s->tos==NULL){
		s->tos=temp;
		temp->next=NULL;
		return;
	}
	else{
		temp->next=s->tos;
		s->tos=temp;
		return;
	}
}

/*Function to pop an element from a stack */
int pop(stack *s){
	node *temp;
	int valueToReturn;
	if(s->tos==NULL){
		printf("UNDERFLOW\n");
		exit(0);
	}
	else{
		temp=s->tos;
		s->tos=temp->next;
		valueToReturn=temp->item;
		free(temp);
		return valueToReturn;
	}
}

/*function to check wheather the stack is empty */
int isEmpty(stack *s){
	return s->tos==NULL;
}


/*Functiont that returns the top of the stack */
int top(stack *s){
	if(!isEmpty(s))
		return s->tos->item;
	else
		return -1;
}



int main(){
	stack *s=createStack();
	int temp,ch,cont;
	do{
		printf("Enter choice\t1.Push\t2.Pop\t3.top :");
		scanf("%d",&ch);
		switch(ch){
			case 1:
				printf("Enter value :");
				scanf("%d",&temp);
				push(s,temp);
				break;
			case 2:
				printf("%d popped \n",pop(s));
				break;
			case 3:
				printf("top : %d\n",top(s));
				break;
		}
		printf("\nContinue (1/0)\n");
		scanf("%d",&cont);
	}while(cont != 0);
return 0;
}


================================================
FILE: Data Structures/C:C++/Stack/Balanced_Brackets.cpp
================================================
/*This program checks whether an entered string is Bracket Balanced ot not.By Bracket balanced we mean a opening bracket ('(','{','[') to be complemented by a closing bracket (')','}',']').
Time Complexity :O(n)
Auxiliary Space :O(n)
Similar quesion(s) for practice :https://www.hackerrank.com/challenges/balanced-brackets/problem
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string str;
	getline(cin,str);
    stack<char> s;
    
    char a,b,c;
    int flag=1;

	for(int i=0;i<str.length();i++)
	{
		if (str[i]=='('||str[i]=='['||str[i]=='{')
        {
            // Push the element in the stack
            s.push(str[i]);
        }
        else
        {
            switch (str[i])
            {
            case ')':
 
                // Store the top element in a
                a = s.top();
                s.pop();
                if (a=='{'||a=='[')
                {
                  
                    flag=0;
                }
                break;
            case '}':
 
                // Store the top element in b
                b = s.top();
                s.pop();
                if (b=='('||b=='[')
                {
                   
                    flag=0;
                }
                break;
            case ']':
 
                // Store the top element in c
                c=s.top();
                s.pop();
                if (c=='('||c=='{')
                {
                
                    flag=0;
                }
                break;
            }
        }
	}
    if (s.empty() && flag==1)
        cout<<"Balanced";
    else
        cout<<"Unbalanced";
}
	



================================================
FILE: Data Structures/C:C++/Stack/Reverse_Queue.cpp
================================================
/*
An effective CPP program to reverse a Queue.In this program,
a Queue is populated with values and then it is reversed using the use of Stack.
Time Complexity:O(n)
Space Complexity:Extra Space for Stack
#include <bits/stdc++.h>
*/
using namespace std; 
void Print(queue<int>& Queue)
{
    while (!Queue.empty()) {
        cout << Queue.front() << " ";
        Queue.pop();
    }
}
 
// Function to reverse the queue
void reverseQueue(queue<int>& Queue)
{
    stack<int> Stack;
    while (!Queue.empty()) {
        Stack.push(Queue.front());
        Queue.pop();
    }
    while (!Stack.empty()) {
        Queue.push(Stack.top());
        Stack.pop();
    }
}
 
// Main Function
int main()
{
    queue<int> Queue;
    Queue.push(1);
    Queue.push(2);
    Queue.push(3);
    Queue.push(4);
    Queue.push(5);
    Queue.push(6);
    Queue.push(7);
    Queue.push(8);
    Queue.push(9);
    Queue.push(10);
 
    reverseQueue(Queue);
    Print(Queue);
}

================================================
FILE: Data Structures/C:C++/Stack/Stack_as_linked_list.cpp
================================================
C++ Program to implement Stack using Linked List:

#include<iostream>
using namespace std;


//   Creating a NODE Structure
struct node
{
    int data;
    struct node *next;
};

// Creating a class STACK
class stack
{
    struct node *top;
    public:
    stack() // constructure
    {
        top=NULL;
    }
    void push(); // to insert an element
    void pop();  // to delete an element
    void show(); // to show the stack
};
// PUSH Operation
void stack::push()
{
    int value;
    struct node *ptr;
    cout<<"\nPUSH Operationn";
    cout<<"Enter a number to insert: ";
    cin>>value;
    ptr=new node;
    ptr->data=value;
    ptr->next=NULL;
    if(top!=NULL)
        ptr->next=top;
    top=ptr;
    cout<<"\nNew item is inserted to the stack!!!";

}

// POP Operation
void stack::pop()
{
    struct node *temp;
    if(top==NULL)
    {
        cout<<"\nThe stack is empty!!!";
    }
    temp=top;
    top=top->next;
    cout<<"\nPOP Operation........\nPoped value is "<<temp->data;
    delete temp;
}

// Show stack
void stack::show()
{
    struct node *ptr1=top;
    cout<<"\nThe stack is\n";
    while(ptr1!=NULL)
    {
        cout<<ptr1->data<<" ->";
        ptr1=ptr1->next;
    }
    cout<<"NULL\n";
}

// Main function
int main()
{
    stack s;
    int choice;
    while(1)
    {
        cout<<"\n-----------------------------------------------------------";
        cout<<"\n\t\tSTACK USING LINKED LIST\n\n";
        cout<<"1:PUSH\n2:POP\n3:DISPLAY STACK\n4:EXIT";
        cout<<"\nEnter your choice(1-4): ";
        cin>>choice;
        switch(choice)
        {
            case 1:
                s.push();
                break;
            case 2:
                s.pop();
                break;
            case 3:
                s.show();
                break;
            case 4:
                return 0;
                break;
            default:
                cout<<"\nPlease enter correct choice(1-4)!!";
                break;
        }
    }
    return 0;
}



================================================
FILE: Data Structures/C:C++/Stack/largestRectangleHistogram.cpp
================================================
#include<iostream>
#include<stack>
#include<climits>
using namespace std;
int main() {
    int n;
    int a[]={6,2,5,4,5,1,6};  //input array
    n = sizeof(a)/sizeof(a[0]);
    int i,q;
    stack <int> s;  // stack to calculate max area
    i=0;
    int area,maxarea=INT_MIN;
    while(i<n){
        if(s.empty()||a[s.top()]<=a[i])
        s.push(i++);
        else{
            q=s.top();
            s.pop();
            area=a[q]*(s.empty()?i:i-s.top()-1);
            if(maxarea<area)
                maxarea=area;
        }
    }
    while(!s.empty()){
        q=s.top();
        s.pop();
        area=a[q]*(s.empty()?i:i-s.top()-1);
        if(maxarea<area)
            maxarea=area;
    }
    cout<<maxarea;
	return 0;
}


================================================
FILE: Data Structures/C:C++/Stack/nextgreaterelement
================================================
//http://www.geeksforgeeks.org/next-greater-element/

//The problem is from geekforgeeks and it is my implementation of it.
#include<bits/stdc++.h>
using namespace std;



int main(){
	int n;
	cin>>n;
	int a[n];
	int ans[n];
	for(int i=0;i<n;i++){
		ans[i]=-1;
	}
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	stack<int> s;
	for(int i=0;i<n;i++){
		
		while(!s.empty()&&a[i]>a[s.top()]){
			ans[s.top()]=a[i];
			s.pop();
		}
		s.push(i);
	}
	for(int i=0;i<n;i++){
		cout<<a[i]<<" "<<ans[i]<<endl;
	}
}


================================================
FILE: Data Structures/C:C++/Stack/stack.hpp
================================================
#include <bits/stdc++.h>
#include "../linked_list/ll.hpp"
using namespace std;

template<class T>
struct stackmp{
	ll_node<T> *top;
	int capacity; // number of elements the stack can contain
	int size; // number of elements in the stack

	stackmp(int cap) : capacity(cap),size(0) {}

	void push(T new_data){
		if(size == capacity){
			cout << "Stack is full! Cannot push new element" << endl;
			return;
		}
		ll_node<T> *new_node = create_node(new_data);
		ll_node<T> *temp_node = this->top;
		new_node->next = temp_node;
		this->top = new_node; // here "this" pointer is used to access the current class's object's parameters
		size++;
	}

	void print(){
		ll_node<T> *temp_node = this->top;
		if(size == 0){
			cout << "Stack is empty" << endl;
			return;
		}
		cout << "Printing stack:" << endl;
		for(int i=0;i<this->size;i++){
			cout << temp_node->data << ' ';
			temp_node = temp_node->next;
		}
		cout << endl;
	}

	T pop(){
		if(size == 0){
			cout << "Stack is empty, can't pop" << endl;
			return '\0';
		}
		T data = this->top->data;
		this->top = this->top->next;
		size--;
		return data;
	}

	T peek(){
		return this->top->data;
	}
};

template<class T>
int get_size(stackmp<T> *s){
	return s->size;
}

template<class T>
int get_capacity(stackmp<T> *s){
	return s->capacity;
}



================================================
FILE: Data Structures/C:C++/Trees/segment_tree/segment_tree.cpp
================================================
#include <bits/stdc++.h>

using namespace std;

void createMinSegmentTree(int arr[],int sg[],int index,int begin,int end){
	//create the segment tree.
	if(begin == end){
		sg[index] = arr[begin];
		return;
	}
	int mid = (begin+end)/2;
	createMinSegmentTree(arr,sg,2*index,begin,mid);
	createMinSegmentTree(arr,sg,2*index+1,mid+1,end);
	sg[index] = min(sg[2*index],sg[2*index+1]);
	return;

}

int queryMinSegmentTree(int sg[],int l,int r,int index,int begin,int end){
	//querying the segment tree

	//complete overlap
	if(l <= begin && r >= end){
		return sg[index];
	}
	//no overlap
	else if(r<begin || l> end){
		return INT_MAX;
	}
	//partial overlap
	else{
		int mid = (begin+end)/2;
		return min(queryMinSegmentTree(sg,l,r,2*index,begin,mid),queryMinSegmentTree(sg,l,r,2*index+1,mid+1,end));
	}

}

void updateMinSegmentTree(int sg[],int l,int r,int index,int begin,int end,int update){

	if(begin == end && begin>=l && begin<=r){
		sg[index]+=update;
		return;
	}
	if(l>end || r<begin){
		return;
	}
	int mid = (begin+end)/2;
	updateMinSegmentTree(sg,l,r,2*index,begin,mid,update);
	updateMinSegmentTree(sg,l,r,2*index+1,mid+1,end,update);
	sg[index] = min(sg[2*index],sg[2*index+1]);
	return;


}

int main(){

	int n; cin >> n;

	int arr[n];

	for(int i=0;i<n;i++){
		arr[i] = rand()%n+1;	
	}

	int sg[4*n]={};
	createMinSegmentTree(arr,sg,1,0,n-1);

	//print the original array
	for(int i =0;i<n;i++){
		cout << arr[i]<<" ";
	}
	cout << endl;

	int q; cin >> q;

	int l,r,option;
	while(q--){
		cin >> option;	

		//option 1 to query the segment tree with range [l,r].
		if(option == 1){
			cin >> l >> r;
			cout << queryMinSegmentTree(sg,l,r,1,0,n-1)<<endl;
		}
		//option 2 to update the segment tree in range [l,r].
		else if(option == 2){
			int update;
			cin >> l >> r >> update;
			updateMinSegmentTree(sg,l,r,1,0,n-1,update);
		}
	}


	return 0;
}

================================================
FILE: Data Structures/C:C++/Trees/segment_tree/segment_trees_lazy.cpp.cpp
================================================
/**
 * In this code we have a very large array called arr, and very large set of operations
 * Operation #1: Increment the elements within range [i, j] with value val
 * Operation #2: Get max element within range [i, j]
 * Build tree: build_tree(1, 0, N-1)
 * Update tree: update_tree(1, 0, N-1, i, j, value)
 * Query tree: query_tree(1, 0, N-1, i, j)
 * Actual space required by the tree = 2*2^ceil(log_2(n)) - 1
 */

#include<iostream>
#include<algorithm>
using namespace std;

#include<string.h>
#include<math.h>

#define N 20
#define MAX (1+(1<<6)) // Why? :D
#define inf 0x7fffffff

int arr[N];
int tree[MAX];
int lazy[MAX];

/**
 * Build and init tree
 */
void build_tree(int node, int a, int b) {
    if(a > b) return; // Out of range

    if(a == b) { // Leaf node
        tree[node] = arr[a]; // Init value
        return;
    }

    build_tree(node*2, a, (a+b)/2); // Init left child
    build_tree(node*2+1, 1+(a+b)/2, b); // Init right child

    tree[node] = max(tree[node*2], tree[node*2+1]); // Init root value
}

/**
 * Increment elements within range [i, j] with value value
 */
void update_tree(int node, int a, int b, int i, int j, int value) {

    if(lazy[node] != 0) { // This node needs to be updated
        tree[node] += lazy[node]; // Update it

        if(a != b) {
            lazy[node*2] += lazy[node]; // Mark child as lazy
            lazy[node*2+1] += lazy[node]; // Mark child as lazy
        }

        lazy[node] = 0; // Reset it
    }

    if(a > b || a > j || b < i) // Current segment is not within range [i, j]
        return;

    if(a >= i && b <= j) { // Segment is fully within range
        tree[node] += value;

        if(a != b) { // Not leaf node
            lazy[node*2] += value;
            lazy[node*2+1] += value;
        }

        return;
    }

    update_tree(node*2, a, (a+b)/2, i, j, value); // Updating left child
    update_tree(1+node*2, 1+(a+b)/2, b, i, j, value); // Updating right child

    tree[node] = max(tree[node*2], tree[node*2+1]); // Updating root with max value
}

/**
 * Query tree to get max element value within range [i, j]
 */
int query_tree(int node, int a, int b, int i, int j) {

    if(a > b || a > j || b < i) return -inf; // Out of range

    if(lazy[node] != 0) { // This node needs to be updated
        tree[node] += lazy[node]; // Update it

        if(a != b) {
            lazy[node*2] += lazy[node]; // Mark child as lazy
            lazy[node*2+1] += lazy[node]; // Mark child as lazy
        }

        lazy[node] = 0; // Reset it
    }

    if(a >= i && b <= j) // Current segment is totally within range [i, j]
        return tree[node];

    int q1 = query_tree(node*2, a, (a+b)/2, i, j); // Query left child
    int q2 = query_tree(1+node*2, 1+(a+b)/2, b, i, j); // Query right child

    int res = max(q1, q2); // Return final result

    return res;
}

int main() {
    for(int i = 0; i < N; i++) arr[i] = 1;

    build_tree(1, 0, N-1);

    memset(lazy, 0, sizeof lazy);

    update_tree(1, 0, N-1, 0, 6, 5); // Increment range [0, 6] by 5. here 0, N-1 represent the current range.
    update_tree(1, 0, N-1, 7, 10, 12); // Incremenet range [7, 10] by 12. here 0, N-1 represent the current range.
    update_tree(1, 0, N-1, 10, N-1, 100); // Increment range [10, N-1] by 100. here 0, N-1 represent the current range.

    cout << query_tree(1, 0, N-1, 0, N-1) << endl; // Get max element in range [0, N-1]
}

================================================
FILE: Data Structures/C:C++/Trees/tree/Fenwick_tree.cpp
================================================
#include<iostream>
using namespace std;
int BIT[1000], arr[1000],l,r,n,s;
void update(int x, int delta)
{
      for( ;x<=n;x+=x&-x)
        BIT[x]+=delta;
}
int query(int x)
{
     int sum=0;
     for(;x>0;x-=x&-x)
        sum+=BIT[x];
     return sum;
}

int main()
{
     cin>>n;
     cout<<"Enter "<<n<<" elemets and more than 8 elemets\n";
     for(int i = 1; i <= n; i++)
     {
       cin>>arr[i];
           update(i,arr[i]);
     }
     cout<<"Give the number of elemets you want sum for\n";
     cin>>s;
     cout<<"Sum of first "<<s<<" elements is "<<query(s)<<endl;
     cout<<"Sum of all elements in range [2,8] is "<<query(8)-query(2-1)<<endl;
     return 0;
}


================================================
FILE: Data Structures/C:C++/Trees/tree/bst.hpp
================================================
#include <bits/stdc++.h>
#include "../queue/queue.hpp"
using namespace std;

template<class T>
struct bst_node{
	T data;
	bst_node *left_child;
	bst_node *right_child;

	bst_node(T new_data) : data(new_data), left_child(NULL), right_child(NULL) {};
};

template<class T>
class BST{
private:
	bst_node<T> *node;

	// helper functions 
	int _get_length(bst_node<T> *node){
		if(node == NULL) return 0;
		return 1 + max(_get_length(node->left_child), _get_length(node->right_child));
	}

	void _insert(bst_node<T> *node, T new_data){
		// if node exists
		if(node->data > new_data){
			// go left
			if(node->left_child){
				_insert(node->left_child, new_data);
			}else{
				node->left_child = new bst_node<T>(new_data);
			}
		}else{
			// right
			if(node->right_child){
				_insert(node->right_child, new_data);
			}else{
				node->right_child = new bst_node<T>(new_data);
			}
		}
	}

	void _print(bst_node<T> *node){
		if(!node) return;
		_print(node->left_child);
		cout << node->data << " ";
		_print(node->right_child);
	}

	void _print_post_order(bst_node<T> *node){
		if(!node) return;
		_print_post_order(node->left_child);
		_print_post_order(node->right_child);
		cout << node->data << " ";
	}

	void _print_pre_order(bst_node<T> *node){
		if(!node) return;
		cout << node->data << " ";
		_print_pre_order(node->left_child);
		_print_pre_order(node->right_child);
	}

	int _count_nodes(bst_node<T> *node){
		if(!node) return 0;
		return 1 + _count_nodes(node->left_child) + _count_nodes(node->right_child);
	}

	bool _find(bst_node<T> *node, T data){
		if(node){
			if(node->data == data){
				return true;
			}
			if(node->data > data){
				// go left
				return _find(node->left_child, data);
			}else{
				return _find(node->right_child, data);
			}
		}
		return false;
	}

	void _print_max_path(bst_node<T> *node){
		if(!node) return;
		cout << node->data << ' ';
		if(_get_length(node->left_child)){
			_print_max_path(node->left_child);
		}else{
			_print_max_path(node->right_child);
		}
	}

	T _get_max(bst_node<T> *node){
		if(node == NULL) return '\0';
		bst_node<T> *temp_node = node;
		while(temp_node->right_child){
			temp_node = temp_node->right_child;
		}
		return temp_node->data;
	}

	T _get_min(bst_node<T> *node){
		if(node == NULL) return '\0';
		bst_node<T> *temp_node = node;
		while(temp_node->left_child){
			temp_node = temp_node->left_child;
		}
		return temp_node->data;
	}

	bst_node<T> *_get_min_node(bst_node<T> *node){
		if(node == NULL) return NULL;
		bst_node<T> *temp_node = node;
		while(temp_node->left_child){
			temp_node = temp_node->left_child;
		}
		return temp_node;
	}

	bst_node<T> *_delete_value(bst_node<T> *root, T del_data){
		if(root == NULL) return root;

		if(del_data < root->data){
			root->left_child = _delete_value(root->left_child, del_data);
		}else if(del_data > root->data){
			root->right_child = _delete_value(root->right_child, del_data);
		}else{
			// check if one child is NULL
			if(root->left_child == NULL){
				bst_node<T> *temp_node = root->right_child;
				delete root;
				return temp_node;
			}else if(root->right_child == NULL){
				bst_node<T> *temp_node = root->left_child;
				delete root;
				return temp_node;
			}

			// if the node has both the 
			bst_node<T> *temp_node = _get_min_node(root->right_child);
			cout << "min node " << temp_node->data << endl; 
			root->data = temp_node->data;
			root->right_child = _delete_value(root->right_child, temp_node->data);
		}
		return root;
	}

	int _get_count(bst_node<T> *node){
		if(node == NULL) return 0;
		return 1 + _get_count(node->left_child) + _get_count(node->right_child);
	}

	void _level_order(bst_node<T> *node){
		if(node == NULL) return;
		cout << "Level order traversal:" << endl;
		queuemp<bst_node<T> *> *q = new queuemp<bst_node<T> *>();
		q->push(node);
		while(q->size){
			bst_node<T> *temp = q->pop();
			if(temp->left_child) q->push(temp->left_child);
			if(temp->right_child) q->push(temp->right_child); 
			cout << temp->data << " ";
		}
		cout << endl;
		delete q;
	}
public:
	BST() : node(NULL) {}
	BST(T new_data) : node(new bst_node<T>(new_data)) {}
	~BST();

	T data(){
		return this->node->data;
	}

	void insert(T new_data){
		bst_node<T> *new_node = new bst_node<T>(new_data);
		if(node == NULL){
			node = new bst_node<T>(new_data);
			return;
		}
		_insert(node, new_data);
	}

	int get_length(){
		return _get_length(node);
	}

	void print(){
		cout << "Printing BST (in order):" << endl;
		_print(node);
		cout << endl;
	}

	void print_post_order(){
		cout << "Printing BST (post order):" << endl;
		_print_post_order(node);
		cout << endl;
	}

	void print_pre_order(){
		cout << "Printing BST (pre order):" << endl;
		_print_pre_order(node);
		cout << endl;
	}

	T get_max(){
		return _get_max(node);
	}

	T get_min(){
		return _get_min(node);
	}

	int count_nodes(){
		return _count_nodes(node);
	}

	bool find(T data){
		return _find(node, data);
	}

	void print_max_path(){
		cout << "Max path:" << endl;
		_print_max_path(node);
		cout << endl;
	}

	void delete_value(T del_data){
		this->node = _delete_value(this->node, del_data);
	}

	int get_count(){
		return _get_count(this->node);
	}

	void level_order(){
		_level_order(this->node);
	}
};


================================================
FILE: Data Structures/C:C++/Trees/tree/segment_tree.hpp
================================================
#include <iostream>
#include <math.h>

class segment_tree{
private:
    int *st;
    int *ar;
    int len;
    int sz; //size of segment tree

    // function to get middle of a segment
    int _get_mid(int start, int end){
        return start + (end - start) / 2;                
    }

    // util function to contruct segment tree
    int _construct(int *v, int start, int end, int current){
    	// if there is 1 element in stray, store in current 
    	// node and return
    	if(start == end){
    		st[current] = v[start];
    		return v[start];
    	}

    	// for more elements, recur for left & right subtrees
    	// store the sum for values in this node
    	int mid = _get_mid(start, end);
    	st[current] = _construct(v, start, mid, current*2 + 1) + 
    					_construct(v, mid + 1, end, current*2 + 2);
    	return st[current];
    }

    // utility to update a value in segment tree
    void _update_value(int start, int end, int i, int difference, int current){
  		if(i<start || i>end) return;
  		st[current] = st[current] + difference;
  		if(end != start){
  			int mid = _get_mid(start, end);
  			_update_value(start, mid, i, difference, 2*current+1);
  			_update_value(mid+1, end, i, difference, 2*current+2);
  		}
    }

    int _get_sum(int start, int end, int q_start, int q_end, int current){
    	if(q_start <= start && q_end >= end) return st[current];

    	// outside range
    	if(end < q_start || start > q_end) return 0;

    	int mid = _get_mid(start, end);
    	return _get_sum(start, mid, q_start, q_end, 2*current+1) + 
    			_get_sum(mid+1, end, q_start, q_end, 2*current+2);
    }
public:
    segment_tree(int *v, int n){
    	ar = new int[n];
    	this->len = n;
    	for(int i=0;i<n;i++) ar[i] = v[i];
    	// construct tree
    	// height of tree
    	this->sz = 0;
    	int h = (int)ceil(log2(n));
    	int max_size = 2 * (int)pow(2, h) - 1;
    	this->sz = max_size;

    	// allocate memory
    	st = new int[max_size];
    	_construct(v, 0, n-1, 0);
    }

    // update value in 
    void update(int i, int new_val){
    	if(i<0 || i>this->len-1) return;
    	int difference = new_val - ar[i];
    	ar[i] = new_val;

    	// update segment tree
    	_update_value(0, this->len-1, i, difference, 0);
    }

    //get sum of range
    int get_sum(int start, int end){
    	if(start < 0 || end > this->len-1 || start > end) return -1;
    	return _get_sum(0, this->len-1, start, end, 0);
    }

    int get(int n){
    	return st[n];
    }
    void print(){
    	cout << "Printing segment tree" << endl;
    	int n = this->sz;
    	for(int i=0;i<n;i++) cout << st[i] << " ";
    	cout << endl;
    }
};

================================================
FILE: Data Structures/C:C++/Trees/tree/tree.hpp
================================================
#include <bits/stdc++.h>
using namespace std;

template<class T>
struct tree_node{
	T data;
	tree_node *left_child;
	tree_node *right_child;

	tree_node(T new_data) : data(new_data), left_child(NULL), right_child(NULL) {};

	void insert_left(T new_data){
		tree_node<T> *new_node = new tree_node<T>(new_data);
		this->left_child = new_node;
	}

	void insert_right(T new_data){
		tree_node<T> *new_node = new tree_node<T>(new_data);
		this->right_child = new_node;
	}
};

template<class T>
int get_length(tree_node<T> *top){
	if(top == NULL) return 0;
	return 1 + max(get_length(top->left_child), get_length(top->right_child));
}


================================================
FILE: Data Structures/C:C++/Trees/tree/trie.cpp
================================================
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
int ii,i,at;
struct no{
	no* nxt[26];
	no *root;
	ll fim,qtdNo;
	
	inline no(char k){
		for(ii=0;ii<26;ii++) nxt[ii] = NULL;
		root = this;
		fim = qtdNo = 0;
	}
	inline bool insert(const string s, ll i){
		if(i == s.size()){
			fim = 1;
			return false;
		}
		at = s[i] - 'a';
		if(!nxt[at]){
			nxt[at] = new no(s[i]);
			nxt[at] -> root = root;
			root -> qtdNo++;
		}
		else if(nxt[at] -> fim) return true;
		return nxt[at] -> insert(s,i+1);
	}
};
 main(){}


================================================
FILE: Data Structures/C:C++/queue/queue.hpp
================================================
#include <bits/stdc++.h>
#include "../linked_list/ll.hpp"
using namespace std;

template<class T>
struct queuemp{
	ll_node<T> *head;
	int size; // number of elements in the queue

	queuemp() : size(0) {}

	void push(T new_data){
		ll_node<T> *new_node = create_node(new_data);
		ll_node<T> *temp_node = this->head;
		new_node->next = temp_node;
		this->head = new_node;
		this->size++;
	}

	void print(){
		if(this->size == 0){
			cout << "queue is empty" << endl;
			return;
		}
		ll_node<T> *temp_node = this->head;
		cout << "Printing queue:" << endl;
		for(int i=0;i<this->size;i++){
			cout << temp_node->data << " ";
			temp_node = temp_node->next;
		}
		cout << endl;
	}

	T pop(){
		if(this->size == 0){
			cout << "queue is empty, can't pop" << endl;
			return '\0';
		}
		if(this->size == 1){
			T data = this->head->data;
			this->head = NULL;
			this->size = 0;
			return data;
		}
		ll_node<T> *new_node = this->head;
		// move to second last element
		for(int i=0;i<this->size-2;i++) new_node = new_node->next;
		//cout << new_node->data << endl;
		T data = new_node->next->data;
		new_node->next = NULL;
		this->size--;
		return data;
	}

	T peek(){
		return this->head->data;
	}
};

template<class T>
int get_size(queuemp<T> *s){
	return s->size;
}


================================================
FILE: Data Structures/Java/Stack/Stack.java
================================================
import java.lang.IndexOutOfBoundsException;
import java.util.Arrays;

public class Stack<E> {
    private int max;
    private int top;
    private Object[] list;

    public Stack() {
        max = 512;
        top = 0;
        list = new Object[max];
    }

    public Stack(int size) {
        max = size;
        top = 0;
        list = new Object[max];
    }

    @SuppressWarnings("unchecked")
    public boolean isEmpty() {
        for(E t : (E[]) list) {
            if(t != null) {
                return false;
            }
        }

        return true;
    }

    @SuppressWarnings("unchecked")
    public E peek() {
        return (E) list[top];
    }

    @SuppressWarnings("unchecked")
    public int size() {
        if(top == 0) {
            return 0;
        }

        int count = 0;
        for(E t : (E[]) list) {
            if(t != null) {
                count++;
            }
        }

        return count;
    }

    @SuppressWarnings("unchecked")
    public E pop() {
        if(isEmpty()) {
            throw new IndexOutOfBoundsException("This stack is empty; nothing to pop.");
        }

        E data = (E) list[top];

        top = (top == 0 ? 0 : top - 1);
        return data; 
    }

    public void push(E data) {
        if(top == max - 1) {
            list = Arrays.copyOf(list, list.length * 2);
        }

        top++;
        list[top] = data;
    }
}


================================================
FILE: Data Structures/Python/Graphs/Graph.py
================================================
from collections import defaultdict


class Graph(object):


    def __init__(self, connections, directed=False):#undirected by default
        self._graph = defaultdict(set)
        self._directed = directed
        self.add_connections(connections)

    def add_connections(self, connections):
        """ Add connections (list of tuple pairs) to graph """

        for node1, node2 in connections:
            self.add(node1, node2)

    def add(self, node1, node2):
        """ Add connection between node1 and node2 """

        self._graph[node1].add(node2)
        if not self._directed:
            self._graph[node2].add(node1)

    def remove(self, node):
        """ Remove all references to node """

        for n, cxns in self._graph.iteritems():
            try:
                cxns.remove(node)
            except KeyError:
                pass
        try:
            del self._graph[node]
        except KeyError:
            pass

    def is_connected(self, node1, node2):
        """ Is node1 directly connected to node2 """

        return node1 in self._graph and node2 in self._graph[node1]

    def find_path(self, node1, node2, path=[]):
        """ Find any path between node1 and node2 (may not be shortest) """

        path = path + [node1]
        if node1 == node2:
            return path
        if node1 not in self._graph:
            return None
        for node in self._graph[node1]:
            if node not in path:
                new_path = self.find_path(node, node2, path)
                if new_path:
                    return new_path
        return None

    def __str__(self):
        return '{}({})'.format(self.__class__.__name__, dict(self._graph))


================================================
FILE: Data Structures/Python/Graphs/dfs.py
================================================
import collections

class Graph:
    def __init__(self):
        self.adjList = collections.defaultdict(set)

    def addEdge(self, node1, node2):
        self.adjList[node1].add(node2)
        self.adjList[node2].add(node1)

def dfsHelper(current, graph, visited, visitFunc):
    if (visited[current]):
        return
    
    visited[current] = True;
    
    visitFunc(current)
    
    for neighbor in graph.adjList[current]:
        dfsHelper(neighbor, graph, visited, visitFunc)
    

def dfs(current, graph, visitFunc):
    visited = collections.defaultdict(bool)
    dfsHelper(current, graph, visited, visitFunc)

def visitPrint(i):
    print(i)

# Testing the depth first search implementation
if __name__ == "__main__":

    # Testing on this tree
    #      1
    #     / \
    #    /   \
    #   2     3
    #  / \   / \
    # 4   5 6   7
    
    g = Graph()
    g.addEdge(1, 2)
    g.addEdge(1, 3)
    g.addEdge(2, 4)
    g.addEdge(2, 5)
    g.addEdge(3, 6)
    g.addEdge(3, 7)

    print("Test 1:")
    dfs(1, g, visitPrint)
    
    print("\nTest2:")
    dfs(2, g, visitPrint)


================================================
FILE: Data Structures/Python/Linked List/singly_linked_list.py
================================================
class Node(object):
 
    def __init__(self, data, next):
        self.data = data
        self.next = next
 
 
class SingleList(object):
 
    head = None
    tail = None
 
    def show(self):
        print "Showing list data:"
        current_node = self.head
        while current_node is not None:
            print current_node.data, " -> ",
            current_node = current_node.next
        print None
 
    def append(self, data):
        node = Node(data, None)
        if self.head is None:
            self.head = self.tail = node
        else:
            self.tail.next = node
        self.tail = node
 
    def remove(self, node_value):
        current_node = self.head
        previous_node = None
        while current_node is not None:
            if current_node.data == node_value:
                # if this is the first node (head)
                if previous_node is not None:
                    previous_node.next = current_node.next
                else:
                    self.head = current_node.next
 
            # needed for the next iteration
            previous_node = current_node
            current_node = current_node.next
 
 
s = SingleList()
s.append(31)
s.append(2)
s.append(3)
s.append(4)
 
s.show()
s.remove(31)
s.remove(3)
s.remove(2)
s.show()


================================================
FILE: Data Structures/Python/Queue/Queue.py
================================================
#List Based Implementation Of Queue in Python.


#Defining a python Class named Queue.

# isEmpty -> Returns True or False.
# enqueue -> Enter the element in Queue.
# dequeue -> Remove the element from Queue.
# size    -> Returns the size of Queue

class Queue:
	
   def __init__(self):
	    self.items = []
	
   def isEmpty(self):
	    return self.items == []
	
   def enqueue(self, item):
	    self.items.insert(0,item)
	
   def dequeue(self):
        return self.items.pop()
	
   def size(self):
        return len(self.items)
	

q=Queue()
#Create an object of Class Queue
#Calling the functions

q.enqueue(4)
q.enqueue('dog')
q.enqueue(True)
print(q.size())


================================================
FILE: Data Structures/Python/Stack/stack.py
================================================

#Make a class Stack
class Stack:
   def __init__(self):
	         self.items = []
	
	  def isEmpty(self):
	         return self.items == []
	
    def push(self, item):
	         self.items.insert(0,item)
	
	   def pop(self):
	         return self.items.pop(0)
	
     def peek(self):
	         return self.items[0]
           
      def size(self):
	         return len(self.items)
	
	#Calling Object of class Stack
  s = Stack()
	
  #Calling the function
  s.push('hello')
	s.push('true')
	print(s.pop())


================================================
FILE: Data Structures/Python/Trees/m-coloring-problem.py
================================================
class Graph:
    def __init__(self,m,v):
        self.adj=m
        self.V=v

def mColoring(k,m,g,x):

    while(True):
        
        x[k]=getNodeColor(k,m,g,x)
        if(x[k]==0):
            return
        if(k==g.V-1):
            print(x) 
        else:
            mColoring(k+1,m,g,x)
    
def getNodeColor(k,m,g,x):

    while(True):
        
        x[k]=(x[k]+1)%(m+1)   #bcoz any vertex should be assigned from 1 to m
        
        if(x[k]==0):
            return x[k]

        #checking for any collisions of color
        for j in range(g.V):
            if(g.adj[k][j]==1 and x[k]==x[j]):   #same color
                break
        else:
            return x[k]
            
        


def main():
    matrix=[[0,1,1,1],
            [1,0,1,0],
            [1,1,0,1],
            [1,0,1,0] ]
    g=Graph(matrix,4)

    m=3  #Number of colors
    x=[0 for i in range(g.V)]
    mColoring(0,m,g,x)

if __name__=='__main__':
    main()


'''
Possible Coloring:
[1, 2, 3, 2]
[1, 3, 2, 3]
[2, 1, 3, 1]
[2, 3, 1, 3]
[3, 1, 2, 1]
[3, 2, 1, 2]
'''


================================================
FILE: Dynamic Programing/Dynamic_fibonacci.py
================================================
# Function for nth fibonacci number - Dynamic Programing
# Taking 1st two fibonacci nubers as 0 and 1
 
FibArray = [0,1]
 
def fibonacci(n):
    if n<0:
        print("Incorrect input")
    elif n<=len(FibArray):
        return FibArray[n-1]
    else:
        temp_fib = fibonacci(n-1)+fibonacci(n-2)
        FibArray.append(temp_fib)
        return temp_fib
 
# Driver Program
#Suppose we wan't to print the 9th fibonacci number
#You can ask for user input and substitute in place of 9

print(fibonacci(9))


================================================
FILE: Dynamic Programing/Edit Distance.Py
================================================
memo={}

def DP(x,y,i,j):
    if i>=len(x):
        memo[(i,j)]=len(y)-j
        return len(y)-j
    if j>=len(y):
        memo[(i,j)]=len(x)-i
        return len(x)-i
    if (i,j) in memo:
        return memo[(i,j)]
    if x[i]==y[j]:
        memo[(i,j)]=min(DP(x,y,i,j+1),DP(x,y,i+1,j),DP(x,y,i+1,j+1))
        return memo[(i,j)]
    else:
        res=1+min(DP(x,y,i,j+1),DP(x,y,i+1,j),DP(x,y,i+1,j+1))
        memo[(i,j)]=res
        return res


'''Driver PRogram'''
x='MICHAELANGELO'
y='HIEROGLYPHOLOGY'
s1='a'
s2='ab'
r=DP(x,y,0,0)
print(r)


================================================
FILE: Dynamic Programing/Knapsack.py
================================================
######'''Knapsack problem'''#####

memo={}
included={}
def DP(val,s,i,x):
    if i==len(val) or x==0:
        return 0
    if i in memo:
        return memo[(i,x)]
    #Not Possible to be added
    if s[i]>x:
        memo[(i,x)]=DP(val,s,i+1,x)
        included[i]=0
        return memo[(i,x)]
    else:
        #Not Added
        if DP(val,s,i+1,x)>val[i]+DP(val,s,i+1,x-s[i]):
            memo[(i,x)]=DP(val,s,i+1,x)
            included[i]=0
        #Added
        else:
            memo[(i,x)]=val[i]+DP(val,s,i+1,x-s[i])
            included[i]=1
        return memo[(i,x)]
        

'''Driver Program'''
val=[4,10,2]
s=[12,4,2]
size=15
value=DP(val,s,0,size)
print('Maximum Value:',value)
print('Subset:',end=' ')
for i in included:
    if included[i]:
        print(val[i],end=' ')


================================================
FILE: Dynamic Programing/Memoized Cut Rod.Py
================================================
import math
memo={}
piece={}

def cut_rod(p,n):
    if n==0:
        return 0
    if n in memo:
        return memo[n]
    else:
        q=-1
        for i in range(1,n+1):
            #q=max(q,p[i]+cut_rod(p,n-i))
            if q<p[i]+cut_rod(p,n-i):
                q=p[i]+cut_rod(p,n-i)
                piece[n]=i
        memo[n]=q
        return q
        
'''Driver Program'''
p={1:1,2:5,3:8,4:9,5:10,6:17,7:17,8:20,9:24,10:30}
n=5
cut_rod(p,n)

while(n>0):
    print (piece[n])
    n-=piece[n]


================================================
FILE: Dynamic Programing/Word_Wrap.Py
================================================
import math
memo={}
parent={}
def badness(i,j,m):
    totsize=0
    extra=0
    for x in range(i,j):
        totsize+=len(ls[x])
        extra+=1
    totsize+=extra-1
    if m>=totsize:
        return ((m-totsize)**3)
    else:
        return math.inf

def minimum(i,ls,w,n):
    p=[]
    for j in range(i+1,n+1):
        p+=[DP(j,ls,w,n)+badness(i,j,w)]
    parent[i]=p.index(min(p))+i+1
    return min(p)

def DP(i,ls,w,n):
    if i in memo:
        return memo[i]
    if i==n:
        parent[n]=None
        return 0
    else:
        #t= min(DP(j,ls,w,n)+badness(i,j,w) for j in range(i+1,n+1))
        t=minimum(i,ls,w,n)
        memo[i]=t
        return t

'''Driver Code'''

s='aaa bb cc ddddd'
ls=s.split()
print('Sample Text:',s)
words=len(ls)
width=6
DP(0,ls,width,words)

#printing text

p=0
while parent[p]!=None:
    print(*ls[p:parent[p]])
    p=parent[p]


================================================
FILE: Dynamic Programing/longest_increasing_subsequence.cpp
================================================
#include <iostream>
using namespace std;
int longestIncreasingSubsequence(int A[],int size){
    int dp[size];
    for(int i=0;i<size;i++) dp[i] = 1;
    for(int i=1;i<size;i++){
        for(int j=0;j<i;j++){
            if(A[j]<A[i]){
                dp[i] = max(dp[i],dp[j]+1);
            }
        }
    }
    int lis = 0;
    for(int i=0;i<size;i++) {
    	lis = max(lis,dp[i]);
    }
    
    return lis;
}
int main() {
	
	int A[] = {1,3,5,9,8};
	cout<<longestIncreasingSubsequence(A,5);
	return 0;
}


================================================
FILE: Mathematical Challenges/C:C++/Fibonacci/Fibonacci Test.cpp
================================================
/*
This code illustrates an easier and faster way to check whether a number is
a Fibonacci Number or not.
*/
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
    int num;                                //Number to be tested
    float chk;
    for (num = 1; num < 100 ; num++)
    {
        chk = sqrt(5*pow(num,2) + 4);
        if(chk - (int)chk == 0)
            cout<<num<<endl;
        chk = sqrt(5*pow(num,2) - 4);
        if(chk - (int)chk == 0)
            cout<<num<<endl;
    }
    return 0;
}


================================================
FILE: Mathematical Challenges/C:C++/Square Root Decomposition/MO's Algorithm/MOAlgo.cpp
================================================
//Problem : http://www.spoj.com/problems/DQUERY/
//Time Complexity : O((n+q)*sqrt(n))

#include <bits/stdc++.h>
 
#define ll long long int
#define mod 1000000007
#define show(a) for(i=0;i<a.size();i++) cout<<a[i]<<" ";
#define fi first
#define se second
#define vi vector<int>
#define vs vector<string>
#define vll vector<long long int>
#define pb push_back
#define pi pair<int,int>
#define si set<int>
#define sll set<ll>
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
#define mp make_pair
#define fast_io() cin.sync_with_stdio(false);cout.sync_with_stdio(false);
#define long_zero 0ll
#define long_one 1ll
inline int sbt(int x){return __builtin_popcount(x);}
using namespace std;
int freq[1111111];
int BLOCK;
//Mo Sorting
bool f(pair<int,pi> a, pair<int,pi> b){
    if(a.se.fi/BLOCK == b.se.fi/BLOCK)
        return a.se.se>b.se.se;
    return a.se.fi/BLOCK>b.se.fi/BLOCK;
}
int main() {
    //fast_io()
    int n;
    scanf("%d",&n);
    int a[n+3];
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    int l,r,s=0,e=0;
    int Q;
    vector<pair<int,pi>>q;
    scanf("%d",&Q);
    //block size:SQRT(N)
    BLOCK = floor(sqrt(1.0*double(n)));
    for(int i=0;i<Q;i++){
        scanf("%d%d",&l,&r);
        q.pb(mp(i,mp(l-1,r-1)));
    }
    int v[Q+4],ans=0;
    sort(q.begin(),q.end(),f);  //f is comparator
	for(int i=0;i<Q;i++){
	    l=q[i].se.fi;
	    r=q[i].se.se;
	    while(s<l){
	        freq[a[s]]--;
	        if(!freq[a[s]])
	            ans--;
	        s++;
	    }
	    while(s>l){
	        freq[a[s-1]]++;
	        if(freq[a[s-1]]==1)
	            ans++;
	        s--;
	    }
	    while(e<=r){
	        freq[a[e]]++; // mantains frequency
	        if(freq[a[e]]==1)
	            ans++;
	        e++;
	    }
	    while(e>r+1){
	        freq[a[e-1]]--;
	        if(freq[a[e-1]]==0)
	            ans--;
	        e--;
	    }
	    v[q[i].fi]=ans;
	}
	for(int i=0;i<Q;i++)
	    printf("%d\n",v[i]);
	return 0;
}


================================================
FILE: Mathematical Challenges/C:C++/armstrong_number/C/armstrong.c
================================================
#include<stdio.h>
#include<math.h>

int main(void)
{
	int n,r,a=0,t,c=0,z;
	printf("Enter a number: ");
	scanf("%d",&n);
	t=n; z=n;
	while(z>0)
    {
       z=z/10;
       c++;
    }
	while(n>0)
    {
        r=n%10;
        a=a+pow(r,c);
        n=n/10;
    }
    if(a==t)
        printf("\nThe number is armstrong\n");
    else printf("\nThe number is not armstrong\n");
    return 0;
}


================================================
FILE: Mathematical Challenges/C:C++/armstrong_number/README.md
================================================
### Armstrong number

Given a number x, determine whether the given number is Armstrong number or not. A positive integer of n digits is called an Armstrong number of order n (order is number of digits) if :

>**abcd... = pow(a,n) + pow(b,n) + pow(c,n) + pow(d,n) + ....**

#### Example:

Input : 1634 <br/>
Output : The number is armstrong <br/>
1<sup>4</sup> + 6<sup>4</sup> + 3<sup>4</sup> + 4<sup>4</sup> = 1634


================================================
FILE: Mathematical Challenges/C:C++/convexHull/ConvexHullScan.cpp
================================================
#include <iostream>
#include <vector>
#include <set>
#include <utility>
#include <algorithm>

using namespace std;

//This function decides if 3 points form a right turn or not
bool Is_Right_Turn(vector <pair<int,int>> Hull){
	pair <int,int> P1, P2, P3;
	int Determinant;

	//P1, P2 and P3 are the last 3 points in the given Hull
	P1 = Hull[Hull.size() - 3];
	P2 = Hull[Hull.size() - 2];
	P3 = Hull[Hull.size() - 1];

	/*Cross Product is given by the determinant of the following 3x3 matrix - 
	1    P1.x    P1.y
	1    P2.x    P2.y
    1    P3.x    P3.y
	*/
	Determinant = ((P2.first - P1.first) * (P3.second - P1.second) - (P2.second - P1.second) * (P3.first - P1.first));

	//Points form right turn only if the determinant is less than 0 (Equal to zero means colinear)
	return (Determinant < 0);
}


int main(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
	#endif

	int Number_of_Points, X, Y, i;

	vector <pair<int,int>> Points, Upper_Hull, Lower_Hull;

	set <pair <int,int>> Convex_Hull;

	cin>>Number_of_Points;

	//Enter the points as (X,Y) coordinates
	for(i = 0; i < Number_of_Points; i++){
		cin>>X>>Y;
		Points.push_back(make_pair(X,Y));
	}

	//Sort the points first by X coordinate and then by Y coordinate
	sort(Points.begin(),Points.end());

	//Form the upper half of convex hull
	Upper_Hull.push_back(Points[0]);
	Upper_Hull.push_back(Points[1]);

	for(i = 2; i < Number_of_Points; i++){
		Upper_Hull.push_back(Points[i]);
		while(Upper_Hull.size() >= 3){
			if(Is_Right_Turn(Upper_Hull))
				break;
			else
				//Remove the middle point from the hull
				Upper_Hull.erase(Upper_Hull.end() - 2);
		}
	}

	//Form the lower half of the hull
	Lower_Hull.push_back(Points[Number_of_Points - 1]);
	Lower_Hull.push_back(Points[Number_of_Points - 2]);

	for(i = Number_of_Points-3; i>= 0; i--){
		Lower_Hull.push_back(Points[i]);
		while(Lower_Hull.size() >= 3){
			if(Is_Right_Turn(Lower_Hull))
				break;
			else
				//Remove the middle point from the hull
				Lower_Hull.erase(Lower_Hull.end() - 2);
		}
	}

	//Merge the Upper and Lower Hulls
	for(auto &upper:Upper_Hull)
		Convex_Hull.insert(upper);
	for(auto &lower:Lower_Hull)
		Convex_Hull.insert(lower);

	//Print the Convex Hull
	for(auto &point:Convex_Hull)
		cout<<"("<<point.first<<", "<<point.second<<")\n";

	return 0;

}


================================================
FILE: Mathematical Challenges/C:C++/factorial/factorial.c
================================================
#include<stdio.h>
int main(){
int x;
printf("Enter the number");
scanf("%d",&x);

int fact=1;

for(fact=1;x>1;x--){
fact=fact*x;
}
printf("%d",fact);
return 0;




}


================================================
FILE: Mathematical Challenges/C:C++/fibbinacci/fibbinacci.c
================================================

#include<stdio.h>
int main(){
int x,y,z;
printf("Enter the number\n");
scanf("%d",&x);

int temp=0;
for(int i=0;i<=x;i++){
temp+=i;


}
printf("%d",temp);


return 0;


}


================================================
FILE: Mathematical Challenges/C:C++/gcd/extended_gcd.cpp
================================================
#include<bits/stdc++.h>

#define F0(i,t) for(int i=0; i<t; i++)
#define F1(i,t) for(int i=1; i<=t; i++)
#define Si(x) scanf("%d",&x)
#define Si2(x,y) scanf("%d %d",&x,&y)
#define Sl(x) scanf("%lld",&x)
#define Sl2(x,y) scanf("%lld %lld",&x,&y)
#define dout if(debugg)cout<<" "

   /* * * * * * * * * * * * * * * * * * * * * * * *
    *                                             *
    *            _/_/_/            _/             *
    *         _/        _/  _/_/  _/_/_/          *
    *          _/_/    _/_/      _/    _/         *
    *             _/  _/        _/    _/          *
    *      _/_/_/    _/        _/_/_/             * 
    *                                             *
    * * * * * * * * * * * * * * * * * * * * * * * */

using namespace std;

typedef unsigned long long int ulli;
typedef unsigned int ui;
typedef pair<int,int> mp;

int debugg = 0;

struct Res_gcd{
    int gcd,x,y;
    Res_gcd(int gcd, int x, int y){
        this -> gcd = gcd;
        this -> x   = x;
        this -> y   = y;
    }
};
/*
 * return object of Res_gcd
 * Res_gcd.gcd ==> gcd of a,b
 * Res_gcd.x and Res_gcd.y ==> x and y such that ax + by = gcd(a,b)
 * NOTE : a must not be 0 ==> if so ans is b,0,1 
 */
Res_gcd gcd_extended(int a,int b){
    if(b%a==0)
        return Res_gcd(a,1,0);    //coz 1*a + 0*b = a { == gcd(a,b)}

    Res_gcd temp = gcd_extended(b%a,a);
    return Res_gcd( temp.gcd , temp.y - (b/a)*temp.x , temp.x );
}

int main(){
	int t=1;
    ios_base::sync_with_stdio(0);cin.tie(0);
    Res_gcd ans(1,1,1);
	cin>>t;
	while(t--){
        int a,b;
        cin>>a>>b;
        if(a==0)//fxn throw divide by 0 exception on a = 0
            ans = Res_gcd(b,0,1);
        else
            ans = gcd_extended(a,b);
        cout<<ans.gcd<<" "<<ans.x<<" "<<ans.y<<endl;
	}
}
// a code by srbcheema1


================================================
FILE: Mathematical Challenges/C:C++/gcd/gcd.cpp
================================================
#include<stdio.h>

/*
 * be careful a must not be zero
 * if so then ans is b
 */
int gcd(int a,int b){
    if(b%a==0)
        return a;
    return gcd(b%a,a);
}

int main()
{
	int t=1,a,b,ans;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d %d",&a,&b);
		if(a==0)//gcd throw exception on a = 0
	        ans = b;
	    else ans=gcd(a,b);
		printf("%d\n",ans);
	}
	return 0;
}


================================================
FILE: Mathematical Challenges/C:C++/gcd/mod_inverse.cpp
================================================
#include<bits/stdc++.h>

#define F0(i,t) for(int i=0; i<t; i++)
#define F1(i,t) for(int i=1; i<=t; i++)
#define Si(x) scanf("%d",&x)
#define Si2(x,y) scanf("%d %d",&x,&y)
#define Sl(x) scanf("%lld",&x)
#define Sl2(x,y) scanf("%lld %lld",&x,&y)
#define dout if(debugg)cout<<" "

   /* * * * * * * * * * * * * * * * * * * * * * * *
    *                                             *
    *            _/_/_/            _/             *
    *         _/        _/  _/_/  _/_/_/          *
    *          _/_/    _/_/      _/    _/         *
    *             _/  _/        _/    _/          *
    *      _/_/_/    _/        _/_/_/             * 
    *                                             *
    * * * * * * * * * * * * * * * * * * * * * * * */

using namespace std;

typedef unsigned long long int ulli;
typedef unsigned int ui;
typedef pair<int,int> mp;

int debugg = 0;

struct Res_gcd{
    int gcd,x,y;
    Res_gcd(int gcd, int x, int y){
        this -> gcd = gcd;
        this -> x   = x;
        this -> y   = y;
    }
};
/*
 * return object of Res_gcd
 * Res_gcd.gcd ==> gcd of a,b
 * Res_gcd.x and Res_gcd.y ==> x and y such that ax + by = gcd(a,b)
 * NOTE : a must not be 0 ==> if so ans is b,0,1 
 */
Res_gcd gcd_extended(int a,int b){
    if(b%a==0)
        return Res_gcd(a,1,0);    //coz 1*a + 0*b = a { == gcd(a,b)}

    Res_gcd temp = gcd_extended(b%a,a);
    return Res_gcd( temp.gcd , temp.y - (b/a)*temp.x , temp.x );
}

/*
 * i created this function because in cpp
 * -1%7 give -1 not 6
 *  this fxn give +ve values for even -ve values of num
 */
int modd(int num,int m){
    return (num%m + m)%m;
}
/*
 *
 */
int mod_inverse(int a,int m){
    Res_gcd temp = gcd_extended(a,m);
    if(temp.gcd != 1)
        return -1;
    else{
        return modd(temp.gcd,m);
    }
}

int main(){
	int t=1;
    ios_base::sync_with_stdio(0);cin.tie(0);
    Res_gcd ans(1,1,1);
	cin>>t;
	while(t--){
        int a,m;
        cin>>a>>m;
        cout<<mod_inverse(a,m)<<endl;
	}
}
// a code by srbcheema1


================================================
FILE: Mathematical Challenges/C:C++/largestoutof3/largestoutof3.c
================================================
#include<stdio.h>
int main(){
int x,y,z;
printf("Enter 1st number");
scanf("%d",&x);

printf("Enter 2nd number");
scanf("%d",&y);

printf("Enter 3rd number");
scanf("%d",&z);
int big=(x>y)?((x>z)?x:z):(y>z)?y:z;
printf("%d",big);
}


================================================
FILE: Mathematical Challenges/C:C++/mathpuzzle.c/matchstick game
================================================
//21 matchstick game in C
#include <stdio.h>
int main (int argc, const char * argv[])
{
    int matchstick = 21;
    int user,computer;
   
    while (matchstick>=1)
    {
       
        if (matchstick==1)
        {
            printf("\nMatch stick status:%d",matchstick);
            printf("\nYou loose!!!!!!:(:(");             
              break;
        }
       
        printf("\nMatch stick status:%d",matchstick);       
        printf("\nEnter the choice (1,2,3,4)):");       
         scanf("%d",&user);
       
        printf("\nYou picked %d",user);       
        if (user>=5 || user <=0)
        {
            printf("\nInvalid value");            continue;
        }
       
        computer = 5 - user;
       
        printf("\nComputer picked%d",computer);       
        matchstick = matchstick - computer - user;
       
    }
    return 0;
}


================================================
FILE: Mathematical Challenges/C:C++/multiplication/multiply 2 numbers greater than 10^6.cpp
================================================
/*
This program can be used to multiply 2 numbers grater than 10^5, usually a major hurdle in languages like C/C++
in competitive programming, using this as a template one can perform implementations like Factorials of 100 etc
*/

#include <iostream>
using namespace std;
int main()
	{
		ios_base::sync_with_stdio(false);
		int n1, n2;
		cin>>n1>>n2;
		int c = 0, ans[100000] = {0}, i = 0, basei = 0, temp = n2, dig = 0, tmp;
		while(n1)
		    {
		        if(n2)
		            {
		                c = ( (n1%10)*(n2%10) );
		                ans[i] += c;
		                if(ans[i]>9)
		                    {
		                        ans[i+1] += ans[i]/10;
		                        ans[i] = ans[i]%10;
		                    }
		                c /= 10;
		                n2 /= 10;
		                dig++;
		                i++;
		            }
                else
                    {
                        tmp = dig;
                        n2 = temp;
                        n1 /= 10;
                        i = ++basei;
                        c=0;
                        dig = basei;
                    }
		    }
        for(int k = tmp-1 ;k>=0;k--)
            cout<<ans[k];
		return 0;
}


================================================
FILE: Mathematical Challenges/C:C++/power/modular_exponention.cpp
================================================
#include<bits/stdc++.h>
#define ui unsigned long long int
#define mod 1000000007
using namespace std;

//faster wayy to calc (b^p)%mod in log(p) 
//it is fast as it dont use recursion
ui modular_expo_no_rec(int base,int p){
    ui ans = 1,fact = base;
    while(p){
        if(p & 1)
            ans = (ans * fact)%mod;
        fact = (fact * fact)%mod;
        p = p>>1;
    }
    return ans%mod;
}

//return (b^p)%mod in log(p)
ui modular_expo_rec(ui b,ui p){
    if(p==1) return b;
    
    ui temp = modular_expo_rec(b,p/2);
    temp = (temp*temp)%mod;
    
    if(p & 1)//odd
        return (temp * b)%mod;
    else return temp;
}

int main(){
    int t,base,pow;
    ui ans;
    cin>>t;
    while(t--){
        cin>>base>>pow;
        cout<<modular_expo_no_rec(base,pow)<<endl;
    }
}


================================================
FILE: Mathematical Challenges/C:C++/power/ques/summation.cpp
================================================
//http://www.spoj.com/problems/SUMMATION/
#include<bits/stdc++.h>
#define ui unsigned long long int
#define mod 100000007

using namespace std;

ui two_pow(int n){
    ui ans = 1,fact = 2;
    while(n){
        if(n & 1)
            ans = (ans * fact)%mod;
        fact = (fact * fact)%mod;
        n = n>>1;
    }
    return ans%mod;
}

//return b^p
ui modular_expo(ui b,ui p){
    if(p==1) return b;
    if(p & 1)
        return ((modular_expo(b,p/2)*modular_expo(b,p/2))%mod * b)%mod;
    else return (modular_expo(b,p/2)*modular_expo(b,p/2))%mod;
}

int main(){
    int t,n;
    ui ans=0,pow,sum,a;
    cin>>t;
    for (int i=1;i<=t;i++){
        sum=0;
        cin>>n;
        pow = modular_expo(2,n-1);
        while(n--){
            cin>>a;
            sum+=a;
        }
        sum=sum%mod;
        ans = (sum*pow)%mod;
        cout<<"Case "<<i<<": "<<ans<<endl;
    }
}


================================================
FILE: Mathematical Challenges/C:C++/power/two_pow.cpp
================================================
#include<bits/stdc++.h>

#define F0(i,t) for(int i=0; i<t; i++)
#define F1(i,t) for(int i=1; i<=t; i++)
#define Si(x) scanf("%d",&x)
#define Si2(x,y) scanf("%d %d",&x,&y)
#define Sl(x) scanf("%lld",&x)
#define Sl2(x,y) scanf("%lld %lld",&x,&y)
#define dout if(debugg)cout<<" "

   /* * * * * * * * * * * * * * * * * * * * * * * *
    *                                             *
    *            _/_/_/            _/             *
    *         _/        _/  _/_/  _/_/_/          *
    *          _/_/    _/_/      _/    _/         *
    *             _/  _/        _/    _/          *
    *      _/_/_/    _/        _/_/_/             * 
    *                                             *
    * * * * * * * * * * * * * * * * * * * * * * * */

using namespace std;

typedef unsigned long long int ulli;
typedef unsigned int ui;
typedef pair<int,int> mp;

int debugg = 0;

int two_pow(int p){
    int ans = 1,fact =2;
    while(p){
        if( p&1 )//p is odd
            ans = ans * fact;
        fact = fact * fact;
        p = p>>1;
    } 
    return ans;
}

int main(){
	int t=1;
    ios_base::sync_with_stdio(0);cin.tie(0);
	cin>>t;
	while(t--){
        int p;
        cin>>p;
        cout<<two_pow(p)<<endl;
	}
}
// a code by srbcheema1


================================================
FILE: Mathematical Challenges/C:C++/powerset/PowerSet.java
================================================
import java.util.*;
public class PowerSet {
    
        public static <T> Set<Set<T>> powerSet( Set<T> set ) {
            T[] element = (T[]) set.toArray();
            final int SET_LENGTH = 1 << element.length;
            Set<Set<T>> powerSet = new HashSet<>();
            for( int binarySet = 0; binarySet < SET_LENGTH; binarySet++ ) {
                Set<T> subset = new HashSet<>();
                for( int bit = 0; bit < element.length; bit++ ) {
                    int mask = 1 << bit;
                    if( (binarySet & mask) != 0 ) {
                        subset.add( element[bit] );
                    }
                }
                powerSet.add( subset );
            }
            return powerSet;
        }
    
        public static void main(String[] args) {
            Set<Character> test = new HashSet<>();
            test.add( 'a' );
            test.add( 'b' );
            test.add( 'c' );
            System.out.println("test = " + test);
            Set<Set<Character>> result = powerSet( test );
            System.out.println( result );
        }
    }

================================================
FILE: Mathematical Challenges/C:C++/prime/PrimeCheck.py
================================================
#Simple way to check for primes using Pyton.

#Prompt user for a integer
Number = int(input("Enter any integer to check if prime number "))
#Set starting divisor to 2
Divisor = 2
for Divisor in range (Divisor, Number) : #Test every number between 2 and the integer
        if Number % Divisor == 0:
            prime = False # Tell computer to make prime false
            break #End loop
        Divisor += 1 #Add 1 to the divisor
            
else:
    prime = True # If number % divisor does not equal 0, number must be a prime, so mark as true
#Print results
if prime == True :
    print("Your number is a prime")
if prime == False :
    print("Your number is not a prime")


================================================
FILE: Mathematical Challenges/C:C++/prime/PrimeToNumber.py
================================================
#Python Prime checker. Not the most efficient way to check for primes, but very easy to code!

num = int(input("Enter a integer to get primes up to ")) #Get highest number for prime
div=2 #Set divisor to intitally 2
for num in range(2,num): #Check if prime
    prime = True #If prime is true set flag.
    for div in range(2,num): #If number can be divided by any number, from 2 to the number-1
        if (num % div == 0):#If evenly divided, the number will therefore be notprime.
            prime = False #set prime to false
    if prime: 
       print (num)


================================================
FILE: Mathematical Challenges/C:C++/prime/prime.c
================================================
#include<stdio.h>
int main(){
int x,y,z;
printf("Enter the number\n");
scanf("%d",&x);
y=x/2;
if(x%2==0 && x!=2){
printf("It is not a  prime\n");
}

else{
for(z=3;z<=y;z++)
{

if(x%z==0){
printf("it is not a prime number ");
}
else{
printf("it is a  prime");
break;
}

}





return 0;


}


================================================
FILE: Mathematical Challenges/C:C++/prime/sieveOferatosthenes.cpp
================================================
#include <iostream>
#include <vector>
using namespace std;
void sieve_of_eratosthenes(std::vector<int>& primes, const int max) {
	vector<bool> isPrime;
	// Initially, all the numbers are considered to be prime
	for (int i = 0; i <= max; i++) {
		isPrime.push_back(true);
	}
	// 0 and 1 are obviously not prime, so we set it in the isPrime vector
	isPrime[0] = isPrime[1] = false;

	// Iterate from 2 up to the square root of max
	for (int i = 2; i*i <= max; i++) {
		if (isPrime[i]) {
			// If the current number is prime, then set i^2, i^2+i, i^2+2i, ... as not prime
			for (int j = i * i; j <= max; j += i) {
				isPrime[j] = false;
			}
		}
	}

	// Iterate from 2 to max again. All the numbers, that are still set to true, are prime
	for (int i = 2; i <= max; i++) {
		if (isPrime[i]) {
			primes.push_back(i);
		}
	}
}

int main() {
	int n = 100;
	vector<int> primes;
	// Find primes up to n
	sieve_of_eratosthenes(primes, n);
	cout << "Primes up to "<<n<<" are:"<<endl;
	for (auto prime : primes) {
		cout << prime << " ";
	}
	return 0;
}


================================================
FILE: Mathematical Challenges/C:C++/prime number tricks/List all primes.cpp
================================================
/*
This code illustrates that all primes are of the form (6k +- 1)
Please note this also includes some non-prime numbers such as 25 (6*4 + 1)
But ALL primes greater than 2 and 3 are included in this form and the non-primes
can be weeded out with a simple IF statement.
If the user needs to operate on (lets say 100) primes, instead of doing primality test on
all 1 to 100 numbers it will only have to test on 34 numbers.
*/

#include
Download .txt
gitextract_r3ies5y1/

├── .gitignore
├── BST/
│   ├── BinarySearchTree.java
│   ├── Delete.c
│   ├── Height.c
│   ├── Insert & Search.cpp
│   ├── MinMax_8.c
│   ├── checkbst
│   ├── createBST.cpp
│   ├── lca.cpp
│   └── spiraltransversal.c
├── Backtrack/
│   ├── NQueen.cpp
│   ├── Rat_Maze_Recurssion_Backtracking.c
│   ├── nqueen_allsol.py
│   └── permutations_of_string.cpp
├── CONTRIBUTING.md
├── Competitive Programming Challenges/
│   └── C:C++/
│       ├── HackerEarth:CodeForces/
│       │   ├── buy_max_with_given_money.cpp
│       │   ├── median searching efficientalgo.cpp
│       │   ├── ques/
│       │   │   └── volcano.cpp
│       │   ├── ques-beat_the_clock/
│       │   │   └── spiral_matrix.cpp
│       │   ├── ques-l1/
│       │   │   ├── codeforces_426_2.cpp
│       │   │   ├── positions.cpp
│       │   │   └── snake/
│       │   │       ├── snake.cpp
│       │   │       └── wrong_snake.cpp
│       │   └── searchmat.cpp
│       └── Patterns/
│           ├── pattern1.cpp
│           ├── pattern2.cpp
│           ├── pattern3.cpp
│           ├── pattern4.cpp
│           ├── pattern6.cpp
│           └── pattern7.cpp
├── Conversions/
│   └── C:C++/
│       └── binary2octal.c
├── Data Structures/
│   ├── C:C++/
│   │   ├── Applications/
│   │   │   ├── Evaluating Postfix Expression.c
│   │   │   ├── Infix to Postfix.c
│   │   │   ├── balance parenthesis.cpp
│   │   │   └── stack_and_its_implementation.c
│   │   ├── Graph/
│   │   │   ├── FloydWarshall.cpp
│   │   │   ├── adjacency_list.hpp
│   │   │   ├── adjacency_matrix.hpp
│   │   │   ├── bfs_dfs/
│   │   │   │   ├── bfs/
│   │   │   │   │   ├── BFS.java
│   │   │   │   │   └── bfs.Py
│   │   │   │   └── ques/
│   │   │   │       ├── graph_connected_components.cpp
│   │   │   │       └── tbbfs.cpp
│   │   │   ├── dijakstra/
│   │   │   │   ├── Dijkstra.java
│   │   │   │   ├── dist_from_source.cpp
│   │   │   │   ├── dist_from_source_oops.cpp
│   │   │   │   └── ques/
│   │   │   │       ├── min_path.cpp
│   │   │   │       └── qgrid_11.cpp
│   │   │   ├── shortest_paths.hpp
│   │   │   ├── topological_sort.hpp
│   │   │   └── tree/
│   │   │       └── binarySearchTree/
│   │   │           └── bsTree.cpp
│   │   ├── Linked List/
│   │   │   ├── Circular_LL.c
│   │   │   ├── Circular_ll.cpp
│   │   │   ├── Doubly LL.c
│   │   │   ├── Insertion_Deletion_SinglyLL.c
│   │   │   ├── Queue using LinkedList.cpp
│   │   │   ├── Queue_using_linkedlist.c
│   │   │   ├── Reverse_SinglyLL.c
│   │   │   ├── all_operations_of_Doubly_ll.cpp
│   │   │   ├── concatinate.c
│   │   │   ├── doubly circular.c
│   │   │   ├── doubly linked list.c
│   │   │   ├── linked_list.c
│   │   │   ├── ordered_linked.c
│   │   │   ├── reverse.cpp
│   │   │   ├── stackLinkedList.cpp
│   │   │   └── stack_Linked_List.c
│   │   ├── Stack/
│   │   │   ├── Balanced_Brackets.cpp
│   │   │   ├── Reverse_Queue.cpp
│   │   │   ├── Stack_as_linked_list.cpp
│   │   │   ├── largestRectangleHistogram.cpp
│   │   │   ├── nextgreaterelement
│   │   │   └── stack.hpp
│   │   ├── Trees/
│   │   │   ├── segment_tree/
│   │   │   │   ├── segment_tree.cpp
│   │   │   │   └── segment_trees_lazy.cpp.cpp
│   │   │   └── tree/
│   │   │       ├── Fenwick_tree.cpp
│   │   │       ├── bst.hpp
│   │   │       ├── segment_tree.hpp
│   │   │       ├── tree.hpp
│   │   │       └── trie.cpp
│   │   └── queue/
│   │       └── queue.hpp
│   ├── Java/
│   │   └── Stack/
│   │       └── Stack.java
│   └── Python/
│       ├── Graphs/
│       │   ├── Graph.py
│       │   └── dfs.py
│       ├── Linked List/
│       │   └── singly_linked_list.py
│       ├── Queue/
│       │   └── Queue.py
│       ├── Stack/
│       │   └── stack.py
│       └── Trees/
│           └── m-coloring-problem.py
├── Dynamic Programing/
│   ├── Dynamic_fibonacci.py
│   ├── Edit Distance.Py
│   ├── Knapsack.py
│   ├── Memoized Cut Rod.Py
│   ├── Word_Wrap.Py
│   └── longest_increasing_subsequence.cpp
├── Mathematical Challenges/
│   ├── C:C++/
│   │   ├── Fibonacci/
│   │   │   └── Fibonacci Test.cpp
│   │   ├── Square Root Decomposition/
│   │   │   └── MO's Algorithm/
│   │   │       └── MOAlgo.cpp
│   │   ├── armstrong_number/
│   │   │   ├── C/
│   │   │   │   └── armstrong.c
│   │   │   └── README.md
│   │   ├── convexHull/
│   │   │   └── ConvexHullScan.cpp
│   │   ├── factorial/
│   │   │   └── factorial.c
│   │   ├── fibbinacci/
│   │   │   └── fibbinacci.c
│   │   ├── gcd/
│   │   │   ├── extended_gcd.cpp
│   │   │   ├── gcd.cpp
│   │   │   └── mod_inverse.cpp
│   │   ├── largestoutof3/
│   │   │   └── largestoutof3.c
│   │   ├── mathpuzzle.c/
│   │   │   └── matchstick game
│   │   ├── multiplication/
│   │   │   └── multiply 2 numbers greater than 10^6.cpp
│   │   ├── power/
│   │   │   ├── modular_exponention.cpp
│   │   │   ├── ques/
│   │   │   │   └── summation.cpp
│   │   │   └── two_pow.cpp
│   │   ├── powerset/
│   │   │   └── PowerSet.java
│   │   ├── prime/
│   │   │   ├── PrimeCheck.py
│   │   │   ├── PrimeToNumber.py
│   │   │   ├── prime.c
│   │   │   └── sieveOferatosthenes.cpp
│   │   ├── prime number tricks/
│   │   │   └── List all primes.cpp
│   │   └── ques/
│   │       └── cpcrc1c.cpp
│   └── python/
│       ├── pernicious_prime/
│       │   └── pernicious.py
│       └── sieve_of_eratoshthenes.py
├── Patterns/
│   ├── pattern10.cpp
│   ├── pattern11.cpp
│   ├── pattern12.cpp
│   ├── pattern13.cpp
│   ├── pattern14.cpp
│   ├── pattern15.cpp
│   ├── pattern16.cpp
│   ├── pattern8.cpp
│   └── pattern9.cpp
├── README.md
├── STL C++/
│   ├── STACK_with_Application/
│   │   ├── Evaluating Postfix Expression.c
│   │   ├── Infix to Postfix.c
│   │   ├── balance parenthesis.cpp
│   │   └── stack_and_its_implementation.c
│   ├── sorting_a_vector.cpp
│   ├── stack/
│   │   ├── Stack.java
│   │   ├── largestRectangleHistogram.cpp
│   │   └── stack.hpp
│   ├── using_map.cpp
│   └── using_set.cpp
├── STRUCTURE.md
├── Searching Algorithms/
│   ├── Bogo_sort.cpp
│   ├── C:C++/
│   │   ├── Binary_Search.cpp
│   │   ├── Binary_search.cpp
│   │   ├── Interpolation Search
│   │   ├── Interpolation_search.cpp
│   │   ├── Jump_Search.cpp
│   │   ├── Liear_search.cpp
│   │   ├── MEDIAN_SEARCH.cpp
│   │   ├── Selection_sort.cpp
│   │   ├── Ternary_search.cpp
│   │   ├── b_search.cpp
│   │   ├── fibonacci_search.cpp
│   │   ├── seaching algorithms [rename]/
│   │   │   ├── binary_search.cpp
│   │   │   ├── binary_search_extras/
│   │   │   │   ├── position_in_sorted_array/
│   │   │   │   │   ├── eq_less_than.cpp
│   │   │   │   │   ├── first_occurance.cpp
│   │   │   │   │   ├── just_less_than_num.cpp
│   │   │   │   │   └── position_in_sorted_array.cpp
│   │   │   │   └── ques/
│   │   │   │       └── aggrcow.cpp
│   │   │   ├── jump_search.cpp
│   │   │   └── linear.cpp
│   │   ├── ternarySearch.cpp
│   │   └── ternary_search.c
│   ├── Java/
│   │   ├── TODO
│   │   ├── algos/
│   │   │   ├── BinarySearch.java
│   │   │   └── LinearSearch.java
│   │   └── driving.java
│   └── Python/
│       ├── binarysearch.py
│       └── bst.py
├── Segment Trees/
│   ├── ADA/
│   │   ├── README.md
│   │   └── segmentree.adb
│   ├── C++/
│   │   ├── RangeMinimumQuery.cpp
│   │   └── SumInGivenRange.cpp
│   └── Java/
│       ├── SegementTree.java
│       └── SegementTreeLazyPropagation.java
├── Sorting Algorithms/
│   ├── C:C++/
│   │   ├── Counting_Sort.cpp
│   │   ├── Insertion_sort.cpp
│   │   ├── Merge_sort.cpp
│   │   ├── QuickSort.c
│   │   ├── Quick_sort.cpp
│   │   ├── Radix_sort.cpp
│   │   ├── bubblesort.c
│   │   ├── bubblesort.cpp
│   │   ├── bucketsort.c
│   │   ├── heapSort.c
│   │   ├── insertion.hpp
│   │   ├── merge.hpp
│   │   ├── quick.hpp
│   │   ├── quick_sort.c
│   │   ├── radix.hpp
│   │   ├── selectionsort.c
│   │   ├── shell_sort.h
│   │   ├── slow.cpp
│   │   └── sorting_a_vector.cpp
│   ├── Java/
│   │   ├── Countsort.java
│   │   ├── HeapSort.java
│   │   └── MergeSort.java
│   ├── Javascript/
│   │   └── bubblesort.js
│   ├── Python/
│   │   ├── QuickSort.py
│   │   ├── bogosort.py
│   │   ├── bubblesort.py
│   │   ├── cocktailsort.py
│   │   ├── insertionsort.py
│   │   ├── mergesort.py
│   │   ├── quicksort.py
│   │   └── topological_sort.py
│   └── sleep sort.c
├── String Manipulation/
│   ├── C:C++/
│   │   ├── String_algo/
│   │   │   ├── KMP.cpp
│   │   │   ├── SUFFIX-ARRAY.cpp
│   │   │   └── z_algorithm.cpp
│   │   └── tokens/
│   │       ├── token_break.cpp
│   │       └── word_break.cpp
│   └── Python/
│       └── LCS.py
├── backtrack/
│   └── sudoku/
│       ├── code2.cpp
│       └── sudoku.cpp
├── binary_tree/
│   └── binarytree.java
├── btree.cpp
├── cryptography/
│   ├── Python/
│   │   └── porta.py
│   └── des/
│       └── java/
│           ├── Converter.java
│           ├── DES.java
│           ├── IO.java
│           └── Main.java
├── dfs.cpp
├── disjoint_set/
│   └── disjoint_set.hpp
├── divide_and_conquer/
│   ├── maximum_sub_array.cpp
│   └── strassen.cpp
├── dp/
│   ├── 0-1knapsack.cpp
│   ├── Digit_dp.cpp
│   ├── coinchange.cpp
│   ├── editDistance.cpp
│   ├── eggdropping.cpp
│   ├── kadane.cpp
│   ├── lcs.cpp
│   ├── lis.cpp
│   └── mcm.cpp
├── euler_totent_function
├── genome_sort.py
├── graph/
│   ├── Kosaraju_algorithm
│   └── bfs_dfs/
│       ├── bfs/
│       │   ├── BFS.cpp
│       │   ├── BFS.py
│       │   └── bfs.cpp
│       └── dfs/
│           ├── DFS.cpp
│           └── DFS.java
├── heap/
│   ├── heap.hpp
│   └── min_heap.cpp
├── os/
│   └── scheduling/
│       ├── fcfs.cpp
│       ├── os_priority.cpp
│       ├── os_roundrobin.cpp
│       ├── os_sjf.cpp
│       ├── os_srtf.cpp
│       └── readme.txt
├── shellsort.c
├── sieve_of_eratoshthenes.cpp
├── square_root_decomposition
└── travelling_salesman_problem
Download .txt
SYMBOL INDEX (1001 symbols across 231 files)

FILE: BST/BinarySearchTree.java
  class BinarySearchTree (line 4) | public class BinarySearchTree {
    class Node (line 7) | class Node {
      method Node (line 11) | public Node(int item) {
    method BinarySearchTree (line 21) | BinarySearchTree() {
    method insert (line 26) | void insert(int key) {
    method insertRec (line 31) | Node insertRec(Node root, int key) {
    method inorder (line 50) | void inorder()  {
    method inorderRec (line 55) | void inorderRec(Node root) {
    method preorder (line 65) | void preorder()  {
    method preorderRec (line 70) | void preorderRec(Node root) {
    method postorder (line 80) | void postorder()  {
    method postorderRec (line 85) | void postorderRec(Node root) {
  class Main (line 97) | public class Main {
    method main (line 98) | public static void main(String args[])

FILE: BST/Delete.c
  type tree (line 4) | struct tree{
  type tree (line 10) | struct tree
  type tree (line 12) | struct tree
  type tree (line 12) | struct tree
  type tree (line 19) | struct tree
  type tree (line 19) | struct tree
  function preorder (line 32) | void preorder(struct tree* n)
  function main (line 46) | void main()

FILE: BST/Height.c
  type tree (line 4) | struct tree{
  type tree (line 10) | struct tree
  type tree (line 12) | struct tree
  type tree (line 12) | struct tree
  type tree (line 12) | struct tree
  function height (line 19) | int height(struct tree* n)
  function node (line 37) | int node(struct tree* n)
  function main (line 50) | void main()

FILE: BST/Insert & Search.cpp
  type node (line 14) | struct node
    type node (line 17) | struct node
    type node (line 18) | struct node
  type node (line 21) | struct node
    type node (line 17) | struct node
    type node (line 18) | struct node
  type node (line 22) | struct node
    type node (line 17) | struct node
    type node (line 18) | struct node
  type node (line 29) | struct node
    type node (line 17) | struct node
    type node (line 18) | struct node
  type node (line 29) | struct node
    type node (line 17) | struct node
    type node (line 18) | struct node
  function search (line 44) | int search(struct node* root, int data){
  function main (line 62) | int main()

FILE: BST/MinMax_8.c
  type tree (line 3) | struct tree{
  type tree (line 8) | struct tree
  type tree (line 10) | struct tree
  type tree (line 10) | struct tree
  type tree (line 16) | struct tree
  type tree (line 16) | struct tree
  function Preo (line 27) | void Preo(struct tree* n)
  function main (line 39) | void main()

FILE: BST/createBST.cpp
  type BST (line 4) | struct BST
    type BST (line 7) | struct BST
    type BST (line 8) | struct BST
  function main (line 15) | int main()
  function node (line 38) | node *create()
  function insert (line 48) | void insert(node *root,node *temp)
  function preorder (line 67) | void preorder(node *root)

FILE: BST/lca.cpp
  type node (line 21) | struct node{
    type node (line 23) | struct node
    type node (line 24) | struct node
  type node (line 28) | struct node
    type node (line 23) | struct node
    type node (line 24) | struct node
  type node (line 29) | struct node
    type node (line 23) | struct node
    type node (line 24) | struct node
  type node (line 37) | struct node
    type node (line 23) | struct node
    type node (line 24) | struct node
  type node (line 37) | struct node
    type node (line 23) | struct node
    type node (line 24) | struct node
  function lca (line 54) | int lca(node* root, int val1, int val2){
  function main (line 72) | int main(){

FILE: BST/spiraltransversal.c
  type node (line 6) | struct node{
  type node (line 11) | struct node
  type node (line 13) | struct node
  type node (line 13) | struct node
  type node (line 17) | struct node
  type node (line 17) | struct node
  function inorder (line 34) | void inorder(struct node* rootptr)
  function printGivenLevel (line 43) | void printGivenLevel(struct node* root, int level, int ltr)
  function height (line 64) | int height(struct node* node)
  function printSpiral (line 81) | void printSpiral(struct node* root)

FILE: Backtrack/NQueen.cpp
  function isSafe (line 4) | bool isSafe(char board[][100], int row, int column, int n){
  function nqueen (line 37) | bool nqueen(char board[][100], int n, int i=0){
  function main (line 60) | int main(){

FILE: Backtrack/Rat_Maze_Recurssion_Backtracking.c
  function display (line 4) | void display(int sol[N][N])
  function issafe (line 16) | int issafe(int maze[N][N],int x,int y)
  function solvemaze (line 24) | int solvemaze(int maze[N][N],int x,int y,int sol[N][N])
  function solve (line 48) | void solve(int maze[N][N])
  function main (line 60) | void main()

FILE: Backtrack/nqueen_allsol.py
  function initialize (line 1) | def initialize(board,n):
  function placequeen (line 14) | def placequeen(r,board,n):
  function printboard (line 17) | def printboard(board,n):
  function isfree (line 22) | def isfree(i,j,board):
  function addqueen (line 25) | def addqueen(i,j,board):
  function undoqueen (line 32) | def undoqueen(i,j,board):
  function placequeen (line 39) | def placequeen(i,board,n):

FILE: Backtrack/permutations_of_string.cpp
  function swap (line 5) | void swap(char *x, char *y)
  function permute (line 18) | void permute(char *a, int l, int r)
  function main (line 34) | int main()

FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/buy_max_with_given_money.cpp
  function sort_fxn (line 30) | bool sort_fxn(mp a,mp b){
  function ulli (line 41) | ulli buyMaximumProducts(ulli n, ulli k, vector <ulli> a) {
  function main (line 59) | int main() {

FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/median searching efficientalgo.cpp
  function main (line 8) | int main()
  function median (line 26) | int median(int *a,int s,int r,int k)
  function pivot (line 69) | int pivot(int *a,int s,int r)

FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques-beat_the_clock/spiral_matrix.cpp
  function func (line 34) | vector<int> func(vector<vector<int> > vec,int m,int n){
  function main (line 73) | int main(){

FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques-l1/codeforces_426_2.cpp
  function main (line 6) | int main(){

FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques-l1/positions.cpp
  function main (line 5) | int main(){

FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques-l1/snake/snake.cpp
  function fill (line 31) | void fill(matrix& mat,int x,int y,int d,int n){
  function main (line 119) | int main(){

FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques-l1/snake/wrong_snake.cpp
  function movehu (line 31) | void movehu(matrix& mat,int x,int y,int num,int n){
  function movehd (line 59) | void movehd(matrix& mat,int x,int y,int num,int n){
  function movevl (line 87) | void movevl(matrix& mat,int x,int y,int num,int n){
  function movevr (line 115) | void movevr(matrix& mat,int x,int y,int num,int n){
  function fill (line 145) | void fill(matrix& mat,int x,int y,int d,int n){
  function main (line 164) | int main(){

FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques/volcano.cpp
  type elem (line 29) | struct elem{
    method elem (line 33) | elem(int x,int y,int w){
  function fill (line 42) | void fill(int x,int y,int w,int n,matrix& mat,matrix& filled){
  function main (line 70) | int main(){

FILE: Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/searchmat.cpp
  function main (line 5) | int main(){

FILE: Competitive Programming Challenges/C:C++/Patterns/pattern1.cpp
  function main (line 4) | int main(){

FILE: Competitive Programming Challenges/C:C++/Patterns/pattern2.cpp
  function main (line 4) | int main(){

FILE: Competitive Programming Challenges/C:C++/Patterns/pattern3.cpp
  function main (line 4) | int main(){

FILE: Competitive Programming Challenges/C:C++/Patterns/pattern4.cpp
  function main (line 4) | int main(){

FILE: Competitive Programming Challenges/C:C++/Patterns/pattern6.cpp
  function main (line 4) | int main(){

FILE: Competitive Programming Challenges/C:C++/Patterns/pattern7.cpp
  function main (line 4) | int main(){

FILE: Conversions/C:C++/binary2octal.c
  function three_digits (line 5) | int three_digits(int n)
  function main (line 19) | int main(void)

FILE: Data Structures/C:C++/Applications/Evaluating Postfix Expression.c
  function isoperator (line 5) | int isoperator(char c){
  type stack (line 9) | struct stack
  function push (line 15) | void push(double c){
  function pop (line 19) | double pop(){
  function perform (line 23) | double perform(double a, double b, char c){
  function post_infix (line 39) | void post_infix(char a[],int l){
  function main (line 58) | int main()

FILE: Data Structures/C:C++/Applications/Infix to Postfix.c
  type temp (line 4) | struct temp{
  type temp (line 8) | struct temp
  function push (line 10) | void push(char item){
  function isempty (line 14) | int isempty(){
  function pop (line 18) | char pop(){
  function isoperator (line 22) | int isoperator(char c){
  function precedence (line 26) | int precedence(char c){
  function main (line 66) | int main(){

FILE: Data Structures/C:C++/Applications/balance parenthesis.cpp
  function main (line 7) | int main(){

FILE: Data Structures/C:C++/Applications/stack_and_its_implementation.c
  type stack (line 7) | struct stack{
  type stack (line 14) | struct stack
  function push (line 17) | void push(){
  function pop (line 33) | void pop(){
  function peep (line 42) | void peep(){
  function print (line 50) | void print(){
  function main (line 64) | int main(){

FILE: Data Structures/C:C++/Graph/FloydWarshall.cpp
  function ll (line 10) | ll gcd(ll a , ll b){return a==0?b:gcd(b%a,a);}
  function main (line 12) | int main(){

FILE: Data Structures/C:C++/Graph/adjacency_list.hpp
  class graph_al (line 7) | class graph_al {
    method graph_al (line 14) | graph_al(T vertices[], int count) : count(count), visited(new bool[cou...
    method connect (line 20) | void connect(int i, int j){
    method connect_both_sides (line 24) | void connect_both_sides(int i, int j){
    method contains (line 29) | bool contains(vector<int> v, int n){
    method bfs (line 33) | bool bfs(int i, int j){
    method dfs (line 52) | void dfs(int i){
    method connected (line 62) | bool connected(int i, int j){
    method print_graph (line 66) | void print_graph(){
    method connected_components (line 78) | int connected_components(){

FILE: Data Structures/C:C++/Graph/adjacency_matrix.hpp
  class graph_am (line 6) | class graph_am {
    method graph_am (line 13) | graph_am(T vertices[], int count) : count(count), vertices(new T[count...
    method connect (line 26) | void connect(int i, int j){
    method connect_both_sides (line 30) | void connect_both_sides(int i, int j){
    method bfs (line 35) | bool bfs(int i, int j){
    method dfs (line 55) | void dfs(int i){
    method connected (line 65) | bool connected(int i, int j){
    method connected_components (line 69) | int connected_components(){

FILE: Data Structures/C:C++/Graph/bfs_dfs/bfs/BFS.java
  class BFS (line 31) | class BFS {
    method main (line 41) | public static void main(String[] args) {
    method readMatrixFromFile (line 47) | private static int[][] readMatrixFromFile() {
    method bfs (line 73) | private static List<Integer> bfs(int[][] matrix) {
    method printSolution (line 93) | private static void printSolution(List<Integer> way) {

FILE: Data Structures/C:C++/Graph/bfs_dfs/bfs/bfs.Py
  class Graph (line 8) | class Graph:
    method __init__ (line 11) | def __init__(self):
    method addEdge (line 17) | def addEdge(self,u,v):
    method BFS (line 21) | def BFS(self, s):

FILE: Data Structures/C:C++/Graph/bfs_dfs/ques/graph_connected_components.cpp
  function dfs (line 8) | void dfs(int s) {
  function initialize (line 16) | void initialize() {
  function main (line 21) | int main() {

FILE: Data Structures/C:C++/Graph/bfs_dfs/ques/tbbfs.cpp
  class Node (line 7) | class Node{
    method Node (line 12) | Node(){
    method clear (line 15) | void clear(){
  function dfs_rec (line 21) | void dfs_rec(vector<Node> &node,int a){
  function dfs (line 30) | void dfs(vector<Node> &node,int a){
  function bfs (line 41) | void bfs(vector<Node> &node,int a){
  function main (line 63) | int main(){

FILE: Data Structures/C:C++/Graph/dijakstra/Dijkstra.java
  class Dijkstra (line 31) | public class Dijkstra {
    method main (line 43) | public static void main(String[] args) {
    method readMatrixFromFile (line 48) | private static int[][] readMatrixFromFile() {
    method dijkstra (line 75) | private static void dijkstra(int[][] matrix) {
    method printSolution (line 112) | private static void printSolution(int[] trip, int[] dist) {

FILE: Data Structures/C:C++/Graph/dijakstra/dist_from_source.cpp
  class Node (line 7) | class Node{
    method clear (line 12) | void clear(){
  type priority_fxn (line 18) | struct priority_fxn{
  function dijakstra (line 23) | void dijakstra(int source){
  function main (line 45) | int main(){

FILE: Data Structures/C:C++/Graph/dijakstra/dist_from_source_oops.cpp
  class Road (line 9) | class Road{
    method Road (line 15) | Road(int l,int r,int d){
  class Node (line 22) | class Node{
    method Node (line 27) | Node(){
  type priority_fxn (line 34) | struct priority_fxn{
  function dijakstra (line 45) | void dijakstra(vector<Node> &ct,int root){
  function main (line 69) | int main()

FILE: Data Structures/C:C++/Graph/dijakstra/ques/min_path.cpp
  class Node (line 11) | class Node{
    method clear (line 17) | void clear(){
    method Node (line 22) | Node(){
    method setparent (line 25) | void setparent(ulli px,ulli py){
  type priority_fxn (line 31) | struct priority_fxn{
  function dijakstra (line 36) | void dijakstra(ulli sx,ulli sy,ulli ex,ulli ey,ulli update){
  function main (line 83) | int main(){

FILE: Data Structures/C:C++/Graph/dijakstra/ques/qgrid_11.cpp
  class Node (line 8) | class Node{
    method clear (line 14) | void clear(){
    method Node (line 19) | Node(){
    method setparent (line 22) | void setparent(ulli px,ulli py){
  type priority_fxn (line 28) | struct priority_fxn{
  function update_weight (line 34) | void update_weight(ulli l,ulli r,ulli update){
  function dijakstra (line 41) | void dijakstra(ulli sx,ulli sy,ulli ex,ulli ey,ulli update){
  function main (line 86) | int main(){

FILE: Data Structures/C:C++/Graph/shortest_paths.hpp
  function unweighted_shortest_path (line 9) | pair< vector<int>, vector<int> > unweighted_shortest_path(vector< vector...

FILE: Data Structures/C:C++/Graph/topological_sort.hpp
  function _ts (line 7) | void _ts(int v, bool visited[], stack<int> *st, vector< vector<int> > gr...
  function topological_sort (line 19) | stack<int> topological_sort(vector< vector<int> > graph){

FILE: Data Structures/C:C++/Graph/tree/binarySearchTree/bsTree.cpp
  type tree (line 15) | struct tree{
  function insert (line 25) | void insert(tree *curr, tree *node){
  function tree (line 70) | tree * minValueNode( tree *curr){
  function tree (line 79) | tree* deleteNode(tree *root, int key){
  function Kpify (line 115) | int Kpify(tree *curr, int pos, int target){
  function main (line 137) | int main(){

FILE: Data Structures/C:C++/Linked List/Circular_LL.c
  type node (line 12) | struct node
  type node (line 20) | struct node
  type node (line 23) | struct node
  type node (line 33) | struct node
  type node (line 33) | struct node
  type node (line 33) | struct node
  function countNode (line 41) | int countNode(){
  function insert_beg (line 59) | void insert_beg(){
  function insert_btw (line 77) | void insert_btw(){
  function insert_end (line 102) | void insert_end(){
  function delete_beg (line 123) | void delete_beg(){
  function delete_btw (line 140) | void delete_btw(){
  function delete_end (line 167) | void delete_end(){
  function search (line 180) | void search(){
  function display (line 204) | void display(){
  function main (line 217) | int main()

FILE: Data Structures/C:C++/Linked List/Circular_ll.cpp
  type node (line 11) | struct node
    type node (line 14) | struct node
  class circular_llist (line 20) | class circular_llist
    method circular_llist (line 31) | circular_llist()
  function main (line 40) | int main()
  type node (line 128) | struct node
    type node (line 14) | struct node
  type node (line 154) | struct node
    type node (line 14) | struct node
  type node (line 171) | struct node
    type node (line 14) | struct node
  type node (line 199) | struct node
    type node (line 14) | struct node
  type node (line 247) | struct node
    type node (line 14) | struct node
  type node (line 276) | struct node
    type node (line 14) | struct node
  type node (line 307) | struct node
    type node (line 14) | struct node
  type node (line 328) | struct node
    type node (line 14) | struct node

FILE: Data Structures/C:C++/Linked List/Doubly LL.c
  type node (line 12) | struct node
  type node (line 21) | struct node
  type node (line 24) | struct node
  type node (line 34) | struct node
  type node (line 34) | struct node
  type node (line 34) | struct node
  function countNode (line 43) | int countNode(){
  function insert_beg (line 61) | void insert_beg(){
  function insert_btw (line 71) | void insert_btw(){
  function insert_end (line 96) | void insert_end(){
  function delete_beg (line 113) | void delete_beg(){
  function delete_btw (line 125) | void delete_btw(){
  function delete_end (line 167) | void delete_end(){
  function search (line 179) | void search(){
  function display (line 203) | void display(){
  function main (line 216) | int main()

FILE: Data Structures/C:C++/Linked List/Insertion_Deletion_SinglyLL.c
  type node (line 3) | struct node{
  type node (line 8) | struct node
  function Insert (line 10) | void Insert(){
  function delete (line 23) | void delete(){
  function Print (line 45) | void Print(){
  function main (line 54) | int main(){

FILE: Data Structures/C:C++/Linked List/Queue using LinkedList.cpp
  type Node (line 10) | struct Node {
    type Node (line 12) | struct Node
  type Node (line 15) | struct Node
    type Node (line 12) | struct Node
  type Node (line 16) | struct Node
    type Node (line 12) | struct Node
  function Enqueue (line 19) | void Enqueue(int x) {
  function Dequeue (line 33) | void Dequeue() {
  function Front (line 48) | int Front() {
  function Print (line 56) | void Print() {
  function main (line 65) | int main(){

FILE: Data Structures/C:C++/Linked List/Queue_using_linkedlist.c
  type node (line 5) | struct node{
  type node (line 10) | struct node
  function push (line 12) | void push(){//insert at the beginning
  function pop (line 25) | void pop(){
  function display (line 42) | void display(){
  function main (line 54) | int main(){

FILE: Data Structures/C:C++/Linked List/Reverse_SinglyLL.c
  type node (line 3) | struct node{
  type node (line 8) | struct node
  type node (line 10) | struct node
  type node (line 11) | struct node
  type node (line 12) | struct node
  type node (line 13) | struct node
  function insert (line 26) | void insert(int item,int n){
  function print (line 46) | void print(){
  function main (line 55) | int main(){

FILE: Data Structures/C:C++/Linked List/all_operations_of_Doubly_ll.cpp
  type node (line 11) | struct node
    type node (line 14) | struct node
    type node (line 15) | struct node
  class double_llist (line 21) | class double_llist
    method double_llist (line 32) | double_llist()
  function main (line 41) | int main()
  type node (line 123) | struct node
    type node (line 14) | struct node
    type node (line 15) | struct node
  type node (line 152) | struct node
    type node (line 14) | struct node
    type node (line 15) | struct node
  type node (line 172) | struct node
    type node (line 14) | struct node
    type node (line 15) | struct node
  type node (line 208) | struct node
    type node (line 14) | struct node
    type node (line 15) | struct node
  type node (line 251) | struct node
    type node (line 14) | struct node
    type node (line 15) | struct node
  type node (line 272) | struct node
    type node (line 14) | struct node
    type node (line 15) | struct node
  type node (line 287) | struct node
    type node (line 14) | struct node
    type node (line 15) | struct node

FILE: Data Structures/C:C++/Linked List/concatinate.c
  type node (line 4) | struct node
  type node (line 9) | struct node
  type node (line 10) | struct node
  type node (line 13) | struct node
  type node (line 13) | struct node
  type node (line 15) | struct node
  type node (line 16) | struct node
  type node (line 16) | struct node
  type node (line 37) | struct node
  type node (line 37) | struct node
  type node (line 39) | struct node
  type node (line 40) | struct node
  type node (line 40) | struct node
  function display (line 62) | void display(struct node*start)
  type node (line 74) | struct node
  type node (line 74) | struct node
  type node (line 77) | struct node
  function con (line 95) | void con(struct node*p,struct node*q)
  type node (line 106) | struct node

FILE: Data Structures/C:C++/Linked List/doubly circular.c
  type node (line 12) | struct node
  type node (line 21) | struct node
  type node (line 22) | struct node
  type node (line 25) | struct node
  type node (line 35) | struct node
  type node (line 35) | struct node
  type node (line 35) | struct node
  function countNode (line 44) | int countNode(){
  function insert_beg (line 62) | void insert_beg(){
  function insert_btw (line 89) | void insert_btw(){//problem hai...
  function insert_end (line 126) | void insert_end(){
  function delete_beg (line 147) | void delete_beg(){
  function delete_btw (line 166) | void delete_btw(){
  function delete_end (line 212) | void delete_end(){
  function search (line 226) | void search(){
  function display (line 250) | void display(){
  function main (line 263) | int main()

FILE: Data Structures/C:C++/Linked List/doubly linked list.c
  type node (line 3) | struct node{
  type node (line 9) | struct node
  type node (line 11) | struct node
  type node (line 12) | struct node
  type node (line 12) | struct node
  function insert (line 22) | void insert(){
  function insert1 (line 33) | void insert1(){
  function print (line 51) | void print(){
  function main (line 60) | int main(){

FILE: Data Structures/C:C++/Linked List/linked_list.c
  type node (line 4) | struct node
  type node (line 12) | struct node
  type node (line 14) | struct node
  type node (line 15) | struct node
  type node (line 15) | struct node
  type node (line 15) | struct node
  type node (line 22) | struct node
  type node (line 23) | struct node
  function countNode (line 29) | int countNode(){
  function ins_beg (line 39) | void ins_beg(int roll,char name[], float cgpa){
  function ins_btw (line 45) | void ins_btw(int roll,char name[], float cgpa,int pos){
  function ins_end (line 62) | void ins_end(int roll,char name[], float cgpa){
  function del_beg (line 76) | void del_beg(){
  function del_btw (line 83) | void del_btw(int pos){
  function del_end (line 99) | void del_end(){
  function search (line 109) | void search(int roll){
  function DISPLAY (line 126) | void DISPLAY(){
  function main (line 137) | int main()

FILE: Data Structures/C:C++/Linked List/ordered_linked.c
  type node (line 4) | struct node
  type node (line 12) | struct node
  type node (line 14) | struct node
  type node (line 15) | struct node
  type node (line 15) | struct node
  type node (line 15) | struct node
  type node (line 23) | struct node
  type node (line 24) | struct node
  function countNode (line 30) | int countNode(){
  function insert (line 40) | void insert(int roll,char name[], float cgpa){
  function del_beg (line 97) | void del_beg(){
  function del_btw (line 102) | void del_btw(int pos){
  function del_end (line 115) | void del_end(){
  function search (line 125) | void search(int roll){
  function DISPLAY (line 142) | void DISPLAY(){
  function main (line 153) | int main()

FILE: Data Structures/C:C++/Linked List/reverse.cpp
  type node (line 5) | struct node
    type node (line 8) | struct node
  type node (line 11) | struct node
    type node (line 8) | struct node
  type node (line 11) | struct node
    type node (line 8) | struct node
  type node (line 13) | struct node
    type node (line 8) | struct node
  type node (line 14) | struct node
    type node (line 8) | struct node
  type node (line 14) | struct node
    type node (line 8) | struct node
  function display (line 34) | void display()
  function reverse (line 47) | void reverse()
  function main (line 64) | int main()

FILE: Data Structures/C:C++/Linked List/stackLinkedList.cpp
  type node (line 3) | struct node{
    type node (line 5) | struct node
  type node (line 8) | struct node
    type node (line 5) | struct node
  function insertathead (line 11) | void insertathead(){
  function pop (line 26) | void pop(){
  function print (line 40) | void print(){
  function main (line 51) | int main(){

FILE: Data Structures/C:C++/Linked List/stack_Linked_List.c
  type node (line 14) | struct node{
  type stack (line 19) | struct stack{
  type node (line 23) | typedef struct node node;
  type stack (line 24) | typedef struct stack stack;
  function stack (line 27) | stack* createStack(){
  function push (line 35) | void push(stack *s,int data){
  function pop (line 56) | int pop(stack *s){
  function isEmpty (line 73) | int isEmpty(stack *s){
  function top (line 79) | int top(stack *s){
  function main (line 88) | int main(){

FILE: Data Structures/C:C++/Stack/Balanced_Brackets.cpp
  function main (line 8) | int main()

FILE: Data Structures/C:C++/Stack/Reverse_Queue.cpp
  function Print (line 9) | void Print(queue<int>& Queue)
  function reverseQueue (line 18) | void reverseQueue(queue<int>& Queue)
  function main (line 32) | int main()

FILE: Data Structures/C:C++/Stack/Stack_as_linked_list.cpp
  type node (line 8) | struct node
    type node (line 11) | struct node
  class stack (line 15) | class stack
    type node (line 17) | struct node
    method stack (line 19) | stack() // constructure
  type node (line 31) | struct node
    type node (line 11) | struct node
  type node (line 48) | struct node
    type node (line 11) | struct node
  type node (line 62) | struct node
    type node (line 11) | struct node
  function main (line 73) | int main()

FILE: Data Structures/C:C++/Stack/largestRectangleHistogram.cpp
  function main (line 5) | int main() {

FILE: Data Structures/C:C++/Stack/stack.hpp
  type stackmp (line 6) | struct stackmp{
    method stackmp (line 11) | stackmp(int cap) : capacity(cap),size(0) {}
    method push (line 13) | void push(T new_data){
    method print (line 25) | void print(){
    method T (line 39) | T pop(){
    method T (line 50) | T peek(){
  function get_size (line 56) | int get_size(stackmp<T> *s){
  function get_capacity (line 61) | int get_capacity(stackmp<T> *s){

FILE: Data Structures/C:C++/Trees/segment_tree/segment_tree.cpp
  function createMinSegmentTree (line 5) | void createMinSegmentTree(int arr[],int sg[],int index,int begin,int end){
  function queryMinSegmentTree (line 19) | int queryMinSegmentTree(int sg[],int l,int r,int index,int begin,int end){
  function updateMinSegmentTree (line 38) | void updateMinSegmentTree(int sg[],int l,int r,int index,int begin,int e...
  function main (line 56) | int main(){

FILE: Data Structures/C:C++/Trees/segment_tree/segment_trees_lazy.cpp.cpp
  function build_tree (line 29) | void build_tree(int node, int a, int b) {
  function update_tree (line 46) | void update_tree(int node, int a, int b, int i, int j, int value) {
  function query_tree (line 82) | int query_tree(int node, int a, int b, int i, int j) {
  function main (line 108) | int main() {

FILE: Data Structures/C:C++/Trees/tree/Fenwick_tree.cpp
  function update (line 4) | void update(int x, int delta)
  function query (line 9) | int query(int x)
  function main (line 17) | int main()

FILE: Data Structures/C:C++/Trees/tree/bst.hpp
  type bst_node (line 6) | struct bst_node{
    method bst_node (line 11) | bst_node(T new_data) : data(new_data), left_child(NULL), right_child(N...
  class BST (line 15) | class BST{
    method _get_length (line 20) | int _get_length(bst_node<T> *node){
    method _insert (line 25) | void _insert(bst_node<T> *node, T new_data){
    method _print (line 44) | void _print(bst_node<T> *node){
    method _print_post_order (line 51) | void _print_post_order(bst_node<T> *node){
    method _print_pre_order (line 58) | void _print_pre_order(bst_node<T> *node){
    method _count_nodes (line 65) | int _count_nodes(bst_node<T> *node){
    method _find (line 70) | bool _find(bst_node<T> *node, T data){
    method _print_max_path (line 85) | void _print_max_path(bst_node<T> *node){
    method T (line 95) | T _get_max(bst_node<T> *node){
    method T (line 104) | T _get_min(bst_node<T> *node){
    method _get_count (line 150) | int _get_count(bst_node<T> *node){
    method _level_order (line 155) | void _level_order(bst_node<T> *node){
    method BST (line 170) | BST() : node(NULL) {}
    method BST (line 171) | BST(T new_data) : node(new bst_node<T>(new_data)) {}
    method T (line 174) | T data(){
    method insert (line 178) | void insert(T new_data){
    method get_length (line 187) | int get_length(){
    method print (line 191) | void print(){
    method print_post_order (line 197) | void print_post_order(){
    method print_pre_order (line 203) | void print_pre_order(){
    method T (line 209) | T get_max(){
    method T (line 213) | T get_min(){
    method count_nodes (line 217) | int count_nodes(){
    method find (line 221) | bool find(T data){
    method print_max_path (line 225) | void print_max_path(){
    method delete_value (line 231) | void delete_value(T del_data){
    method get_count (line 235) | int get_count(){
    method level_order (line 239) | void level_order(){

FILE: Data Structures/C:C++/Trees/tree/segment_tree.hpp
  class segment_tree (line 4) | class segment_tree{
    method _get_mid (line 12) | int _get_mid(int start, int end){
    method _construct (line 17) | int _construct(int *v, int start, int end, int current){
    method _update_value (line 34) | void _update_value(int start, int end, int i, int difference, int curr...
    method _get_sum (line 44) | int _get_sum(int start, int end, int q_start, int q_end, int current){
    method segment_tree (line 55) | segment_tree(int *v, int n){
    method update (line 72) | void update(int i, int new_val){
    method get_sum (line 82) | int get_sum(int start, int end){
    method get (line 87) | int get(int n){
    method print (line 90) | void print(){

FILE: Data Structures/C:C++/Trees/tree/tree.hpp
  type tree_node (line 5) | struct tree_node{
    method tree_node (line 10) | tree_node(T new_data) : data(new_data), left_child(NULL), right_child(...
    method insert_left (line 12) | void insert_left(T new_data){
    method insert_right (line 17) | void insert_right(T new_data){
  function get_length (line 24) | int get_length(tree_node<T> *top){

FILE: Data Structures/C:C++/Trees/tree/trie.cpp
  type no (line 6) | struct no{
    method no (line 11) | inline no(char k){
    method insert (line 16) | inline bool insert(const string s, ll i){
  function main (line 31) | main(){}

FILE: Data Structures/C:C++/queue/queue.hpp
  type queuemp (line 6) | struct queuemp{
    method queuemp (line 10) | queuemp() : size(0) {}
    method push (line 12) | void push(T new_data){
    method print (line 20) | void print(){
    method T (line 34) | T pop(){
    method T (line 55) | T peek(){
  function get_size (line 61) | int get_size(queuemp<T> *s){

FILE: Data Structures/Java/Stack/Stack.java
  class Stack (line 4) | public class Stack<E> {
    method Stack (line 9) | public Stack() {
    method Stack (line 15) | public Stack(int size) {
    method isEmpty (line 21) | @SuppressWarnings("unchecked")
    method peek (line 32) | @SuppressWarnings("unchecked")
    method size (line 37) | @SuppressWarnings("unchecked")
    method pop (line 53) | @SuppressWarnings("unchecked")
    method push (line 65) | public void push(E data) {

FILE: Data Structures/Python/Graphs/Graph.py
  class Graph (line 4) | class Graph(object):
    method __init__ (line 7) | def __init__(self, connections, directed=False):#undirected by default
    method add_connections (line 12) | def add_connections(self, connections):
    method add (line 18) | def add(self, node1, node2):
    method remove (line 25) | def remove(self, node):
    method is_connected (line 38) | def is_connected(self, node1, node2):
    method find_path (line 43) | def find_path(self, node1, node2, path=[]):
    method __str__ (line 58) | def __str__(self):

FILE: Data Structures/Python/Graphs/dfs.py
  class Graph (line 3) | class Graph:
    method __init__ (line 4) | def __init__(self):
    method addEdge (line 7) | def addEdge(self, node1, node2):
  function dfsHelper (line 11) | def dfsHelper(current, graph, visited, visitFunc):
  function dfs (line 23) | def dfs(current, graph, visitFunc):
  function visitPrint (line 27) | def visitPrint(i):

FILE: Data Structures/Python/Linked List/singly_linked_list.py
  class Node (line 1) | class Node(object):
    method __init__ (line 3) | def __init__(self, data, next):
  class SingleList (line 8) | class SingleList(object):
    method show (line 13) | def show(self):
    method append (line 21) | def append(self, data):
    method remove (line 29) | def remove(self, node_value):

FILE: Data Structures/Python/Queue/Queue.py
  class Queue (line 11) | class Queue:
    method __init__ (line 13) | def __init__(self):
    method isEmpty (line 16) | def isEmpty(self):
    method enqueue (line 19) | def enqueue(self, item):
    method dequeue (line 22) | def dequeue(self):
    method size (line 25) | def size(self):

FILE: Data Structures/Python/Stack/stack.py
  class Stack (line 3) | class Stack:
    method __init__ (line 4) | def __init__(self):
    method isEmpty (line 7) | def isEmpty(self):
    method push (line 10) | def push(self, item):
    method pop (line 13) | def pop(self):
    method peek (line 16) | def peek(self):
    method size (line 19) | def size(self):

FILE: Data Structures/Python/Trees/m-coloring-problem.py
  class Graph (line 1) | class Graph:
    method __init__ (line 2) | def __init__(self,m,v):
  function mColoring (line 6) | def mColoring(k,m,g,x):
  function getNodeColor (line 18) | def getNodeColor(k,m,g,x):
  function main (line 37) | def main():

FILE: Dynamic Programing/Dynamic_fibonacci.py
  function fibonacci (line 6) | def fibonacci(n):

FILE: Dynamic Programing/Edit Distance.Py
  function DP (line 3) | def DP(x,y,i,j):

FILE: Dynamic Programing/Knapsack.py
  function DP (line 5) | def DP(val,s,i,x):

FILE: Dynamic Programing/Memoized Cut Rod.Py
  function cut_rod (line 5) | def cut_rod(p,n):

FILE: Dynamic Programing/Word_Wrap.Py
  function badness (line 4) | def badness(i,j,m):
  function minimum (line 16) | def minimum(i,ls,w,n):
  function DP (line 23) | def DP(i,ls,w,n):

FILE: Dynamic Programing/longest_increasing_subsequence.cpp
  function longestIncreasingSubsequence (line 3) | int longestIncreasingSubsequence(int A[],int size){
  function main (line 20) | int main() {

FILE: Mathematical Challenges/C:C++/Fibonacci/Fibonacci Test.cpp
  function main (line 8) | int main()

FILE: Mathematical Challenges/C:C++/Square Root Decomposition/MO's Algorithm/MOAlgo.cpp
  function sbt (line 24) | inline int sbt(int x){return __builtin_popcount(x);}
  function f (line 29) | bool f(pair<int,pi> a, pair<int,pi> b){
  function main (line 34) | int main() {

FILE: Mathematical Challenges/C:C++/armstrong_number/C/armstrong.c
  function main (line 4) | int main(void)

FILE: Mathematical Challenges/C:C++/convexHull/ConvexHullScan.cpp
  function Is_Right_Turn (line 10) | bool Is_Right_Turn(vector <pair<int,int>> Hull){
  function main (line 31) | int main(){

FILE: Mathematical Challenges/C:C++/factorial/factorial.c
  function main (line 2) | int main(){

FILE: Mathematical Challenges/C:C++/fibbinacci/fibbinacci.c
  function main (line 3) | int main(){

FILE: Mathematical Challenges/C:C++/gcd/extended_gcd.cpp
  type Res_gcd (line 29) | struct Res_gcd{
    method Res_gcd (line 31) | Res_gcd(int gcd, int x, int y){
  function Res_gcd (line 43) | Res_gcd gcd_extended(int a,int b){
    method Res_gcd (line 31) | Res_gcd(int gcd, int x, int y){
  function main (line 51) | int main(){

FILE: Mathematical Challenges/C:C++/gcd/gcd.cpp
  function gcd (line 7) | int gcd(int a,int b){
  function main (line 13) | int main()

FILE: Mathematical Challenges/C:C++/gcd/mod_inverse.cpp
  type Res_gcd (line 29) | struct Res_gcd{
    method Res_gcd (line 31) | Res_gcd(int gcd, int x, int y){
  function Res_gcd (line 43) | Res_gcd gcd_extended(int a,int b){
    method Res_gcd (line 31) | Res_gcd(int gcd, int x, int y){
  function modd (line 56) | int modd(int num,int m){
  function mod_inverse (line 62) | int mod_inverse(int a,int m){
  function main (line 71) | int main(){

FILE: Mathematical Challenges/C:C++/largestoutof3/largestoutof3.c
  function main (line 2) | int main(){

FILE: Mathematical Challenges/C:C++/multiplication/multiply 2 numbers greater than 10^6.cpp
  function main (line 8) | int main()

FILE: Mathematical Challenges/C:C++/power/modular_exponention.cpp
  function ui (line 8) | ui modular_expo_no_rec(int base,int p){
  function ui (line 20) | ui modular_expo_rec(ui b,ui p){
  function main (line 31) | int main(){

FILE: Mathematical Challenges/C:C++/power/ques/summation.cpp
  function ui (line 8) | ui two_pow(int n){
  function ui (line 20) | ui modular_expo(ui b,ui p){
  function main (line 27) | int main(){

FILE: Mathematical Challenges/C:C++/power/two_pow.cpp
  function two_pow (line 29) | int two_pow(int p){
  function main (line 40) | int main(){

FILE: Mathematical Challenges/C:C++/powerset/PowerSet.java
  class PowerSet (line 2) | public class PowerSet {
    method powerSet (line 4) | public static <T> Set<Set<T>> powerSet( Set<T> set ) {
    method main (line 21) | public static void main(String[] args) {

FILE: Mathematical Challenges/C:C++/prime number tricks/List all primes.cpp
  function main (line 12) | int main()

FILE: Mathematical Challenges/C:C++/prime/prime.c
  function main (line 2) | int main(){

FILE: Mathematical Challenges/C:C++/prime/sieveOferatosthenes.cpp
  function sieve_of_eratosthenes (line 4) | void sieve_of_eratosthenes(std::vector<int>& primes, const int max) {
  function main (line 31) | int main() {

FILE: Mathematical Challenges/C:C++/ques/cpcrc1c.cpp
  function ui (line 10) | ui sum_of_digits(string str){
  function ui (line 17) | ui digit_sum(string str){
  function main (line 37) | int main(){

FILE: Mathematical Challenges/python/pernicious_prime/pernicious.py
  function isprime (line 20) | def isprime(num): #function to check whether a number is prime or not
  function count_ones (line 44) | def count_ones(num): #function to calculate the number of set bits in a ...

FILE: Mathematical Challenges/python/sieve_of_eratoshthenes.py
  function sieve (line 5) | def sieve():

FILE: Patterns/pattern10.cpp
  function main (line 4) | int main(){

FILE: Patterns/pattern11.cpp
  function main (line 4) | int main(){

FILE: Patterns/pattern12.cpp
  function main (line 4) | int main(){

FILE: Patterns/pattern13.cpp
  function main (line 4) | int main(){

FILE: Patterns/pattern14.cpp
  function main (line 4) | int main(){

FILE: Patterns/pattern15.cpp
  function main (line 4) | int main(){

FILE: Patterns/pattern16.cpp
  function main (line 4) | int main(){

FILE: Patterns/pattern8.cpp
  function main (line 4) | int main(){

FILE: Patterns/pattern9.cpp
  function main (line 4) | int main(){

FILE: STL C++/STACK_with_Application/Evaluating Postfix Expression.c
  function isoperator (line 5) | int isoperator(char c){
  type stack (line 9) | struct stack
  function push (line 15) | void push(double c){
  function pop (line 19) | double pop(){
  function perform (line 23) | double perform(double a, double b, char c){
  function post_infix (line 39) | void post_infix(char a[],int l){
  function main (line 58) | int main()

FILE: STL C++/STACK_with_Application/Infix to Postfix.c
  type temp (line 4) | struct temp{
  type temp (line 8) | struct temp
  function push (line 10) | void push(char item){
  function isempty (line 14) | int isempty(){
  function pop (line 18) | char pop(){
  function isoperator (line 22) | int isoperator(char c){
  function precedence (line 26) | int precedence(char c){
  function main (line 66) | int main(){

FILE: STL C++/STACK_with_Application/balance parenthesis.cpp
  function main (line 7) | int main(){

FILE: STL C++/STACK_with_Application/stack_and_its_implementation.c
  type stack (line 7) | struct stack{
  type stack (line 14) | struct stack
  function push (line 17) | void push(){
  function pop (line 33) | void pop(){
  function peep (line 42) | void peep(){
  function print (line 50) | void print(){
  function main (line 64) | int main(){

FILE: STL C++/sorting_a_vector.cpp
  function compare (line 7) | bool compare(int a,int b){
  function main (line 11) | int main(){

FILE: STL C++/stack/Stack.java
  class Stack (line 4) | public class Stack<E> {
    method Stack (line 9) | public Stack() {
    method Stack (line 15) | public Stack(int size) {
    method isEmpty (line 21) | @SuppressWarnings("unchecked")
    method peek (line 32) | @SuppressWarnings("unchecked")
    method size (line 37) | @SuppressWarnings("unchecked")
    method pop (line 53) | @SuppressWarnings("unchecked")
    method push (line 65) | public void push(E data) {

FILE: STL C++/stack/largestRectangleHistogram.cpp
  function main (line 5) | int main() {

FILE: STL C++/stack/stack.hpp
  type stackmp (line 6) | struct stackmp{
    method stackmp (line 11) | stackmp(int cap) : capacity(cap),size(0) {}
    method push (line 13) | void push(T new_data){
    method print (line 25) | void print(){
    method T (line 39) | T pop(){
    method T (line 50) | T peek(){
  function get_size (line 56) | int get_size(stackmp<T> *s){
  function get_capacity (line 61) | int get_capacity(stackmp<T> *s){

FILE: Searching Algorithms/Bogo_sort.cpp
  function main (line 12) | int main()
  function is_sorted (line 32) | int is_sorted(int *a, int n)
  function shuffle (line 45) | void shuffle(int *a, int n)
  function bogosort (line 58) | void bogosort(int *a, int n)

FILE: Searching Algorithms/C:C++/Binary_Search.cpp
  function main (line 4) | int main()

FILE: Searching Algorithms/C:C++/Binary_search.cpp
  function main (line 5) | void main()

FILE: Searching Algorithms/C:C++/Interpolation_search.cpp
  function interpolation_search (line 10) | long long int interpolation_search(int arr[],int n,int x)
  function main (line 37) | int main()

FILE: Searching Algorithms/C:C++/Jump_Search.cpp
  function jumpSearch (line 6) | int jumpSearch(int arr[], int x, int n)
  function main (line 41) | int main()

FILE: Searching Algorithms/C:C++/Liear_search.cpp
  function main (line 5) | void main()

FILE: Searching Algorithms/C:C++/MEDIAN_SEARCH.cpp
  function findMedian (line 26) | int findMedian(int arr[], int size_of_array)
  function partition (line 32) | int partition(int arr[], int low, int high, int variable_to_be_found)
  function kthSmallest (line 56) | int kthSmallest(int arr[], int low, int high, int k)
  function main (line 101) | int main()

FILE: Searching Algorithms/C:C++/Selection_sort.cpp
  function main (line 5) | void main()

FILE: Searching Algorithms/C:C++/Ternary_search.cpp
  function main (line 7) | int main()
  function ternary_search (line 31) | int ternary_search (int v[],int n, int left, int right, int x)

FILE: Searching Algorithms/C:C++/b_search.cpp
  function b_search (line 3) | int b_search(int a[],int l,int u,int s)
  function main (line 16) | int main()

FILE: Searching Algorithms/C:C++/fibonacci_search.cpp
  function _fibonacci_search (line 6) | int _fibonacci_search(int n, int arr[], int x)

FILE: Searching Algorithms/C:C++/seaching algorithms [rename]/binary_search.cpp
  function binarySearch (line 7) | int binarySearch(int array[], int left, int right, int search)
  function main (line 22) | int main()

FILE: Searching Algorithms/C:C++/seaching algorithms [rename]/binary_search_extras/position_in_sorted_array/eq_less_than.cpp
  function binary_search (line 9) | int binary_search(vector<int> &vec,int l,int r,int num,int best){
  function main (line 26) | int main(){

FILE: Searching Algorithms/C:C++/seaching algorithms [rename]/binary_search_extras/position_in_sorted_array/first_occurance.cpp
  function binary_search (line 9) | int binary_search(vector<int> &vec,int l,int r,int num,int best){
  function main (line 30) | int main(){

FILE: Searching Algorithms/C:C++/seaching algorithms [rename]/binary_search_extras/position_in_sorted_array/just_less_than_num.cpp
  function binary_search (line 9) | int binary_search(vector<int> &vec,int l,int r,int num,int best){
  function main (line 26) | int main(){

FILE: Searching Algorithms/C:C++/seaching algorithms [rename]/binary_search_extras/position_in_sorted_array/position_in_sorted_array.cpp
  function binary_search (line 8) | int binary_search(vector<int> &vec, int l, int r, int num){
  function main (line 23) | int main(){

FILE: Searching Algorithms/C:C++/seaching algorithms [rename]/binary_search_extras/ques/aggrcow.cpp
  function find (line 6) | int find(int l,int r){
  function main (line 28) | int main(){

FILE: Searching Algorithms/C:C++/seaching algorithms [rename]/jump_search.cpp
  function jumpSearch (line 8) | int jumpSearch(int array[], int search, int size)
  function main (line 33) | int main()

FILE: Searching Algorithms/C:C++/seaching algorithms [rename]/linear.cpp
  function main (line 6) | int main()

FILE: Searching Algorithms/C:C++/ternarySearch.cpp
  function ternarySearch (line 11) | int ternarySearch(int arr[],int l,int r, int x){
  function main (line 31) | int main(){

FILE: Searching Algorithms/C:C++/ternary_search.c
  function ternarySearch (line 6) | int ternarySearch(int arr[],int l,int r, int x){
  function main (line 27) | int main(){

FILE: Searching Algorithms/Java/algos/BinarySearch.java
  class BinarySearch (line 3) | public class BinarySearch{
    method binarySearch (line 4) | public static int binarySearch(int [] arr, int key, int low, int high) {

FILE: Searching Algorithms/Java/algos/LinearSearch.java
  class LinearSearch (line 3) | public class LinearSearch{
    method linearSearch (line 4) | public static int linearSearch(int [] arr, int key) {

FILE: Searching Algorithms/Java/driving.java
  class LinearSearch (line 3) | public class LinearSearch{
    method linearSearch (line 4) | public static int linearSearch(int [] arr, int key) {
    method main (line 14) | public static void main(String a[]) {

FILE: Searching Algorithms/Python/binarysearch.py
  function binary_search (line 1) | def binary_search(item_list,item):

FILE: Searching Algorithms/Python/bst.py
  class Node (line 6) | class Node:
    method __init__ (line 7) | def __init__(self,key):
  function insert (line 13) | def insert(root,node):
  function inorder (line 29) | def inorder(root):

FILE: Segment Trees/C++/RangeMinimumQuery.cpp
  function rmq (line 5) | int rmq(int *st, int n, int ss, int se, int qs, int qe, int si) {
  function buildTree (line 22) | int buildTree(int a[], int n, int ss, int se, int *st, int si) {
  function main (line 48) | int main()

FILE: Segment Trees/C++/SumInGivenRange.cpp
  function getSum (line 5) | int getSum(int *st, int n, int ss, int se, int qs, int qe, int si) {
  function UpdateUtil (line 22) | void UpdateUtil(int *st, int ss, int se, int i, int diff, int si) {
  function UpdateValue (line 37) | void UpdateValue(int a[], int *st, int n, int i, int new_value) {
  function buildTree (line 51) | int buildTree(int a[], int n, int ss, int se, int *st, int si) {
  function main (line 77) | int main()

FILE: Segment Trees/Java/SegementTree.java
  class SegmentTree (line 5) | public class SegmentTree {
    method main (line 10) | public static void main(String args[])
    method build (line 64) | public static void build(int node, int start, int end)
    method query (line 79) | public static int query(int node, int start, int end, int l, int r)
    method update (line 98) | public static void update(int node, int start, int end, int idx, int val)

FILE: Segment Trees/Java/SegementTreeLazyPropagation.java
  class LazySegmentTree (line 6) | class LazySegmentTree
    method updateRangeUtil (line 18) | void updateRangeUtil(int si, int ss, int se, int us,
    method updateRange (line 89) | void updateRange(int n, int us, int ue, int diff)  {
    method getSumUtil (line 104) | int getSumUtil(int ss, int se, int qs, int qe, int si)
    method getSum (line 153) | int getSum(int n, int qs, int qe)
    method constructSTUtil (line 168) | void constructSTUtil(int arr[], int ss, int se, int si)
    method constructST (line 195) | void constructST(int arr[], int n)
    method main (line 203) | public static void main(String args[])

FILE: Sorting Algorithms/C:C++/Counting_Sort.cpp
  function main (line 4) | int main()

FILE: Sorting Algorithms/C:C++/Insertion_sort.cpp
  function main (line 5) | void main()

FILE: Sorting Algorithms/C:C++/Merge_sort.cpp
  function Merge (line 6) | void Merge(int *a, int low, int high, int mid)
  function MergeSort (line 56) | void MergeSort(int *a, int low, int high)
  function main (line 71) | int main()

FILE: Sorting Algorithms/C:C++/QuickSort.c
  function swap (line 15) | void swap (int a[], int left, int right)
  function quicksort (line 23) | void quicksort( int a[], int low, int high )
  function partition (line 35) | int partition( int a[], int low, int high )
  function main (line 62) | int main()
  function printarray (line 79) | void printarray(int a[], int n)

FILE: Sorting Algorithms/C:C++/Quick_sort.cpp
  function main (line 76) | int main()
  function quick_sort (line 95) | void quick_sort(int a[],int l,int u)
  function partition (line 106) | int partition(int a[],int l,int u)

FILE: Sorting Algorithms/C:C++/Radix_sort.cpp
  class radixsort (line 5) | class radixsort{
  function main (line 61) | void main(){

FILE: Sorting Algorithms/C:C++/bubblesort.c
  function main (line 5) | int main(){

FILE: Sorting Algorithms/C:C++/bubblesort.cpp
  function main (line 5) | void main()

FILE: Sorting Algorithms/C:C++/bucketsort.c
  function bucketSort (line 5) | void bucketSort(int a[], int n) {
  function main (line 19) | int main() {

FILE: Sorting Algorithms/C:C++/heapSort.c
  function heapify (line 3) | int heapify(int* a, int i, int n)
  function buildheap (line 21) | int buildheap(int *a, int n)
  function sort (line 28) | int sort(int* a, int n)
  function main (line 44) | int main()

FILE: Sorting Algorithms/C:C++/insertion.hpp
  function insertion_sort (line 4) | void insertion_sort(int length, int v[]){

FILE: Sorting Algorithms/C:C++/merge.hpp
  function _merge (line 4) | void _merge(int v[], int left, int mid, int right){
  function _merge_sort (line 50) | void _merge_sort(int v[], int left, int right){
  function merge_sort (line 61) | void merge_sort(int length, int v[]){

FILE: Sorting Algorithms/C:C++/quick.hpp
  function _partition (line 4) | int _partition(int v[], int left, int right){
  function _quick (line 18) | void _quick(int v[], int left, int right){
  function quick_sort (line 26) | void quick_sort(int length, int v[]){

FILE: Sorting Algorithms/C:C++/quick_sort.c
  function quicksort (line 2) | void quicksort(int number[25],int first,int last){
  function main (line 31) | int main(){

FILE: Sorting Algorithms/C:C++/radix.hpp
  function _count_sort (line 4) | void _count_sort(int arr[], int length, int exp){
  function radix_sort (line 26) | void radix_sort(int length, int v[]){

FILE: Sorting Algorithms/C:C++/selectionsort.c
  function swap (line 11) | void swap(int *xp, int *yp)
  function selectionSort (line 18) | void selectionSort(int arr[], int n)
  function printArray (line 37) | void printArray(int arr[], int size)
  function main (line 46) | int main()

FILE: Sorting Algorithms/C:C++/shell_sort.h
  function namespace (line 4) | namespace alg {

FILE: Sorting Algorithms/C:C++/slow.cpp
  function _slow_sort (line 4) | void _slow_sort(int v[], int i, int j) {
  function slow_sort (line 14) | void slow_sort(int length, int v[]) {

FILE: Sorting Algorithms/C:C++/sorting_a_vector.cpp
  function compare (line 7) | bool compare(int a,int b){
  function main (line 11) | int main(){

FILE: Sorting Algorithms/Java/Countsort.java
  class CountingSort (line 1) | public class CountingSort
    method sort (line 3) | public static void sort(char arr[])
    method main (line 38) | public static void main(String args[])

FILE: Sorting Algorithms/Java/HeapSort.java
  class HeapSort (line 5) | public class HeapSort {
    method main (line 7) | public static void main(String[] args) {
    method sort (line 15) | public static void sort(int[] a) {
    method heapify (line 33) | public static void heapify(int arr[], int n, int i)

FILE: Sorting Algorithms/Java/MergeSort.java
  class test (line 3) | public class test {
    method main (line 5) | public static void main(String[] args) {
    method mergeSort (line 17) | public static void mergeSort(String[] a, int low, int high) {
    method merge (line 27) | public static void merge(String[] a, int low, int mid, int high) {

FILE: Sorting Algorithms/Python/QuickSort.py
  function partition (line 1) | def partition(arr,low,high):
  function quickSort (line 24) | def quickSort(arr,low,high):

FILE: Sorting Algorithms/Python/bogosort.py
  function bogosort (line 7) | def bogosort(my_array):

FILE: Sorting Algorithms/Python/bubblesort.py
  function bubble_sort (line 1) | def bubble_sort(arr):

FILE: Sorting Algorithms/Python/cocktailsort.py
  function cocktailsort (line 6) | def cocktailsort(a):

FILE: Sorting Algorithms/Python/insertionsort.py
  function insertion_sort (line 1) | def insertion_sort(my_array):

FILE: Sorting Algorithms/Python/mergesort.py
  function mergeSort (line 1) | def mergeSort(nlist):

FILE: Sorting Algorithms/Python/quicksort.py
  function quickSort (line 1) | def quickSort(data_list):
  function quickSortHlp (line 4) | def quickSortHlp(data_list,first,last):
  function partition (line 13) | def partition(data_list,first,last):

FILE: Sorting Algorithms/Python/topological_sort.py
  class Graph (line 5) | class Graph:
    method __init__ (line 6) | def __init__(self,vertices):
    method addEdge (line 11) | def addEdge(self,u,v):
    method topologicalSortUtil (line 15) | def topologicalSortUtil(self,v,visited,stack):
    method topologicalSort (line 30) | def topologicalSort(self):

FILE: Sorting Algorithms/sleep sort.c
  function routine (line 5) | void routine(void *a)

FILE: String Manipulation/C:C++/String_algo/KMP.cpp
  function preprocess (line 24) | void preprocess(string a)
  function kmp (line 40) | void kmp(string a,string t)
  function main (line 58) | int main()

FILE: String Manipulation/C:C++/String_algo/SUFFIX-ARRAY.cpp
  type mytuple (line 22) | struct mytuple{
  function cmp (line 27) | bool cmp(mytuple a,mytuple b)
  function main (line 33) | int main()

FILE: String Manipulation/C:C++/String_algo/z_algorithm.cpp
  function ll (line 21) | ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * ...
  function readLI (line 23) | long long readLI(){  register char c;  for(c = getchar(); !(c>='0' && c<...
  function z_function (line 31) | void z_function(string s)
  function main (line 42) | int main()

FILE: String Manipulation/C:C++/tokens/token_break.cpp
  function main (line 6) | int main ()

FILE: String Manipulation/C:C++/tokens/word_break.cpp
  function dictionaryContains (line 7) | int dictionaryContains(string &word)
  function wordBreak (line 23) | void wordBreak(string str)
  function wordBreakUtil (line 30) | void wordBreakUtil(string str, int n, string result)
  function main (line 58) | int main()

FILE: String Manipulation/Python/LCS.py
  function lcs (line 1) | def lcs(a, b):

FILE: backtrack/sudoku/code2.cpp
  function check_possibility (line 8) | bool check_possibility(matrix& vec,int num,int row,int col){
  function isGood (line 27) | bool isGood(matrix& vec,int num,int row,int col){
  function back_track (line 39) | bool back_track(matrix& vec,int row,int col){
  function main (line 72) | int main(){

FILE: backtrack/sudoku/sudoku.cpp
  function check_possibility (line 7) | bool check_possibility(matrix& vec,int num,int row,int col){
  function isGood (line 26) | bool isGood(matrix& vec,int num,int row,int col){
  function back_track (line 38) | bool back_track(matrix& vec,int row,int col){
  function main (line 71) | int main(){

FILE: binary_tree/binarytree.java
  class Node (line 1) | class Node{
    method Node (line 5) | public Node(int data){
    method Node (line 164) | public Node(int data){
  class BinarySearchTree (line 10) | public class BinarySearchTree {
    method BinarySearchTree (line 12) | public BinarySearchTree(){
    method find (line 16) | public boolean find(int id){
    method delete (line 29) | public boolean delete(int id){
    method getSuccessor (line 92) | public Node getSuccessor(Node deleleNode){
    method insert (line 110) | public void insert(int id){
    method display (line 135) | public void display(Node root){
    method main (line 142) | public static void main(String arg[]){
  class Node (line 160) | class Node{
    method Node (line 5) | public Node(int data){
    method Node (line 164) | public Node(int data){

FILE: btree.cpp
  type alg (line 21) | namespace alg {
    class BTree (line 22) | class BTree {
      type node_t (line 26) | struct node_t {
      type node_t (line 34) | struct node_t
      type Res (line 38) | struct Res {
      method BTree (line 48) | BTree(const char * path) {
      method Res (line 64) | Res Search(int32_t x) {
      method Insert (line 69) | void Insert(int32_t k) {
      method DeleteKey (line 89) | void DeleteKey(int32_t k) {
      method Res (line 98) | Res search(node x, int32_t k) {
      method insert_nonfull (line 120) | void insert_nonfull(node x, int32_t k) {
      method split_child (line 153) | void split_child(node x, int32_t i) {
      method delete_op (line 191) | void delete_op(node x, int32_t k) {
      method case1 (line 229) | void case1(node x, int32_t i, int32_t k) {
      method case2 (line 238) | void case2(node x, int32_t i, int32_t k) {
      method case3 (line 313) | void case3(node x, int32_t i, int32_t k) {
      method delete_i (line 454) | void delete_i(node x, int32_t i)  {
      method node (line 486) | node ROOT() {
      method node (line 496) | node READ(node x, int32_t i) {
      method WRITE (line 508) | void WRITE(node x) {

FILE: cryptography/Python/porta.py
  class Porta (line 4) | class Porta(Cipher):
    method __init__ (line 9) | def __init__(self,key='FORTIFICATION'):
    method encipher (line 12) | def encipher(self,string):
    method decipher (line 39) | def decipher(self,string):

FILE: cryptography/des/java/Converter.java
  class Converter (line 9) | public class Converter {
    method convertToBinaryCode (line 11) | public static String convertToBinaryCode(String text) {
    method getBytes (line 36) | private static byte[] getBytes (String text) {

FILE: cryptography/des/java/DES.java
  class DES (line 3) | public class DES {
    method getKey (line 11) | public String getKey() {
    method setKey (line 15) | public void setKey(String key) {
    method getMessage (line 19) | public String getMessage() {
    method setMessage (line 23) | public void setMessage(String message) {
    method encrypt (line 27) | public String encrypt() {
    method messagePermutation (line 84) | private String messagePermutation(String input) {
    method generateKeys (line 99) | private void generateKeys(String key) {
    method beginKeyPermutation (line 112) | private String beginKeyPermutation(String input) {
    method leftShiftBits (line 127) | private String leftShiftBits(String input, int step) {
    method finishKeyPermutation (line 138) | private String finishKeyPermutation(String input) {
    method E (line 151) | private String E(String input) {
    method xor (line 170) | private static String xor(String x1, String x2) {
    method sBox (line 196) | private String sBox(int boxNumber, String b) {
    method cPermute (line 265) | private String cPermute(String input) {
    method lastInverse (line 280) | private String lastInverse(String input) {

FILE: cryptography/des/java/IO.java
  class IO (line 5) | public class IO {
    method IO (line 11) | public IO(String inputFilePath, String outputFilePath) {
    method readMessageFromFile (line 16) | public String readMessageFromFile() {
    method readKeyFromFile (line 26) | public String readKeyFromFile() {
    method writeStringInFile (line 37) | public void writeStringInFile(String text) {

FILE: cryptography/des/java/Main.java
  class Main (line 7) | public class Main {
    method main (line 9) | public static void main(String[] args) {

FILE: dfs.cpp
  function main (line 6) | void main()
  function DFS (line 27) | void DFS(int i)

FILE: disjoint_set/disjoint_set.hpp
  class disjoint_set (line 4) | class disjoint_set {
    method disjoint_set (line 8) | disjoint_set(int n) : id(new int[n]), size(new int[n]), count(n) {
    method get_count (line 21) | int get_count(){
    method find (line 26) | int find(int n){
    method merge (line 37) | void merge(int x, int y){
    method connected (line 54) | bool connected(int x, int y){

FILE: divide_and_conquer/maximum_sub_array.cpp
  function main (line 23) | int main(){

FILE: divide_and_conquer/strassen.cpp
  function main (line 17) | int main() {
  function Add (line 64) | void Add(int **A, int **B, int **T, int n) {
  function Sub (line 73) | void Sub(int **A, int **B, int **T, int n) {
  function createMatrix (line 83) | void createMatrix(int **A,int size) {
  function output (line 92) | void output(int **A, int size) {
  function standardMult (line 103) | void standardMult(int **A, int **B, int **C, int size) {
  function strassens (line 115) | void strassens(int **A, int **B, int **C, int size) {

FILE: dp/0-1knapsack.cpp
  function knapsack (line 4) | int knapsack(int n, int w, int weight[], int val[])
  function main (line 25) | int main() {

FILE: dp/Digit_dp.cpp
  function getDigits (line 6) | long long int getDigits(long long int x, vector <int> &digits) {
  function digitSum (line 13) | long long int digitSum(int idx, int sum, int tight, vector <int> &digit) {
  function rangeDigitSum (line 40) | long long int rangeDigitSum(int a, int b) {
  function main (line 58) | int main()

FILE: dp/coinchange.cpp
  function coinWaysTD (line 7) | int coinWaysTD(int amt,int coins[],int n){
  function coinWaysBU (line 29) | int coinWaysBU(int amt,int coins[],int n){
  function main (line 44) | int main(){

FILE: dp/editDistance.cpp
  function min (line 8) | inline int min(int a,int b,int c){
  function editDistance (line 14) | int editDistance(string a,string b,int m,int n){
  function main (line 28) | int main(){

FILE: dp/eggdropping.cpp
  function eggdrop (line 4) | int eggdrop(int n, int k)
  function main (line 32) | int main() {

FILE: dp/kadane.cpp
  function main (line 4) | int main() {

FILE: dp/lcs.cpp
  function lcs (line 5) | int lcs(string s1,string s2,int i,int j){
  function lcsMatrix (line 16) | int lcsMatrix(string s1,string s2) {
  function main (line 61) | int main(){

FILE: dp/lis.cpp
  function main (line 4) | int main() {

FILE: dp/mcm.cpp
  function mcmdnc (line 13) | int mcmdnc(int a,int b)
  function mcmdp (line 34) | int mcmdp(int p[], int n){
  function main (line 52) | int main(){

FILE: genome_sort.py
  function gnomeSort (line 1) | def gnomeSort( arr, n):

FILE: graph/bfs_dfs/bfs/BFS.cpp
  class Graph (line 9) | class Graph
  function main (line 74) | int main()

FILE: graph/bfs_dfs/bfs/BFS.py
  class Graph (line 6) | class Graph:
    method __init__ (line 9) | def __init__(self):
    method addEdge (line 15) | def addEdge(self,u,v):
    method BFS (line 20) | def BFS(self, s):

FILE: graph/bfs_dfs/bfs/bfs.cpp
  function bfs (line 5) | void bfs(int n, std::vector<int> v[], int s){
  function main (line 27) | int main(){

FILE: graph/bfs_dfs/dfs/DFS.cpp
  function dfs (line 28) | void dfs(int u) {
  function printTree (line 53) | void printTree(int V) {
  function main (line 68) | int main() {

FILE: graph/bfs_dfs/dfs/DFS.java
  class DFS (line 32) | public class DFS {
    method main (line 44) | public static void main(String[] args) {
    method readMatrixFromFile (line 51) | private static int[][] readMatrixFromFile() {
    method dfs (line 77) | private static String dfs(int[][] matrix, int v) {
    method printSolution (line 91) | private static void printSolution(String answer) {

FILE: heap/heap.hpp
  class heap (line 5) | class heap {
    method heap (line 12) | heap() : arr(NULL), size(0), capacity(0), type(0) {}
    method heap (line 13) | heap(int capacity, int type) : arr(new T[capacity]), size(0), capacity...
    method get_size (line 16) | int get_size(){ return this->size; }
    method get_capacity (line 17) | int get_capacity(){ return this->capacity; }
    method get_type (line 18) | int get_type(){ return this->type; }
    method get_parent (line 22) | int get_parent(int child_index){
    method has_left_child (line 27) | bool has_left_child(int parent_index){
    method has_right_child (line 31) | bool has_right_child(int parent_index){
    method get_left_child (line 36) | int get_left_child(int parent_index){
    method get_right_child (line 43) | int get_right_child(int parent_index){
    method T (line 51) | T get_min(){
    method T (line 57) | T get_max(){
    method down (line 65) | void down(int parent_index){
    method is_full (line 93) | bool is_full(){
    method is_empty (line 97) | bool is_empty(){
    method resize (line 101) | void resize(){
    method insert (line 113) | void insert(T data){
    method heap (line 125) | heap(T ar[], int capacity, int type) : arr(new T[capacity]), size(capa...
    method print (line 130) | void print(){
    method is_heap (line 136) | bool is_heap(){

FILE: heap/min_heap.cpp
  class minHeap (line 5) | class minHeap{
    method heapify (line 8) | void heapify(int i){
    method minHeap (line 25) | minHeap(){
    method push (line 28) | void push(int data){
    method getmin (line 40) | int getmin(){
    method pop (line 43) | void pop(){
    method isEmpty (line 50) | bool isEmpty(){
  function main (line 55) | int main(){

FILE: os/scheduling/fcfs.cpp
  function findWaitingTime (line 8) | void findWaitingTime(int processes[], int n,
  function findTurnAroundTime (line 20) | void findTurnAroundTime( int processes[], int n,
  function findavgTime (line 30) | void findavgTime( int processes[], int n, int bt[])
  function main (line 61) | int main()

FILE: os/scheduling/os_priority.cpp
  type Process (line 6) | struct Process
  function comparison (line 14) | bool comparison(Process a, Process b)
  function findWaitingTime (line 21) | void findWaitingTime(Process proc[], int n,
  function findTurnAroundTime (line 33) | void findTurnAroundTime( Process proc[], int n,
  function findavgTime (line 43) | void findavgTime(Process proc[], int n)
  function priorityScheduling (line 74) | void priorityScheduling(Process proc[], int n)
  function main (line 87) | int main()

FILE: os/scheduling/os_roundrobin.cpp
  function findWaitingTime (line 6) | void findWaitingTime(int processes[], int n,
  function findTurnAroundTime (line 69) | void findTurnAroundTime(int processes[], int n,
  function findavgTime (line 79) | void findavgTime(int processes[], int n, int bt[],
  function main (line 111) | int main()

FILE: os/scheduling/os_sjf.cpp
  type Process (line 5) | struct Process
  function comparison (line 14) | bool comparison(Process a, Process b)
  function findWaitingTime (line 21) | void findWaitingTime(Process proc[], int n, int wt[])
  function findTurnAroundTime (line 32) | void findTurnAroundTime(Process proc[], int n,
  function findavgTime (line 42) | void findavgTime(Process proc[], int n)
  function main (line 74) | int main()

FILE: os/scheduling/os_srtf.cpp
  type Process (line 6) | struct Process {
  function findWaitingTime (line 14) | void findWaitingTime(Process proc[], int n,
  function findTurnAroundTime (line 82) | void findTurnAroundTime(Process proc[], int n,
  function findavgTime (line 92) | void findavgTime(Process proc[], int n)
  function main (line 129) | int main()

FILE: shellsort.c
  function shellsort (line 3) | void shellsort(int arr[], int num)
  function main (line 31) | int main()

FILE: sieve_of_eratoshthenes.cpp
  function sieve (line 6) | void sieve() {
Condensed preview — 253 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (430K chars).
[
  {
    "path": ".gitignore",
    "chars": 554,
    "preview": "build*/\n\n# ----------- C++ ------------------\n# Prerequisites\n*.d\n\n# Compiled Object files\n*.slo\n*.lo\n*.o\n*.obj\n\n# Preco"
  },
  {
    "path": "BST/BinarySearchTree.java",
    "chars": 2167,
    "preview": "/*\n* @author Nikunj Khokhar\n*/\npublic class BinarySearchTree {\n\n\n    class Node {\n        int key;\n        Node left, ri"
  },
  {
    "path": "BST/Delete.c",
    "chars": 972,
    "preview": "#include<stdio.h>\n#include<stdlib.h>\n\nstruct tree{\n\t\tint data;\n\t\tstruct tree *left;\n\t\tstruct tree *right;\n}*root=NULL,*n"
  },
  {
    "path": "BST/Height.c",
    "chars": 925,
    "preview": "#include<stdio.h>\n#include<stdlib.h>\n\nstruct tree{\n\t\tint data;\n\t\tstruct tree* left;\n\t\tstruct tree* right;\n};\n\nstruct tre"
  },
  {
    "path": "BST/Insert & Search.cpp",
    "chars": 1342,
    "preview": "/******************************************\r\n*    AUTHOR         :   VIVEK SHAH        *\r\n*    INSTITUTION    :   NIT SU"
  },
  {
    "path": "BST/MinMax_8.c",
    "chars": 1024,
    "preview": "#include<stdio.h>\n#include<stdlib.h>\nstruct tree{\n\t\tint data;\n\t\tstruct tree *left;\n\t\tstruct tree *right;\n}*root=NULL,*ne"
  },
  {
    "path": "BST/checkbst",
    "chars": 1409,
    "preview": "/ C++ program to check if a given tree is BST.\n#include <bits/stdc++.h>\nusing namespace std;\n \n/* A binary tree node has"
  },
  {
    "path": "BST/createBST.cpp",
    "chars": 1290,
    "preview": "#include<stdio.h>\n#include<stdlib.h>\n \ntypedef struct BST\n{\n    int data;\n    struct BST *left;\n    struct BST *right;\n}"
  },
  {
    "path": "BST/lca.cpp",
    "chars": 1908,
    "preview": "/*\n\tAuthor: Pritish Thakkar\n\tCodechef : joe001\n\tBlog : http://sleepincode.blogspot.com\n*/\n\n/// SUMMARY: \n/// The lowest "
  },
  {
    "path": "BST/spiraltransversal.c",
    "chars": 2778,
    "preview": "#include <stdio.h>\r\n#include <stdlib.h>\r\n#include <stdbool.h>\r\n#include<malloc.h>\r\n//structure of node\r\nstruct node{\r\nin"
  },
  {
    "path": "Backtrack/NQueen.cpp",
    "chars": 1514,
    "preview": "#include <iostream>\nusing namespace std;\n\nbool isSafe(char board[][100], int row, int column, int n){\n\t\n\t//check that wh"
  },
  {
    "path": "Backtrack/Rat_Maze_Recurssion_Backtracking.c",
    "chars": 889,
    "preview": "#include<stdio.h>\n#define N 4\n\nvoid display(int sol[N][N])\n{\n\tint i,j;\n\tfor(i=0;i<N;i++)\n\t{\n\t\tfor(j=0;j<N;j++)\n\t\t\tprintf"
  },
  {
    "path": "Backtrack/nqueen_allsol.py",
    "chars": 1366,
    "preview": "def initialize(board,n):\r\n    keys=['queen','row','col','pdiag','sdiag']\r\n    for i in keys:\r\n        board[i]={}\r\n    f"
  },
  {
    "path": "Backtrack/permutations_of_string.cpp",
    "chars": 797,
    "preview": "// Solution for printing all the permutations of a string.\n#include<bits/stdc++.h>\n\n/* Function to swap values at two po"
  },
  {
    "path": "CONTRIBUTING.md",
    "chars": 2226,
    "preview": "<h1>Contributing Guidelines for Algo_Ds</h1>\n\n<p>Thanks for taking the time to contribute to this project. Before making"
  },
  {
    "path": "Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/buy_max_with_given_money.cpp",
    "chars": 1917,
    "preview": "//https://www.hackerrank.com/contests/gs-codesprint/challenges/buy-maximum-stock////i///////i/s\n#include<bits/stdc++.h>\n"
  },
  {
    "path": "Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/median searching efficientalgo.cpp",
    "chars": 1087,
    "preview": "#include<iostream>\n#include<vector>\n#include<algorithm>\n#include<array>\nusing namespace std;\nint median(int *a,int s,int"
  },
  {
    "path": "Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques/volcano.cpp",
    "chars": 2369,
    "preview": "//https://www.hackerrank.com/contests/university-codesprint-3/challenges/erupting-volcanoes\n#include<bits/stdc++.h>\n\n#de"
  },
  {
    "path": "Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques-beat_the_clock/spiral_matrix.cpp",
    "chars": 2391,
    "preview": "#include<bits/stdc++.h>\n\n#define F0(i,t) for(int i=0; i<t; i++)\n#define F1(i,t) for(int i=1; i<=t; i++)\n#define Si(x) sc"
  },
  {
    "path": "Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques-l1/codeforces_426_2.cpp",
    "chars": 816,
    "preview": "//http://codeforces.com/problemset/problem/834/B\n#include<bits/stdc++.h>\n\nusing namespace std;\n\nint main(){\n    int g,k;"
  },
  {
    "path": "Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques-l1/positions.cpp",
    "chars": 508,
    "preview": "//https://www.hackerearth.com/problem/algorithm/attack-on-daleks/\n#include<bits/stdc++.h>\nusing namespace std;\n\nint main"
  },
  {
    "path": "Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques-l1/snake/snake.cpp",
    "chars": 3559,
    "preview": "//https://www.hackerrank.com/contests/university-codesprint-3/challenges/the-snake-vs-the-wind\n#include<bits/stdc++.h>\n\n"
  },
  {
    "path": "Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/ques-l1/snake/wrong_snake.cpp",
    "chars": 4275,
    "preview": "//https://www.hackerrank.com/contests/university-codesprint-3/challenges/the-snake-vs-the-wind\n#include<bits/stdc++.h>\n\n"
  },
  {
    "path": "Competitive Programming Challenges/C:C++/HackerEarth:CodeForces/searchmat.cpp",
    "chars": 1154,
    "preview": "// A program to search for an element in a 2D matrix in which each row and coloumn is sorted in ascending order\n#include"
  },
  {
    "path": "Competitive Programming Challenges/C:C++/Patterns/pattern1.cpp",
    "chars": 228,
    "preview": "#include <iostream>\nusing namespace std;\n\nint main(){\n\n\tint n;\n\tcin >> n;\n\n\tfor( int i = 0; i < n; i++ ){\n\t\tfor( int j ="
  },
  {
    "path": "Competitive Programming Challenges/C:C++/Patterns/pattern2.cpp",
    "chars": 226,
    "preview": "#include <iostream>\nusing namespace std;\n\nint main(){\n\n\tint n;\n\tcin >> n;\n\n\tfor( int i = 0; i < n; i++ ){\n\t\tfor( int j ="
  },
  {
    "path": "Competitive Programming Challenges/C:C++/Patterns/pattern3.cpp",
    "chars": 225,
    "preview": "#include <iostream>\nusing namespace std;\n\nint main(){\n\n\tint n;\n\tcin >> n;\n\n\tfor( int i = n; i > 0; i-- ){\n\t\tfor( int j ="
  },
  {
    "path": "Competitive Programming Challenges/C:C++/Patterns/pattern4.cpp",
    "chars": 347,
    "preview": "#include <iostream>\nusing namespace std;\n\nint main(){\n\n\tint n;\n\tcin >> n;\n\n\tfor( int i = 0; i < n; i++ ){\n\t\tfor( int j ="
  },
  {
    "path": "Competitive Programming Challenges/C:C++/Patterns/pattern6.cpp",
    "chars": 226,
    "preview": "#include <iostream>\nusing namespace std;\n\nint main(){\n\n\tint n;\n\tcin >> n;\n\n\tfor( int i = 1; i <= n; i++ ){\n\t\tfor( int j "
  },
  {
    "path": "Competitive Programming Challenges/C:C++/Patterns/pattern7.cpp",
    "chars": 279,
    "preview": "#include <iostream>\nusing namespace std;\n\nint main(){\n\tint n;\n\tcin >> n;\n\n\tint count = 1;\n\tfor( int i = 0; i < n; i++ ){"
  },
  {
    "path": "Conversions/C:C++/binary2octal.c",
    "chars": 1134,
    "preview": "// Binary number to octal number conversion\r\n#include<stdio.h>\r\n\r\n//Function that returns the last three digits\r\nint thr"
  },
  {
    "path": "Data Structures/C:C++/Applications/Evaluating Postfix Expression.c",
    "chars": 983,
    "preview": "#include <stdio.h>\r\n#include <string.h>\r\n#define MAX 200\r\n\r\nint isoperator(char c){\r\n\treturn (c=='*' || c=='/' || c=='+'"
  },
  {
    "path": "Data Structures/C:C++/Applications/Infix to Postfix.c",
    "chars": 1461,
    "preview": "#include<stdio.h>\r\n\r\nint j;\r\nstruct temp{\r\n\tchar a[200];\r\n\tint top;\r\n};\r\nstruct temp s;\r\n\r\nvoid push(char item){\r\n\ts.a[+"
  },
  {
    "path": "Data Structures/C:C++/Applications/balance parenthesis.cpp",
    "chars": 820,
    "preview": "#include<iostream>\r\n#include<bits/stdc++.h>\r\n#include<string.h>\r\n#include<stack>\r\nusing namespace std;\r\n\r\nint main(){\r\n\t"
  },
  {
    "path": "Data Structures/C:C++/Applications/stack_and_its_implementation.c",
    "chars": 1703,
    "preview": "//Auhor : VIVEK SHAH\r\n/*Performs Push, Pop, Peep and Displays elements of Stack*/\r\n\r\n\r\n#include<stdio.h>\r\n\r\nstruct stack"
  },
  {
    "path": "Data Structures/C:C++/Graph/FloydWarshall.cpp",
    "chars": 940,
    "preview": "//Floyd Warshall Algorithm for All Pair Shortest Path Problem\n#include <bits/stdc++.h>\n#define FOR(i,n) for(size_t i=0;i"
  },
  {
    "path": "Data Structures/C:C++/Graph/adjacency_list.hpp",
    "chars": 2005,
    "preview": "#include <iostream>\r\n#include <vector>\r\n#include \"../queue/queue.hpp\"\r\nusing namespace std;\r\n\r\ntemplate<typename T>\r\ncla"
  },
  {
    "path": "Data Structures/C:C++/Graph/adjacency_matrix.hpp",
    "chars": 1671,
    "preview": "#include <iostream>\r\n#include \"../queue/queue.hpp\"\r\nusing namespace std;\r\n\r\ntemplate<typename T>\r\nclass graph_am {\r\npriv"
  },
  {
    "path": "Data Structures/C:C++/Graph/bfs_dfs/bfs/BFS.java",
    "chars": 2878,
    "preview": "/**\n * Input file example:\n *\n *\n * 8\n * INF 1 1 INF INF INF INF INF\n * 1 INF INF 1 1 INF INF INF\n * 1 INF INF INF INF 1"
  },
  {
    "path": "Data Structures/C:C++/Graph/bfs_dfs/bfs/bfs.Py",
    "chars": 1523,
    "preview": "# Program to print BFS traversal from a given source\n# vertex. BFS(int s) traverses vertices reachable\n# from s.\nfrom co"
  },
  {
    "path": "Data Structures/C:C++/Graph/bfs_dfs/ques/graph_connected_components.cpp",
    "chars": 907,
    "preview": "#include <iostream>\n#include <vector>\nusing namespace std;\n\nvector <int> adj[12];\nbool visited[12];\n\nvoid dfs(int s) {\n "
  },
  {
    "path": "Data Structures/C:C++/Graph/bfs_dfs/ques/tbbfs.cpp",
    "chars": 1678,
    "preview": "//http://www.spoj.com/problems/TDBFS/\n#include<bits/stdc++.h>\n#define dout if(debugg) cout<<\" \"\nusing namespace std;\n\nin"
  },
  {
    "path": "Data Structures/C:C++/Graph/dijakstra/Dijkstra.java",
    "chars": 3654,
    "preview": "import java.io.BufferedWriter;\nimport java.io.FileInputStream;\nimport java.io.FileWriter;\nimport java.io.IOException;\nim"
  },
  {
    "path": "Data Structures/C:C++/Graph/dijakstra/dist_from_source.cpp",
    "chars": 1369,
    "preview": "//https://www.codechef.com/problems/BUG2K17B\n#include<bits/stdc++.h>\n#define mp pair<int,int>\nusing namespace std;\n\nint "
  },
  {
    "path": "Data Structures/C:C++/Graph/dijakstra/dist_from_source_oops.cpp",
    "chars": 1936,
    "preview": "//https://www.codechef.com/APRIL17/problems/CLIQUED\n//  only dijastra ques not complete\n#include<bits/stdc++.h>\n#define "
  },
  {
    "path": "Data Structures/C:C++/Graph/dijakstra/ques/min_path.cpp",
    "chars": 2838,
    "preview": "//https://www.codechef.com/SEPT17/problems/QGRID\n#include<bits/stdc++.h>\n#define ulli long long int\n#define dout if(debu"
  },
  {
    "path": "Data Structures/C:C++/Graph/dijakstra/ques/qgrid_11.cpp",
    "chars": 2993,
    "preview": "#include<bits/stdc++.h>\n#define ulli long long int\nusing namespace std;\ntypedef pair<ulli,ulli> mp; \ntypedef pair<mp,ull"
  },
  {
    "path": "Data Structures/C:C++/Graph/shortest_paths.hpp",
    "chars": 685,
    "preview": "#include <vector>\r\n#include <queue>\r\n#include <utility> // for pair, make_pair etc\r\nusing namespace std;\r\n\r\n/*\r\n * Short"
  },
  {
    "path": "Data Structures/C:C++/Graph/topological_sort.hpp",
    "chars": 1013,
    "preview": "#include <iostream>\r\n#include <vector>\r\n#include <stack>\r\nusing namespace std;\r\n\r\n// util function\r\nvoid _ts(int v, bool"
  },
  {
    "path": "Data Structures/C:C++/Graph/tree/binarySearchTree/bsTree.cpp",
    "chars": 4233,
    "preview": "// This a program to demonstrate insert in a binary tree through recursion it also keeps count of all child of a node an"
  },
  {
    "path": "Data Structures/C:C++/Linked List/Circular_LL.c",
    "chars": 4799,
    "preview": "/*\r\n\t***********************\r\n\tAuthor   : Vivek Shah\r\n\tQuestion : Circular LL\r\n\t***********************\r\n*/\r\n\r\n#include<"
  },
  {
    "path": "Data Structures/C:C++/Linked List/Circular_ll.cpp",
    "chars": 7687,
    "preview": "/*\n * C++ Program to Implement Circular Linked List \n */\n#include<iostream>\n#include<cstdio>\n#include<cstdlib>\nusing nam"
  },
  {
    "path": "Data Structures/C:C++/Linked List/Doubly LL.c",
    "chars": 4663,
    "preview": "/*\r\n\t***********************\r\n\tAuthor   : Vivek Shah\r\n\tQuestion : Doubly LL\r\n\t***********************\r\n*/\r\n\r\n#include<st"
  },
  {
    "path": "Data Structures/C:C++/Linked List/Insertion_Deletion_SinglyLL.c",
    "chars": 1258,
    "preview": "#include<stdio.h>\r\n\r\nstruct node{\r\n\tint item;\r\n\tstruct node* next;\r\n};\r\n\r\nstruct node* head;\r\n\r\nvoid Insert(){\r\n\tstruct "
  },
  {
    "path": "Data Structures/C:C++/Linked List/Queue using LinkedList.cpp",
    "chars": 1386,
    "preview": "/******************************************\n*    AUTHOR         :   VIVEK SHAH        *\n*    INSTITUTION    :   NIT SURA"
  },
  {
    "path": "Data Structures/C:C++/Linked List/Queue_using_linkedlist.c",
    "chars": 1216,
    "preview": "#include<stdio.h>\r\n\r\n//insert at beginning and remove at the end\r\n\r\nstruct node{\r\n\tint item;\r\n\tstruct node* next;\r\n};\r\n\r"
  },
  {
    "path": "Data Structures/C:C++/Linked List/Reverse_SinglyLL.c",
    "chars": 987,
    "preview": "#include<stdio.h>\r\n\r\nstruct node{\r\n\tint item;\r\n\tstruct node* next;\r\n};\r\n\r\nstruct node* head;\r\n\r\nstruct node* reverse(){\r"
  },
  {
    "path": "Data Structures/C:C++/Linked List/all_operations_of_Doubly_ll.cpp",
    "chars": 6303,
    "preview": "/*\n * C++ Program to Implement Doubly Linked List \n */\n#include<iostream>\n#include<cstdio>\n#include<cstdlib>\n/*\n * Node "
  },
  {
    "path": "Data Structures/C:C++/Linked List/concatinate.c",
    "chars": 2478,
    "preview": "#include<stdio.h>\r\n#include<conio.h>\r\n#include<malloc.h>\r\nstruct node\r\n{\r\n    int data;\r\n    struct node *next;\r\n};\r\nstr"
  },
  {
    "path": "Data Structures/C:C++/Linked List/doubly circular.c",
    "chars": 5599,
    "preview": "/*\r\n\t***********************\r\n\tAuthor   : Vivek Shah\r\n\tQuestion : Doubly Circular LL\r\n\t***********************\r\n*/\r\n\r\n#i"
  },
  {
    "path": "Data Structures/C:C++/Linked List/doubly linked list.c",
    "chars": 1078,
    "preview": "#include<stdio.h>\r\n\r\nstruct node{\r\n\tint item;\r\n\tstruct node* pre;\r\n\tstruct node* next;\r\n};\r\n\r\nstruct node *head, *ptr;\r\n"
  },
  {
    "path": "Data Structures/C:C++/Linked List/linked_list.c",
    "chars": 4061,
    "preview": "#include <stdio.h>\r\n#include<stdlib.h>\r\n#include<string.h>\r\nstruct node\r\n{\r\n\tint roll;\r\n\tchar name[100];\r\n\tfloat cgpa;\r\n"
  },
  {
    "path": "Data Structures/C:C++/Linked List/ordered_linked.c",
    "chars": 3820,
    "preview": "#include <stdio.h>\n#include<stdlib.h>\n#include<string.h>\nstruct node\n{\n\tint roll;\n\tchar name[100];\n\tfloat cgpa;\n\tstruct "
  },
  {
    "path": "Data Structures/C:C++/Linked List/reverse.cpp",
    "chars": 1897,
    "preview": "#include<iostream>\r\n#include<malloc.h>\r\nusing namespace std;\r\n//structure of node\r\nstruct node\r\n{\r\n    int data;\r\n    st"
  },
  {
    "path": "Data Structures/C:C++/Linked List/stackLinkedList.cpp",
    "chars": 1063,
    "preview": "#include<bits/stdc++.h>\r\n\r\nstruct node{\r\n\tint item;\r\n\tstruct node* next;\r\n};\r\n\r\nstruct node* head;\r\nint size;\r\n\r\nvoid in"
  },
  {
    "path": "Data Structures/C:C++/Linked List/stack_Linked_List.c",
    "chars": 1916,
    "preview": "/*Implementation of stack using linked list */\r\n\r\n/*Stack is a LIFO (Last In Fast Out Data Structure */\r\n\r\n/*\r\n * push o"
  },
  {
    "path": "Data Structures/C:C++/Stack/Balanced_Brackets.cpp",
    "chars": 1640,
    "preview": "/*This program checks whether an entered string is Bracket Balanced ot not.By Bracket balanced we mean a opening bracket"
  },
  {
    "path": "Data Structures/C:C++/Stack/Reverse_Queue.cpp",
    "chars": 952,
    "preview": "/*\nAn effective CPP program to reverse a Queue.In this program,\na Queue is populated with values and then it is reversed"
  },
  {
    "path": "Data Structures/C:C++/Stack/Stack_as_linked_list.cpp",
    "chars": 1999,
    "preview": "C++ Program to implement Stack using Linked List:\n\n#include<iostream>\nusing namespace std;\n\n\n//   Creating a NODE Struct"
  },
  {
    "path": "Data Structures/C:C++/Stack/largestRectangleHistogram.cpp",
    "chars": 729,
    "preview": "#include<iostream>\n#include<stack>\n#include<climits>\nusing namespace std;\nint main() {\n    int n;\n    int a[]={6,2,5,4,5"
  },
  {
    "path": "Data Structures/C:C++/Stack/nextgreaterelement",
    "chars": 497,
    "preview": "//http://www.geeksforgeeks.org/next-greater-element/\n\n//The problem is from geekforgeeks and it is my implementation of "
  },
  {
    "path": "Data Structures/C:C++/Stack/stack.hpp",
    "chars": 1357,
    "preview": "#include <bits/stdc++.h>\r\n#include \"../linked_list/ll.hpp\"\r\nusing namespace std;\r\n\r\ntemplate<class T>\r\nstruct stackmp{\r\n"
  },
  {
    "path": "Data Structures/C:C++/Trees/segment_tree/segment_tree.cpp",
    "chars": 1864,
    "preview": "#include <bits/stdc++.h>\n\nusing namespace std;\n\nvoid createMinSegmentTree(int arr[],int sg[],int index,int begin,int end"
  },
  {
    "path": "Data Structures/C:C++/Trees/segment_tree/segment_trees_lazy.cpp.cpp",
    "chars": 3410,
    "preview": "/**\n * In this code we have a very large array called arr, and very large set of operations\n * Operation #1: Increment t"
  },
  {
    "path": "Data Structures/C:C++/Trees/tree/Fenwick_tree.cpp",
    "chars": 674,
    "preview": "#include<iostream>\nusing namespace std;\nint BIT[1000], arr[1000],l,r,n,s;\nvoid update(int x, int delta)\n{\n      for( ;x<"
  },
  {
    "path": "Data Structures/C:C++/Trees/tree/bst.hpp",
    "chars": 5232,
    "preview": "#include <bits/stdc++.h>\n#include \"../queue/queue.hpp\"\nusing namespace std;\n\ntemplate<class T>\nstruct bst_node{\n\tT data;"
  },
  {
    "path": "Data Structures/C:C++/Trees/tree/segment_tree.hpp",
    "chars": 2653,
    "preview": "#include <iostream>\n#include <math.h>\n\nclass segment_tree{\nprivate:\n    int *st;\n    int *ar;\n    int len;\n    int sz; /"
  },
  {
    "path": "Data Structures/C:C++/Trees/tree/tree.hpp",
    "chars": 629,
    "preview": "#include <bits/stdc++.h>\nusing namespace std;\n\ntemplate<class T>\nstruct tree_node{\n\tT data;\n\ttree_node *left_child;\n\ttre"
  },
  {
    "path": "Data Structures/C:C++/Trees/tree/trie.cpp",
    "chars": 535,
    "preview": "#include <bits/stdc++.h>\nusing namespace std;\n\ntypedef long long int ll;\nint ii,i,at;\nstruct no{\n\tno* nxt[26];\n\tno *root"
  },
  {
    "path": "Data Structures/C:C++/queue/queue.hpp",
    "chars": 1328,
    "preview": "#include <bits/stdc++.h>\r\n#include \"../linked_list/ll.hpp\"\r\nusing namespace std;\r\n\r\ntemplate<class T>\r\nstruct queuemp{\r\n"
  },
  {
    "path": "Data Structures/Java/Stack/Stack.java",
    "chars": 1404,
    "preview": "import java.lang.IndexOutOfBoundsException;\nimport java.util.Arrays;\n\npublic class Stack<E> {\n    private int max;\n    p"
  },
  {
    "path": "Data Structures/Python/Graphs/Graph.py",
    "chars": 1702,
    "preview": "from collections import defaultdict\n\n\nclass Graph(object):\n\n\n    def __init__(self, connections, directed=False):#undire"
  },
  {
    "path": "Data Structures/Python/Graphs/dfs.py",
    "chars": 1093,
    "preview": "import collections\n\nclass Graph:\n    def __init__(self):\n        self.adjList = collections.defaultdict(set)\n\n    def ad"
  },
  {
    "path": "Data Structures/Python/Linked List/singly_linked_list.py",
    "chars": 1290,
    "preview": "class Node(object):\n \n    def __init__(self, data, next):\n        self.data = data\n        self.next = next\n \n \nclass Si"
  },
  {
    "path": "Data Structures/Python/Queue/Queue.py",
    "chars": 662,
    "preview": "#List Based Implementation Of Queue in Python.\n\n\n#Defining a python Class named Queue.\n\n# isEmpty -> Returns True or Fal"
  },
  {
    "path": "Data Structures/Python/Stack/stack.py",
    "chars": 506,
    "preview": "\n#Make a class Stack\nclass Stack:\n   def __init__(self):\n\t         self.items = []\n\t\n\t  def isEmpty(self):\n\t         ret"
  },
  {
    "path": "Data Structures/Python/Trees/m-coloring-problem.py",
    "chars": 1059,
    "preview": "class Graph:\n    def __init__(self,m,v):\n        self.adj=m\n        self.V=v\n\ndef mColoring(k,m,g,x):\n\n    while(True):\n"
  },
  {
    "path": "Dynamic Programing/Dynamic_fibonacci.py",
    "chars": 508,
    "preview": "# Function for nth fibonacci number - Dynamic Programing\n# Taking 1st two fibonacci nubers as 0 and 1\n \nFibArray = [0,1]"
  },
  {
    "path": "Dynamic Programing/Edit Distance.Py",
    "chars": 547,
    "preview": "memo={}\n\ndef DP(x,y,i,j):\n    if i>=len(x):\n        memo[(i,j)]=len(y)-j\n        return len(y)-j\n    if j>=len(y):\n     "
  },
  {
    "path": "Dynamic Programing/Knapsack.py",
    "chars": 789,
    "preview": "######'''Knapsack problem'''#####\n\nmemo={}\nincluded={}\ndef DP(val,s,i,x):\n    if i==len(val) or x==0:\n        return 0\n "
  },
  {
    "path": "Dynamic Programing/Memoized Cut Rod.Py",
    "chars": 501,
    "preview": "import math\nmemo={}\npiece={}\n\ndef cut_rod(p,n):\n    if n==0:\n        return 0\n    if n in memo:\n        return memo[n]\n "
  },
  {
    "path": "Dynamic Programing/Word_Wrap.Py",
    "chars": 870,
    "preview": "import math\nmemo={}\nparent={}\ndef badness(i,j,m):\n    totsize=0\n    extra=0\n    for x in range(i,j):\n        totsize+=le"
  },
  {
    "path": "Dynamic Programing/longest_increasing_subsequence.cpp",
    "chars": 507,
    "preview": "#include <iostream>\nusing namespace std;\nint longestIncreasingSubsequence(int A[],int size){\n    int dp[size];\n    for(i"
  },
  {
    "path": "Mathematical Challenges/C:C++/Fibonacci/Fibonacci Test.cpp",
    "chars": 525,
    "preview": "/*\nThis code illustrates an easier and faster way to check whether a number is\na Fibonacci Number or not.\n*/\n#include <i"
  },
  {
    "path": "Mathematical Challenges/C:C++/Square Root Decomposition/MO's Algorithm/MOAlgo.cpp",
    "chars": 1975,
    "preview": "//Problem : http://www.spoj.com/problems/DQUERY/\n//Time Complexity : O((n+q)*sqrt(n))\n\n#include <bits/stdc++.h>\n \n#defin"
  },
  {
    "path": "Mathematical Challenges/C:C++/armstrong_number/C/armstrong.c",
    "chars": 414,
    "preview": "#include<stdio.h>\r\n#include<math.h>\r\n\r\nint main(void)\r\n{\r\n\tint n,r,a=0,t,c=0,z;\r\n\tprintf(\"Enter a number: \");\r\n\tscanf(\"%"
  },
  {
    "path": "Mathematical Challenges/C:C++/armstrong_number/README.md",
    "chars": 427,
    "preview": "### Armstrong number\r\n\r\nGiven a number x, determine whether the given number is Armstrong number or not. A positive inte"
  },
  {
    "path": "Mathematical Challenges/C:C++/convexHull/ConvexHullScan.cpp",
    "chars": 2349,
    "preview": "#include <iostream>\n#include <vector>\n#include <set>\n#include <utility>\n#include <algorithm>\n\nusing namespace std;\n\n//Th"
  },
  {
    "path": "Mathematical Challenges/C:C++/factorial/factorial.c",
    "chars": 166,
    "preview": "#include<stdio.h>\nint main(){\nint x;\nprintf(\"Enter the number\");\nscanf(\"%d\",&x);\n\nint fact=1;\n\nfor(fact=1;x>1;x--){\nfact"
  },
  {
    "path": "Mathematical Challenges/C:C++/fibbinacci/fibbinacci.c",
    "chars": 172,
    "preview": "\n#include<stdio.h>\nint main(){\nint x,y,z;\nprintf(\"Enter the number\\n\");\nscanf(\"%d\",&x);\n\nint temp=0;\nfor(int i=0;i<=x;i+"
  },
  {
    "path": "Mathematical Challenges/C:C++/gcd/extended_gcd.cpp",
    "chars": 1817,
    "preview": "#include<bits/stdc++.h>\n\n#define F0(i,t) for(int i=0; i<t; i++)\n#define F1(i,t) for(int i=1; i<=t; i++)\n#define Si(x) sc"
  },
  {
    "path": "Mathematical Challenges/C:C++/gcd/gcd.cpp",
    "chars": 371,
    "preview": "#include<stdio.h>\n\n/*\n * be careful a must not be zero\n * if so then ans is b\n */\nint gcd(int a,int b){\n    if(b%a==0)\n "
  },
  {
    "path": "Mathematical Challenges/C:C++/gcd/mod_inverse.cpp",
    "chars": 2010,
    "preview": "#include<bits/stdc++.h>\n\n#define F0(i,t) for(int i=0; i<t; i++)\n#define F1(i,t) for(int i=1; i<=t; i++)\n#define Si(x) sc"
  },
  {
    "path": "Mathematical Challenges/C:C++/largestoutof3/largestoutof3.c",
    "chars": 232,
    "preview": "#include<stdio.h>\nint main(){\nint x,y,z;\nprintf(\"Enter 1st number\");\nscanf(\"%d\",&x);\n\nprintf(\"Enter 2nd number\");\nscanf("
  },
  {
    "path": "Mathematical Challenges/C:C++/mathpuzzle.c/matchstick game",
    "chars": 867,
    "preview": "//21 matchstick game in C\n#include <stdio.h>\nint main (int argc, const char * argv[])\n{\n    int matchstick = 21;\n    int"
  },
  {
    "path": "Mathematical Challenges/C:C++/multiplication/multiply 2 numbers greater than 10^6.cpp",
    "chars": 1203,
    "preview": "/*\nThis program can be used to multiply 2 numbers grater than 10^5, usually a major hurdle in languages like C/C++\nin co"
  },
  {
    "path": "Mathematical Challenges/C:C++/power/modular_exponention.cpp",
    "chars": 792,
    "preview": "#include<bits/stdc++.h>\n#define ui unsigned long long int\n#define mod 1000000007\nusing namespace std;\n\n//faster wayy to "
  },
  {
    "path": "Mathematical Challenges/C:C++/power/ques/summation.cpp",
    "chars": 880,
    "preview": "//http://www.spoj.com/problems/SUMMATION/\n#include<bits/stdc++.h>\n#define ui unsigned long long int\n#define mod 10000000"
  },
  {
    "path": "Mathematical Challenges/C:C++/power/two_pow.cpp",
    "chars": 1247,
    "preview": "#include<bits/stdc++.h>\n\n#define F0(i,t) for(int i=0; i<t; i++)\n#define F1(i,t) for(int i=1; i<=t; i++)\n#define Si(x) sc"
  },
  {
    "path": "Mathematical Challenges/C:C++/powerset/PowerSet.java",
    "chars": 1094,
    "preview": "import java.util.*;\npublic class PowerSet {\n    \n        public static <T> Set<Set<T>> powerSet( Set<T> set ) {\n        "
  },
  {
    "path": "Mathematical Challenges/C:C++/prime/PrimeCheck.py",
    "chars": 678,
    "preview": "#Simple way to check for primes using Pyton.\n\n#Prompt user for a integer\nNumber = int(input(\"Enter any integer to check "
  },
  {
    "path": "Mathematical Challenges/C:C++/prime/PrimeToNumber.py",
    "chars": 562,
    "preview": "#Python Prime checker. Not the most efficient way to check for primes, but very easy to code!\n\nnum = int(input(\"Enter a "
  },
  {
    "path": "Mathematical Challenges/C:C++/prime/prime.c",
    "chars": 290,
    "preview": "#include<stdio.h>\nint main(){\nint x,y,z;\nprintf(\"Enter the number\\n\");\nscanf(\"%d\",&x);\ny=x/2;\nif(x%2==0 && x!=2){\nprintf"
  },
  {
    "path": "Mathematical Challenges/C:C++/prime/sieveOferatosthenes.cpp",
    "chars": 1045,
    "preview": "#include <iostream>\n#include <vector>\nusing namespace std;\nvoid sieve_of_eratosthenes(std::vector<int>& primes, const in"
  },
  {
    "path": "Mathematical Challenges/C:C++/prime number tricks/List all primes.cpp",
    "chars": 692,
    "preview": "/*\nThis code illustrates that all primes are of the form (6k +- 1)\nPlease note this also includes some non-prime numbers"
  },
  {
    "path": "Mathematical Challenges/C:C++/ques/cpcrc1c.cpp",
    "chars": 1119,
    "preview": "//http://www.spoj.com/problems/CPCRC1C/\n#include<bits/stdc++.h>\n#define ui unsigned long long int\n\nusing namespace std;\n"
  },
  {
    "path": "Mathematical Challenges/python/pernicious_prime/pernicious.py",
    "chars": 2869,
    "preview": "'''This is a proposed brute force algorithm writtem in python \nto test whether a given input positive integer other than"
  },
  {
    "path": "Mathematical Challenges/python/sieve_of_eratoshthenes.py",
    "chars": 354,
    "preview": "import sys\nimport array\nimport math\nisprime=array.array('i',(0 for i in range(0,1001)))\ndef sieve():\n    for i in range("
  },
  {
    "path": "Patterns/pattern10.cpp",
    "chars": 343,
    "preview": "#include <iostream>\nusing namespace std;\n\nint main(){\n\n\tint n;\n\tcin >> n;\n\n\tint count = 1;\n\n\tchar spaces = ' ';\n\tfor( in"
  },
  {
    "path": "Patterns/pattern11.cpp",
    "chars": 361,
    "preview": "#include <iostream>\nusing namespace std;\n\nint main(){\n\n\tint n;\n\tcin >> n;\n\n\tint count = 1;\n\n\tchar spaces = ' ';\n\tfor( in"
  },
  {
    "path": "Patterns/pattern12.cpp",
    "chars": 343,
    "preview": "#include <iostream>\nusing namespace std;\n\nint main(){\n\n\tint n;\n\tcin >> n;\n\n\tint count = 1;\n\n\tchar spaces = ' ';\n\tfor( in"
  },
  {
    "path": "Patterns/pattern13.cpp",
    "chars": 328,
    "preview": "#include <iostream>\nusing namespace std;\n\nint main(){\n\n\tint n;\n\tcin >> n;\n\tint count = 1;\n\n\tchar spaces = ' ';\n\tfor( int"
  },
  {
    "path": "Patterns/pattern14.cpp",
    "chars": 588,
    "preview": "#include <iostream>\nusing namespace std;\n\nint main(){\n\n\tint n;\n\tcin >> n;\n\n\tint count = 1;\n\n\tchar spaces = ' ';\n\tfor( in"
  },
  {
    "path": "Patterns/pattern15.cpp",
    "chars": 555,
    "preview": "#include <iostream>\nusing namespace std;\n\nint main(){\n\n\tint n;\n\tcin >> n;\n\n\tint count = 1;\n\n\tchar spaces = ' ';\n\tfor( in"
  },
  {
    "path": "Patterns/pattern16.cpp",
    "chars": 509,
    "preview": "#include <iostream>\nusing namespace std;\n\nint main(){\n\n\tint n;\n\tcin >> n;\n\n\tint count = 1;\n\n\tchar spaces = ' ';\n\tfor( in"
  },
  {
    "path": "Patterns/pattern8.cpp",
    "chars": 313,
    "preview": "#include <iostream>\nusing namespace std;\n\nint main(){\n\tint n;\n\tcin >> n;\n\n\tint count = 1;\n\tfor( int i = 0; i < n; i++ ){"
  },
  {
    "path": "Patterns/pattern9.cpp",
    "chars": 315,
    "preview": "#include <iostream>\nusing namespace std;\n\nint main(){\n\n\tint n;\n\tcin >> n;\n\n\tchar spaces = ' ';\n\tfor( int i = 1; i <= 5; "
  },
  {
    "path": "README.md",
    "chars": 1552,
    "preview": "# Algo_Ds\n\n\n## Overview:\nThis repo is a conglomeration of algorithms for competitive programming, data structure, sortin"
  },
  {
    "path": "STL C++/STACK_with_Application/Evaluating Postfix Expression.c",
    "chars": 983,
    "preview": "#include <stdio.h>\r\n#include <string.h>\r\n#define MAX 200\r\n\r\nint isoperator(char c){\r\n\treturn (c=='*' || c=='/' || c=='+'"
  },
  {
    "path": "STL C++/STACK_with_Application/Infix to Postfix.c",
    "chars": 1461,
    "preview": "#include<stdio.h>\r\n\r\nint j;\r\nstruct temp{\r\n\tchar a[200];\r\n\tint top;\r\n};\r\nstruct temp s;\r\n\r\nvoid push(char item){\r\n\ts.a[+"
  },
  {
    "path": "STL C++/STACK_with_Application/balance parenthesis.cpp",
    "chars": 820,
    "preview": "#include<iostream>\r\n#include<bits/stdc++.h>\r\n#include<string.h>\r\n#include<stack>\r\nusing namespace std;\r\n\r\nint main(){\r\n\t"
  },
  {
    "path": "STL C++/STACK_with_Application/stack_and_its_implementation.c",
    "chars": 1703,
    "preview": "//Auhor : VIVEK SHAH\r\n/*Performs Push, Pop, Peep and Displays elements of Stack*/\r\n\r\n\r\n#include<stdio.h>\r\n\r\nstruct stack"
  },
  {
    "path": "STL C++/sorting_a_vector.cpp",
    "chars": 570,
    "preview": "#include<iostream>\r\n#include<cstring>\r\n#include<vector>\r\n#include<algorithm>\r\nusing namespace std;\r\n\r\nbool compare(int a"
  },
  {
    "path": "STL C++/stack/Stack.java",
    "chars": 1404,
    "preview": "import java.lang.IndexOutOfBoundsException;\nimport java.util.Arrays;\n\npublic class Stack<E> {\n    private int max;\n    p"
  },
  {
    "path": "STL C++/stack/largestRectangleHistogram.cpp",
    "chars": 729,
    "preview": "#include<iostream>\n#include<stack>\n#include<climits>\nusing namespace std;\nint main() {\n    int n;\n    int a[]={6,2,5,4,5"
  },
  {
    "path": "STL C++/stack/stack.hpp",
    "chars": 1276,
    "preview": "#include <bits/stdc++.h>\r\n#include \"../linked_list/ll.hpp\"\r\nusing namespace std;\r\n\r\ntemplate<class T>\r\nstruct stackmp{\r\n"
  },
  {
    "path": "STL C++/using_map.cpp",
    "chars": 425,
    "preview": "map <int, int> m;\nmap <int, int> :: iterator it;\n\nm[1] = 2;\nm[2] = 3;\nm[6] = 4;\nm[5] = 5;\n\nit = m.find(5);\nif (it != m.e"
  },
  {
    "path": "STL C++/using_set.cpp",
    "chars": 566,
    "preview": "set <int> s;\ns.insert(5); // 5 is inserted into set\ns.insert(2); // 2 is inserted into set\ns.insert(3); // 3 is inserted"
  },
  {
    "path": "STRUCTURE.md",
    "chars": 532,
    "preview": "\n# Directory Structure Example\n\n## please maintain the directory structure as in this example\n\n- Data structures\n   - st"
  },
  {
    "path": "Searching Algorithms/Bogo_sort.cpp",
    "chars": 1270,
    "preview": "// C Program to Implement BogoSort in an Integer Array\n#include <stdio.h>\n#include <stdlib.h>\n \n#define size 7\n/* Functi"
  },
  {
    "path": "Searching Algorithms/C:C++/Binary_Search.cpp",
    "chars": 648,
    "preview": "//Time Complexity: O(logn)\n#include<bits/stdc++.h>\nusing namespace std;\nint main()\n{\n\n    int a[100],n,i,beg,end,mid,ite"
  },
  {
    "path": "Searching Algorithms/C:C++/Binary_search.cpp",
    "chars": 737,
    "preview": "/* C++ Program - Binary Search */\n\t\n#include<iostream.h>\n#include<conio.h>\nvoid main()\n{\n\tclrscr();\n\tint n, i, arr[50], "
  },
  {
    "path": "Searching Algorithms/C:C++/Interpolation Search",
    "chars": 1045,
    "preview": "//Time Complexity : O(log(logn))\n\n#include<iostream>\nusing namespace std;\n\n\nint main(){\n\n    int N,x;\n\n    cin>>N;\n    i"
  },
  {
    "path": "Searching Algorithms/C:C++/Interpolation_search.cpp",
    "chars": 1436,
    "preview": "//Time Complexity: O(log(logn))\n\n#include<iostream>\n#include<algorithm>\nusing namespace std;\n\n// If x is present in arr["
  },
  {
    "path": "Searching Algorithms/C:C++/Jump_Search.cpp",
    "chars": 1206,
    "preview": "//Time Complexity: O(sqrt(n))\n\n#include <bits/stdc++.h>\nusing namespace std;\n \nint jumpSearch(int arr[], int x, int n)\n{"
  },
  {
    "path": "Searching Algorithms/C:C++/Liear_search.cpp",
    "chars": 503,
    "preview": "/* C++ Program - Linear Search */\n\t\t\n#include<iostream.h>\n#include<conio.h>\nvoid main()\n{\n\tclrscr();\n\tint arr[10], i, nu"
  },
  {
    "path": "Searching Algorithms/C:C++/MEDIAN_SEARCH.cpp",
    "chars": 3048,
    "preview": "//Libraries Included\n#include<iostream>\n#include<algorithm>\nusing namespace std;\n \n\n/* \n\nint findMedian()  -> Returns th"
  },
  {
    "path": "Searching Algorithms/C:C++/Selection_sort.cpp",
    "chars": 558,
    "preview": "/* C++ Program - Selection Sort */\n\t\t\n#include<iostream.h>\n#include<conio.h>\nvoid main()\n{\n\tclrscr();\n\tint size, arr[50]"
  },
  {
    "path": "Searching Algorithms/C:C++/Ternary_search.cpp",
    "chars": 1231,
    "preview": "#include <iostream>\nusing namespace std;\n\n#define s 12 //I gave space in the array as 12,but you can give the number you"
  },
  {
    "path": "Searching Algorithms/C:C++/b_search.cpp",
    "chars": 747,
    "preview": "#include<iostream>\nusing namespace std;\nint b_search(int a[],int l,int u,int s)\n{\n    int m=(l+u)/2;\n      if(l>=u)\n    "
  },
  {
    "path": "Searching Algorithms/C:C++/fibonacci_search.cpp",
    "chars": 1709,
    "preview": "#include <algorithm>\n\n\nusing namespace std;\n\nint _fibonacci_search(int n, int arr[], int x)\n{\n    /*Assuming the Input a"
  },
  {
    "path": "Searching Algorithms/C:C++/seaching algorithms [rename]/binary_search.cpp",
    "chars": 1530,
    "preview": "/*\nThis code illustrates a recursive implementation of binary search in a sorted array.\n*/\n#include <iostream>\nusing nam"
  },
  {
    "path": "Searching Algorithms/C:C++/seaching algorithms [rename]/binary_search_extras/position_in_sorted_array/eq_less_than.cpp",
    "chars": 997,
    "preview": "#include<bits/stdc++.h>\nusing namespace std;\n\n/*\n * return position of last elem less than or equal to num\n * best is be"
  },
  {
    "path": "Searching Algorithms/C:C++/seaching algorithms [rename]/binary_search_extras/position_in_sorted_array/first_occurance.cpp",
    "chars": 1058,
    "preview": "\n#include<bits/stdc++.h>\nusing namespace std;\n\n/*\n * return position of last elem less than or equal to num\n * best is b"
  },
  {
    "path": "Searching Algorithms/C:C++/seaching algorithms [rename]/binary_search_extras/position_in_sorted_array/just_less_than_num.cpp",
    "chars": 971,
    "preview": "#include<bits/stdc++.h>\nusing namespace std;\n\n/*\n * return position of elem just less than num\n * best is best position "
  },
  {
    "path": "Searching Algorithms/C:C++/seaching algorithms [rename]/binary_search_extras/position_in_sorted_array/position_in_sorted_array.cpp",
    "chars": 718,
    "preview": "#include<bits/stdc++.h>\nusing namespace std;\n\n/*\n * return position of num in sorted array\n * if not there then return -"
  },
  {
    "path": "Searching Algorithms/C:C++/seaching algorithms [rename]/binary_search_extras/ques/aggrcow.cpp",
    "chars": 716,
    "preview": "#include<bits/stdc++.h>\nusing namespace std;\nint arr[100002];\nint np,nc;\nint ans;\nint find(int l,int r){ \n    int m=(l+r"
  },
  {
    "path": "Searching Algorithms/C:C++/seaching algorithms [rename]/jump_search.cpp",
    "chars": 1645,
    "preview": "/*\nThis code illustrates implementation of Jump Search in a sorted array.\n*/\n#include <iostream>\n#include <math.h>\nusing"
  },
  {
    "path": "Searching Algorithms/C:C++/seaching algorithms [rename]/linear.cpp",
    "chars": 367,
    "preview": "/*\nThis code illustrates how Linear Search works\n*/\n#include <iostream>\nusing namespace std;\nint main()\n{\n    int array "
  },
  {
    "path": "Searching Algorithms/C:C++/ternarySearch.cpp",
    "chars": 1056,
    "preview": "//Time Complexity : O(log3(n))\n\n//Ternary Search Uses Divide And Conquer Technique\n#include<iostream>\n\n/*\n * Part of Cos"
  },
  {
    "path": "Searching Algorithms/C:C++/ternary_search.c",
    "chars": 991,
    "preview": "//Time Complexity : O(log3(n))\n\n//Ternary Search Uses Divide And Conquer Technique\n#include<stdio.h>\n\nint ternarySearch("
  },
  {
    "path": "Searching Algorithms/Java/TODO",
    "chars": 574,
    "preview": "* Write all the search algorithms in different classes.\n* Make one driving program containing the main to access all the"
  },
  {
    "path": "Searching Algorithms/Java/algos/BinarySearch.java",
    "chars": 423,
    "preview": "package asset;\n\npublic class BinarySearch{\n\tpublic static int binarySearch(int [] arr, int key, int low, int high) {\n\t\ti"
  },
  {
    "path": "Searching Algorithms/Java/algos/LinearSearch.java",
    "chars": 221,
    "preview": "package asset;\n\npublic class LinearSearch{\n\tpublic static int linearSearch(int [] arr, int key) {\n\t\tint size = arr.lengt"
  },
  {
    "path": "Searching Algorithms/Java/driving.java",
    "chars": 415,
    "preview": "package pkg;\n\npublic class LinearSearch{\n\tpublic static int linearSearch(int [] arr, int key) {\n\t\tint size = arr.length;"
  },
  {
    "path": "Searching Algorithms/Python/binarysearch.py",
    "chars": 660,
    "preview": "def binary_search(item_list,item):\r\n\tfirst = 0\r\n\tlast = len(item_list)-1\r\n\tfound = False\r\n\twhile( first<=last and not fo"
  },
  {
    "path": "Searching Algorithms/Python/bst.py",
    "chars": 1245,
    "preview": "#Time Complexity : O(height)\n\n# Python program to demonstrate insert operation in binary search tree \n \n# A utility clas"
  },
  {
    "path": "Segment Trees/ADA/README.md",
    "chars": 1536,
    "preview": "# Compile and run an ADA program\ngnatmake nome_do_programa.adb\n./nome_do_programa\n\nor\n\ngcc-4.9 -c nome_do_programa.adb\ng"
  },
  {
    "path": "Segment Trees/ADA/segmentree.adb",
    "chars": 2573,
    "preview": "with Ada.Integer_Text_IO, Ada.Text_IO;\nuse Ada.Integer_Text_IO, Ada.Text_IO;\n\n--To compile an ADA program you have to in"
  },
  {
    "path": "Segment Trees/C++/RangeMinimumQuery.cpp",
    "chars": 1202,
    "preview": "//Following code calculates the minimum value in the range l to r\n#include <bits/stdc++.h>\nusing namespace std;\n\nint rmq"
  },
  {
    "path": "Segment Trees/C++/SumInGivenRange.cpp",
    "chars": 1812,
    "preview": "//Following  is the code where in you can update the value in the array and Query for the sum in l to r\n#include <bits/s"
  },
  {
    "path": "Segment Trees/Java/SegementTree.java",
    "chars": 2782,
    "preview": "import java.util.Scanner;\n/*\n* @author Nikunj Khokhar\n*/\npublic class SegmentTree {\n\n    static int MAX = 1000005;\n    s"
  },
  {
    "path": "Segment Trees/Java/SegementTreeLazyPropagation.java",
    "chars": 7953,
    "preview": "/*\n* @author Nikunj Khokhar\n*/\n\n// Java program to demonstrate lazy propagation in segment tree\nclass LazySegmentTree\n{\n"
  },
  {
    "path": "Sorting Algorithms/C:C++/Counting_Sort.cpp",
    "chars": 1093,
    "preview": "#include<iostream>\nusing namespace std;\n\nint main()\n{\n int N,x;\n\n    cin>>N;\n    int A[N];\n    //The elements of the arr"
  },
  {
    "path": "Sorting Algorithms/C:C++/Insertion_sort.cpp",
    "chars": 544,
    "preview": "/* C++ Program - Insertion Sort */\n\t\t\n#include<iostream.h>\n#include<conio.h>\nvoid main()\n{\n\tclrscr();\n\tint size, arr[50]"
  },
  {
    "path": "Sorting Algorithms/C:C++/Merge_sort.cpp",
    "chars": 1464,
    "preview": "#include <iostream>\n \nusing namespace std;\n \n// A function to merge the two half into a sorted data.\nvoid Merge(int *a, "
  },
  {
    "path": "Sorting Algorithms/C:C++/QuickSort.c",
    "chars": 1817,
    "preview": "/***********************************************************\n* You can use all the programs on  www.c-program-example.co"
  },
  {
    "path": "Sorting Algorithms/C:C++/Quick_sort.cpp",
    "chars": 1200,
    "preview": "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n"
  },
  {
    "path": "Sorting Algorithms/C:C++/Radix_sort.cpp",
    "chars": 1458,
    "preview": "#include <iostream.h>\n#include <conio.h>\n#define MAX 10\n\nclass radixsort{\n    int arr[MAX],n;\n    public:\n    void getda"
  },
  {
    "path": "Sorting Algorithms/C:C++/bubblesort.c",
    "chars": 689,
    "preview": "#include<iostream>\nusing namespace std;\n\n\nint main(){\n\n    int a[10]; ///Creates an array of 10 integers\n    int n,key;\n"
  },
  {
    "path": "Sorting Algorithms/C:C++/bubblesort.cpp",
    "chars": 616,
    "preview": "/* C++ Program - Bubble Sort */\n\t\t\n#include<iostream.h>\n#include<conio.h>\nvoid main()\n{\n\tclrscr();\n\tint n, i, arr[50], j"
  },
  {
    "path": "Sorting Algorithms/C:C++/bucketsort.c",
    "chars": 636,
    "preview": "#include<stdio.h>\n \n#define SIZE 10\n \nvoid bucketSort(int a[], int n) {\n    int i, j, k, buckets[SIZE];\n    \n    for(i ="
  },
  {
    "path": "Sorting Algorithms/C:C++/heapSort.c",
    "chars": 530,
    "preview": "#include <stdio.h>\n\nint heapify(int* a, int i, int n)\n{\n\tint j=(2*i+1),k=(2*i+2),x;\n\tif(j<=n)\n\t{\n\t\tif(k<=n)\n\t\t\tif(a[k]>a"
  },
  {
    "path": "Sorting Algorithms/C:C++/insertion.hpp",
    "chars": 213,
    "preview": "#include <bits/stdc++.h>\r\nusing namespace std;\r\n\r\nvoid insertion_sort(int length, int v[]){\r\n\tfor(int i=0;i<length;i++){"
  },
  {
    "path": "Sorting Algorithms/C:C++/merge.hpp",
    "chars": 1534,
    "preview": "#include <bits/stdc++.h>\r\nusing namespace std;\r\n\r\nvoid _merge(int v[], int left, int mid, int right){\r\n\tint i, j, k;\r\n\ti"
  },
  {
    "path": "Sorting Algorithms/C:C++/quick.hpp",
    "chars": 559,
    "preview": "#include <bits/stdc++.h>\r\nusing namespace std;\r\n\r\nint _partition(int v[], int left, int right){\r\n\tint pivot = v[right];\r"
  },
  {
    "path": "Sorting Algorithms/C:C++/quick_sort.c",
    "chars": 952,
    "preview": "#include<stdio.h>\nvoid quicksort(int number[25],int first,int last){\n   int i, j, pivot, temp;\n\n   if(first<last){\n     "
  },
  {
    "path": "Sorting Algorithms/C:C++/radix.hpp",
    "chars": 951,
    "preview": "#include <bits/stdc++.h>\r\nusing namespace std;\r\n\r\nvoid _count_sort(int arr[], int length, int exp){\r\n    int output[leng"
  },
  {
    "path": "Sorting Algorithms/C:C++/selectionsort.c",
    "chars": 1313,
    "preview": "/*Take as input N, the size of array. Take N more inputs and store that in an array. \nWrite a function that selection so"
  },
  {
    "path": "Sorting Algorithms/C:C++/shell_sort.h",
    "chars": 528,
    "preview": "#ifndef ALGO_SHELL_SORT_H__\n#define ALGO_SHELL_SORT_H__\n\nnamespace alg {\n\t/**\n\t * shell sort an array\n\t */\n\ttemplate<typ"
  },
  {
    "path": "Sorting Algorithms/C:C++/slow.cpp",
    "chars": 321,
    "preview": "#include <bits/stdc++.h>\nusing namespace std;\n\nvoid _slow_sort(int v[], int i, int j) {\n  if (i >= j) return;\n  int m = "
  },
  {
    "path": "Sorting Algorithms/C:C++/sorting_a_vector.cpp",
    "chars": 570,
    "preview": "#include<iostream>\r\n#include<cstring>\r\n#include<vector>\r\n#include<algorithm>\r\nusing namespace std;\r\n\r\nbool compare(int a"
  },
  {
    "path": "Sorting Algorithms/Java/Countsort.java",
    "chars": 1366,
    "preview": "public class CountingSort\n{\n    public static void sort(char arr[])\n    {\n        int n = arr.length;\n \n        // The o"
  },
  {
    "path": "Sorting Algorithms/Java/HeapSort.java",
    "chars": 1418,
    "preview": "import java.util.*;\n/*\n * Part of Cosmos by OpenGenus Foundation\n*/\npublic class HeapSort {\n    \n    public static void "
  },
  {
    "path": "Sorting Algorithms/Java/MergeSort.java",
    "chars": 1499,
    "preview": "package test;\n\npublic class test {\n\n\tpublic static void main(String[] args) {\n\n\t\tString[] nums = { \"AB\", \"DD\", \"CC\", \"BB"
  },
  {
    "path": "Sorting Algorithms/Javascript/bubblesort.js",
    "chars": 489,
    "preview": "//function takes in array\nconst bubblesort = (array) => {\n  let length = array.length;\n  \n \n  for (let i=0;i<length-1;i+"
  },
  {
    "path": "Sorting Algorithms/Python/QuickSort.py",
    "chars": 1080,
    "preview": "def partition(arr,low,high):\n    i = ( low-1 )         # index of smaller element\n    pivot = arr[high]     # pivot\n \n  "
  },
  {
    "path": "Sorting Algorithms/Python/bogosort.py",
    "chars": 413,
    "preview": "from random import shuffle\n\n# Sorting algorithm that relies solely on shuffling all\n# numbers until the array is sorted."
  },
  {
    "path": "Sorting Algorithms/Python/bubblesort.py",
    "chars": 255,
    "preview": "def bubble_sort(arr):\n    changed = True\n    while changed:\n        changed = False\n        for i in range(len(arr) - 1)"
  },
  {
    "path": "Sorting Algorithms/Python/cocktailsort.py",
    "chars": 516,
    "preview": "# Cocktail sorting\n\n\n\n\ndef cocktailsort(a):\n\tn=len(a)\n\tswapped=True\n\tstart=0\n\tend=n-1\n\twhile(swapped==True):\n\t\tswapped=F"
  }
]

// ... and 53 more files (download for full content)

About this extraction

This page contains the full source code of the srbcheema1/Algo_Ds GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 253 files (367.4 KB), approximately 120.1k tokens, and a symbol index with 1001 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!