Sorting Arrays in Java - Tutorial | Selection Sort and Bubble Sort

preview_player
Показать описание
Sorting is a process in which we arrange the elements of an array either in ascending or in descending order.
There are generally two types of Sorting in Java, they are :
1. Selction Sorting
2. Bubble Sorting

Hey There!
Its Teja here!
This video is a Java tutorial!
In this video, I am going to teach you about Sorting in Java.

If you have any doubts regarding this, feel free to comment below.

SUBSCRIBE for more videos!
Thanks For Watching!
Cheers!

-~-~~-~~~-~~-~-
Please watch: "How the INTERNET actually works? "
-~-~~-~~~-~~-~-
Рекомендации по теме
Комментарии
Автор

I want to notify everyone that there is a mistake in this video. The Bubble Sort algorithm explained in this video is incorrect. I will try to make an updated video correcting all the mistakes as soon as possible. Sorry for the blunder in this video!

TechRaj
Автор

sir main apko kaise shukriya wajah se aj mere icse me bahut help mili .15 marks i scored just because of usi thanku very doing a good job, keep it up.

Farid.biology
Автор

Sorry man, I did not understand what was the difference between Selection Sort and Bubble Sort in your video. You used the same technique to change places of the array elements. Besides, too many unnecessary variables declared.

MunavarovSuhrob
Автор

selection sort code is wrong brother? you are just implement the buble sort in both case??

OsamaAlatraqchi
Автор

I put time markers for the two most important expressions

For those of us looking for explanation line by line see my commented code using Tech Raj's values


public class SortingArrayAscendingOrder {
public static void main(String[] args) {

//define original array
int [] arr = {2, 8, 15, 1, 24, 13, 4};
int n;
n = arr.length;
System.out.println("the original array has " + n + " values"); //tells me how many elements are in array
System.out.println("Those values are :" + Arrays.toString(arr)); // prints all original values of array

for(int i = 0; i <= n; i++) { //outer loop to repeat 7 times
for(int j = 0; j<(n-1); j++) { // inner loop to handle all elements within 7 situations starting with element 2
int k = j + 1; // starts with first position letter "j" but adds 1 position which is 8
int a = arr[j]; //stores the "j" value which variable "a"
int b = arr[k]; //stores the "k" value as "b"


// This is where the magic swaps happen aka control flow
if(b<a) {//if 8 is less than 2 see video marker at 3:34
int temp1 = a; //temp1 is a holding space for "a"
int temp2 = b; //temp2 is a holding space for "b"
arr[j] = b; //now we swap b for a see video marker at 4:21
arr[k] = a; // now we swap a for b
}
}
}
System.out.println( Arrays.toString(arr)); // prints out the outer loop on one line vs... line by line
}

DonPierreHalfaway
Автор

If 1 goes to the 0th position. How can you consider 1 in the 3rd position to compare with other numbers? Shouldn't you compare the other numbers with 2 cause after swapping. 2 comes in the place of 1 and 1 is in the 0th position

sendilkumar
Автор

low code
why did you declare temp1 and temp2

gixx
Автор

For sorting primitive data types in ascending order in Java you use Arrays.sort(insert your array here), however in descending order you must use an algorithm for primitive types, you also cannot use collections with primitive data types.

mortyjr
Автор

Hai bro, it seems good, but my dought is the code is same for both sorting techniques.just difference is i, j values in loop....in bubbole sort you repeated outer loop for 6times only,

chaitanyavoleti
Автор

what is the difference between the two codes ?

pallavikumar
Автор

I am extremely astonished why did you not edited this video ? You should have explained the algorithm of both the sorting manually first and then should have explained the code. Got any idea that you have used two different techniques to explain selection sort only and not bubble sort?

anamikadas
Автор

What's the difference between the ??

shinyjohny
Автор

can u please expalin quick and merge sort
the explanation is so gud and understandble

shanthimanu
Автор

this coding is not working in other application of java

yoursely_respect_officials
Автор

Sir... even for selection sorting you used the technique of bubble sort...

ramanantr
Автор

why did u write last for loop for(int d=0;d<n;d++)

shanthimanu
Автор

What is different in writing a program of both types of array

dynamomagical
Автор

Thank you so much sir really very helpfull

arpansingh
Автор

bro bubble sorting was very good but selection sorting tutorial was totally wrong

prothomeshbasak
Автор

nice presentation boss i really understand very easy

raghavachitrachedu