Hi! Here We Will dicuss about various programming challenges using C++ Language
Hey there!!! Let's begin our journey with a very simple problem. You are given an array and you need to sort it. Try yourself. I will be posting different approaches to tackle it.
Well there, sorting is an important tool to solve many problems. You will never be asked to sort an array in any competitive programming contest but sometimes you might have to sort an array as per requirements. So , you need to master the art of sorting an array correctly and quickly.
Some of the popular sorting algorithms are:
1) Bubble sort - https://www.geeksforgeeks.org/bubble-sort
2) Selection sort - https://www.geeksforgeeks.org/selection-sort
3) Insertion sort - https://www.geeksforgeeks.org/insertion-sort
4) Quick Sort - https://www.geeksforgeeks.org/quick-sort
5)Merge sort - https://www.geeksforgeeks.org/merge-sort
6)Count sort - https://www.geeksforgeeks.org/counting-sort
Of these sortng algorithms, Quick sort and Merge sort is more used as time taken by these algorithm is quite less than compared to bubble sort, insertion sort or selection sort. So it is recommended to use one of the Merge or Quick sort.
BUT WAIT!!!!! You surely don't want to write such a huge code during an ongoing competition. There is an easy way...........
Use the in-built sorting function of C++. It's just the matter of a line now!!!!
The prototype of the function is:
sort(start address, end address)
Eg: Suppose you have to sort an array A[n]. Then you just have to simply write
sort(A , A+n ) ;
and there you go you have a sorted array with very few efforts.
Remember to include "bits/stdc++.h" header file at the begining of you code.
I will be posting more on this sorting function as soon as possible.
AND HAA....here is the solution of the problem given:
https://www.codechef.com/viewsolution/23726104
Try to submit by yourself!!!!!!!!!
Some of the popular sorting algorithms are:
1) Bubble sort - https://www.geeksforgeeks.org/bubble-sort
2) Selection sort - https://www.geeksforgeeks.org/selection-sort
3) Insertion sort - https://www.geeksforgeeks.org/insertion-sort
4) Quick Sort - https://www.geeksforgeeks.org/quick-sort
5)Merge sort - https://www.geeksforgeeks.org/merge-sort
6)Count sort - https://www.geeksforgeeks.org/counting-sort
Of these sortng algorithms, Quick sort and Merge sort is more used as time taken by these algorithm is quite less than compared to bubble sort, insertion sort or selection sort. So it is recommended to use one of the Merge or Quick sort.
BUT WAIT!!!!! You surely don't want to write such a huge code during an ongoing competition. There is an easy way...........
Use the in-built sorting function of C++. It's just the matter of a line now!!!!
The prototype of the function is:
sort(start address, end address)
Eg: Suppose you have to sort an array A[n]. Then you just have to simply write
sort(A , A+n ) ;
and there you go you have a sorted array with very few efforts.
Remember to include "bits/stdc++.h" header file at the begining of you code.
I will be posting more on this sorting function as soon as possible.
AND HAA....here is the solution of the problem given:
https://www.codechef.com/viewsolution/23726104
Try to submit by yourself!!!!!!!!!
GeeksforGeeks
Bubble Sort Algorithm - GeeksforGeeks
Your All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and more.
We have seen that the sort function of c++ sorts the array in increasing order by default, but what if we want to sort the array in decreasing order? We can simply do it by just modifying the function call statement. We just need to give an extra parameter during calling.
The syntax of the sort function will be:
sort (arr , arr+n , greater<int>());
A program which sorts an array in decreasing order is given here - https://pastebin.com/9zWH71Mz
The syntax of the sort function will be:
sort (arr , arr+n , greater<int>());
A program which sorts an array in decreasing order is given here - https://pastebin.com/9zWH71Mz
Pastebin
Sort in Descding order - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Further more, we can use this sorting function to sort a structure according to one of its member element.
Here is an example of that - https://pastebin.com/LzYqHBVJ
In this example we use function named "func" to compare two elements. Basically the sort function passes two elements to the func function and if it gets 1 in return then first element is placed before the second element. And if 0 is returned then second element is placed before the first element. In this way we can sort a structure according to our need.
Here is an example of that - https://pastebin.com/LzYqHBVJ
In this example we use function named "func" to compare two elements. Basically the sort function passes two elements to the func function and if it gets 1 in return then first element is placed before the second element. And if 0 is returned then second element is placed before the first element. In this way we can sort a structure according to our need.
Pastebin
Sort Structure - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
A prime number is a whole number greater than 1, which is only divisible by 1 and itself. First few prime numbers are : 2 3 5 7 11 13 17 19 23 …..
In many programming problems we have to check prime numbers efficiently. One of efficeient algorithms to find prime numbers is Seive of Eratosthenes. Check it out at GEEKS FOR GEEKS.
https://www.geeksforgeeks.org/sieve-of-eratosthenes/
For any query you can ask me
@saranyanaharoy
Thanks for joining our channel. 😄😄😄😄😄
In many programming problems we have to check prime numbers efficiently. One of efficeient algorithms to find prime numbers is Seive of Eratosthenes. Check it out at GEEKS FOR GEEKS.
https://www.geeksforgeeks.org/sieve-of-eratosthenes/
For any query you can ask me
@saranyanaharoy
Thanks for joining our channel. 😄😄😄😄😄
GeeksforGeeks
Sieve of Eratosthenes - GeeksforGeeks
Your All-in-One Learning Portal: GeeksforGeeks is a comprehensive educational platform that empowers learners across domains-spanning computer science and programming, school education, upskilling, commerce, software tools, competitive exams, and more.
Hello coding enthusiasts !!!!! This time we are upto something very interesting. It's PREFIX ARRAY!!!!! Prefix array is an important tool in competitive programming and it is something which every beginners should know. It comes under the category of basic dynamic programming and it reduces the repeated calculation process. Here is an excellent post on prefix array which will definitely help you to grab it in an easy way -
https://codeforces.com/blog/rash42
Though you may not get a direct problem which will ask you to create a prefix array, but sometimes you will have to use it in some other problem to reduce repeated calculations. So make yourself prepared for it.
Happy coding!!!
https://codeforces.com/blog/rash42
Though you may not get a direct problem which will ask you to create a prefix array, but sometimes you will have to use it in some other problem to reduce repeated calculations. So make yourself prepared for it.
Happy coding!!!
Codeforces
Blog entries - Codeforces
Codeforces. Programming competitions and contests, programming community
