### Selection Sort in JAVA

What is selection sort?

It is a sorting technique that is based on the partitioning of array into two parts, sorted and unsorted.

The process is:-

1) Find minimum element in unsorted array.
2) Swap the element at the end of sorted array.

when i=0 we don't have any sorted array so element will be replaced from first element later the sorted array end will growas the index.

Steps:-

`underline elements are sorted array, the length is increasing with each minimum element added at the end.`

```minimum element11
11 25 12 22 64
minimum element12
11 12 25 22 64
minimum element22
11 12 22 25 64
minimum element25
11 12 22 25 64
minimum element64
11 12 22 25 64
```

Program:-

```package sorting;

public class SelectionSort {

//function to print array
public static void print(int[] arr)
{
for(int i=0;i<=arr.length-1;i++)
System.out.print(" "+arr[i]);
System.out.println(" ");
}

//function to swap elements
public static int[] swap(int[] arr,int i, int j)
{
int temp;
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;

return arr;
}

//program to find minimum element in unsorted array( i to end)
public static int min(int[] arr,int i)
{
int min=i;
for(;i<=arr.length-1;i++)
{
if(arr[i]<arr[min])
{
min=i;
}
}
System.out.println("minimum element"+arr[min]);
return min;

}

public static void main(String[] args)
{
int[] arr={64,25,12,22,11};
int min;
for(int i=0;i<=arr.length-1;i++)
{
//find minimum element in unsorted array ( i to end)
min=min(arr,i);
//swap minimum element with then end of sorted array(i)
swap(arr,min,i);
//print the array
print(arr);

}

}

}
```

### 5 books that your college doesn’t tell to read seriously for PLACEMENTS

1.Let us C - It can be the best book to pick in your first semester itself. The book is written in a very simple style so you can easily grasp most of the concepts of programming by just working hard on it. It will help you in building basics of programming around c language.

2.HEAD FIRST JAVA-This book you should buy in third semester and invest your whole second year into it by working on all the codes. This book will help you teaching the concepts in a very attractive way. You will never bore while working  through this book.

3.Data Structure Made Easy In Java - As soon you finished studying core java in the 4th semester just pick this book to understand the logic’s of data structure and algorithms. It will help you to go deep inside this subject from which questions are frequently asked in all the interviews. This book carries a great set of problems that will help in developing intellectual knowledge around algorithms.

4.Cracking The Coding Interview – This book you should start pra…

### Bubble Sort in JAVA

What is bubble sort?

It is a sorting technique that is based on the comparison.Here we compare adjacent element, if the first element is larger than the second we swap each other. We do the same procedure again and again until array do not sort completely.

Example:-
5 1 4 2 8

51428here pass is nothing but iterating the loops equal to number of elements in the array but if it already sorted before then we can break the loop anddo existPASS1 case0 1 //check 0 and first element15428 case1 2 //check 1 and 2 element14528 case2 314258 case3 414258 swap istruePASS2 //first pass completed now do second pass case0 114258 case1 212458 case2 312458 case3 412458 swap istrue PASS3 // third pass case0 112458 case1 212458 case2 312458 case3 412458 swap isfalse since swap is false we break from the loop and do not go for fourth and fifth pass
Program:-

package sorting;publicclassBubbleSort{//function to print arraypublicstaticvoidprint(int[] arr){for(int i=0;i<=arr.length-1;i++) Syst…