Software Development Exam  >  Software Development Tests  >  Test: Searching and Sorting - 2 - Software Development MCQ

Test: Searching and Sorting - 2 - Software Development MCQ


Test Description

15 Questions MCQ Test - Test: Searching and Sorting - 2

Test: Searching and Sorting - 2 for Software Development 2024 is part of Software Development preparation. The Test: Searching and Sorting - 2 questions and answers have been prepared according to the Software Development exam syllabus.The Test: Searching and Sorting - 2 MCQs are made for Software Development 2024 Exam. Find important definitions, questions, notes, meanings, examples, exercises, MCQs and online tests for Test: Searching and Sorting - 2 below.
Solutions of Test: Searching and Sorting - 2 questions in English are available as part of our course for Software Development & Test: Searching and Sorting - 2 solutions in Hindi for Software Development course. Download more important topics, notes, lectures and mock test series for Software Development Exam by signing up for free. Attempt Test: Searching and Sorting - 2 | 15 questions in 30 minutes | Mock test for Software Development preparation | Free important questions MCQ to study for Software Development Exam | Download free PDF with solutions
Test: Searching and Sorting - 2 - Question 1

Which of the following search algorithms require the input to be sorted in ascending order?

Detailed Solution for Test: Searching and Sorting - 2 - Question 1

Binary search is an efficient search algorithm that requires the input to be sorted in ascending order. It follows a divide-and-conquer approach to find the target element by repeatedly dividing the search space in half.

Test: Searching and Sorting - 2 - Question 2

Which sorting algorithm has the worst-case time complexity of O(n^2)?

Detailed Solution for Test: Searching and Sorting - 2 - Question 2

Insertion sort has a worst-case time complexity of O(n^2) when the input array is in reverse order. It repeatedly selects an element from the unsorted part and inserts it into the sorted part of the array.

1 Crore+ students have signed up on EduRev. Have you? Download the App
Test: Searching and Sorting - 2 - Question 3

Which of the following is a stable sorting algorithm?

Detailed Solution for Test: Searching and Sorting - 2 - Question 3

Bubble sort is a stable sorting algorithm as it compares adjacent elements and swaps them if they are in the wrong order. It maintains the relative order of elements with equal values.

Test: Searching and Sorting - 2 - Question 4

Which search algorithm has a time complexity of O(log n)?

Detailed Solution for Test: Searching and Sorting - 2 - Question 4

Binary search has a time complexity of O(log n), where n is the size of the sorted input array. It repeatedly divides the search space in half, reducing the search space in each iteration.

Test: Searching and Sorting - 2 - Question 5

Which sorting algorithm is known for its in-place sorting property?

Detailed Solution for Test: Searching and Sorting - 2 - Question 5

Quick sort is an in-place sorting algorithm as it sorts the array by partitioning it into smaller subarrays and sorting them in-place. It avoids the need for additional memory.

Test: Searching and Sorting - 2 - Question 6

What will be the output of the following code snippet?
#include <iostream>
using namespace std;

void selectionSort(int arr[], int size) {
   for (int i = 0; i < size - 1; i++) {
      int minIndex = i;
      for (int j = i + 1; j < size; j++) {
         if (arr[j] < arr[minIndex]) {
            minIndex = j;
         }
      }
      swap(arr[i], arr[minIndex]);
   }
}

int main() {
   int arr[] = {5, 2, 9, 1, 7};
   int size = sizeof(arr) / sizeof(arr[0]);

   selectionSort(arr, size);

   for (int i = 0; i < size; i++) {
      cout << arr[i] << " ";
   }
   return 0;
}

Detailed Solution for Test: Searching and Sorting - 2 - Question 6

The code implements the selection sort algorithm to sort the given array. The sorted array will be {1, 2, 5, 7, 9}.

Test: Searching and Sorting - 2 - Question 7

What will be the output of the following code snippet?
#include <iostream>
using namespace std;

void bubbleSort(int arr[], int size) {
   for (int i = 0; i < size - 1; i++) {
      for (int j = 0; j < size - i - 1; j++) {
         if (arr[j] > arr[j + 1]) {
            swap(arr[j], arr[j + 1]);
         }
      }
   }
}

int main() {
   int arr[] = {3, 8, 1, 6, 4};
   int size = sizeof(arr) / sizeof(arr[0]);

   bubbleSort(arr, size);

   for (int i = 0; i < size; i++) {
      cout << arr[i] << " ";
   }
   return 0;
}

Detailed Solution for Test: Searching and Sorting - 2 - Question 7

The code implements the bubble sort algorithm to sort the given array. The sorted array will be {1, 3, 4, 6, 8}.

Test: Searching and Sorting - 2 - Question 8

What will be the output of the following code snippet?
#include <iostream>
using namespace std;

int binarySearch(int arr[], int low, int high, int target) {
   while (low <= high) {
      int mid = low + (high - low) / 2;

      if (arr[mid] == target) {
         return mid;
      }

      if (arr[mid] < target) {
         low = mid + 1;
      } else {
         high = mid - 1;
      }
   }
   return -1;
}

int main() {
   int arr[] = {2, 5, 8, 12, 16};
   int size = sizeof(arr) / sizeof(arr[0]);
   int target = 8;

   int index = binarySearch(arr, 0, size - 1, target);

   cout << "Element found at index: " << index;

   return 0;
}

Detailed Solution for Test: Searching and Sorting - 2 - Question 8

The code implements the binary search algorithm to find the target element in the given sorted array. The target element 8 is found at index 3.

Test: Searching and Sorting - 2 - Question 9

What will be the output of the following code snippet?
#include <iostream>
using namespace std;

void insertionSort(int arr[], int size) {
   for (int i = 1; i < size; i++) {
      int key = arr[i];
      int j = i - 1;

      while (j >= 0 && arr[j] > key) {
         arr[j + 1] = arr[j];
         j = j - 1;
      }
      arr[j + 1] = key;
   }
}

int main() {
   int arr[] = {7, 3, 9, 2, 5};
   int size = sizeof(arr) / sizeof(arr[0]);

   insertionSort(arr, size);

   for (int i = 0; i < size; i++) {
      cout << arr[i] << " ";
   }
   return 0;
}

Detailed Solution for Test: Searching and Sorting - 2 - Question 9

The code implements the insertion sort algorithm to sort the given array. The sorted array will be {2, 3, 5, 7, 9}.

Test: Searching and Sorting - 2 - Question 10

What will be the output of the following code snippet?
#include <iostream>
using namespace std;

int linearSearch(int arr[], int size, int target) {
   for (int i = 0; i < size; i++) {
      if (arr[i] == target) {
         return i;
      }
   }
   return -1;
}

int main() {
   int arr[] = {4, 9, 2, 7, 5};
   int size = sizeof(arr) / sizeof(arr[0]);
   int target = 7;

   int index = linearSearch(arr, size, target);

   cout << "Element found at index: " << index;

   return 0;
}

Detailed Solution for Test: Searching and Sorting - 2 - Question 10

The code implements the linear search algorithm to find the target element in the given array. The target element 7 is found at index 3.

Test: Searching and Sorting - 2 - Question 11

Which of the following sorting algorithms has the best average-case time complexity?

Detailed Solution for Test: Searching and Sorting - 2 - Question 11

Quick sort has an average-case time complexity of O(n log n), which is better than the average-case time complexity of selection sort, bubble sort, and insertion sort (O(n^2)).

Test: Searching and Sorting - 2 - Question 12

Which of the following search algorithms can be applied on a singly linked list?

Detailed Solution for Test: Searching and Sorting - 2 - Question 12

Linear search can be applied to search for an element in a singly linked list by traversing the list from the head node to the tail node.

Test: Searching and Sorting - 2 - Question 13

Which sorting algorithm is the most suitable for sorting a large collection of elements with a small range of values?

Detailed Solution for Test: Searching and Sorting - 2 - Question 13

Counting sort is most suitable for sorting a large collection of elements with a small range of values because it operates by counting the occurrences of each element and then using that information to determine the sorted order.

Test: Searching and Sorting - 2 - Question 14

Which sorting algorithm is an example of an in-place and stable sorting algorithm?

Detailed Solution for Test: Searching and Sorting - 2 - Question 14

Merge sort is an in-place and stable sorting algorithm. It operates by dividing the input array into smaller subarrays, sorting them, and then merging the sorted subarrays to obtain the final sorted array.

Test: Searching and Sorting - 2 - Question 15

Which of the following is true about binary search?

Detailed Solution for Test: Searching and Sorting - 2 - Question 15

Binary search can be applied to search for an element in a sorted linked list by using the divide-and-conquer approach. However, it requires random access to elements, which is not efficiently supported by a singly linked list.

Information about Test: Searching and Sorting - 2 Page
In this test you can find the Exam questions for Test: Searching and Sorting - 2 solved & explained in the simplest way possible. Besides giving Questions and answers for Test: Searching and Sorting - 2, EduRev gives you an ample number of Online tests for practice

Top Courses for Software Development

Download as PDF

Top Courses for Software Development