DSA Assignment Kabi
DSA Assignment Kabi
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
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.
Solution: (A)
The average case occurs in the linear search algorithm when the item to
The best-case occurs in the linear search algorithm when the item is to
The worst case occurs in the linear search algorithm when the item is to
be searched at the ar
Answer :
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.
D. pointer array
Answer :
Explanation :
A linked list only allows sequential access, so binary search is impossible even if the list is sorted.
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.
Answer :
Explanation :
It is characterized as
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.
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 .