Sorting Solution To Assignment 02 Written DECODE DSA With C 2.0652649a67774af00183e8ef1
Sorting Solution To Assignment 02 Written DECODE DSA With C 2.0652649a67774af00183e8ef1
Solution :
b)In each iteration we find the index of the minimum element in the unsorted
part of the array.
Which of the following examples represent the worst case input for an insertion sort?
a) array in sorted order
b) large array
c) normal unsorted array
d) array sorted in reverse order
Solution :
d) array sorted in reverse order.
How many passes would be required during insertion sort to sort an array of 5 elements?
a) 1
b) Depends on order of elements
c) 4
d) 5
Solution :
c) 4
Given an array of digits (values are from 0 to 9), the task is to find the minimum possible sum of
two numbers formed from digits of the array. Please note that all digits of the given array must be
used to form the two numbers.
Solution :
1
#include <iostream>
using namespace std;
int main() {
int arr[5]={7,2,32,5,20};
int N=5;
insertionSort(arr,N);
int a = 0, b = 0;
Given an array of strings arr[] with all strings in lowercase. Sort given strings using Bubble Sort
and display the sorted array.
Solution :
2
#include<iostream>
#include<cstring>
using namespace std;
int main() {
char arr[][20] = {"physicswallah", "quiz", "practice", "pwskills","coding" };
int n = sizeof(arr) / sizeof(arr[0]);
char temp[20];
for (int i = 0; i < n ; i++) {
for (int j = 0; j < n - 1 - i; j++) {
if (strcmp(arr[j], arr[j + 1]) > 0) {
strcpy(temp, arr[j]);
strcpy(arr[j], arr[j + 1]);
strcpy(arr[j + 1], temp);
}
}
}
for (int i = 0; i < n; i++) {
cout<<arr[i]<<endl;
}
return 0;
}