Data Structure Questions and Answers-Quicksort

 

 Buy/Download all MCQ Ebook   >>>Click Here<<<

Data Structure Questions and Answers-Quicksort

Click on any option to know the CORRECT ANSWERS

Question 1
QuickSort can be categorized into which of the following?
A
Brute Force technique
B
Divide and conquer
C
Greedy algorithm
D
Dynamic programming


Question 1 Explanation: 
First you divide(partition) the array based on the pivot element and sort accordingly.

Question 2
Select the appropriate recursive call for QuickSort.(arr is the array, low is the starting index and high is the ending index of the array, partition returns the pivot element, we will see the code for partition very soon)
A
public static void quickSort(int[] arr, int low, int high)
{
	int pivot;
	if(high>low)
	{
		pivot = partition(arr, low, high);
		quickSort(arr, low, pivot-1);
		quickSort(arr, pivot+1, 
B
public static void quickSort(int[] arr, int low, int high) { int pivot; if(high
C
public static void quickSort(int[] arr, int low, int high) { int pivot; if(high>low) { pivot = partition(arr, low, high); quickSort(arr, low, pivot); quickSort(arr, pivot, high); } }class="hk1....style-wrap2">
public static void quickSort(int[] arr, int low, int high) { 	int pivot; 	if(high>low) 	{ 		pivot = partition(arr, low, high
private static int partition(int[] arr, int low, int high) { 	int left, right, pivot....item = arr[low]; 	left = low; 	right = high; 	while(left > 
B
private static int partition(int[] arr, int low, int high) { 	int left, right, pivot....item = arr[low]; 	left = low; 	right = high; 	while
C

private static int partition(int[] arr, int low, int high) { 	int left, right, pivot....item = arr[low]; 	left = low; 	right = high; 	while(left <= ri
D

private static int partition(int[] arr, int low, int high) { 	int left, right, pivot....item = arr[low]; 	left = low; 	right = high; 	while(left > rig


Question 5 Explanation: 
The array is partitioned such that the elements left to the pivot are lesser than the pivot while the elements right of the pivot are greater than the pivot.

There are 5 questions to complete.

 

 Buy/Download all MCQ Ebook >>>CLICK HERE<<<