This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Selected Item: i5 Weight: 1 Value: 3 Total Weight: 1.000000 Total Benefit: 3.000000 | |
Selected Item: i6 Weight: 3 Value: 5 Total Weight: 4.000000 Total Benefit: 8.000000 | |
Selected Item: i4 Weight: 5 Value: 8 Total Weight: 9.000000 Total Benefit: 16.000000 | |
Selected Item: i1 Weight: 6 Value: 6 Total Weight: 15.000000 Total Benefit: 22.000000 | |
Selected Item: i3 Weight: 1 Value: 0.333333 Total Weight: 16.000000 Total Benefit: 22.333334 | |
Total Weight: 16.000000 | |
Total Benefit: 22.333334 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Step 1 − Set MIN to location 0 | |
Step 2 − Search the minimum element in the list | |
Step 3 − Swap with value at location MIN | |
Step 4 − Increment MIN to point to next element | |
Step 5 − Repeat until list is sorted |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (int i=1; i<=n; i++) { | |
for (int j=i+1; j<=n; j++) { | |
if(num[i]>num[j]){ | |
//swap is inside algorithm header. | |
swap(num[i], num[j]); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C program for implementation of selection sort | |
#include <stdio.h> | |
void swap(int *xp, int *yp) | |
{ | |
int temp = *xp; | |
*xp = *yp; | |
*yp = temp; | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorted array: 11 12 22 25 64 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python program for implementation of Selection | |
# Sort | |
import sys | |
A = [64, 25, 12, 22, 11] | |
# Traverse through all array elements | |
for i in range(len(A)): | |
# Find the minimum element in remaining | |
# unsorted array |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorted array: 11 12 22 25 64 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin BubbleSort(list) | |
for all elements of list | |
if list[i] > list[i+1] | |
swap(list[i], list[i+1]) | |
end if | |
end for | |
return list | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for(i=1; i<=n; i++) | |
{ | |
for (j=1; j<n; j++) | |
if(num[j+1] > num[j]) | |
{ | |
temp=num[j]; | |
num[j] = num[j+1]; | |
num[j+1] = temp; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// C program for implementation of Bubble sort | |
#include <stdio.h> | |
void swap(int *xp, int *yp) | |
{ | |
int temp = *xp; | |
*xp = *yp; | |
*yp = temp; | |
} | |