Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Samenvatting

Summary - CSE201

Beoordeling
-
Verkocht
-
Pagina's
12
Geüpload op
10-06-2025
Geschreven in
2024/2025

Complete notes for Programming and Problem solving

Instelling
Vak

Voorbeeld van de inhoud

SWAMI VIVEKANANDA INSTITUTE OF SCIENCE & TECHNOLOGY
Department of CSE
sub: C Programming

Sorting Algorithms

A sorting algorithm is used to rearrange the elements of an array or list into a specific order—
typically increasing or decreasing.
For example, given an array [10, 20, 5, 2]:

 Sorting in increasing order yields [2, 5, 10, 20]
 Sorting in decreasing order yields [20, 10, 5, 2]

In C programming, sorting algorithms are used to sort data (such as integers, strings, or
other objects) stored in arrays or lists. Sorting can help in faster searching, organizing
data, or improving the efficiency of other algorithms.

Importance of Sorting Algorithms:

Sorting algorithms are fundamental in computer science because they help organize data and reduce
complexity in solving problems. They play a crucial role in a wide range of applications, improving
efficiency and enabling faster operations.

Some of the most common sorting algorithms are:

 Bubble Sort
 Selection Sort
 Insertion Sort
 Merge Sort
 Quick Sort
 Heap Sort
 Radix Sort
 Counting Sort
 Bucket Sort




Bubble Sort in C:
Bubble Sort is a simple comparison-based sorting algorithm. It repeatedly steps through the list, compares
adjacent elements, and swaps them if they are in the wrong order. This process continues until no more
swaps are needed, indicating the list is sorted.




1

, SWAMI VIVEKANANDA INSTITUTE OF SCIENCE & TECHNOLOGY
Department of CSE
sub: C Programming

How does Bubble Sort Work?

Example array: [5, 3, 8, 4, 2]

Pass Compare Swap? Array State
1 5 vs 3 Yes [3, 5, 8, 4, 2]
5 vs 8 No [3, 5, 8, 4, 2]
8 vs 4 Yes [3, 5, 4, 8, 2]
8 vs 2 Yes [3, 5, 4, 2, 8]
2 3 vs 5 No [3, 5, 4, 2, 8]
5 vs 4 Yes [3, 4, 5, 2, 8]
5 vs 2 Yes [3, 4, 2, 5, 8]
3 3 vs 4 No [3, 4, 2, 5, 8]
4 vs 2 Yes [3, 2, 4, 5, 8]
4 3 vs 2 Yes [2, 3, 4, 5, 8]
Final Sorted Array: [2, 3, 4, 5, 8]

Key Points:

 Each pass compares adjacent elements and swaps them if needed.

 The largest element "bubbles" to the end with each pass.

 Repeat until no more swaps are needed, meaning the array is sorted.




Example:
#include <stdio.h>

// Function to perform Bubble Sort
void bubbleSort(int arr[], int n) {
int i, j, temp;
// Outer loop for the number of passes through the array
for (i = 0; i < n - 1; i++) {
// Inner loop to compare adjacent elements
for (j = 0; j < n - i - 1; j++) {
// If the current element is greater than the next, swap them
if (arr[j] > arr[j + 1]) {
temp = arr[j];

2

Geschreven voor

Instelling
Vak

Documentinformatie

Geüpload op
10 juni 2025
Aantal pagina's
12
Geschreven in
2024/2025
Type
SAMENVATTING

Onderwerpen

€3,09
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF

Maak kennis met de verkoper
Seller avatar
khopdibreaker

Maak kennis met de verkoper

Seller avatar
khopdibreaker Swami Vivekananda Institute of Science and technology
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
-
Lid sinds
1 jaar
Aantal volgers
0
Documenten
1
Laatst verkocht
-

0,0

0 beoordelingen

5
0
4
0
3
0
2
0
1
0

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen