JAVA
Basic Sorting
Assignment Questions
Assignment Questions
Q1. Which of the following(s) is/are true about bubble sort:
It is stable sor
It has a worst case space complexity of O(n
It involves swapping of adjacent element
After each iteration, the greatest element is placed at the end of the array.
Q2. What will the following array look like after one iteration of bubble sort [1,6,2,5,4,3].
[1,3,2,4,5,6
[1,2,3,4,5,6
[1,2,5,4,3,6
[1,2,4,5,3,6]
Q3. In which case does bubble sort works in the most efficient way:
When the array is sorted in increasing orde
When the array is sorted partiall
When the array is sorted in decreasing order
When the array is nearly sorted.
Q4. Sort the array in descending order using Bubble Sort.
Q5. Check if the given array is almost sorted. (elements are at-most one position away)
Q6. Which of the following is true about selection sort:
In each iteration we find the minimum element in the unsorted part of the array
In each iteration we find the index of the minimum element in the unsorted part of the array
We swap the index of the minimum element with the first element of the array
It takes O(n^2) swaps.
Q7. Which of the following examples represent the worst case input for an insertion sort?
array in sorted orde
large arra
normal unsorted arra
array sorted in reverse order
Java + DSA
Assignment Questions
Q8. How many passes would be required during insertion sort to sort an array of 5 elements?
Depends on order of element
Q9. 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.
Q10. Given an array of strings arr[] with all strings in lowercase. Sort given strings using Bubble Sort and
display the sorted array.
Q11. What is an in-place sorting algorithm?
It needs O(1) or O(logn) memory to create auxiliary location
The input is already sorted and in-plac
It requires additional storag
It requires additional space
Q12. In the following scenarios, when will you use selection sort?
The input is already sorte
A large file has to be sorte
Large values need to be sorted with small key
Small values need to be sorted with large keys
Q13. Given an integer array and an integer k where k<=size of array, We need to return the kth smallest
element of the array.
Q14. Find the minimum operations required to sort the array in increasing order. In one operation ,you can
set each occurrence of one element to 0.
Q15. Given an array, arr[] containing n integers, the task is to find an integer (say K) such that after
replacing each and every index of the array by |ai – K| where ( i ∈ [1, n]), results in a sorted array. If no such
integer exists that satisfies the above condition then return -1.
Java + DSA
THANK
YOU !