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

Data Structure and Algorithms

Rating
-
Sold
-
Pages
6
Uploaded on
10-05-2023
Written in
2022/2023

Data Structure and Algorithms in c++

Institution
Course

Content preview

Sorting Algorithms are ways to implement an array or list as an input and arrange the items into
a particular order.

Some of the most common sorting algorithms are:

• Bubble sort
• Selection sort
• Insertion sort
• Merge sort
• Quick sort
• Heap sort
• Radix sort

Bubble sort is a comparison sort technique, where pairs of elements are compared at a time,
across multiple iterations; and in the process, smaller (or larger) elements “bubble up” to the top
of the list until the whole list is sorted.




//Recursive solution for Bubble Sort
#include<bits/stdc++.h>
using namespace std;
void Bubblesort(int input[],int endIndex){
if(endIndex == 0)
return;

for(int i=0;i<endIndex;i++){
if(input[i]>input[i+1]){ //if(input[i]<input[i+1]) for decending order

int temp = input[i];
input[i]=input[i+1];
input[i+1]=temp;

}
}

Bubblesort(input,endIndex-1);
}

, int main()
{
int arr[]={-2,45,0,11,-9};
Bubblesort(arr,4);
for(int i=0;i<5;i++){
cout<<arr[i]<<endl;
}
}
//OUTPUT
[Success] Your code was executed successfully
-9
-2
0
11
45

Selection sort is an in-place sort technique, which divides the input into a sorted region and an
unsorted region. In each iteration, the algorithm picks an appropriate element from the unsorted
region and appends it to the sorted region




img src: https://miro.medium.com/max/463/0*J2ta_c6YA870MKor
//Recursive solution for selection sort

#include<bits/stdc++.h>
using namespace std;
void Selectionsort(int input[],int beginIndex, int size){
if(beginIndex >= size-1)
return;

int minIndex = beginIndex;
for(int i=beginIndex; i<size; i++){
if(input[i]<input[minIndex]){
minIndex = i;
}
}
int temp = input[minIndex];
input[minIndex]=input[beginIndex];
input[beginIndex]=temp;

Written for

Course

Document information

Uploaded on
May 10, 2023
Number of pages
6
Written in
2022/2023
Type
Class notes
Professor(s)
Data structure and algorithms
Contains
All classes

Subjects

$8.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
gunjansahu

Get to know the seller

Seller avatar
gunjansahu Teachme2-tutor
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 year
Number of followers
0
Documents
3
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

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