Posts

Showing posts from September, 2017

What is Selection Sort? And how it works?

Image
Click here for more contents Selection Sort Selection Sort algorithm is used to arrange a list of elements in a particular order (Ascending or Descending). In selection sort, the first element in the list is selected and it is compared repeatedly with remaining all the elements in the list. If any element is smaller than the selected element (for Ascending order), then both are swapped. Then we select the element at second position in the list and it is compared with remaining all elements in the list. If any element is smaller than the selected element, then both are swapped. This procedure is repeated till the entire list is sorted. The selection sort algorithm is performed using following steps... Step 1:  Select the first element of the list (i.e., Element at first position in the list). Step 2:  Compare the selected element with all other elements in the list. Step 3:  For every comparision, if any element is smaller than selected element (for Ascending order), then

Insertion Sort

Image
                                                                     Insertion Sort This is very easy technique to arrange the list of elements either in ascending or descending order. Insertion sort algorithm arranges a list of elements in a particular order. In insertion sort algorithm, every iteration moves an element from unsorted portion to sorted portion until all the elements are sorted in the list. The insertion sort algorithm is performed using following steps... Step 1:  Assume that first element in the list is in sorted portion of the list and remaining all elements are in unsorted portion. Step 2:  Consider first element from the unsorted list and insert that element into the sorted list in order specified. Step 3:  Repeat the above process until all the elements from the unsorted list are moved into the sorted list. Lets see how it works: Insertion sort start's sorting an array by picking 1st element of array. (We begin by assuming that

What is Link List?

Image
                                                                        Link List in Java  Click here for   home     page        When we want to work with unknown number of data values, we use a linked list data structure to organize that data. Linked list is a linear data structure that contains sequence of elements such that each element links to its next element in the sequence. Each element in a linked list is called as  "Node" . Simply a list is a sequence of data, and linked list is a sequence of data linked with each other.  The formal definition of a single linked list is as follows... Single linked list is a sequence of elements in which every element has link to its next element in the sequence. In any single linked list, the individual element is called as  "Node" . Every  "Node"  contains two fields,  data  and  next . The  data  field is used to store actual value of that node and next field is used to store the address of the next