Class 10 ICSE - Java

Class 10th Java aims to empower students by enabling them to build their own applications introducing some effective tools to enable them to enhance their knowledge, broaden horizons, foster creativity, improve the quality of work and increase efficiency.
It also develops logical and analytical thinking so that they can easily solve interactive programs. Students learn fundamental concepts of computing using object oriented approach in one computer language with a clear idea of ethical issues involved in the field of computing
Class 10th java topics includes revision of class 9th, constructors, user-defined methods, objects and classes, library classes , etc.

Selection & Bubble Sort

Sorting means arranging elements of an array in ascending or descending order.


Bubble Sort





Bubble sort is a sorting algorithm which iterates through a given array of elements and compares each pair of adjacent elements one after the other.

How Bubble Sort works ( For descending order) :

So in this technique we do sorting upto (size - 1), if there are 5 elements, it takes (5-1), i.e 4 iterations to completely sort the array.

In any of the adjacent pairs, if the first element is smaller than the second element, then it swaps the elements and if not, then it moves on to the next pair of elements (i.e. at first we are placing the smallest element at the extreme right and then before that the second smallest element and so on and so forth). After each iteration, the smallest element among the unsorted elements is placed at the extreme right. At the end the given array is sorted in descending order.

For (I-Iteration) :



For (II-Iteration) :



For (III-Iteration) :



For (IV-Iteration) :



For user-defined values :




Program :



Output :



For pre-defined values :




Program :



Output :

Selection Sort





The selection sort technique is a method in which the smallest element in the array is selected and then swapped with the element that is located in the first position, then the second smallest element in the remaining unsorted array is selected and put in the second position, and so on. Have a look at the implementation explained below.

How Selection Sort works (In ascending order) :

In this technique we do sorting upto (size - 1), if there are 5 elements, it takes (5-1), i.e 4 iterations to completely sort the array.

For 0th index (I Iteration) : We will store value at zeroth index (i.e. 2) then compare it with all the elements and swap it with the smallest value (i.e. 1 at index 3) as shown below.



For 1st index (II Iteration) : We will start with value at first index (i.e. 6) then compare it with all the elements (except the value at zeroth index) and swap it with the smallest value (i.e. 2 at index 3) as shown below.



For 2nd index (III Iteration) : We will start with value at second index (i.e. 9) then compare it with all the elements (except the values at zeroth index & first index) and swap it with the smallest value (i.e. 6 at index 3) as shown below.



For 3rd index (IV Iteration) : We will start with value at third index which is 9 then compare it with all the elements (except the values at zeroth index , first index & second index ) and swap it with the smallest value (i.e. 8 at index 4) as shown below.


Now, our array is sorted in ascending order.

For user-defined value :




Program :



Output :



For pre-defined values :




Program :



Output :

Contact Us

REACH US

SERVICES

  • CODING
  • ON-LINE PREPARATION
  • JAVA & PYTHON

ADDRESS

B-54, Krishna Bhawan, Parag Narain Road, Near Butler Palace Colony Lucknow
Contact:+ 919839520987
Email:info@alexsir.com