This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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<algorithm> | |
| using namespace std; | |
| int euclid_gcd(int a, int b) | |
| { | |
| while (b != 0) | |
| { | |
| int r = a % b; | |
| a = b; |
This file contains hidden or 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 hidden or 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 hidden or 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
| // Stack - Array based implementation. | |
| // Creating a stack of integers. | |
| #include<stdio.h> | |
| #define MAX_SIZE 101 | |
| int A[MAX_SIZE]; // integer array to store the stack | |
| int top = -1; // variable to mark top of stack in array | |
| // Push operation to insert an element on top of stack. |
This file contains hidden or 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
| /* | |
| Evaluation Of postfix Expression in C++ | |
| Input Postfix expression must be in a desired format. | |
| Operands must be integers and there should be space in between two operands. | |
| Only '+' , '-' , '*' and '/' operators are expected. | |
| */ | |
| #include<iostream> | |
| #include<stack> | |
| #include<string> |
This file contains hidden or 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 hidden or 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
| // Stack - Object oriented implementation using arrays | |
| #include <iostream> | |
| using namespace std; | |
| #define MAX_SIZE 101 | |
| class Stack | |
| { | |
| private: | |
| int A[MAX_SIZE]; // array to store the stack | |
| int top; // variable to mark the top index of stack. |
OlderNewer