Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Tree in C #25

Open
wants to merge 44 commits into
base: maths
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
0ad9ae4
Merge pull request #3 from ShivamDubey7/maths
ShivamDubey7 Oct 17, 2020
8e1d9c5
Merge pull request #4 from ShivamDubey7/maths
ShivamDubey7 Oct 17, 2020
601ecae
Added efficient MergeSort
ShivamDubey7 Oct 17, 2020
db964f8
Merge pull request #5 from the-geeky-wizard/sorting
ShivamDubey7 Oct 17, 2020
ab81275
Added LinearSort
ShivamDubey7 Oct 17, 2020
324fb8a
Merge pull request #6 from the-geeky-wizard/sorting
ShivamDubey7 Oct 17, 2020
4412459
Added HeapSort
ShivamDubey7 Oct 17, 2020
9574e42
Merge pull request #7 from the-geeky-wizard/sorting
ShivamDubey7 Oct 17, 2020
371e6d7
Merge pull request #1 from the-geeky-wizard/sorting
the-geeky-wizard Oct 17, 2020
5929fa4
Added BinarySeach
ShivamDubey7 Oct 17, 2020
5a779e9
Merge pull request #2 from the-geeky-wizard/search_algorithms
the-geeky-wizard Oct 17, 2020
056ede3
Merge pull request #8 from the-geeky-wizard/master
ShivamDubey7 Oct 17, 2020
e53f68e
Create bubblesort_java
huntingcodes Oct 18, 2020
392deed
Create mirror inverse_java
huntingcodes Oct 18, 2020
990b851
Create ascii-char_cpp
huntingcodes Oct 18, 2020
f3708d6
Merge pull request #1 from huntingcodes/huntingcodes-patch-1
huntingcodes Oct 18, 2020
55ffc5f
Merge pull request #9 from huntingcodes/master
ShivamDubey7 Oct 18, 2020
1769869
Added Recursive BinarySeach
ShivamDubey7 Oct 18, 2020
e1e274a
Merge pull request #10 from dubey7/master
ShivamDubey7 Oct 18, 2020
3791d65
Renamed
ShivamDubey7 Oct 18, 2020
d63881b
Removed
ShivamDubey7 Oct 18, 2020
71c7c04
Merge pull request #11 from dubey7/master
ShivamDubey7 Oct 18, 2020
f1a9b4f
Added Iterative exponentiation
ShivamDubey7 Oct 18, 2020
446692b
Merge pull request #12 from dubey7/master
ShivamDubey7 Oct 18, 2020
8dceaf5
Added DFS
ShivamDubey7 Oct 18, 2020
f5f82a4
Merge pull request #13 from dubey7/master
ShivamDubey7 Oct 18, 2020
d8bd23d
Create 1552b.cpp
email11235868 Oct 31, 2021
a708847
Merge pull request #33 from email11235868/patch-1
ShivamDubey7 Oct 31, 2021
8bbb555
Create 1530d.cpp
email11235868 Oct 31, 2021
d1d46b6
Create 1530c.cpp
email11235868 Oct 31, 2021
58d6ddc
Create 1550b.cpp
email11235868 Oct 31, 2021
1d350f6
Merge pull request #36 from email11235868/patch-4
ShivamDubey7 Oct 31, 2021
7bd394d
Merge pull request #35 from email11235868/patch-3
ShivamDubey7 Oct 31, 2021
5cad23e
Merge pull request #34 from email11235868/patch-2
ShivamDubey7 Oct 31, 2021
7697bac
Added Selection Sort
shaurya-sharma064 Oct 31, 2021
9af438a
Create 1550b
email11235866 Oct 31, 2021
bc2c613
Create second.cpp
email11235866 Oct 31, 2021
3a3b0c9
Create third.cpp
email11235866 Oct 31, 2021
4190927
Create fourth.cpp
email11235866 Oct 31, 2021
fd99aa9
Merge pull request #38 from email11235866/patch-1
ShivamDubey7 Oct 31, 2021
c24605e
Merge pull request #39 from email11235866/patch-2
ShivamDubey7 Oct 31, 2021
a6cb5d4
Merge pull request #40 from email11235866/patch-3
ShivamDubey7 Oct 31, 2021
923683a
Merge pull request #41 from email11235866/patch-4
ShivamDubey7 Oct 31, 2021
3efe1ed
Merge pull request #37 from ShaSha-Codes/master
ShivamDubey7 Oct 31, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions Graph/DFS.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int LIM = 50;
int vis[LIM];
vector<vector<int> >AdjList(LIM);
void dfs(int u){
cout<<u<<" , ";
vis[u]=1;
for(auto v:AdjList[u]){
if(vis[v]==0){
dfs(v);
}
}
}
int main(){
int n,m;
cin>>n>>m;
for(int i=0;i<m;i++){
int u,v;
cin>>u>>v;
AdjList[u].pb(v);
AdjList[v].pb(u);
}
dfs(1);

}
14 changes: 13 additions & 1 deletion Maths/FastExponentiation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,21 @@ ll fastExpo(ll base, ll power){
}
return temp*temp;
}
ll fastExpoIterative(ll base, ll power){
ll res = 1;
while(power >0){
if(power&1){
res*=base;
}
power/=2;
base*=base;
}
return res;

}
int main(){
ll base = 5;
ll power = 3;
cout<<fastExpo(base,power);
cout<<fastExpoIterative(base,power);

}
36 changes: 36 additions & 0 deletions Searching/BinarySearch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include<bits/stdc++.h>
using namespace std;
//Create a predicate to return T/F for an ind
bool predicate(vector<int>&v, int ind, int search_token){
return v[ind] >= search_token;
}
int binarySeach(vector<int>&v, int search_token){
int low = 0,high = v.size(),mid;
while(low<high){
mid = (low+high)/2;
if(predicate(v,mid,search_token)){
high = mid;
}
else
low = mid+1;
}
if(v[low]==search_token) return low;
return -1;
}
int recursiveBinarySearch(vector<int>&v, int search_token, int begin, int end){
if(begin==end){
if(v[begin]==search_token)
return begin;
return -1;
}
int mid = (begin+end)/2;
if(predicate(v,mid,search_token)){
return recursiveBinarySearch(v,search_token,begin,mid);
}
return recursiveBinarySearch(v,search_token,mid+1,end);
}
int main(){
vector<int> v = {1,2,4,5,11,20,25};
cout<<recursiveBinarySearch(v,6,0,6);
return 0;
}
34 changes: 34 additions & 0 deletions Sorting/BubbleSort.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
public class BubbleSortExample {
static void bubbleSort(int[] arr) {
int n = arr.length;
int temp = 0;
for(int i=0; i < n; i++){
for(int j=1; j < (n-i); j++){
if(arr[j-1] > arr[j]){
//swap elements
temp = arr[j-1];
arr[j-1] = arr[j];
arr[j] = temp;
}

}
}
}
public static void main(String[] args) {
int arr[] ={3,60,35,2,45,320,5};

System.out.println("Array Before Bubble Sort");
for(int i=0; i < arr.length; i++){
System.out.print(arr[i] + " ");
}
System.out.println();

bubbleSort(arr);//sorting array elements using bubble sort

System.out.println("Array After Bubble Sort");
for(int i=0; i < arr.length; i++){
System.out.print(arr[i] + " ");
}

}
}
40 changes: 40 additions & 0 deletions Sorting/HeapSort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include<bits/stdc++.h>
#define sz(v) ((int)v.size())
using namespace std;
void heapify(vector<int>&v, int SIZE, int ind){
int left_child = (ind<<1)+1;
int right_child = left_child+1;
int to_swap;
if(left_child<SIZE && v[left_child] > v[ind])
to_swap = left_child;
else
to_swap = ind;
if(right_child<SIZE && v[right_child] > v[to_swap])
to_swap = right_child;
if(to_swap !=ind){
int temp = v[to_swap];
v[to_swap] = v[ind];
v[ind] = temp;
heapify(v,SIZE,to_swap);
}
}
void heapSort(vector<int>&v){
vector<int>heap(sz(v));
for(int i=(sz(v)-2)/2;i>=0;i--){
heapify(v,sz(v),i);
}
for(int i=sz(v)-1;i>0;i--){
int temp = v[0];
v[0] = v[i];
v[i] = temp;

heapify(v,i,0);
}
}
int main(){
vector<int>temp = {1,3,2,12,444,5};
heapSort(temp);
for(int v:temp){
cout<<v<<" ";
}
}
21 changes: 21 additions & 0 deletions Sorting/LinearSort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<bits/stdc++.h>
using namespace std;
void linearSort(vector<int>&v){
for(int i=0;i<v.size();i++){
for(int j=i+1;j<v.size();j++){
if(v[j]<v[i]){
int temp = v[i];
v[i] = v[j];
v[j] = temp;
}
}

}
}
int main(){
vector<int>temp = {1,3,2,12,444,5};
linearSort(temp);
for(int v:temp){
cout<<v<<" ";
}
}
33 changes: 33 additions & 0 deletions Sorting/MergeSort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include<bits/stdc++.h>
using namespace std;
void merge(vector<int>&v, int startIndex, int mid, int endIndex){
vector<int>temp;
int i1 = startIndex;
int i2 = mid+1;
while(i1<=mid && i2<=endIndex){
if(v[i1]<=v[i2])
temp.push_back(v[i1]),i1++;
else
temp.push_back(v[i2]),i2++;
}
while(i1<=mid)temp.push_back(v[i1]),i1++;
while(i2<=endIndex)temp.push_back(v[i2]),i2++;
for(int i=0;i<temp.size();i++)
v[startIndex+i] = temp[i];
}
void mergeSort(vector<int>&v, int startIndex, int endIndex){
if(startIndex<endIndex){
int mid = (startIndex+endIndex)/2;
mergeSort(v,startIndex,mid);
mergeSort(v,mid+1,endIndex);
merge(v,startIndex,mid,endIndex);
}

}
int main(){
vector<int>temp = {1,3,2,12,444,5};
mergeSort(temp,0, temp.size()-1);
for(int v:temp){
cout<<v<<" ";
}
}
27 changes: 27 additions & 0 deletions Sorting/SelectionSort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Selection sort takes n-1 passes to complete
# During every iteration index of minimum number/string is found in the innermost loop and then swapped once it comes out of that loop
# No flag like improvised Bubble Sort so even if we put sorted list it is still going to take O(n^2) time complexity
# Worst Time Complexity: O(n^2)
# Average Time Complexity: O(n^2)
# Best Time Complexity: O(n^2)

print("Number Sequence Before Selection Sort")
seq=[5,2,1,8,3,5,3]
print(seq)

def selectionSort(nums):
n=len(nums)
for i in range(n-1):
iMin=i
for j in range(i+1,n):
if(nums[iMin]>nums[j]):
iMin=j
temp=nums[i]
nums[i]=nums[iMin]
nums[iMin]=temp
return nums

print("Number Sequence After Selection Sort")
print(selectionSort(seq))


10 changes: 10 additions & 0 deletions ascii-char_cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// CPP program to print
// ASCII Value of Character
#include <iostream>
using namespace std;
int main()
{
char c = 'A';
cout << "The ASCII value of " << c << " is " << int(c);
return 0;
}
42 changes: 42 additions & 0 deletions cf/1550b
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include<bits/stdc++.h>
#define ll long long int
#define loop(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) for(int (i)=0;(i)<n;(i)++)
#define bp 1000000007
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define F first
#define S second
using namespace std;
typedef pair<ll,ll> ii;
void solve(){
int n,a,b;
cin>>n>>a>>b;
string s;
cin>>s;
vector<int>c(2,0);
c[s[0]-'0']++;
for(int i=1;i<sz(s);i++){
if(s[i]!=s[i-1]){
c[s[i]-'0']++;
}
}
int ans = a*n;
if(b>0)
ans += b*n;
else
ans += b*(min(c[0],c[1])+1);
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
solve();
return 0;
}
68 changes: 68 additions & 0 deletions cf/fourth.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include<bits/stdc++.h>
#define ll long long int
#define loop(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) for(int (i)=0;(i)<n;(i)++)
#define bp 1000000007
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define F first
#define S second
using namespace std;
typedef pair<ll,ll> ii;
void solve(){
int n;
cin>>n;
vector<vector<int>>v(n,vector<int>(5,0));
rep(i,n){
rep(j,5){
cin>>v[i][j];
}
}
vector<int>w = v[0];
int ans=0;
bool exists= false;

for(int i=1;i<n;i++){
int c=0,c2=0;
rep(j,5){
if(v[i][j] < w[j])c++;
else if(v[i][j] > w[j])c2++;
}
if(c>=3 || c2>=3)exists = true;
if(c>=3){
w = v[i];
ans = i;
}
}
if(n > 1 && !exists){
cout<<-1<<endl;
return;
}

rep(i,n){
if(i!=ans){
int c=0;
rep(j,5){
if(v[i][j] > w[j])c++;
}
if(c < 3){
cout<<-1<<endl;
return;
}
}
}
cout<<ans+1<<endl;

}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin>>t;
while(t--)
solve();
return 0;
}
Loading