This set of MCQ(multiple choice questions) focuses on the **Problem Solving Through Programming In C Week 9 Solutions.**

### Course layout (Answers Link)

*Answers COMING SOON! Kindly Wait!*

**Week 0 : Assignment** **Week 1 :** Introduction to Problem Solving through programs**Week 2 :** Arithmetic expressions, Relational Operations, Logical expressions; Introduction to Conditional Branching**Week 3 :** Conditional Branching and Iterative Loops* Programming Assignment*

**Week 4 :**Arranging things : Arrays

*Programming Assignment*

**Week 5 :**2-D arrays, Character Arrays and Strings

*Programming Assignment*

**Week 6 :**Basic Algorithms including Numerical Algorithms**Week 7 :**Functions and Parameter Passing by Value**Week 8 :**Passing Arrays to Functions, Call by Reference

*Programming Assignment*

**Week 9 :**Recursion**Week 10 :**Structures and Pointers**Week 11 :**Self-Referential Structures and Introduction to Lists**Week 12 :**Advanced Topics**NOTE:** You can check your answer immediately by clicking show answer button. **Problem Solving Through Programming In C Week 9 answers**” contains 10 questions.

Now, start attempting the quiz.

**Problem Solving Through Programming In C Week 9 answers**

**Problem Solving Through Programming In C Week 9 answers**

**Q1.** What is the worst case complexity of selection sort?

a) O(nlogn)

b) O(logn)

c) O(n)

d) O(n^{2})

**Answer:** d) O(n2)

**Q2.** What is the best case and worst case complexity of ordered linear search?

a) O(nlogn), O(logn)

b) O(logn), O(nlogn)

c) O(n), O(1)

d) O(1), O(n)

**Answer:** d) O(1), O(n)

**Q3.** Given an array arr = {12, 34, 47, 62, 85, 92, 95, 99, 105} and key = 34; what are the mid values (corresponding array elements) generated in the first and second iterations?

a) 85 and 12

b) 85 and 34

c) 62 and 34

d) 62 and 47

**Answer:** b) 85 and 34

**Q4.** When the Binary search is best applied to an array?

a) For very large size array

b) When the array is sorted

c) When the array elements are mixed data type

d) When the array is unsorted

**Answer:** b) When the array is sorted

**Q5.** Consider the array A[] = {5, 4, 9, 1, 3} apply the insertion sort to sort the array. Consider the cost associated with each sort is 25 rupees, what is the total cost of the insertion sort for sorting the entire array?

a) 25

b) 50

c) 75

d) 100

**Answer:** c) 75

**Q6.** Select the code snippet which performs unordered lienar search iteratively?

```
int unorderedLinearSearch(int arr[], int size, int data)
{
int index;
for(int i = 0; i < size; i++)
{
if(arr[i] == data)
{
index = i;
break;
}
}
return index;
}
```

**Answer:** a)

**Q7.** What will be the output?

```
#include <stdio.h>
#define func1(a, b) a > b ? b : a
#define func2(a, b); { temp = a; a = b; b = temp; }
int main() {
int a = 3, b = 5, temp;
if(( 3 + func1(a, b) ) > b)
func2(a, b);
printf("%d %d", a, b);
return 0;
}
```

a) 3 5

b) 3 0

c) 5 0

d) 5 3

**Answer:** d) 5 3

**Q8.** Consider an array of elements arr[5] = {5, 4, 3, 2, 1}, what are the steps of insertions done while doing insertion sort in the array.

**a)**

4 5 3 2 1

3 4 5 2 1

2 3 4 5 1

1 2 3 4 5**b)**

5 4 3 1 2

5 4 1 2 3

5 1 2 3 4

1 2 3 4 5**c)**

4 3 2 1 5

3 2 1 5 4

2 1 5 4 3

1 5 4 3 2**d) **

4 5 3 2 1

2 3 4 5 1

3 4 5 2 1

1 2 3 4 5

**Answer:** a)

**Q9.** What will be the output of the following C code?

```
#include <stdio.h>
#if A == 1
#define B 0
#else
#define B 1
#endif
int main()
{
printf("%d", B);
return 0;
}
```

a) 0

b) 1

c) 01

d) None of the above

**Answer:** b) 1

**Q10.** What will be the output?

```
#include<stdio.h>
#define a 10
int main()
{
printf( "%d ", a);
int a = 50;
printf("%d ", a);
return 0;
}
```

a) 10 10

b) 10 50

c) 50 50

d) Compilation error

**Answer:** d) Compilation error

**Problem Solving Through Programming In C Week 9 answers**

**Problem Solving Through Programming In C Week 9 answers**

**Q1.** What is the best case complexity of ordered linear search and worst case complexity of selection sort respectively?

a) O(1), O(n^{2})

b) O(logn), O(1)

c) O(n), O(logn)

d) O(n^{2}), O(nlogn)

**Answer:** a) O(1), O(n2)

**Q2.** Which of the following is/are correct?

I. Binary search is applied when elements are sorted.

II. Linear search can be applied when elements are in random order.

III. Binary search can be categorized into divide and conquer rule.

a) I & II

b) Only I

c) I and III

d) I, II & III

**Answer:** d) I, II & III

**Q3.** What is the recurrence relation for the linear search recursive algorithm?

a) T(n-2) + c

b) 2T(n-1) + c

c) T(n-1) + c

d) T(n+1) + c

**Answer:** c) T(n-1) + c

**Q4.** Given an array arr = {20, 45, 77, 89, 91, 94, 98, 100} and key=45; what are the mid values(corresponding array elements) generated in the first and second iterations?

a) 91 and 98

b) 89 and 45

c) 89 and 77

d) 91 and 94

**Answer:** b) 89 and 45

**Q5.** Consider an array of elements A[7] = {10, 4, 7, 23, 67, 12, 5}, what will be the resultant array A after third pass of insertion sort.

a) 67, 12, 10, 5, 4, 7, 23

b) 4, 7, 10, 23, 67, 12, 5

c) 4, 5, 7, 67, 10, 12, 23

d) 10, 7, 4, 67, 23, 12, 5

**Answer:** b) 4, 7, 10, 23, 67, 12, 5

**Q6.** Select the code snippet which performs unordered linear search iteratively?

**Answer:** a)

**Q7.** Which of the following input will give worst case time complexity for selection sort to sort an array in ascending order?

I. 1, 2, 3, 4, 5, 6, 7, 8

II. 8, 7, 6, 5, 4, 3, 2, 1

III. 8, 7, 5, 6, 3, 2, 1, 4

a) I

b) II

c) II and III

d) I, II and III

**Answer:** d) I, II and III

**Q8.** Consider the array A[] = {5, 4, 9, 1, 3} apply the insertion sort to sort the array. Consider the cost associated with each sort is 25 rupees, what is the total cost of the insertion sort for sorting the entire array?

a) 25

b) 50

c) 75

d) 100

**Answer:** c) 75

**Q9.** A sorting technique is called stable if:

a) It takes O(nlogn) time

b) It maintains the relative order of occurrence of non-distinct elements

c) It uses divide and conquer paradigm

d) It takes O(n) space

**Answer:** b) It maintains the relative order of occurrence of non-distinct elements

**Q10.** The average case occurs in the Linear Search Algorithm when

a) The item to be searched is in some where middle of the Array

b) The item to be searched is not in the array

c) The item to be searched is in the last of the array

d) The item to be searched is either in the last or not in the array

**Answer:** a) The item to be searched is in some where middle of the Array

**Previous Course – NPTEL Week 9 assignment answers**

**Q1.** What is the worst-case complexity of selection sort?

a) O(nlogn)

b) O(logn)

c) O(n)

d) O(n^{2})

**Answer:** d)

**Q2.** What is the correct order of insertion sort (in ascending order) of the array arr[5]={8 3 5 9 4}?

a) {3 8 5 9 4}–> {3 5 8 9 4}–>(3 4 5 8 9}

b) {3 8 5 9 4}–> {3 5 8 9 4}–> {3 5 8 4 9}–> {3 5 4 8 9}–>{3 4 5 8 9}

c) {3 8 5 9 4}–>{3 4 8 5 9}–>{3 4 5 8 9}–>{3 4 5 8 9}–>{3 4 5 8 9}

d) {8 3 5 4 9}–>{8 3 4 5 9}–>{3 4 5 8 9}

**Answer:** a) {3 8 5 9 4}–> {3 5 8 9 4}–>(3 4 5 8 9}

**Q3.** When the Binary search is best applied to an array?

a) For very large size array

b) When the array is sorted

c) When the array elements are mixed data type

d) When the array is unsorted

**Answer:** b) When the array is sorted

**Q4. **Select the code snippet which performs unordered linear search iteratively?

**Answer:** a)

**Q5.** What is the best case and worst case complexity of ordered linear search?

a) O(nlogn), O(logn)

b) O(logn), O(nlogn)

c) O(n), O(1)

d) O(1), O(n)

**Answer:** d) O(1), O(n)

**Q6.** Given an array arr = {45, 77, 89, 91, 94, 98, 100} and key = 100; what are the mid values (corresponding array elements) generated in the first and second iterations?

a) 91 and 98

b) 91 and 100

c) 89 and 94

d) 94 and 98

**Answer:** a) 91 and 98

**Q7.** Binary Search can be categorized into which of the following?

a) Brute Force technique

b) Divide and conquer

c) Greedy algorithm

d) Dynamic programming

**Answer:** b) Divide and conquer

**Q8.** Consider the array A[]= {5,4,9,1,3} apply the insertion sort to sort the array . Consider the cost associated with each sort is 25 rupees, what is the total cost of the insertion sort when element 1 reaches the first position of the array?

a) 25

b) 50

c) 75

d) 100

**Answer:** b) 50

**Q9.** Select the appropriate pseudo code that performs selection sort

**Answer:** a)

**Q10.** Find the output of the following C program

```
#include<stdio.h>
int main()
{
int a;
int arr[5] = {1, 2, 3, 4, 5};
arr[1] = ++arr[1];
a = arr[1]++;
arr[1] = arr[a++];
printf("%d, %d", a, arr[1]);
return 0;
}
```

a) 5, 4

b) 5, 5

c) 4, 4

d) 3, 4

**Answer:** c) 4, 4

**<< Prev – An Introduction to Programming Through C Week 8 Solutions**

**>> Next- An Introduction to Programming Through C Week 10 Solutions**

DISCLAIMER:Use these answers only for the reference purpose. Quizermania doesn't claim these answers to be 100% correct. So, make sure you submit your assignments on the basis of your knowledge.

*For discussion about any question, join the below comment section. And get the solution of your query.* Also, try to share your thoughts about the topics covered in this particular quiz.