functions (3.papers)

loops (1.papers)

Conditional statements (2.papers)

arrays (2.papers)

structures (3.papers)

unions (1.papers)

Enums and TypeDefs (3.papers)

pointers (7.papers)

null pointers (1.papers)

strings (2.papers)

misc c concepts (1.papers)

Data structures (5.papers)

linked lists (3.papers)

trees (1.papers)

basics (5.papers)

bitwise operators (1.papers)

Show Answer

2

What is below function fun doing? #include <stdio.h> void fun(int item, int n); int arr[10] = {0,1,2,3,7,12,23,24,90}; int main() { fun(17, 9); for(int j=0; j<10; j++){ printf("%d ", arr[j]); } return 0; } void fun(int item, int n){ int i; for(i=n-1; i>=0 && item<arr[i]; i--){ arr[i+1] = arr[i]; } arr[i+1] = item; }

it is finding if the given number is available in the array or not. if it is available, then it is adding 1 to that number and replacing the same.

it is trying to insert element 9, at the location 17 in the array.

it is trying to insert item 17, in this given sorted array of current size 9. but actual size of this array is 10. since array is in sorted order, it inserts it before 23.

it is trying to insert item 17, in this given sorted array of current size 10. since array is in sorted order, it inserts it before after 12, after traversing through 12.

Show Answer

3

What is below sorting algorithm? #include <stdio.h> int arr[10] = {12,2,3,0,1,17,23,90,24,7}; int main(void) { sort(10); for(int i=0; i<10; i++){ printf("%d ", arr[i]); } return 0; } void sort(int n){ for(int i=1; i<n; i++){ embed(i, arr[i]); } } void embed(int n, int item){ int i; for(i=n-1; i>=0 && item<arr[i]; i--){ arr[i+1] = arr[i]; } arr[i+1] = item; }

selection sort

quick sort

insertion sort

range sort

Show Answer

4

What is the worst case time complexity of insertion sort? (i.e number of comparisons?)

(n-1)n/2

n

2(n^2)

2(n log n)

Show Answer

5

what is below function fun() is doing? #include <stdio.h> int arr[10] = {0,1,2,3,7,12,17,23,24,90}; int main(void) { int i = fun(7,10); return 0; } int fun(int item, int n){ int l=0, r=n-1; while(l<=r){ int m = (l+r)/2; if(item == arr[m]){ return m; } if(item > arr[m]){ l = m+1; }else{ r = m-1; } } return -1; }

it is trying to insert a new element 7 in the given array of size 10 in the appropriate location so that resultant array will be still in sorted order.

it is trying to find given element 7 if it is available in the given array of 10 elements using linear search algorithm.

it is trying to find given element 7 if it is available in the given array of 10 elements using binary search algorithm.

it is trying to insert a new element 7 in the given array of size 10 in the last location.

Show Answer

Show Answer

Show Answer

8

What is the worst case time complexity of a linear search algorithm, if array is already sorted?

O(n log n)

O(log n)

O(n)

O(n log n^2)

Show Answer

Show Answer

Show Answer

Show Answer

12

Which of the below sorting algorithms follow divide and conquer mechanism

bubble sort

insertion sort

merge sort

selection sort

Show Answer

13

I wanted store all the words of an English dictionary along with their meanings. Then what is the suitable data structures I have to use for it, to store efficiently so that I can insert and find a word meaning easily.

Use array to store all the meanings of all the words, with the help of hash code for each word [or] key.

create a separate linked list for each word, where each linked list will have all the synonyms of a given word. and maintain all the words in an array.

Use hash table (table of buckets) technique, where each bucket will contain linked list of entries for words with key,value pairs. each word will have a pointer to particular bucket based on its hash code.

User binary tree to insert all the words, and in the leaf nodes maintain a pointer to a linked list which will contain synonyms for that word.

Show Answer

14

Which of the below sorting algorithms follow divide and conquer mechanism

Linear search

Binary search

both option 1 and 2

none

Show Answer

15

Which of the below algorithms it is not possible to follow divide and conquer mechanism

finding power of a number

Finding fibonacci series

quick sort

none

Show Answer

Show Answer

17

What is the best case time complexity of a binary search algorithm? (Best case means given item is in middle position)

O(n)

O(log n)

O(n log n)

O(1)

Show Answer

18

What is the problem with below sorting algorithm? Can you optimize this? #include <stdio.h> int arr[10] = {12,2,3,0,1,17,23,90,24,7}; int main(void) { sort(10); for(int i=0; i<10; i++){ printf("%d ", arr[i]); } return 0; } void sort(int size){ for(int i=size; i>1; i--){ int k = max(i); int temp = arr[k]; arr[k] = arr[i-1]; arr[i-1] = temp; } } int max(int size){ int pos = 0; for(int i=1; i<size; i++) { if(arr[pos] < arr[i]) pos = i; } return pos; }

There is no problem with this sorting algorithm. if you want optimization then go for merge sort.

the problem with this sorting algorithm, in the worst case if the array is already in sorted order, then unnecessarily we are looping through the array for (n-1)n/2 times. To optimize this, we can put a check in max() function, if all elements are in sorted order, then maintaining one boolean flag so that outer for loop will keep checking that flag to stop iterating.

the problem with this sorting algorithm, in the worst case if the array is already in sorted order, then unnecessarily we are looping through the array for (n-1)n/2 times. To optimize this, we better use merge sort algorithm it takes only O(n log n) iterations to sort the array elements.

the problem with this sorting algorithm, in the worst case if the array is already in sorted order, then unnecessarily we are looping through the array for (n-1)n/2 times. To optimize this, we can put a check in sort() function, if all elements are in sorted order, then maintaining one boolean flag so that outer for loop will keep checking that flag to stop iterating.

Show Answer

Show Answer

20

What is the best case time complexity of above mentioned question improvised selection sort algorithm?

n-1 comparisons + 3(n-1) swaps

n-1(n/2) comparisons + 3(n-1) swaps

log n comparisons + 3(n-1) swaps

n log n comparisons + 3(n-1) swaps

Show Answer