View MaximumSumSubarray_Kadane.cpp
#include<cmath> | |
#include<iostream> | |
#include<climits> | |
using namespace std; | |
int Maximum_Sum_Subarray(int arr[],int n) //Overall Time Complexity O(n) | |
{ | |
int ans = A[0],sum = 0; | |
for(int i = 1;i < n; ++i) //Check if all are negative | |
ans = max(ans,arr[i]); |
View MaximumSumSubarray_NlogN.cpp
#include<cmath> | |
#include<iostream> | |
#include<climits> | |
using namespace std; | |
int Max_Subarray_Sum(int arr[],int n) | |
{ | |
if(n==1) | |
{ | |
return arr[0]; |
View MaximumSumSubarray_Bruteforce02.cpp
#include<cmath> | |
#include<iostream> | |
#include<climits> | |
using namespace std; | |
int Maximum_Sum_Subarray(int arr[],int n) //Overall Time Complexity O(n^2) | |
{ | |
int ans = INT_MIN; | |
for(int start_index = 0;start_index < n; ++start_index) //O(n) | |
{ |
View MaximumSumSubarray_bruteforce01.cpp
#include<cmath> | |
#include<iostream> | |
#include<climits> | |
using namespace std; | |
int Maximum_Sum_Subarray(int arr[],int n) //Overall Time Complexity O(n^3) | |
{ | |
int ans = INT_MIN; // #include<climits> | |
for(int sub_array_size = 1;sub_array_size <= n; ++sub_array_size) //O(n) | |
{ |
View FindMergePointOfLinkedList.cpp
#include<iostream> | |
#include<cstdlib> | |
#include<set> | |
using namespace std; | |
struct Node { | |
int data; | |
struct Node *next; | |
}; | |
int length(struct Node *head) { |
View BST_InorderSuccessor_CPP.cpp
/* C++ program to find Inorder successor in a BST */ | |
#include<iostream> | |
using namespace std; | |
struct Node { | |
int data; | |
struct Node *left; | |
struct Node *right; | |
}; | |
//Function to find some data in the tree |
View BSTDeletion_CPP.cpp
/* Deleting a node from Binary search tree */ | |
#include<iostream> | |
using namespace std; | |
struct Node { | |
int data; | |
struct Node *left; | |
struct Node *right; | |
}; | |
//Function to find minimum in a tree. | |
Node* FindMin(Node* root) |
View PreorderInorderPostorder_CPP.cpp
/* Binary Tree Traversal - Preorder, Inorder, Postorder */ | |
#include<iostream> | |
using namespace std; | |
struct Node { | |
char data; | |
struct Node *left; | |
struct Node *right; | |
}; |
View MergeSort_C.C
/* Merge sort in C */ | |
#include<stdio.h> | |
#include<stdlib.h> | |
// Function to Merge Arrays L and R into A. | |
// lefCount = number of elements in L | |
// rightCount = number of elements in R. | |
void Merge(int *A,int *L,int leftCount,int *R,int rightCount) { | |
int i,j,k; |
View LevelOrder_CPP.cpp
/* Binary tree - Level Order Traversal */ | |
#include<iostream> | |
#include<queue> | |
using namespace std; | |
struct Node { | |
char data; | |
Node *left; | |
Node *right; | |
}; |
NewerOlder