From c46a3a847c0463b50a6610671a738c9887b9b5a3 Mon Sep 17 00:00:00 2001 From: amit Date: Thu, 2 Nov 2023 22:02:42 +0530 Subject: [PATCH 1/3] some-problems --- Data-Structures/Trees/01-intro.md | 2 +- .../Trees/problems/check-for-balanced-bt.cpp | 57 +++++++++++++++++++ .../Trees/problems/depth-of-bt.cpp | 54 ++++++++++++++++++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 Data-Structures/Trees/problems/check-for-balanced-bt.cpp create mode 100644 Data-Structures/Trees/problems/depth-of-bt.cpp diff --git a/Data-Structures/Trees/01-intro.md b/Data-Structures/Trees/01-intro.md index 16ea5c1..4d9ff67 100644 --- a/Data-Structures/Trees/01-intro.md +++ b/Data-Structures/Trees/01-intro.md @@ -28,6 +28,6 @@ A Binary tree is a type of tree where each parent node consists of at **max 2** 3. **Perfect Binary Tree :** All leaf nodes are at same level. -4. **Blnced Binary Tree :** The tree can at max have a height of **Log2(n)**, where n is number of nodes. +4. **Balnced Binary Tree :** The tree can at max have a height of **Log2(n)**, where n is number of nodes. For every node, height(left sub-tree) - height(right sub-tree) <= 1. 5. **Degenerate Tree :** When every node only have a single child or parent node. This type resembles to a Linked List. diff --git a/Data-Structures/Trees/problems/check-for-balanced-bt.cpp b/Data-Structures/Trees/problems/check-for-balanced-bt.cpp new file mode 100644 index 0000000..b8d9dbd --- /dev/null +++ b/Data-Structures/Trees/problems/check-for-balanced-bt.cpp @@ -0,0 +1,57 @@ +#include +using namespace std; + +struct TreeNode { + int val; + TreeNode *left; + TreeNode *right; + TreeNode() : val(0), left(nullptr), right(nullptr) {} + TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} + TreeNode(int x, TreeNode *left, TreeNode *right) + : val(x), left(left), right(right) {} +}; + +class Solution { +public: + // a function to check if tree is balanced or not on basis of it's height. + bool isBalanced(TreeNode *root) { return dfsHeight(root) != -1; } + + /* a function to calculate height of tree, if this function returns -1, + the tree is not balanced. The tree will always be balanced if this function + returns some non-negative height */ + + int dfsHeight(TreeNode *root) { + if (root == NULL) + return 0; + + int lh = dfsHeight(root->left); + if (lh == -1) + return -1; + + int rh = dfsHeight(root->right); + if (rh == -1) + return -1; + + // for a balanced BT, height(left sub-tree) - height(right sub-tree) <= 1 + if (abs(lh - rh) > 1) + return -1; + + return max(lh, rh) + 1; + } +}; + +int main() { + Solution solution; + + TreeNode *balancedTree = new TreeNode(1); + balancedTree->left = new TreeNode(2); + balancedTree->right = new TreeNode(3); + balancedTree->left->left = new TreeNode(4); + balancedTree->left->right = new TreeNode(5); + balancedTree->right->left = new TreeNode(6); + balancedTree->right->right = new TreeNode(7); + + bool isBalancedResult = solution.isBalanced(balancedTree); + cout << "tree balanced? " << (isBalancedResult ? "Yes" : "No") << endl; + return 0; +} diff --git a/Data-Structures/Trees/problems/depth-of-bt.cpp b/Data-Structures/Trees/problems/depth-of-bt.cpp new file mode 100644 index 0000000..7922044 --- /dev/null +++ b/Data-Structures/Trees/problems/depth-of-bt.cpp @@ -0,0 +1,54 @@ +#include +#include +using namespace std; + +struct TreeNode { + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} +}; + +class Solution { +public: + int maxDepth(TreeNode *root) { + if (root == NULL) + return 0; + int lh = maxDepth(root->left); + int rh = maxDepth(root->right); + return 1 + max(lh, rh); // formula + } + int minDepth(TreeNode *root) { + if (root == NULL) + return 0; + + // if the tree is a skew tree + if (root->left == NULL && root->right != NULL) { + return minDepth(root->right) + 1; + } else if (root->left != NULL && root->right == NULL) { + return minDepth(root->left) + 1; + } + + // if a normal binary tree + int lh = minDepth(root->left); + int rh = minDepth(root->right); + return 1 + min(lh, rh); // formula + } +}; + +int main() { + TreeNode *root = new TreeNode(3); + root->left = new TreeNode(9); + root->right = new TreeNode(20); + root->right->left = new TreeNode(15); + root->right->right = new TreeNode(7); + + Solution solution; + + int maxDepth = solution.maxDepth(root); + int minDepth = solution.maxDepth(root); + std::cout << "Max Depth of tree : " << maxDepth << std::endl; + std::cout << "Min Depth of tree : " << minDepth << std::endl; + + return 0; +} From d6f2e09bd6ebd5b6f6c24d72defa0f0fb58f246c Mon Sep 17 00:00:00 2001 From: amit Date: Tue, 14 Nov 2023 20:26:54 +0530 Subject: [PATCH 2/3] some problems on trees --- .../Trees/problems/diameter-of-bt.cpp | 54 +++++++++++++++++++ .../Trees/problems/symmetric-bt.cpp | 49 +++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 Data-Structures/Trees/problems/diameter-of-bt.cpp create mode 100644 Data-Structures/Trees/problems/symmetric-bt.cpp diff --git a/Data-Structures/Trees/problems/diameter-of-bt.cpp b/Data-Structures/Trees/problems/diameter-of-bt.cpp new file mode 100644 index 0000000..4ff6df5 --- /dev/null +++ b/Data-Structures/Trees/problems/diameter-of-bt.cpp @@ -0,0 +1,54 @@ +#include +using namespace std; + +struct TreeNode { + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} +}; + +/* +The diameter of a binary tree is the length of the longest path between any two +nodes in a tree. This path may or may not pass through the root. +The length of a path between two nodes is represented by the number of edges +between them. +*/ + +class Solution { +public: + int diameter = 0; + int diameterOfBinaryTree(TreeNode *root) { + height(root); + return diameter; + } + int height(TreeNode *node) { + if (!node) + return 0; + int lh = height(node->left); + int rh = height(node->right); + diameter = max(diameter, lh + rh); + return 1 + max(lh, rh); + } +}; + +int main() { + TreeNode *root = new TreeNode(3); + root->left = new TreeNode(9); + root->right = new TreeNode(20); + root->right->left = new TreeNode(15); + root->right->right = new TreeNode(7); + + Solution solution; + + int result = solution.diameterOfBinaryTree(root); + + cout << "Diameter of the binary tree: " << result << endl; + + delete root->left; + delete root->right->left; + delete root->right->right; + delete root; + + return 0; +} diff --git a/Data-Structures/Trees/problems/symmetric-bt.cpp b/Data-Structures/Trees/problems/symmetric-bt.cpp new file mode 100644 index 0000000..b800b9e --- /dev/null +++ b/Data-Structures/Trees/problems/symmetric-bt.cpp @@ -0,0 +1,49 @@ +#include +using namespace std; + +struct TreeNode { + int val; + TreeNode *left; + TreeNode *right; + TreeNode(int x) : val(x), left(nullptr), right(nullptr) {} +}; + +/* +A symmetric binary tree is a binary tree where the left and right subtrees of +the root node are mirror images of each other. +*/ + +class Solution { +public: + bool isSymmetric(TreeNode *root) { + return root == NULL || helper(root->left, root->right); + } + bool helper(TreeNode *left, TreeNode *right) { + if (left == NULL || right == NULL) + return left == right; + if (left->val != right->val) + return false; + return helper(left->left, right->right) && helper(left->right, right->left); + } +}; + +int main() { + TreeNode *root = new TreeNode(1); + root->left = new TreeNode(2); + root->right = new TreeNode(2); + root->left->left = new TreeNode(3); + root->left->right = new TreeNode(4); + root->right->left = new TreeNode(4); + root->right->right = new TreeNode(3); + + Solution solution; + bool isSymmetric = solution.isSymmetric(root); + + if (isSymmetric) { + cout << "The tree is symmetric." << endl; + } else { + cout << "The tree is not symmetric." << endl; + } + + return 0; +} \ No newline at end of file From 2ebaa5333227dcd8429a76661a16b7c7519c3d33 Mon Sep 17 00:00:00 2001 From: amit Date: Mon, 20 Nov 2023 17:35:34 +0530 Subject: [PATCH 3/3] Removed-unwanted-files --- .../time-complexity.md | 0 C-Notes/pps-module-6.md | 31 -- C-Notes/pps-notes-module-5.md | 122 ------ C-Notes/pps-notes-module4.md | 243 ------------ C-Notes/pps-prac.md | 354 ------------------ COOS/Experiment-2.md | 64 ---- COOS/Experiment-3.md | 83 ---- COOS/Experiment-4.md | 60 --- .../stl-reference.md | 0 Example-Code/bubble-sort.cpp | 25 -- Example-Code/classes-example.py | 37 -- Example-Code/find.cpp | 23 -- Example-Code/search.cpp | 38 -- Example-Code/selection-sort.cpp | 29 -- Example-Code/singly-linked-list-simple.cpp | 47 --- Example-Code/singly-linked-list.cpp | 55 --- Git/commands.md | 110 ------ Java/intro.md | 35 -- Java/java-basics.md | 118 ------ JavaSript/{intro.md => 01-intro.md} | 0 JavaSript/{basics.md => 02-basics.md} | 0 JavaSript/{operators.md => 03-operators.md} | 0 JavaSript/{variables.md => 04-variables.md} | 0 .../{array-methods.md => 05-array-methods.md} | 0 .../{promise.md => promise-1.md} | 0 .../{promiseAPI.md => promise-2.md} | 2 +- Python/PPCA/Experiment-2.1.md | 73 ---- Python/PPCA/Experiment-2.2.md | 101 ----- Python/PS-1/Experiment-1.md | 24 -- Python/PS-1/Experiment-2.md | 34 -- Python/PS-1/Experiment-3.ipynb | 0 Python/PS-1/Experiment-3.md | 47 --- Python/PS-1/Experiment-4.md | 47 --- Python/PS-3/Experiment-3.md | 47 --- .../01-useState.md | 0 .../02-dataFromAPI.md | 0 .../03-eventListners.md | 0 37 files changed, 1 insertion(+), 1848 deletions(-) rename time-complexity.md => Algorithms/time-complexity.md (100%) delete mode 100644 C-Notes/pps-module-6.md delete mode 100644 C-Notes/pps-notes-module-5.md delete mode 100644 C-Notes/pps-notes-module4.md delete mode 100644 C-Notes/pps-prac.md delete mode 100644 COOS/Experiment-2.md delete mode 100644 COOS/Experiment-3.md delete mode 100644 COOS/Experiment-4.md rename stl-reference.md => Data-Structures/stl-reference.md (100%) delete mode 100644 Example-Code/bubble-sort.cpp delete mode 100644 Example-Code/classes-example.py delete mode 100644 Example-Code/find.cpp delete mode 100644 Example-Code/search.cpp delete mode 100644 Example-Code/selection-sort.cpp delete mode 100644 Example-Code/singly-linked-list-simple.cpp delete mode 100644 Example-Code/singly-linked-list.cpp delete mode 100644 Git/commands.md delete mode 100644 Java/intro.md delete mode 100644 Java/java-basics.md rename JavaSript/{intro.md => 01-intro.md} (100%) rename JavaSript/{basics.md => 02-basics.md} (100%) rename JavaSript/{operators.md => 03-operators.md} (100%) rename JavaSript/{variables.md => 04-variables.md} (100%) rename JavaSript/{array-methods.md => 05-array-methods.md} (100%) rename JavaSript/Asynchronous JS/{promise.md => promise-1.md} (100%) rename JavaSript/Asynchronous JS/{promiseAPI.md => promise-2.md} (97%) delete mode 100644 Python/PPCA/Experiment-2.1.md delete mode 100644 Python/PPCA/Experiment-2.2.md delete mode 100644 Python/PS-1/Experiment-1.md delete mode 100644 Python/PS-1/Experiment-2.md delete mode 100644 Python/PS-1/Experiment-3.ipynb delete mode 100644 Python/PS-1/Experiment-3.md delete mode 100644 Python/PS-1/Experiment-4.md delete mode 100644 Python/PS-3/Experiment-3.md rename {TypeScript-For-TSX => TypeScript-For-React}/01-useState.md (100%) rename {TypeScript-For-TSX => TypeScript-For-React}/02-dataFromAPI.md (100%) rename {TypeScript-For-TSX => TypeScript-For-React}/03-eventListners.md (100%) diff --git a/time-complexity.md b/Algorithms/time-complexity.md similarity index 100% rename from time-complexity.md rename to Algorithms/time-complexity.md diff --git a/C-Notes/pps-module-6.md b/C-Notes/pps-module-6.md deleted file mode 100644 index 5aa6e04..0000000 --- a/C-Notes/pps-module-6.md +++ /dev/null @@ -1,31 +0,0 @@ -## yehi ayega - -```c -#include -struct Person { - int id; - char name[20]; - char address[30]; - struct DOB { - int day; - int month; - int year; - } d1; -} p1; - -int main() { - printf("Enter ID :\n"); - scanf("%d", &p1.id); - printf("Enter Name :\n"); - scanf("%s", &p1.name); - printf("Enter Address :\n"); - scanf("%s", &p1.address); - printf("Enter Date of Birth in dd/mm/yyyy form :\n"); - scanf("%d%d%d", &p1.d1.day, &p1.d1.month, &p1.d1.year); - printf("\n PERSON INFORMATION :"); - printf("\nID = %d", p1.id); - printf("\nNAME = %s", p1.name); - printf("\nADDRESS = %s", p1.address); - printf("\nDATE OF BIRTH = %d:%d:%d", p1.d1.day, p1.d1.month, p1.d1.year); -} -``` diff --git a/C-Notes/pps-notes-module-5.md b/C-Notes/pps-notes-module-5.md deleted file mode 100644 index 952cb4a..0000000 --- a/C-Notes/pps-notes-module-5.md +++ /dev/null @@ -1,122 +0,0 @@ -# PPS Notes Module 5 - -## Arrays and Strings - -### Arrays - -- #### What are arrays? - - - It is a derived data type - - Collection of similar type of elements that is of same type - - stored in continuous memory location - - fixed size once its created - - Instead of declaring individual variables, such as A0, - A1,A2,….A99, you declare one array variable such as A[100] - and use A[0], A[1], and ..., A[99] to represent individual - variables. - - Array index starts with 0 and ends with size-1. - -- #### Array declaration - - To declare an array in C, a programmer specifies the type of - the elements, and the number of elements required by an - array as follows: - ```c - data_type array_name[array_size]; - ``` - - This is a single dimension array, array size must be a positive integer - data type can be any, examples of array declaration - - ```c - double balance[10]; - int A[10]; - ``` -- #### Array initialization - - - `int a[5] = {100, 200, 300, 400, 500}` - - The number of values between braces {} cannot be larger than the number - of elements that we declare for the array between square brackets [ ]. - -- #### Accessing Array elements - - An element is accessed by indexing the array name. - ```c - int num = A[4]; - ``` - - To read Array elements - ```c - for(i=0; i < size; i++){ - scanf("%d", &A[i]); - } - ``` - - To display array elements - ```c - for(i=0; i < size; i++ ){ - printf("%d", A[i]); - } - ``` -- #### 2d Array - - - `int A[3][3]` will make an array of 3 x 3 that is a matrix of 3x3 - - It will look like this - - ![image](https://user-images.githubusercontent.com/53911515/214111673-32d2c764-ea91-437a-b1b5-66bf039ee02b.png) - - 2D array declaration - - `int A[][] = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}` - - To read 2D array elements - ```c - for(i=0;i - int main() { - int a[2][3], b[2][3], c[2][3], i, j; - printf("\nENTER VALUES FOR MATRIX A:\n"); - for (i = 0; i < 2; i++) - for (j = 0; j < 3; j++) - scanf("%d", &a[i][j]); - printf("\nENTER VALUES FOR MATRIX B:\n"); - for (i = 0; i < 2; i++) - for (j = 0; j < 3; j++) - scanf("%d", &b[i][j]); - for (i = 0; i < 2; i++) - for (j = 0; j < 3; j++) - c[i][j] = a[i][j] + b[i][j]; - printf("\nTHE VALUES OF MATRIX C ARE:\n"); - for (i = 0; i < 2; i++) { - for (j = 0; j < 3; j++) - printf("%5d", c[i][j]); - printf("\n"); - } - } - ``` - -### Strings - -- #### What are Strings - - Strings in C are represented by One- dimensional Character Arrays - - An array formed by characters is a string in C. - - The end of the string is marked with a special character, the null - character The null character is represented by character escape sequence, - '\0'. -- #### String declaration - - Strings can be declared like one-dimensional arrays. - `data_type string_name[size]` - - examples - ```c - char str[5]; - char name[10]; - ``` diff --git a/C-Notes/pps-notes-module4.md b/C-Notes/pps-notes-module4.md deleted file mode 100644 index 5d9be63..0000000 --- a/C-Notes/pps-notes-module4.md +++ /dev/null @@ -1,243 +0,0 @@ -# PPS Notes Module 4 - -## Functions - -- A ‘C’ program is made up of one or more functions. -- All C programs contain at least one function, called main() where - execution starts. - -- ### Advantages - - - Modular programming - - Source code length can be reduced - - can be called as many times as you like - -- ### Types of function - - - Library Built in functions written in header files like - - - stdio.h - - Ctype.h - - math.h - - stdlib.h - - 4 types of function - - 1. without arguments and without return - - 2. with arguments and without return - - 3. without arguments and with return - - 4. with arguments and with return - -- #### Call by value and Call by reference - - - On the basis of arguments there are two types of function are available in C - language, they are If a function take any arguments, it must declare variables that - accept the values as a arguments. These variables are called the formal parameters of the function. There are two - ways to pass value or data to function in C language which is given below - - • Call by value - - • Call by reference - - - Call by value - - in this the original value cant be changed or modified - - when the value is modified its for local or caller function only - and not the original function. - - Call by reference - - in this the original value is changed or modified because we pass - the address to the variable like with `type *var name` - - value is modified in the original function also. - - #### differences between them - ![image](https://user-images.githubusercontent.com/53911515/214080799-b3e400d4-59a9-416c-b085-d62d4e7feab1.png) - -- ### Parts of function - - - #### Function prototype/ declaration. - `void add();` - - specify the value that needs to be returned from the function - - defined before function call - - #### Function call. - `add();` - - calls the function with the parameters - - #### Function definition / body. - ```c - void add() - { - int a=10,b=20,c; - printf("Sum=%d",a+b) - } - ``` - - independent program module - - specifies what function needs to do - - Syntax - ```c - return_type function name(formal_parameter list){ - function_body - } - ``` - - #### Sample function call - ```c - #include - void main(){ - printf("hello world"); - } - ``` - - ##### Four types of function - - - no arguments and no returns - - arguments but no return - - no arguments and return - - arguments and return - - - ## Function to check whether a number is prime or not - - ```c - #include - void prime(int n); - void main() - { - char c; - int n; - printf("Enter a positive integer: "); - scanf("%d",&n); - prime(n); - } - - void prime(int n){ - int i,count=0; - for(i=1; i<=n; i++) { - if(n%i==0) - count++; - } - if(count==2) - printf("\n%d is a prime number.", n); - else - printf("\n%d is not a prime number.", n); - } - ``` - - ## Program for Armstrong number using function between ranges - - ```c - #include - - int isarmstrong(int num); - void printarmstrong(int start, int end); - - int main() { - int start, end; - - printf("Enter lower limit to print armstrong numbers: "); - scanf("%d", &start); - printf("Enter the upper limit to print armstrong: "); - scanf("%d", &end); - printf("All armstrong numbers between %d to %d are: \n", start, end); - printarmstrong(start, end); - return 0; - } - - int isarmstrong(int num) { - int temp, lastdigit, sum; - temp = num; - sum = 0; - - while (temp != 0) { - lastdigit = temp % 10; - sum += lastdigit * lastdigit * lastdigit; - temp /= 10; - } - - if (num == sum) { - return 1; - } else { - return 0; - } - - return 0; - } - - void printarmstrong(int start, int end) { - while (start <= end) { - if (isarmstrong(start)) { - printf("%d, ", start); - } - start++; - } - } - ``` - - - #### Recursion - - - A function that calls itself is known as recursive - function and this technique is known as recursion - in C programming. - - Simple example - ```c - void main(){ - print("somethig"); - main(); - } - ``` - - ### program to calculate the factorial - - ```c - #include - - int factorial(int); - int main() { - int n, f; - printf("Enter the no"); - scanf("%d", &n); - f = factorial(n); - printf("\n Factorial of %d = %d", n, f); - } - int factorial(int x) { - if (x == 1 || x == 0) - return 1; - else - return x * factorial(x - 1); - } - ``` - - - ### function to calculate the fibonacci series - ```c - #include - void fibonacci(int); - int main() { - int k, n; - int i = 0, j = 1, f; - printf("enter the range of the fibonacci series: "); - scanf("%d", &n); - printf("fibonacci series: "); - printf("%d %d ", 0, 1); - fibonacci(n); - } - void fibonacci(int n) { - static int first = 0, second = 1, sum; - if (n > 0) { - sum = first + second; - first = second; - second = sum; - printf("%ld ", sum); - fibonacci(n - 1); - } - } - ``` - - - ### Differences between recursion and iteration - ![image](https://user-images.githubusercontent.com/53911515/214092152-39384ba3-1fe4-4a98-9da8-f0f494407c7e.png) - -- ### Storage clases - - automatic - - default storage class if no class is defined - - are only local to there block and destroyed when exited - - static - - local scope - - acts like an auto class - - lifetime is till when program exits until then stored in memory - - external - - assumes that the variable was declared somewhere else so only access - the data and doesnt declares them - - there scope is global and lifetime is till program exits - - register - - are very similar to automatic class - - are stored in CPU registers rather than memory - - useful when needed to access a variable again and again - - only for local scope diff --git a/C-Notes/pps-prac.md b/C-Notes/pps-prac.md deleted file mode 100644 index b23448c..0000000 --- a/C-Notes/pps-prac.md +++ /dev/null @@ -1,354 +0,0 @@ -# Code for PPS practical - -## **This only contains code that was done in PPS practical and no others** - -## And only those which i though were somewhat difficult i haven't included the very easy one which anyone can do - -## I dont guarantee that only these code will come in practical any other can also come - -## Prac 2 - -### to swap two vars without a temp var - -```c -#include -#include -#include -#include - -int main() { - int a, b; - scanf("%i%i", &a, &b); - a = a + b; - b = a - b; - a = a - b; - printf("%i %i", a, b); - return 0; -} -``` - -## Prac 3 - -### To find roots of the quadratic equation - -**execute with `-lm` flag on linux** - -```c -#include -#include -#include -#include - -int main() { - int a, b, c, d; - double root1, root2; - printf("this program will find the roots of the ax^2+bx+c=0"); - printf("enter a, b and c\n"); - scanf("%i%i%i", &a, &b, &c); - d = b * b - 4 * a * c; - - if (d < 0) { - double e = -(b) / (double)(2 * a); - double f = sqrt(-d) / 2 * a; - printf("first root = %.2lf + i%.2lf\n", e, f); - printf("second root = %.2lf - i%.2lf\n", e, f); - } - - else { - root1 = (-b + sqrt(d)) / (2 * a); - root2 = (-b + sqrt(d)) / (2 * a); - printf("first root= %.2lf\n", root1); - printf("second root= %.2lf\n", root2); - } - return 0; -} -``` - -### Whether input is number or uppercase or lowercase - -```c -#include -#include -#include -#include -#include - -int main() { - char a; - scanf("%c", &a); - if (islower(a)) { - printf("lowercase character"); - } else if (isupper(a)) { - printf("uppercase character"); - } else if (isdigit(a)) { - printf("number"); - } else { - printf("special"); - } - return 0; -} -``` - -## Prac 4 - -### prob 1 - -### To find the sum of 1/1! + 1/2! + 1/3! + .... + 1/n! - -```c -#include -#include -#include -#include - -int main() { - int i, fact, j; - int n; - float sum; - printf("Enter the value of N :"); - scanf("%d", &n); - sum = 0.0f; - for (i = 1; i <= n; i++) { - fact = 1; - for (j = 1; j <= i; j++) { - fact = fact * j; - } - sum = sum + ((float)1 / (float)fact); - } - printf("sum of series is : %f\n", sum); - return 0; -} -``` - -### Prob 2 - -![image](https://user-images.githubusercontent.com/53911515/215794827-ea48fdf5-85e7-450e-955c-c552980be5d2.png) - -```c -#include - -int main() { - for (int i = 1; i <= 4; i++) { - // inner loop to print spaces - for (int j = 4; j >= i; j--) { - printf(" "); - } - // inner loop to print numbers - for (int k = 1; k <= i; k++) { - printf("%d ", k); - } - // inner loop to print alphabets - int m = 65; - for (int l = 2; l < i; l++) { - printf("%c ", (char)m); - m++; - } - printf("\n"); - } - return 0; -} -``` - -## Prac 5 - -- ### expt 1 - armstrong number - -```c -#include - -int isarmstrong(int num); -void printarmstrong(int start, int end); - -int main() { - int start, end; - - printf("Enter lower limit to print armstrong numbers: "); - scanf("%d", &start); - printf("Enter the upper limit to print armstrong: "); - scanf("%d", &end); - printf("All armstrong numbers between %d to %d are: \n", start, end); - printarmstrong(start, end); - return 0; -} - -int isarmstrong(int num) { - int temp, lastdigit, sum; - temp = sum; - sum = 0; - - while (temp != 0) { - lastdigit = temp % 10; - sum += lastdigit * lastdigit * lastdigit; - temp /= 10; - } - - if (num == sum) { - return 1; - } else { - return 0; - } - - return 0; -} - -void printarmstrong(int start, int end) { - while (start <= end) { - if (isarmstrong(start)) { - printf("%d, ", start); - } - start++; - } -} -``` - -- ### expt 2 is prime? - -```c -#include -void prime(int n); -void main() -{ - char c; - int n; - printf("Enter a positive integer: "); - scanf("%d",&n); - prime(n); -} - -void prime(int n){ - int i,count=0; - for(i=1; i<=n; i++) { - if(n%i==0) - count++; - } - if(count==2) - printf("\n%d is a prime number.", n); - else - printf("\n%d is not a prime number.", n); -} -``` - -- ### expt 3 factorial - -```c -#include - -int factorial(int); -int main() { -int n, f; -printf("Enter the no"); -scanf("%d", &n); -f = factorial(n); -printf("\n Factorial of %d = %d", n, f); -} -int factorial(int x) { -if (x == 1 || x == 0) - return 1; -else - return x * factorial(x - 1); -} -``` - -## prac 6 - -## if you get this one you are pretty fucked - -- ### expt 1 deleting elemts from array - -```c -#include -#include -#include -#include - -int main() { - int a[1000], pos, c, n; - char ch = 'y'; - printf("Enter number of elements in the array\n"); - scanf("%d", &n); - printf("Enter %d elements\n", n); - for (c = 0; c < n; c++) { - scanf("%d", &a[c]); - } - do { - if (ch == 'y') { - printf("Enter the location you wish to delete element\n"); - } - scanf("%d", &pos); - if (pos > n + 1) { - printf("deletion not possible\n"); - } else { - for (c = pos - 1; c < n - 1; c++) { - a[c] = a[c + 1]; - } - n = n - 1; - if (n > 0) { - printf("resultant array: \n"); - for (c = 0; c < n; c++) { - printf("%d\n", a[c]); - } - } else { - printf("Array is empty\n"); - exit(0); - } - } - printf("Continue??\n"); - char flushall(); - scanf("%c", &ch); - } while (ch == 'y' && n != 0); - return 0; -} -``` - -### expt 3 ascending or descending order - -```c -#include -#include -#include -#include - -int main() { - int a, n, number[30]; - char ch; - printf("Enter the value of N \n"); - scanf("%i", &n); - printf("Enter the numbers\n"); - for (int i; i < n; i++) { - scanf("%d", &number[i]); - } - printf("assecending or descending order 'a' or 'd'\n"); - scanf("%c", &ch); - if (ch == 'a') { - for (int i = 0; i < n; i++) { - for (int j = i + 1; j < n; j++) { - if (number[i] > number[j]) { - a = number[i]; - number[i] = number[j]; - number[j] = a; - } - } - } - printf("the numbers arranged in assecending order is: \n"); - for (int i = 0; i < n; i++) { - printf("%d\n", number[i]); - } - } - if (ch == 'd') { - for (int i = 0; i < n; i++) { - for (int j = i + 1; j < n; j++) { - if (number[i] < number[j]) { - a = number[i]; - number[i] = number[j]; - number[j] = a; - } - } - } - printf("the numbers arranged in descending order is: \n"); - for (int i = 0; i < n; i++) { - printf("%d\n", number[i]); - } - } - return 0; -} -``` diff --git a/COOS/Experiment-2.md b/COOS/Experiment-2.md deleted file mode 100644 index 8beae95..0000000 --- a/COOS/Experiment-2.md +++ /dev/null @@ -1,64 +0,0 @@ -- For one’s complement, we simply need to flip all bits. -- For 2’s complement, we first find one’s complement. We traverse the one’s complement starting from LSB (least significant bit), and look for 0. -- We flip all 1’s (change to 0) until we find a 0. Finally, we flip the found 0. -- For example, 2’s complement of “01000” is “11000” (Note that we first find one’s complement of 01000 as 10111). -- If there are all 1’s (in one’s complement), we add an extra 1 in the string. For example, 2’s complement of “000” is “1000” (1’s complement of “000” is “111”). - -```cpp -// C++ program to print 1's and 2's complement of -// a binary number -#include -using namespace std; - -// Returns '0' for '1' and '1' for '0' -char flip(char c) {return (c == '0')? '1': '0';} - -// Print 1's and 2's complement of binary number -// represented by "bin" -void printOneAndTwosComplement(string bin) -{ - int n = bin.length(); - int i; - - string ones, twos; - ones = twos = ""; - - // for ones complement flip every bit - for (i = 0; i < n; i++) - ones += flip(bin[i]); - - // for two's complement go from right to left in - // ones complement and if we get 1 make, we make - // them 0 and keep going left when we get first - // 0, make that 1 and go out of loop - twos = ones; - for (i = n - 1; i >= 0; i--) - { - if (ones[i] == '1') - twos[i] = '0'; - else - { - twos[i] = '1'; - break; - } - } - - // If No break : all are 1 as in 111 or 11111; - // in such case, add extra 1 at beginning - if (i == -1) - twos = '1' + twos; - - - cout << "1's complement: " << ones << endl; - cout << "2's complement: " << twos << endl; -} - -// Driver program -int main() -{ - string bin = "1100"; - printOneAndTwosComplement(bin); - return 0; -} - -``` diff --git a/COOS/Experiment-3.md b/COOS/Experiment-3.md deleted file mode 100644 index 7df9b21..0000000 --- a/COOS/Experiment-3.md +++ /dev/null @@ -1,83 +0,0 @@ -# Program to do binary addition and octal addition - -### For binary addition - -```cpp -#include -#include -using namespace std; - -string addBinary(string a, string b) { - int carry = 0; - string result = ""; - - // Make sure the binary numbers have the same length by padding zeros - int maxLength = max(a.length(), b.length()); - a = string(maxLength - a.length(), '0') + a; - b = string(maxLength - b.length(), '0') + b; - - // Iterate through the binary numbers from right to left - for (int i = maxLength - 1; i >= 0; i--) { - int bit1 = a[i] - '0'; - int bit2 = b[i] - '0'; - - // Calculate the sum and carry - int currentSum = bit1 + bit2 + carry; - int currentBit = currentSum % 2; - carry = currentSum / 2; - - // Add the current bit to the result - result = to_string(currentBit) + result; - } - - // If there is a carry left after the iteration, add it to the result - if (carry) { - result = "1" + result; - } - - return result; -} - -int main() { - string num1 = "101"; - string num2 = "011"; - string result = addBinary(num1, num2); - cout << "The sum of " << num1 << " and " << num2 << " is: " << result << endl; - - return 0; -} -``` - -### For octal to binary - -```cpp -#include -#include - -using namespace std; - -// Function to add two octal numbers -string addOctal(string num1, string num2) { - // Convert the octal numbers to decimal - int decimal1 = stoi(num1, nullptr, 8); - int decimal2 = stoi(num2, nullptr, 8); - - // Add the decimal numbers - int sum = decimal1 + decimal2; - - // Convert the sum back to octal - string octalSum = to_string(sum); - return "0" + octalSum; -} - -int main() { - string octal1 = "17"; // Octal number 17 - string octal2 = "43"; // Octal number 43 - - string result = addOctal(octal1, octal2); - - cout << "Sum: " << result << endl; - - return 0; -} -``` diff --git a/COOS/Experiment-4.md b/COOS/Experiment-4.md deleted file mode 100644 index 35f266c..0000000 --- a/COOS/Experiment-4.md +++ /dev/null @@ -1,60 +0,0 @@ -```cpp -#include -using namespace std; - -int flipFlops[4]; - -void initializeFlipFlops() { - cout << "Enter a 4 bit value: "; - for (int i = 0; i < 4; i++) { - cin >> flipFlops[i]; - } -} - -void leftShift() { - // Shift the bits to the left - cout << "After left shift, "; - for (int i = 3; i > 0; i--) { - flipFlops[i] = flipFlops[i - 1]; - } -// Set the least significant bit to 0 - flipFlops[0] = 0; -} - -void rightShift() { -// Shift the bits to the right - cout << "After right shift, "; - int temp = flipFlops[0]; - for (int i = 0; i < 3; i++) { - flipFlops[i] = flipFlops[i + 1]; - } - // Set the most significant bit to 0 - flipFlops[3] = temp; -} - -// Function to print the contents of the register -void printRegister() { - cout << "Register stores: "; - for (int i = 3; i >= 0; i--) { - cout << flipFlops[i]; - } - cout << endl; -} - -int main() { - initializeFlipFlops(); - - printRegister(); - - leftShift(); - - printRegister(); - - rightShift(); - - printRegister(); - - return 0; -} - -``` diff --git a/stl-reference.md b/Data-Structures/stl-reference.md similarity index 100% rename from stl-reference.md rename to Data-Structures/stl-reference.md diff --git a/Example-Code/bubble-sort.cpp b/Example-Code/bubble-sort.cpp deleted file mode 100644 index da9d787..0000000 --- a/Example-Code/bubble-sort.cpp +++ /dev/null @@ -1,25 +0,0 @@ -#include -using namespace std; - -void bubbleSort(int arr[], int n) { - int i, j; - for (i = 0; i < n; i++) { - for (j = 0; j < n; j++) { - if (arr[j] > arr[j + 1]) { - int temp = arr[j]; - arr[j] = arr[j + 1]; - arr[j + 1] = temp; - } - } - } -} - -int main() { - int arr[] = {64, 25, 12, 22, 11}; - int n = sizeof(arr) / sizeof(arr[0]); - bubbleSort(arr, n); - cout << "Sorted array: "; - for (int i = 0; i < n; i++) - cout << arr[i] << " "; - return 0; -} diff --git a/Example-Code/classes-example.py b/Example-Code/classes-example.py deleted file mode 100644 index c88107e..0000000 --- a/Example-Code/classes-example.py +++ /dev/null @@ -1,37 +0,0 @@ -# way to make a class with empty body -class person2: - pass - - -class person: - def __init__(self, name, age, SSN, alive): - self.name = name - self.age = age - # _ is just a Convention to point that this attribute is private - # but it just a convention and still can be accessed and modified - self._SSN = SSN - - # __ is used to make an attribute protected and its also a convention - self.__alive = "yes" - - # _ and __ have the same meaning for methods also - def sayHello(self): - print(f"Hello {self.name}!") - - -class police(person): - def __init__(self, name, age, SSN, badge, alive): - super().__init__(name, age, SSN, alive) - self.badge = badge - self.__alive = "no" - - def sayHello(self): - print(f"{self.name} is a {self.badge}") - - -if __name__ == "__main__": - rahul = person("rishabh", 20, 69420, "no") - rahul.sayHello() - - aditya = police("Aditya", 20, 42, "inspector", alive="no") - aditya.sayHello() diff --git a/Example-Code/find.cpp b/Example-Code/find.cpp deleted file mode 100644 index dc8062b..0000000 --- a/Example-Code/find.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// find example -#include // find -#include // cout -#include // vector - -using namespace std; - -int main() { - // using find with array and pointer: - int myints[] = {10, 20, 30, 40}; - - // using find with vector and iterator: - vector myvector(myints, myints + 4); - vector::iterator it; - - it = find(myvector.begin(), myvector.end(), 30); - if (it != myvector.end()) - cout << "Element found in myvector: " << *it << '\n'; - else - cout << "Element not found in myvector\n"; - - return 0; -} diff --git a/Example-Code/search.cpp b/Example-Code/search.cpp deleted file mode 100644 index 4b53005..0000000 --- a/Example-Code/search.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// search algorithm example -#include // search -#include // cout -#include // vector - -using namespace std; - -bool mypredicate(int i, int j) { return (i == j); } - -int main() { - vector haystack; - - // set some values: haystack: 10 20 30 40 50 60 70 80 90 - for (int i = 1; i < 10; i++) - haystack.push_back(i * 10); - - // using default comparison: - int needle1[] = {40, 50, 60, 70}; - vector::iterator it; - it = search(haystack.begin(), haystack.end(), needle1, needle1 + 4); - - if (it != haystack.end()) - cout << "needle1 found at position " << (it - haystack.begin()) << '\n'; - else - cout << "needle1 not found\n"; - - // using predicate comparison: - int needle2[] = {20, 30, 50}; - it = search(haystack.begin(), haystack.end(), needle2, needle2 + 3, - mypredicate); - - if (it != haystack.end()) - cout << "needle2 found at position " << (it - haystack.begin()) << '\n'; - else - cout << "needle2 not found\n"; - - return 0; -} diff --git a/Example-Code/selection-sort.cpp b/Example-Code/selection-sort.cpp deleted file mode 100644 index 675feec..0000000 --- a/Example-Code/selection-sort.cpp +++ /dev/null @@ -1,29 +0,0 @@ -#include -using namespace std; - -void selectionSort(int arr[], int n) { - int i, j, min_idx; - - // One by one move boundary of unsorted subarray - for (i = 0; i < n - 1; i++) { - // Find the minimum element in unsorted array - min_idx = i; - for (j = i + 1; j < n; j++) - if (arr[j] < arr[min_idx]) - min_idx = j; - - // Swap the found minimum element with the first element - swap(arr[min_idx], arr[i]); - } -} - -int main() { - int arr[] = {64, 25, 12, 22, 11}; - int n = sizeof(arr) / sizeof(arr[0]); - selectionSort(arr, n); - cout << "Sorted array: \n"; - for (int i = 0; i < n; i++) - cout << arr[i] << " "; - cout << endl; - return 0; -} diff --git a/Example-Code/singly-linked-list-simple.cpp b/Example-Code/singly-linked-list-simple.cpp deleted file mode 100644 index 3b7a859..0000000 --- a/Example-Code/singly-linked-list-simple.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include -using namespace std; - -// we create a class called Node which has two variables data and next -// the data variable is used to store the data and the next variable is used to -// store the address of the next node -class Node { - public: - int data; - Node *next; -}; - -int main() { - // We created three nodes head, second and third and point them to NULL - // because we don't have any nodes yet - Node *head = NULL; - Node *second = NULL; - Node *third = NULL; - - // then we allocate the nodes in the heap memory - head = new Node(); - second = new Node(); - third = new Node(); - - // then we put the data in the nodes - head->data = 1; - head->next = second; - - second->data = 2; - second->next = third; - - third->data = 3; - third->next = NULL; - - // then we create a current node and point it to the head node - Node *current = head; - - // then we print the data of the current node and then we point the current - // node to the next node we do this until the current node is not equal to - // NULL - while (current != NULL) { - cout << current->data << " "; - current = current->next; - } - cout << endl; - return 0; -} diff --git a/Example-Code/singly-linked-list.cpp b/Example-Code/singly-linked-list.cpp deleted file mode 100644 index 179ea6d..0000000 --- a/Example-Code/singly-linked-list.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include -using namespace std; - -class Node { - public: - int data; - Node *next; - - Node(int val) { - data = val; - next = NULL; - } -}; - -class LinkedList { - public: - Node *head; - - LinkedList() { head = NULL; } - - void insert(int val) { - Node *newNode = new Node(val); - - if (head == NULL) { - head = newNode; - } else { - Node *curr = head; - while (curr->next != NULL) { - curr = curr->next; - } - curr->next = newNode; - } - } - - void display() { - if (head == NULL) { - cout << "List is empty" << endl; - } else { - Node *curr = head; - while (curr != NULL) { - cout << curr->data << " -> "; - curr = curr->next; - } - cout << "NULL" << endl; - } - } -}; - -int main() { - LinkedList myList; - myList.insert(5); - myList.insert(10); - myList.insert(15); - myList.display(); -} diff --git a/Git/commands.md b/Git/commands.md deleted file mode 100644 index fe210e3..0000000 --- a/Git/commands.md +++ /dev/null @@ -1,110 +0,0 @@ -# Contributing to a Repository. - -## 1. Fork a GitHub Repository - -## 2. Cloning the repo to your device. - -- Click on the **<> Code** button on the right side and copy the repo's **HTTPS url** which looks like [https://github.com/username/repo-name.git]() -- Open Git Bash, locate your directory, and clone this repo with the help of this command : - -``` -git clone https://github.com/username/repo-name.git -``` - -**You'll be able to see something similar to this:** - -``` -Cloning into 'repo-name'... -remote: Enumerating objects: 32, done. -remote: Counting objects: 100% (2/2), done. -remote: Compressing objects: 100% (2/2), done. -remote: Total 32 (delta 0), reused 0 (delta 0), pack-reused 30 -Receiving objects: 100% (32/32), 23.68 KiB | 516.00 KiB/s, done. -Resolving deltas: 100% (7/7), done. -``` - -**Your Repo is cloned :)** - -## 3. Making your personal branch. - -**What's branch btw ?** -In Git, a branch is a new/separate version of the main repository. -_Learn more about branch at [Branch](./branch.md)._ - -To make a branch: - -``` -git switch -c your-branch-name -``` - -**This will create a branch and switch to it.** - -## 4. Open IDE (VS Code Probably) - -**Once your branch is made, open the repo in an IDE.** - -Use the below command to directly open the IDE from terminal. - -``` -code . -``` - -## 5. Make changes in the repo which you were supposed to. - -## 6. Adding changes to stagged area. - -- As you are working, you may be **adding**, **editing** and **removing** files. -- But whenever you hit a milestone or finish a part of the work, you should **add** the files to a **Staging Environment.** - Use the command : - -``` -git add . -``` - -**Note: ' . ' stands for All changes** - -## 7. Commiting the Changes. - -- Since we have finished our work, we are ready move from stage to commit for our repo. - -- Adding commits keep track of our progress and changes as we work. - -- Git considers each commit change point or "save point". It is a point in the project you can go back to if you find a bug, or want to make a change. - -- When we commit, we should always include a message. - -``` -git commit -m "your message" -``` - -## 8. Pull changes from main branch. - -**Pulling to Keep up-to-date with Changes** - -- When working as a team on a project, it is important that everyone stays up to date. - -- Any time you start working on a project, you should get the most recent changes to your local copy. - -- With Git, you can do that with pull. - -``` -git pull origin main -``` - -## 9. Push your changes. - -- Now push the branch from our local Git repository, to GitHub, where everyone can see the changes: - -``` -git push origin your-branch-name -``` - -- Go to GitHub, and confirm that the repository has a new branch. - -## 10. Open a Pull Request - -- Click the **Compare & pull request** , you can go through the changes made and new files added. -- If the changes look good, you can go forward, creating a **pull request**. -- A pull request is how you propose changes. You can ask some to review your changes or pull your contribution and merge it into their branch. - -**Note: You can merge your pull request yourself if is your own repository.** diff --git a/Java/intro.md b/Java/intro.md deleted file mode 100644 index b90f0ee..0000000 --- a/Java/intro.md +++ /dev/null @@ -1,35 +0,0 @@ -# Java - Introduction - -- Java is a widely-used programming language. -- Java is designed to be a versatile, robust, and platform-independent language, meaning that Java code can run on different operating systems without modification. - -## Why Java ? - -- Among Top 3 most popular Languages 📈 -- Extremely Flexible [Web Apps, Mobile Apps, Games, etc] 😌 -- Easy to find Job as a Developer 💸 - -## Java Platform - -
-
- Java Developer Kit ( JDM ) -
- Java Runtime Environment ( JRE ) -
- Java Virtual Machine ( JVM ) -
-
-
-
- -## Java Code Compilation - -
- java code process -
- -
- -**Continue Learning** [Java Basics.](./java-basics.md) diff --git a/Java/java-basics.md b/Java/java-basics.md deleted file mode 100644 index 8328adb..0000000 --- a/Java/java-basics.md +++ /dev/null @@ -1,118 +0,0 @@ -# Java Basics - -## 1. Java Template code - -```java -pubic class Main { - public static void main(string [] args){ - // code goes here - } -} -``` - -**Now, let's go through the code step by step:** - -1. **public class Main :** - - - **public:** This is an access modifier that specifies the visibility of the class. In this case, it means the class Main is accessible from any other class. - - **class:** This keyword is used to define a class in Java. - - **Main:** This is the name of the class. _The name of the Java file should match the class name._ - -2. **public static void main(String[] args)** - - - **public:** This is another access modifier that specifies the visibility of the method main(). It means the main() method can be accessed from any other class. - - **static:** This keyword indicates that the main() method belongs to the class itself, not an instance of the class. It allows the program to run without creating an object of the class. - - **void:** This is the return type of the main() method, indicating that it doesn't return any value. - - **main:** This is the name of the method. _The main() method is the entry point of a Java program, and it's executed when the program starts._ - - **String[] args:** This is the parameter list of the main() method. It allows you to pass command-line arguments to the program. The args variable is an array of strings that can hold the command-line arguments. - -## 2. Output - -```java -System.out.println("Hello World"); -``` - -**Now, let's go through the code step by step:** - -1. **System:** System is the predefined class that provides access to standard Input / Output. and Error streams. -2. **out:** out is a public static member of System class which represents standard output. -3. **println:** println is a member of print stream class, println prints a "new line" of text in output. - -## 3. Input - -```java -import java.util.Scanner; // Import the Scanner class to read user input - -public class UserInputExample { - public static void main(String[] args) { - - // Create a Scanner object to read user input - Scanner scanner = new Scanner(System.in); - - // Read the user's input (name) as a String - String name = scanner.nextLine(); - - // Close the Scanner to release resources - scanner.close(); - - // Display the user's input - System.out.println("Hello, " + name); - } -} -``` - -**NOTE: .nextLine() reads string or character values. To accept integer or float values, we can use .nextInt() or .nextFloat()** - -
- -## 4. Variables and Data types - -#### Variables: - -**Declaring variables in Java is same as that of most other programming languages like C, C++, etc.** - -```java -int x; // declaration -x = 123; // assignment -int y = 123 // initialization -``` - -#### Primitive Data Types: - -```java -int x = 123; // integer values -double y = 3.1416; // decimal values -boolean z = true; // true or false -char symbol = '@'; // single characters -String name = "Amit"; // String or sentences -``` - - - -## Let's Add two Numbers using Input - Output - -```java -import java.util.Scanner; - -public class UserInputExample { - public static void main(String[] args) { - - Scanner sc = new Scanner(System.in); - - System.out.println("Enter Number 1: "); - int num1 = sc.nextInt(); - - System.out.println("Enter Number 2: "); - int num2 = sc.nextInt(); - - int sum = a + b; - - sc.close(); - - System.out.println("Sum of the numbers: " + sum); - } -} -``` - -- **Similarly you can use other Operators (-, \*, /, %) and try it by your own!** -- **Try making a Simple Calculator using If-Else ladder or Switch-Case.** diff --git a/JavaSript/intro.md b/JavaSript/01-intro.md similarity index 100% rename from JavaSript/intro.md rename to JavaSript/01-intro.md diff --git a/JavaSript/basics.md b/JavaSript/02-basics.md similarity index 100% rename from JavaSript/basics.md rename to JavaSript/02-basics.md diff --git a/JavaSript/operators.md b/JavaSript/03-operators.md similarity index 100% rename from JavaSript/operators.md rename to JavaSript/03-operators.md diff --git a/JavaSript/variables.md b/JavaSript/04-variables.md similarity index 100% rename from JavaSript/variables.md rename to JavaSript/04-variables.md diff --git a/JavaSript/array-methods.md b/JavaSript/05-array-methods.md similarity index 100% rename from JavaSript/array-methods.md rename to JavaSript/05-array-methods.md diff --git a/JavaSript/Asynchronous JS/promise.md b/JavaSript/Asynchronous JS/promise-1.md similarity index 100% rename from JavaSript/Asynchronous JS/promise.md rename to JavaSript/Asynchronous JS/promise-1.md diff --git a/JavaSript/Asynchronous JS/promiseAPI.md b/JavaSript/Asynchronous JS/promise-2.md similarity index 97% rename from JavaSript/Asynchronous JS/promiseAPI.md rename to JavaSript/Asynchronous JS/promise-2.md index 0cd560a..f21b265 100644 --- a/JavaSript/Asynchronous JS/promiseAPI.md +++ b/JavaSript/Asynchronous JS/promise-2.md @@ -1,6 +1,6 @@ ```js /* -Promise API Is nothing but some Promise Class methods. +Promise Is nothing but some Promise Class methods. 1. Promise.all() : if we want all the values at same time, when every promise is resolved, we use promise.all() but, promise.all() only works for all resolved values and fails if any of the promise gets rejected. So if still we want to get the values, even if any of the promise is rejected, we use promise.allSettled() diff --git a/Python/PPCA/Experiment-2.1.md b/Python/PPCA/Experiment-2.1.md deleted file mode 100644 index e760f1d..0000000 --- a/Python/PPCA/Experiment-2.1.md +++ /dev/null @@ -1,73 +0,0 @@ -## Decision making statements - -### Write a program to check whether a number is even or odd - -```py -a = int(input("Enter the number: ")) -if a%2==0: - print("The number is even") -else: - print("The number is odd") -``` - -### Write a program to find largest number out of three numbers entered by a user. - -```py -a, b, c = map(int, input("Enter three numbers: ").split()) - -if a > b: - if a > c: - print(f"the larget number is {a}") - else: - print(f"the larget number is {c}") -else: - if b > c: - print(f"the larget number is {b}") - else: - print(f"the larget number is {c}") -``` - -### Write a program to check whether the last digit of a number is divisible by 4 or not - -```py -a = int(input("Enter the number: ")) -last_digit = a % 10 - -if last_digit % 4 == 0: - print("Last digit is divisible by 4") -else: - print("Last digit is not divisible by 4") -``` - -### Write a program to check whether a year entered by the user is leap or not. - -```py -year = int(input("Enter the Year: ")) -if year % 4 == 0: - print("The year is a leap year") -else: - print("The year is not a leap year") -``` - -### A college grading system - -```py -marks = int(input("Enter the marks: ")) - -if marks < 40: - print("You have failed") -elif marks >= 40 and marks < 45: - print("The grade is P") -elif marks >= 45 and marks < 50: - print("The grade is E") -elif marks >= 50 and marks < 60: - print("The grade is D") -elif marks >= 60 and marks < 70: - print("The grade is C") -elif marks >= 70 and marks < 75: - print("The grade is B") -elif marks >= 75 and marks < 80: - print("The grade is A") -else: - print("The grade is O") -``` diff --git a/Python/PPCA/Experiment-2.2.md b/Python/PPCA/Experiment-2.2.md deleted file mode 100644 index 29d2f37..0000000 --- a/Python/PPCA/Experiment-2.2.md +++ /dev/null @@ -1,101 +0,0 @@ -## Functions - -```py -def function_name(parameters): # define the function - # code goes here -function_name(arguments) # call function -``` - -## Define a function to add two numbers - -```py -def add(a, b): - return a + b -print(add(2, 3)) -``` - -## Define a function to greet user - -```py -def greetUser(name, time): - time = time.upper() - if (time == "MORNING" or time == "DIN"): - return f"Good Morning, {name}" - elif (time == "AFTERNOON" or time == "DOPHAR"): - return f"Good Afternoon, {name}" - elif (time == "NIGHT" or time == "SHAAM"): - return f"Good Evening, {name}" - else: - return f"Good Night, {name}" - - -x = input("What's your name: ") -y = input("What's your day time: ") - -print(greetUser(x, y)) -``` - -## Define a function to calculate GCD of two numbers - -```py -def gcd(n1, n2): - if (n2 == 0): - return abs(n1) - else: - return gcd(n2, n1 % n2) - -n, m = map(int, input("Enter two numbers: ").split()) -print(f"GCD of {n} and {m} is {gcd(n, m)}") -``` - -## Define a function to print first nth terms in fibonacci terms. - -```py -def fibo(n): - if n <= 0: - return "Invalid input" - elif n == 1: - return 0 - elif n == 2: - return 1 - else: - return fibo(n - 1) + fibo(n - 2) - -d = int(input("Enter the value of 'n': ")) - -if d > 0: - for i in range(1, d + 1): - print(fibo(i), end=" ") -else: - print("Invalid Input, n should be a positive integer!") -``` - -## Define a function to print factorial of a number. - -```py -def fact(n): - if n <= 0: - return "Invalid input" - elif n < 2: - return 1 - else: - return n * fact(n - 1) - -e = int(input("Enter the value of 'n': ")) -print(f"Factorial of {e} is {fact(e)}") -``` - -## Define a function to convert decimal to binary - -```py -def toBinary(n): - ans = "" - while(n != 0): - rem = n % 2 - ans = ans + str(rem) - n //= 2 - return ans[::-1] # reverse the returned string - -num = int(input("Enter any decimal value: ")) -print(f"Binary representation of {num} is {toBinary(num)}") -``` diff --git a/Python/PS-1/Experiment-1.md b/Python/PS-1/Experiment-1.md deleted file mode 100644 index d93b4dc..0000000 --- a/Python/PS-1/Experiment-1.md +++ /dev/null @@ -1,24 +0,0 @@ -## BIG DATA & AI - -- Big data primarily refers to data sets that are too large - or complex to be dealt with by traditional data-processing - application. - -- Big data and artificial intelligence have a work-together - relationship. - -- AI requires a massive scale of data to learn and - improve decision-making processes and big data analytics - leverages AI for better data analysis. - -- By bringing together big data and AI technology, - companies can improve business performance and efficiency by: - -1. Analyzing consumer behavior and automating customer - segmentation. - -2. Personalizing and optimizing the performance of - digital marketing campaigns. - -3. Using intelligent decision support systems fueled by - big data, AI, and predictive analytics. diff --git a/Python/PS-1/Experiment-2.md b/Python/PS-1/Experiment-2.md deleted file mode 100644 index 907899e..0000000 --- a/Python/PS-1/Experiment-2.md +++ /dev/null @@ -1,34 +0,0 @@ -## Import Statistics and Numpy library: - -```py -import statistics as st -import numpy as np -``` - -## Make a data storage: - -```py -data = np.array([1, 2, 3, 4, 5, 6, 6, 7, 8, 9]) -``` - -## Calculate by using Statistics functions: - -```py -print("Mean:", st.mean(data)) -print("Median:", st.median(data)) -print("Mode:", st.mode(data)) -print("Range:", max(data) - min(data)) -print("Variance:", st.variance(data)) -print("STD:", round(st.stdev(data))) -``` - -## Output: - -``` -Mean: 5 -Median: 5.5 -Mode: 6 -Range: 8 -Variance: 6 -STD: 2 -``` diff --git a/Python/PS-1/Experiment-3.ipynb b/Python/PS-1/Experiment-3.ipynb deleted file mode 100644 index e69de29..0000000 diff --git a/Python/PS-1/Experiment-3.md b/Python/PS-1/Experiment-3.md deleted file mode 100644 index 28f90b0..0000000 --- a/Python/PS-1/Experiment-3.md +++ /dev/null @@ -1,47 +0,0 @@ -## Pearson's Correlation coefficient. - -### To measure linear relationship between two variables in a dataset. - -#### The coefficient lies between -1 to +1, where -1 is negative (unlike) relationship, +1 is a positive (like) relationship and 0 is no relationship between those datasets - -```py -## Pearson's Correlation - finding a coefficient with justifies relationship -import numpy as np - -## generating random data for two variables. - -np.random.seed(42) -dataset1 = np.random.rand(20) -dataset2 = 2 * dataset1 + 1 + 0.1 * np.random.randn(20) # simulating linear relationship with some noise - -# calculating Pearson's Correlation coefficient -def pearson_correlation(x, y): - mean_x = np.mean(x) - mean_y = np.mean(y) - numerator = np.sum((x - mean_x)*(y - mean_y)) - denominator = np.sqrt(np.sum((x - mean_x)**2)* np.sum((y -mean_y)**2)) - correlation_coefficient = numerator / denominator - return correlation_coefficient - -correlation_coefficient = pearson_correlation(dataset1, dataset2) - -print("Dataset 1: ", dataset1) -print("Dataset 2: ", dataset2) -print("Pearson's Correlation Coefficient: ", correlation_coefficient) -``` - -**output :** - -``` -Dataset 1: [0.5881308 0.89771373 0.89153073 0.81583748 0.03588959 0.69175758 - 0.37868094 0.51851095 0.65795147 0.19385022 0.2723164 0.71860593 - 0.78300361 0.85032764 0.77524489 0.03666431 0.11669374 0.7512807 - 0.23921822 0.25480601 0.85762553 0.94977903 0.56168686 0.17878052 - 0.77025193 0.49238104 0.63125307 0.83949792 0.4610394 0.49794007] -Dataset 2: [2.28827483 2.92870528 2.75872758 2.61867188 1.06087743 2.53913381 - 1.77023972 1.83032702 2.22735362 1.27724249 1.63791944 2.64319567 - 2.47251342 2.53935626 2.60319676 0.91821854 1.2663488 2.38890874 - 1.44458737 1.54170911 2.65502026 3.05403089 2.18807712 1.41688276 - 2.58430632 2.12054098 2.38295726 2.81417546 1.97142252 1.72544362] -Pearson's Correlation Coefficient: 0.9804978183283416 -``` diff --git a/Python/PS-1/Experiment-4.md b/Python/PS-1/Experiment-4.md deleted file mode 100644 index a1fcd03..0000000 --- a/Python/PS-1/Experiment-4.md +++ /dev/null @@ -1,47 +0,0 @@ -# Corelation technique using method of least squares - -### Code implemtation - -```py -x = [1,2,3,4,5] -y = [3,5,7,8,10] - -mean_x = sum(x) / len(x) -mean_y = sum(y) / len(y) - -ssxx = 0 -spxy = 0 -ssyy = 0 - -for i in range(len(x)): - ssxx += pow((x[i]-mean_x), 2.0) - -for i in range(len(y)): - ssyy += pow((y[i] - mean_y), 2.0) - -for i in range(len(x)): - spxy += (x[i] - mean_x)*(y[i] - mean_y) - -m = spxy/ssxx -b = mean_y - m*mean_x - -print(f"{ssxx}, {ssyy}, {spxy}") - -print(f"slope: {m}, intercept: {b}") - -import matplotlib.pyplot as plt - -plt.scatter(x, y, label="Data points") -plt.plot(x, [m * x + b for x in x], color='red', label="Best-fitting line") -plt.xlabel('X') -plt.ylabel('Y') -plt.title('Linear Regression') -plt.legend() -plt.grid(True) -plt.show() - -``` - -### Output - -![image](https://github.com/Rishabh672003/Programming-Notes/assets/53911515/531d2a20-5827-4758-a519-bdf3a48fc180) diff --git a/Python/PS-3/Experiment-3.md b/Python/PS-3/Experiment-3.md deleted file mode 100644 index 28f90b0..0000000 --- a/Python/PS-3/Experiment-3.md +++ /dev/null @@ -1,47 +0,0 @@ -## Pearson's Correlation coefficient. - -### To measure linear relationship between two variables in a dataset. - -#### The coefficient lies between -1 to +1, where -1 is negative (unlike) relationship, +1 is a positive (like) relationship and 0 is no relationship between those datasets - -```py -## Pearson's Correlation - finding a coefficient with justifies relationship -import numpy as np - -## generating random data for two variables. - -np.random.seed(42) -dataset1 = np.random.rand(20) -dataset2 = 2 * dataset1 + 1 + 0.1 * np.random.randn(20) # simulating linear relationship with some noise - -# calculating Pearson's Correlation coefficient -def pearson_correlation(x, y): - mean_x = np.mean(x) - mean_y = np.mean(y) - numerator = np.sum((x - mean_x)*(y - mean_y)) - denominator = np.sqrt(np.sum((x - mean_x)**2)* np.sum((y -mean_y)**2)) - correlation_coefficient = numerator / denominator - return correlation_coefficient - -correlation_coefficient = pearson_correlation(dataset1, dataset2) - -print("Dataset 1: ", dataset1) -print("Dataset 2: ", dataset2) -print("Pearson's Correlation Coefficient: ", correlation_coefficient) -``` - -**output :** - -``` -Dataset 1: [0.5881308 0.89771373 0.89153073 0.81583748 0.03588959 0.69175758 - 0.37868094 0.51851095 0.65795147 0.19385022 0.2723164 0.71860593 - 0.78300361 0.85032764 0.77524489 0.03666431 0.11669374 0.7512807 - 0.23921822 0.25480601 0.85762553 0.94977903 0.56168686 0.17878052 - 0.77025193 0.49238104 0.63125307 0.83949792 0.4610394 0.49794007] -Dataset 2: [2.28827483 2.92870528 2.75872758 2.61867188 1.06087743 2.53913381 - 1.77023972 1.83032702 2.22735362 1.27724249 1.63791944 2.64319567 - 2.47251342 2.53935626 2.60319676 0.91821854 1.2663488 2.38890874 - 1.44458737 1.54170911 2.65502026 3.05403089 2.18807712 1.41688276 - 2.58430632 2.12054098 2.38295726 2.81417546 1.97142252 1.72544362] -Pearson's Correlation Coefficient: 0.9804978183283416 -``` diff --git a/TypeScript-For-TSX/01-useState.md b/TypeScript-For-React/01-useState.md similarity index 100% rename from TypeScript-For-TSX/01-useState.md rename to TypeScript-For-React/01-useState.md diff --git a/TypeScript-For-TSX/02-dataFromAPI.md b/TypeScript-For-React/02-dataFromAPI.md similarity index 100% rename from TypeScript-For-TSX/02-dataFromAPI.md rename to TypeScript-For-React/02-dataFromAPI.md diff --git a/TypeScript-For-TSX/03-eventListners.md b/TypeScript-For-React/03-eventListners.md similarity index 100% rename from TypeScript-For-TSX/03-eventListners.md rename to TypeScript-For-React/03-eventListners.md