Question 1
Question 2
Which of the following changes to typical QuickSort improves its performance on average and are generally done in practice.
1) Randomly picking up to make worst case less likely to occur. 2) Calling insertion sort for small sized arrays to reduce recursive calls. 3) QuickSort is tail recursive, so tail call optimizations can be done. 4) A linear time median searching algorithm is used to pick the median, so that the worst case time reduces to O(nLogn)
1 and 2
2, 3, and 4
1, 2 and 3
2, 3 and 4
Question 3
#include <stdio.h>
char str1[100];
char *fun(char str[])
{
static int i = 0;
if (*str)
{
fun(str+1);
str1[i] = *str;
i++;
}
return str1;
}
int main()
{
char str[] = "GATE CS 2015 Mock Test";
printf("%s", fun(str));
return 0;
}
Question 4
Question 5
void fun(int arr[], int n)
{
for (int i = 0; i < n; i+=2)
{
if (i>0 && arr[i-1] > arr[i] )
swap(&arr[i], &arr[i-1]);
if (i<n-1 && arr[i] < arr[i+1] )
swap(&arr[i], &arr[i + 1]);
}
}
Question 6
Question 7
Consider the following two problems of graph. 1) Given a graph, find if the graph has a cycle that visits every vertex exactly once except the first visited vertex which must be visited again to complete the cycle. 2) Given a graph, find if the graph has a cycle that visits every edge exactly once. Which of the following is true about above two problems.
Question 8
T(x, c) = Θ(x) for c <= 2, T(c, y) = Θ(y) for c <= 2, and T(x, y) = Θ(x+y) + T(x/2, y/2)
Θ(n2)
Θ(n2Logn)
Question 9
Consider the following three table to store student enrollements in different courses.
Student(EnrollNo, Name) Course(CourseID, Name) EnrollMents(EnrollNo, CourseID)
What does the following query do?
SELECT S.Name
FROM Student S, Course C, Enrollments E
WHERE S.EnrollNo = E.EnrollNo AND
C.Name = "DBMS" AND
E.CourseID = C.CourseID AND
S.EnrollNo IN
(SELECT S2.EnrollNo
FROM Student S2, Course C2, Enrollments E2
WHERE S2.EnrollNo = E2.EnrollNo AND
E2.CourseID = C2.CourseID
C2.Name = "OS")
Name of all students who are either enrolled in "DBMS" or "OS" courses
Name of all students who are enrolled in "DBMS" and "OS"
Name of all students who are either enrolled in "DBMS" or "OS" or both.
None of the above
Question 10
Consider the following Employee table
ID salary DeptName 1 10000 EC 2 40000 EC 3 30000 CS 4 40000 ME 5 50000 ME 6 60000 ME 7 70000 CS
How many rows are there in the result of following query?
SELECT E.ID
FROM Employee E
WHERE EXISTS (SELECT E2.salary
FROM Employee E2
WHERE E2.DeptName = 'CS'
AND E.salary > E2.salary)
6
5
4
0
There are 18 questions to complete.