Skip to content

Instantly share code, notes, and snippets.

/* 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;
@mycodeschool
mycodeschool / PreorderInorderPostorder_CPP.cpp
Last active October 29, 2023 09:20
Binary tree traversal: Preorder, Inorder, Postorder
/* Binary Tree Traversal - Preorder, Inorder, Postorder */
#include<iostream>
using namespace std;
struct Node {
char data;
struct Node *left;
struct Node *right;
};
/* 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)
@mycodeschool
mycodeschool / BST_InorderSuccessor_CPP.cpp
Last active October 29, 2023 09:20
C++ program to find Inorder successor in a BST
/* 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
#include<iostream>
#include<cstdlib>
#include<set>
using namespace std;
struct Node {
int data;
struct Node *next;
};
int length(struct Node *head) {
#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)
{
#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)
{
#include<cmath>
#include<iostream>
#include<climits>
using namespace std;
int Max_Subarray_Sum(int arr[],int n)
{
if(n==1)
{
return arr[0];
#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]);