Posts

Showing posts from July, 2017

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