Roll: ____ Time: 1 hour Marks: 15
1. You are given a list of numbers as input where all the items except three are placed in sorted order. 3
Write down an efficient algorithm (pseudocode) for sorting the entire list. Mention the runtime and space
complexity of your algorithm.
2. You are given two head nodes of two sorted singly linked list as input. Write down an efficient algorithm 3
(pseudocode) for combining both the lists into one. The resultant linked list must have to be sorted.
Example: Linked list 1: {1,3,4} ; Linked list 2: {2, 5} => result: {1, 2, 3, 4, 5}
3. Write down an algorithm (pseudocode) for printing all the words: (i) consisting of letters {A, B, C}, (ii) of 3
length K where K>5, (iii) having more than four “A”.
4. You are given a sorted array of numbers and a number k as input. Write down an efficient algorithm 3
(pseudocode) for finding the largest number in the array that is smaller than k. Mention the runtime and
space complexity of your algorithm.
5. Write down the output of the following codes. 3
(a) (b)
#include <iostream> #include <iostream>
using namespace std; using namespace std;
void pr(int n){ void fun(int n) {
if(n<1) return; if (n > 0) {
pr(n/2); fun(n - 1);
cout<<n; cout << n;
} fun(n - 1);
int main() { }
pr(17); }
return 0; int main()
} {
fun(4);
return 0;
}