Skip to content

Commit

Permalink
pushing day 16 to 20
Browse files Browse the repository at this point in the history
  • Loading branch information
soumya997 committed Jun 22, 2021
1 parent 025a932 commit ee5a5e4
Show file tree
Hide file tree
Showing 83 changed files with 2,391 additions and 6 deletions.
24 changes: 24 additions & 0 deletions Day_11_to_20/Day_13/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
- It works in FIFO(first in first out) order.
- push happens from the back and pop happens from the front.

<p align="center">
<img src="../../imgs/queue1.png" width="500">
</p>


```cpp
#include <iostream>
#include <array>
Expand Down Expand Up @@ -76,6 +81,11 @@ int main(){
```
## queue implelntation using Linkedlist;
- If we use linkedlist for creating the queue then its not possible that a queue will be full.

<p align="center">
<img src="../../imgs/queue2.png" width="500">
</p>

```cpp
#include<list> // doubly Linkedlist
class queue{
Expand Down Expand Up @@ -151,6 +161,10 @@ e.g: file structure in a computer.
- sibling: children of the same parent. here 10,3 is sibling then 1,6 is sibling etc.
- leafnode: which dont have any children, eg 4,7 and 13.

<p align="center">
<img src="../../imgs/bt1.png" width="500">
</p>

### Build tree:
top down approach, algorithm is like,
1. build the root
Expand Down Expand Up @@ -189,6 +203,11 @@ void print_bt(node* root){
<br>
it is a process where we visit each node of a tree one times in some order.
here visiting means reading the data of the node.There are two type of tree traversal,
<p align="center">
<img src="../../imgs/bt2.png" width="500">
</p>
1. breadth first
- Level order traversal
2. Depth first
Expand Down Expand Up @@ -237,6 +256,11 @@ int height(node*root){
- 1st calaculate the height
- 2nd loop through each level and use `print_kth_level()` to print each level.
- complexity of this algorithm is O(N^2)
<p align="center">
<img src="../../imgs/bt3.png" width="500">
</p>
```cpp
void print_kth_level(noe*root,int k){
if(root==NULL){
Expand Down
7 changes: 7 additions & 0 deletions Day_11_to_20/Day_14/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,18 @@ example of the problem that heap solves, 10k students appeared for a coding cont
2. It should be a complete binary tree(CBT).(n.b: if all level of the tree are complet;y filled except last level, but filling should be left to right order.)
3. Heap order property, maxheap and min heap.Heap order property for max/min says, every parent node in the heap will have high/low value than its children.

<p align="center">
<img src="../../imgs/heap.png" width="500">
</p>

## Hash Table:
- It is an array of fixed size table
- Array elements indexed by a key, which is mapped to an array index(0 to table-1)

<p align="center">
<img src="../../imgs/hash_map.png" width="500">
</p>

### Perpose:
- To support insertion,deletion and search in average-case constant time.
+ Assumption: Order of elements irrelevant
Expand Down
Empty file added Day_11_to_20/Day_16/Error.txt
Empty file.
41 changes: 41 additions & 0 deletions Day_11_to_20/Day_16/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Things I learned in: Day_16
**Note:** use the github provided TOC for navigaing.

## Binary to decimal:
**Formula:**
For binary number fedcba , Decimal number = f * 2^5 + e * 2^4 + d * 2^3 + …..+ a * 2^0.
```cpp
int main(){
int t=1;
cin>>t;
while((t--)>0){
long long data;
cin>>data;
int len = 0;

long long dec = 0;

while(data!=0){
dec += (data%10)*pow(2,len);
len++;
data /= 10;
}
cout<<dec<<endl;

}
return 0;
}
```

## Farenhiet to celsius:
got to know that there are different kinds of divisions available, integer devision,float devision, double devision etc.
Source: [https://stackoverflow.com/questions/27971967/c-does-not-take-5-9-and-seems-to-typecast-it](https://stackoverflow.com/questions/27971967/c-does-not-take-5-9-and-seems-to-typecast-it)

**For example:** if you do `cout<<5/9` then its a integer devide so it will give you 0,not 0.55555, so u need to do it in floating way.
```
5 // int
5l // long
5.0 // double
5.0f // float
5ul // unsigned long
```
50 changes: 50 additions & 0 deletions Day_11_to_20/Day_16/bin_to_dec.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include<bits/stdc++.h>
using namespace std;
#define print(x) cout << x
#define deb(x) cout << #x << "=" << x << endl;
// 101 -> 5
// For binary number fedcba , Decimal number = f * 2^5 + e * 2^4 + d * 2^3 + …..+ a * 2^0.
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

int main(){
#ifndef ONLINE_JUDGE
freopen("errorf.in", "w", stderr);
#endif

ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int t;
cin>>t;
while((t--)>0){
long long data;
cin>>data;
int len = 0;
debug(len);
long long dec = 0;
debug(dec);
while(data!=0){
dec += (data%10)*pow(2,len);
len++;
data /= 10;
}
cout<<dec<<endl;

}
return 0;
}

Binary file added Day_11_to_20/Day_16/bin_to_dec.exe
Binary file not shown.
Empty file added Day_11_to_20/Day_16/errorf.in
Empty file.
82 changes: 82 additions & 0 deletions Day_11_to_20/Day_16/farenheit_to_celsius.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// https://youtu.be/8ymiMHQPgZY
#include<bits/stdc++.h>

using namespace std;



#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nline "\n"
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
typedef long double lld;
// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

int main() {
#ifndef ONLINE_JUDGE
freopen("errorf.in", "w", stderr);
#endif
fastio();
int start=0;
int end = 0;
int gap=0;
cin>>start;
cin>>end;
cin>>gap;
debug(start);
debug(end);
debug(gap);
for(int i=start;i<=end;i+=gap){
// https://stackoverflow.com/questions/27971967/c-does-not-take-5-9-and-seems-to-typecast-it
// if you do 5/9 then its a integer devide so it will give you 0, if u need to do it in floating
// way,do this
/*
5 // int
5l // long
5.0 // double
5.0f // float
5ul // unsigned long
*/
cout<<i<<"\t"<<(int)((5.0f/9.0f)*(i-32))<<nline;
}
// cout<<(5/9)*(20-32);
}
Binary file added Day_11_to_20/Day_16/farenheit_to_celsius.exe
Binary file not shown.
1 change: 1 addition & 0 deletions Day_11_to_20/Day_16/input.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4
3 changes: 3 additions & 0 deletions Day_11_to_20/Day_16/inputf.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
0
100
20
Empty file added Day_11_to_20/Day_16/output.txt
Empty file.
Empty file added Day_11_to_20/Day_16/outputf.in
Empty file.
78 changes: 78 additions & 0 deletions Day_11_to_20/Day_16/pythagoras_triplet.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// https://youtu.be/8ymiMHQPgZY
#include<bits/stdc++.h>

using namespace std;



#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define nline "\n"
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define PI 3.141592653589793238462
#define set_bits __builtin_popcountll
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long long int lli;
typedef unsigned long long ull;
typedef long double lld;
// typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

int main() {
#ifndef ONLINE_JUDGE
freopen("errorf.in", "w", stderr);
#endif
fastio();
ll data;
cin>>data;

if(data==0||data==1){
cout<<"-1";
}
else if (data%2==0){
/* code */
int val = (data*data)/4;
cout<<val-1<<" "<<val+1;
}

else if(data%2!=0){
int val = (data*data)+1;
cout<<val/2-1<<" "<<val/2;
}

return 0;

}
Binary file added Day_11_to_20/Day_16/pythagoras_triplet.exe
Binary file not shown.
24 changes: 24 additions & 0 deletions Day_11_to_20/Day_16/touch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/sh

# Author : Soumyadip Sarkar
# License = "Feel free to copy, I appreciate if you star 🌟 the repo"
# Github: soumya997

# Usage:
# file generator with boilerplate code




echo "Enter the file name: " # asking user for giving a file name
read file_name # taking file name from user

touch $file_name # creating the file

# A single liner for a basic boilerplate
# echo -e "#include<bits/stdc++.h>\nusing namespace std;\nint main(){\n\n\treturn 0;\n}" >> $file_name


# comment out the above echo line and uncomment this to take the boiler plate from a cpp file(here its a.cpp)
value=$(<../../template.cpp) # reading the template file
echo -e "$value" >> $file_name # putting the read content in the new file
2 changes: 2 additions & 0 deletions Day_11_to_20/Day_17/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Things I learned in: Day_11_to_20/Day_17
**Note:** use the github provided TOC for navigaing.
Loading

0 comments on commit ee5a5e4

Please sign in to comment.