0% found this document useful (0 votes)
23 views

DSA Assignment Kabi

This document contains a data structures and algorithms assignment with 10 multiple choice questions. The questions cover topics like time complexity of algorithms, sorting algorithms like selection sort, bubble sort, and linear search. The summary provides an overview of the key topics covered in the assignment questions.

Uploaded by

gowshik ram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

DSA Assignment Kabi

This document contains a data structures and algorithms assignment with 10 multiple choice questions. The questions cover topics like time complexity of algorithms, sorting algorithms like selection sort, bubble sort, and linear search. The summary provides an overview of the key topics covered in the assignment questions.

Uploaded by

gowshik ram
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

DATA STRUCTURES AND ALGORITHMS

ASSIGNMENT – 1

18CSC201J

DATE : 07-02-2023

KABILAN

RA2111043010052

ECE – CE

J SECTION
1) Consider a sorted array of size n. What would be the time

complexity for the best-known algorithm to find 'a' & 'b' such that |a-b|

= k, k is a positive integer?

A. O(n)

B. O(n log)

C. O(n2

D. O(logn)

Solution: (A)

Maintain two pointers at the start and then increment one depending upon

whether the difference is greater than or less than. A single pass is

required, so the answer is O(n).

2) If the number of records to be sorted is small, then …… sorting can be efficient.

A. Merge

B. Heap

C. Selection

D. Bubble

Answer :

Selection

Explanation :

The selection sort method sorts an array by repeatedly finding the smallest element (in ascending order)
from the unsorted segment and inserting it at the start.

3) The complexity of the sorting algorithm measures the …… as a function of the number n of items to
be sorter.

A. average time

B. running time
C. average-case complexity

D. case-complexity

Answer :

running time

Explanation :

The complexity of sorting algorithm measures the running time as a function of the number n of items to
be sorter.

4) he average case occurs in the linear search algorithm when:

A. The item to search is in somewhere the middle of the array.

B. The item to search is not in the array.

C. The item to search is in the last of the array.

D. The item to search is either in the last or not in the array.

Solution: (A)

 The average case occurs in the linear search algorithm when the item to

be searched is somewhere in the middle of the array.

 The best-case occurs in the linear search algorithm when the item is to

be searched at starting of the array.

 The worst case occurs in the linear search algorithm when the item is to

be searched at the ar

5) The Average case occurs in the linear search algorithm ……….

A. when the item is somewhere in the middle of the array

B. when the item is not the array at all

C. when the item is the last element in the array


D. Item is the last element in the array or item is not there at all

Answer :

when the item is somewhere in the middle of the array.

Explanation :

The average case occurs in the Linear Search Algorithm when the item to be searched is in some where
middle of the Array. The best case occurs in the Linear Search Algorithm when the item to be searched is
in starting of the Array.

6) Binary search algorithm cannot be applied to …

A. sorted linked list

B. sorted binary trees

C. sorted linear array

D. pointer array

Answer :

sorted linked list

Explanation :

A linked list only allows sequential access, so binary search is impossible even if the list is sorted.

7) Complexity of linear search algorithm is ………

A. O(n)

B. O(logn)

C. O(n2)
D. O(n logn)

Answer :

O(n)

Explanation :

The linear search algorithm takes up no extra space; its space complexity is O(n) for an array of n
elements.

8) Sorting algorithm can be characterized as ……

A. Simple algorithm which require the order of n2 comparisons to sort n items.

B. Sophisticated algorithms that require the O(nlog2n) comparisons to sort items.

C. Both of the above

D. None of the above

Answer :

Both of the above

Explanation :

It is characterized as

1) Simple algorithm which require the order of n2 comparisons to sort n items.

2) Sophisticated algorithms that require the O(nlog2n) comparisons to sort items.

9) The complexity of bubble sort algorithm is …..

A. O(n)

B. O(logn)

C. O(n2)
D. O(n logn)

Answer :

O(n2)

Explanation :

This algorithm has a worst-case time complexity of O(n2). The bubble sort has a space complexity of
O(1). The number of swaps in bubble sort equals the number of inversion pairs in the given array. When
the array elements are few and the array is nearly sorted, bubble sort is effective and efficient.

10) State True or False for internal sorting algorithms.

i) Internal sorting are applied when the entire collection if data to be sorted is small enough that the
sorting can take place within main memory.

ii) The time required to read or write is considered to be significant in evaluating the performance of
internal sorting.

A. i-True, ii-True

B. i-True, ii-False

C. i-False, ii-True

D. i-False, ii-False

Answer :

i-True, ii-False

Explanation :

Internal sorting . when the elements to be sorted are all in the main memory while in external sort all
are not present in memory during sorting . as in internal sort all elements are in main memory the time
to read write is not that much significant as compared to external sorting .

You might also like