Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

SORTING WITH THEIR DIFFERENT METHODS(C PROGRAMMING)

Rating
-
Sold
-
Pages
5
Uploaded on
05-07-2025
Written in
2024/2025

THIS PDF IS RELATED TO THE EXPLANATION OF SORTING AND THEIR DIFFERENT METHODS . 1 GIVEN PROPER EXPLANATION AND PROGRAM FOR EACH METHOD WITH ALGORITHM . MY WORK IS EASY TO UNDERSTAND AND IS PROPERLY DETAILED IN EACH ASPECTS . IMPORTANT FOR EXAM FOR COURSE CODE (BTPS101-18) OR IF IT IS IN YOUR SYLLABUS . CHECK IT OUT FOR A REASONABLE PRICE.

Show more Read less
Institution
Course

Content preview

B TECH COMPUTER SCIENCE
PROGRAMMING FOR PROBLEM SOLVING(C)
SUBJECT CODE-BTPH101-23
SORTING AND THEIR DIFFERENT METHODS
Sorting:- Sorting means arranging the elements in an array so that they are placed in
ascending or descending order. For example, an unsorted array a[5] = {3, 10, 11, 2, 1} becomes
sorted in ascending order as a[5] = {1, 2, 3, 10, 11}.


METHODS:-

Bubble

Selection

Insertion

Sorting Techniques

Bubble Sort

Bubble sort is a very simple method that sorts array elements by repeatedly moving the
largest element to the highest index position of the array segment. In bubble sort,
consecutive adjacent elements in the array are compared with each other. If the element at
the lower index is greater than the element at the higher index, the two elements are
swapped.

PROGRAM:-

#include <stdio.h>​
int main() {​
int a[5] = {5, 2, 15, 22, 1};​
int i, j, temp;​
for (i = 4; i > 0; i--) {​
for (j = 0; j <= i - 1; j++) {​
if (a[j] > a[j+1]) {​
temp = a[j];​
a[j] = a[j+1];​
a[j+1] = temp;​

, }​
}​
}​
printf("The sorted array is = ");​
for (i = 0; i < 5; i++) {​
printf("%d\n", a[i]);​
}​
return 0;​
}



OUTPUT: 1 2 5 15 22 ​

Bubble Sort Algorithm Steps:

1.​ Start ​

2.​ Bubble sort (a, N) where N is the size of the array ​

3.​ Repeat step 2 for i = 4 to i >= 0 ​

4.​ Repeat for j = 0 to i-1 ​

5.​ If (a[j] > a[j+1]), swap a[j] and a[j+1] ​

6.​ Exit ​



Selection Sort


The following table is an example:
10, 4, 6, 3, 2
0, 1, 2, 3, 4 (index position)
For i = 0 (i <= 4 or i < 5)

min = a[0] = 10

To travel elements: j = i + 1, j <= 4

If a[j] < a[min]

For j = 1: a[1] < a[0] => 4 < 10 (True). min = a[1]

Written for

Institution
Course

Document information

Uploaded on
July 5, 2025
Number of pages
5
Written in
2024/2025
Type
Class notes
Professor(s)
Muskan
Contains
All classes

Subjects

$3.49
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
muskanbhatoya

Get to know the seller

Seller avatar
muskanbhatoya CHANDIGARH GROUP OF COLLEGES
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
10 months
Number of followers
0
Documents
13
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions