Posts

sorting algorithms explained part 2

Selection Sort Algorithm Selection sort algorithm starts by compairing first two elements of an array and swapping if necessary, i.e., if you want to sort the elements of array in ascending order and if the first element is greater than second then, you need to swap the elements but, if the first element is smaller than second, leave the elements as it is. Then, again first element and third element are compared and swapped if necessary. This process goes on until first and last element of an array is compared. This completes the first step of selection sort. If there are  n  elements to be sorted then, the process mentioned above should be repeated  n-1  times to get required result. But, for better performance, in second step, comparison starts from second element because after first step, the required number is automatically placed at the first (i.e, In case of sorting in ascending order, smallest element will be at first and in case of sorting in descending order, larges

Sorting algorithm explained part 1.

Introduction to Sorting Sorting is nothing but storage of data in sorted order, it can be in ascending or descending order. The term Sorting comes into picture with the term Searching. There are so many things in our real life that we need to search, like a particular record in database, roll numbers in merit list, a particular telephone number, any particular page in a book etc. Sorting  arranges data in a sequence which makes searching easier. Every record which is going to be sorted will contain one key. Based on the key the record will be sorted. For example, suppose we have a record of students, every such record will have the following data: Roll No. Name Age Class Here Student roll no. can be taken as key for sorting the records in ascending or descending order. Now suppose we have to search a Student with roll no. 15, we don't need to search the complete record we will simply search between the Students with roll no. 10 to 20. Sorting Efficiency: There are

How many questions, on an average basis, shall I solve daily, to become a top-level competitive programmer?

As many as you’ll manage to solve while practicing intensively instead of running for numbers. This question in fact make not too much sense. You don’t even give definition of “top-level competitive programmer”. I know people who say a coder with yellow rating is basically a stupid newbie. I know people saying that making into CF div1 means being a top-level contestant, an inspiration for everyone around. Which one fits better for your scale? You didn’t put any timetable - do you want to reach that level in a year, or two, or ten years?.. Number of problems that you solve isn’t the exact indicator of how productive you are, or how intense is your preparation, or how much new stuff you learned. There is some probability that you’ll use fixed number to motivate yourself: “I haven’t solved enough problems today, I should keep practicing instead of going to do something else”. But, on the other hand, there is decent probability that you’ll intentionally or unintentionally switch to

Is it possible to join ACM-ICPC with a team of 2 members only?

There must be three per team. If you have a team of only two, reach out to a third person at your university, even if their skill set is not up to your expectation. Then, train smart. In October 2016, we had an ICPC Alumni Meeting at Stanford, courtesy of Sutter Hills Ventures. It was a resounding success. One past ICPC World Finalist told of his floundering in school, seeing something about the ICPC, and joining a team of two. They accepted him only for the team to have enough members. He flourished n the team environment, where it is in everyone’s best interest for all to advance quickly. His F’s became A’s. His team advanced to the World Finals. He volunteered as a judge during a time of spectacular growth of his region. He became a trusted member of the ICPC family. He was recruited to a prominent position in Silicon Valley. He is doing well. He shared this story at the ICPC Alumni Meeting. He brought his young son who is a pistol. He knew that the ICPC family is exactly th

Should I quit competitive programming? I am not good at it, but I like it very much?

Think about the reasons you are doing it and make a decision correspondingly. You are doing it because of some benefits you are going to get once you’ll reach decent level? Think if it is worth it - maybe you don’t have other way, or maybe you can get these benefits by doing something else and investing smaller amount of time. Or maybe you simply don’t need them. Look how much you improved over time and scale it to get some approximation on time it will take you to reach the level you want/need. You are going to improve over time. Maybe you aren’t going to improve fast. Even if you can improve quickly - it will require investing great amount of time and effort. What do you need from competitive programming? Why are you doing it? You like it very much, right? This reason sounds good enough - but you have to consider everything carefully and weight it. Just imagine that you are doing some other fun (but possibly useless) activity instead; imagine saying “Should I quit playing compute

Which books should i use for competitive programming?

Image
One must have IMO is  Introduction to algorithms . It's huge to be honest, and gives both depth and breadth of a extensive coverage of different data structures and algorithms techniques. You may not need to study it from page to page, but use it as a reference resource. When you need to understand some topic, read that part in it, and this will give you a very solid foundation on algorithm analysis and design. Another book focus on math topic is Knuth's  Concrete Mathematics,   I believe any ambitious competitive programmer who want to do well on math problems should read this book. If you find this book a little difficult to follow, you may also try the following book which is much easy to understand.   A Friendly introduction to number theory  will teach your most of the knowledge about number theory you need in competitive programming and is extremely easy to follow. Algorithm Design by JON KLEINBERG is a book on some advanced topics on algorithm, which is ver

level-wise breakup of competitive programming

I spent continuous 2 months of fully-dedicated work on algorithms, those were my best days, I can give advice on what felt from that time: First you need to do some good programming in string manipulation, etc., some really shortcut coding is a must, for example using C++ STL, you need to write 1 line that will give you an understanding of about 5-10 lines. This way, you ideas will flow easily, that is, you write one/two line, what you want to do is already accomplished, so understanding of the whole library you are using is mandatory like C++ STL, etc. Searching, linear & binary search are basic. Linear is too inefficient for many tasks, you will binary search in different forms in many other topics, but it is not easy to look & understand on how to apply a binary search at first, if you modify the problem slightly, you will know a binary search operation is possible. Sorting, most times, quick sort will work, rarely others are required, I used Hoare variation implem