This file contains 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 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 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 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 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 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 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 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 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; | |
} | |
This file contains 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 Bubble Sort | |
def bubbleSort(arr): | |
n = len(arr) | |
# Traverse through all array elements | |
for i in range(n): | |
# Last i elements are already in place | |
for j in range(0, n-i-1): |