From d01f0220687fb27c8d86651557c76373ab39c03a Mon Sep 17 00:00:00 2001 From: Kazi Rifat Morshed Date: Sun, 18 Aug 2024 00:27:32 +0600 Subject: [PATCH] updated --- src/Recursion/Practice_on_Recursion.md | 173 ++++++++++++++++++++----- src/SUMMARY.md | 8 ++ src/StartHere/Books_Tutorials.md | 17 ++- src/StartHere/StartHere.md | 5 + 4 files changed, 166 insertions(+), 37 deletions(-) diff --git a/src/Recursion/Practice_on_Recursion.md b/src/Recursion/Practice_on_Recursion.md index 0fb52f5..3c67ac3 100644 --- a/src/Recursion/Practice_on_Recursion.md +++ b/src/Recursion/Practice_on_Recursion.md @@ -7,12 +7,7 @@ You can use the [Competitive Programming Helper (cph)](https://marketplace.visua ### Problems on Recursion -1. Print 1 to 50 with a recursive function.\ - Input: - - ``` - 50 - ``` +1. Print 1 to 50 with a recursive function.\\ Output: @@ -37,7 +32,7 @@ You can use the [Competitive Programming Helper (cph)](https://marketplace.visua ~ if (number > 50) { // in a new recursive call, if the value of number is greater than 50, recursive call should terminate ~ return; ~ } else { - ~ // printf("%d ", number); + ~ printf("%d ", number); ~ // recursive call ~ printer(number + 1); // value of number increments here ~ } @@ -47,7 +42,39 @@ You can use the [Competitive Programming Helper (cph)](https://marketplace.visua ~} ``` -2. Print out the series 1 + 2 + 3 + ... + n w and determine the sum.\ +2. Print 1 to 50 reversely with a recursive function.\\ + + Output: + + ``` + 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 + ``` + + Hint: + + ``` + uno reverse... + write down only 5 recursive call (with code and variable value) in your notebook + ``` + + Solution: + + ```c + ~#include + ~void printer(int number) { + ~ if (number > 50) { + ~ return; + ~ } else { + ~ printer(number + 1); // notice the change here + ~ printf("%d ", number); // and think, how ? + ~ } + ~} + ~int main(void) { + ~ printer(1); + ~} + ``` + +3. Print out the series $$ 1 + 2 + 3 + ... + n $$ and determine the sum.\ Input: ``` 5 @@ -79,7 +106,7 @@ You can use the [Competitive Programming Helper (cph)](https://marketplace.visua ~ } // done ``` -3. You will be given an array of integers. Write a recursive solution to print it in (inputted) order.\ +4. You will be given an array of integers. Write a recursive solution to print it in (inputted) order.\ Input: ``` 5 @@ -91,7 +118,7 @@ You can use the [Competitive Programming Helper (cph)](https://marketplace.visua ``` Hint: -4. Same as before. Add index number (starting from 1) to each int output in (inputted) order.\ +5. Same as before. Add index number (starting from 1) to each int output in (inputted) order.\ Input: ``` 5 @@ -102,7 +129,7 @@ You can use the [Competitive Programming Helper (cph)](https://marketplace.visua 1.69 2.87 3.45 4.21 5.47 ``` -5. Same as before. Add index number (starting from n) to each int and get output in reverse order.\ +6. Same as before. Add index number (starting from n) to each int and get output in reverse order.\ Input: ``` 7 @@ -113,45 +140,67 @@ You can use the [Competitive Programming Helper (cph)](https://marketplace.visua 7.69 6.87 5.45 4.21 3.47 2.76 1.2 ``` -6. You will be given an array of integers. Write a recursive solution to print it in reverse order. +7. You will be given an array of integers. Write a recursive solution to print it in reverse order. Input: + ``` 5 62 87 45 24 47 + ``` Output: + ``` 47 24 45 87 62 + ``` -7. Same as before. The program will print inputted numbers except even integers. +8. Same as before. The program will print inputted numbers except even integers. Input: + ``` 5 62 87 45 24 47 + ``` Output: + ``` 47 45 87 + ``` -8. Use recursion to find max among 2 integers. +9. Use recursion to find max among 2 integers. -9. Use recursion to find the max among 3 integers. +10. Use recursion to find the max among 3 integers. -10. Use recursion to find min among 2 integers. +11. Use recursion to find min among 2 integers. -11. Use recursion to find min among 3 integers. +12. Use recursion to find min among 3 integers. -12. Write a recursive function to print an array in the following order. \[0] \[n-1] \[1] \[n-2] … \[(n-1)/2] \[n/2] +13. Write a recursive function to print an array in the following order. + ``` + [0] [n-1] + [1] [n-2] + ... + [(n-1)/2] [n/2] + ``` Input: + ``` 5 1 5 7 8 9 + ``` Output: + ``` 1 9 5 8 7 7 + ``` -13. Write a recursive program to remove all odd integers from an array. You must not use any extra array or print anything in the function. Just read the input, call the recursive function, and then print the array in main(). +14. Write a recursive program to remove all odd integers from an array. You must not use any extra array or print anything in the function. Just read the input, call the recursive function, and then print the array in main().\ Input: + ``` 6 1 54 88 6 55 7 + ``` Output: + ``` 54 88 6 + ``` -14. Write a recursive solution to print the polynomial series for any input n: $$ 1 + x + x^2 + ... + x^{n-1} $$ +15. Write a recursive solution to print the polynomial series for any input n: $$ 1 + x + x^2 + ... + x^{n-1} $$ \ Input: ``` 5 @@ -161,25 +210,25 @@ You can use the [Competitive Programming Helper (cph)](https://marketplace.visua 1 + x + x^2 + x^3 + x^4 ``` -15. Write a recursive solution to evaluate the previous polynomial for any given x and n. Like, when x=2 and n=5, we have 1 + x + x2 + ................. + xn-1 = 31 +16. Write a recursive solution to evaluate the previous polynomial for any given x and n. Like, when x=2 and n=5, we have $$ 1 + x + x^2 + ... + x^{n-1} = 31 $$ \ Input: 2 5 Output: 31 -16. Write a recursive program to compute n! +17. Write a recursive program to compute n!\ Input: 5 Output: 120 -17. Write a recursive program to compute the n-th Fibonacci number. 1st and 2nd Fibonacci numbers are 1, 1. +18. Write a recursive program to compute the ~n-th~ Fibonacci number. 1st and 2nd Fibonacci numbers are 1, 1.\ Input: 6 Output: 8 -18. Write a recursive program to determine whether a given integer is prime or not. +19. Write a recursive program to determine whether a given integer is prime or not.\ Input: 49 999983 @@ -189,33 +238,33 @@ You can use the [Competitive Programming Helper (cph)](https://marketplace.visua prime not prime -19. Write a recursive function that finds the gcd of two non-negative integers. +20. Write a recursive function that finds the gcd of two non-negative integers.\ Input: 25 8895 Output: 5 -20. Write a recursive solution to compute the LCM of two integers. You must not use the formula lcm(a,b) = (a x b) / gcd(a,b); find lcm from scratch... +21. Write a recursive solution to compute the LCM of two integers. You must not use the formula lcm(a,b) = (a x b) / gcd(a,b); find lcm from scratch...\ Input: 23 488 Output: 11224 -21. Suppose you are given an array of integers in an arbitrary order. Write a recursive solution to find the maximum element from the array. +22. Suppose you are given an array of integers in an arbitrary order. Write a recursive solution to find the maximum element from the array.\ Input: 5 7 4 9 6 2 Output: 9 -22. Write a recursive solution to find the second maximum number from a given set of integers. +23. Write a recursive solution to find the second maximum number from a given set of integers.\ Input: 5 5 8 7 9 3 Output: 8 -23. Implement linear search recursively, i.e. given an array of integers, find a specific value from it. Input format: first n, the number of elements. Then n integers. Then, q, the number of queries, then q integers. Output format: for each of the q integers, print its index (within 0 to n-1) in the array or print 'not found', whichever is appropriate. +24. Implement linear search recursively, i.e. given an array of integers, find a specific value from it. Input format: first n, the number of elements. Then n integers. Then, q, the number of queries, then q integers. Output format: for each of the q integers, print its index (within 0 to n-1) in the array or print 'not found', whichever is appropriate.\ Input: 5 2 9 4 7 6 @@ -225,7 +274,7 @@ You can use the [Competitive Programming Helper (cph)](https://marketplace.visua not found 1 -24. Implement binary search recursively, i.e. given an array of sorted integers, find a query integer from it. Input format: first n, the number of elements. Then n integers. Then, q, the number of queries, then q integers. Output format: for each of the q integers, print its index (within 0 to n-1) in the array or print 'not found', whichever is appropriate. +25. Implement binary search recursively, i.e. given an array of sorted integers, find a query integer from it. Input format: first n, the number of elements. Then n integers. Then, q, the number of queries, then q integers. Output format: for each of the q integers, print its index (within 0 to n-1) in the array or print 'not found', whichever is appropriate.\ Input: 5 1 2 3 4 5 @@ -235,19 +284,19 @@ You can use the [Competitive Programming Helper (cph)](https://marketplace.visua 2 not found -25. Write a recursive solution to get the reverse of a given integer. The function must return an int. +26. Write a recursive solution to get the reverse of a given integer. The function must return an int.\ Input: 123405 Output: 504321 -26. Read a string from keyboard and print it in reversed order. You must not use any array to store the characters. Write a recursive solutions to solve this problem. +27. Read a string from keyboard and print it in reversed order. You must not use any array to store the characters. Write a recursive solutions to solve this problem.\ Input: helloo Output: oolleh -27. Write a recursive program that determines whether a given sentence is palindromic or not just considering the alpha-numeric characters ('a'-'z'), ('A'-'Z'), ('0'-'9').\ +28. Write a recursive program that determines whether a given sentence is palindromic or not just considering the alpha-numeric characters ('a'-'z'), ('A'-'Z'), ('0'-'9').\ \ Input: ``` @@ -266,14 +315,42 @@ You can use the [Competitive Programming Helper (cph)](https://marketplace.visua not palindromic ``` -28. Implement strcat(), stracpy(), strcmp() and strlen() recursively.\ +29. Implement prime number determining algorithm recursively. + + Hint: + + ```c + isPrime(num, j + 2); + ``` + + Solution: + + ```c + ~int isPrime(int num, int j) { // RECURSIVE + ~ if (num <= 1) { + ~ return false; + ~ } + ~ if (num % 2 == 0) { + ~ return false; + ~ } + ~ if (num % j == 0) { + ~ return false; + ~ } + ~ if (j * j <= num) { + ~ isPrime(num, j + 2); + ~ } + ~ return true; + ~} + ``` + +30. Implement strcat(), stracpy(), strcmp() and strlen() recursively.\ \ Input: test on your own\ Output: test on your own -29. If you already solved the problem for finding the nth fibonacci number, then you must have a clear vision on how the program flow works. So now, in this problem, print the values of your fibonacci function in pre-order, in-order and post-order traversal. For example, when n = 5, your program calls 3 and 4 from it, from the call of 3, your program calls 1 and 2 again....... here is the picture: +31. If you already solved the problem for finding the nth fibonacci number, then you must have a clear vision on how the program flow works. So now, in this problem, print the values of your fibonacci function in pre-order, in-order and post-order traversal. For example, when n = 5, your program calls 3 and 4 from it, from the call of 3, your program calls 1 and 2 again....... here is the picture: Input: ``` @@ -288,8 +365,32 @@ You can use the [Competitive Programming Helper (cph)](https://marketplace.visua Postorder: 1 2 3 2 1 2 3 4 5 ``` -30. All of you have seen the tower of Hanoi. You have 3 pillars 'a', 'b' and 'c', and you need transfer all disks from one pillar to another. Conditions are, only one disk at a time is movable, and you can never place a larger disk over a smaller one. Write a recursive solution to print the moves that simulates the task, a -> b means move the topmost of tower a to tower b. +32. Convert a Decimal number to Binary.\ + Hint: + + ``` + return Decimal_to_Binary_RECURSIVE(i / 2) ... ; + ``` + + Solution: + + ```c + ~#include + ~int Decimal_to_Binary_RECURSIVE(int i) { + ~ if (i == 0){ + ~ return 0; + ~ } + ~ return Decimal_to_Binary_RECURSIVE(i / 2) * 10 + i % 2; + ~} + ~int main(void) { + ~ int i = 0; + ~ scanf("%d", &i); + ~ printf("the binary of the decimal num %d is %d", i, Decimal_to_Binary_RECURSIVE(i)); + ~} + ``` +33. All of you have seen the tower of Hanoi. You have 3 pillars 'a', 'b' and 'c', and you need transfer all disks from one pillar to another. Conditions are, only one disk at a time is movable, and you can never place a larger disk over a smaller one. Write a recursive solution to print the moves that simulates the task, a -> b means move the topmost of tower a to tower b.\ + \ Input: ``` diff --git a/src/SUMMARY.md b/src/SUMMARY.md index 6cbed9a..1509209 100644 --- a/src/SUMMARY.md +++ b/src/SUMMARY.md @@ -5,6 +5,8 @@ *** +# Guide to Structured Programming + * [Start Here](./StartHere/StartHere.md) * [Get your system ready](./StartHere/Get_your_system_ready.md) * [Books & Tutorials](./StartHere/Books_Tutorials.md) @@ -47,5 +49,11 @@ *** +# Guide to Competitive Programming + +* [Welcome to CP]() + +*** + [Contributions](./ending/Contributions.md) [The End](./ending/TheEnd.md) diff --git a/src/StartHere/Books_Tutorials.md b/src/StartHere/Books_Tutorials.md index 095070f..125d082 100644 --- a/src/StartHere/Books_Tutorials.md +++ b/src/StartHere/Books_Tutorials.md @@ -3,6 +3,21 @@ Now let's get you started on your learning journey. Choose any of the following ones to start. If you love to read and you can understand well from reading then you may choose option 1. Otherwise choose the other options. (Those are videos. I'll suggest that you try both and then decide.) | Author/Channel Name | Medium | Link | -| --------------------- | -------------- | ----------------------------------------------------------------------------------------- | +| - | - | - | +| Harvard CS50 | English (Youtube Playlist[^note]) | [Playlist](https://youtube.com/playlist?list=PLhQjrBD2T381WAHyx1pq-sBfykqMBI7V4\&si=45C8iSl3q8JbDCvB) | | Tamim Shahriar Subeen | Bangla (Book) | [CPBook](http://cpbook.subeen.com/) | | Anisul Islam | Bangla (Video) | [C Programming](https://www.youtube.com/playlist?list=PLgH5QX0i9K3pCMBZcul1fta6UivHDbXvz) | + +How to Start C (Resources) +Firstly, watch Harvard CS50 to build up concepts. It is Highly Recommended for Basics. +Anisul Islam or CollegeWallah or Jennys Lectures or LearnWithHarry or TheCherno or BroCode +GeeksForGeeks +A Book, ANSI C by E Balaguruswamy + +More Resources: +MIT OpenCourseWare +https://nptel.ac.in + +--- + +[^note]: If you want to download a whole youtube playlist with subtitle, you can check this [link](https://blogofkazirifatjr.blogspot.com/2024/08/techtalk01-better-uu-d-dnld.html). diff --git a/src/StartHere/StartHere.md b/src/StartHere/StartHere.md index 0021a84..7fac5d0 100644 --- a/src/StartHere/StartHere.md +++ b/src/StartHere/StartHere.md @@ -1 +1,6 @@ # Start Here + +Start with C (NOT PYTHON) + +Some of the Notes on C are given below: +https://github.com/KaziRifatMorshed/WelcomeToProgramming