This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<cmath> | |
#include<iostream> | |
#include<climits> | |
using namespace std; | |
int Max_Subarray_Sum(int arr[],int n) | |
{ | |
if(n==1) | |
{ | |
return arr[0]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<cstdlib> | |
#include<set> | |
using namespace std; | |
struct Node { | |
int data; | |
struct Node *next; | |
}; | |
int length(struct Node *head) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Binary Tree Traversal - Preorder, Inorder, Postorder */ | |
#include<iostream> | |
using namespace std; | |
struct Node { | |
char data; | |
struct Node *left; | |
struct Node *right; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Binary tree - Level Order Traversal */ | |
#include<iostream> | |
#include<queue> | |
using namespace std; | |
struct Node { | |
char data; | |
Node *left; | |
Node *right; | |
}; |
NewerOlder