PHD PDF
PHD PDF
PHD PDF
(Kalasalingam University)
Anand Nagar, Krishnankoil: 626 126
3. The system should provide which thing, to avoid error in transcription and transposition,
during data entry?
(a)A check digit
(b)A hand totals
(c) Batch totals
(d)All of these
4. HIPO is
(a)A forms driven technique in which standard forms are used to documents the information
(b)Consists of a hierarchy chart and an associate set of input/process/output charts
(c) Captures essence of top down decomposition
(d)All of these
5. DFD shows
(a) The flow of data
(b)The processes
(c) The areas where they are stored
(d)All of the above
6. The time lag, between initiating a query and receiving a response is called
(a)Response time
(b)Waiting time
(c) Processing time
(d)Turn around time
8. The mistakes, committed by intercharging two digits in a numeic ield, during data enty, is called
(a)Transposition error
(b)Transcription error
(c) Beta testing error
(d)Alpha testing error
10. The best file organization in which one has to process all data records in a file called
(a)Indexed
(b)Sequential
(c) Direct access
(d) Random access
14. The largest percentage of total life cycle cost of software is:
(a) Design cost
(b)Maintenance cost
(c) Coding cost
(d)Testing cost
16. Which of the following is not a major design consideration of the system.
(a) Response time required
(b)Frequency of record updates
(c) Availability of technically qualified personal to carry out design and development
(d)Data integrity constant.
19. The role of an integrated CASE tool in system analysis and design project is
(a) Proving a CASE study for software development
(b)To provide an environment that automate key tasks throughout sotware development process
(c) To provide tool for reacting a word file
(d)None of the above
22. The most creative and challenging phase of system life cycle is
(a)Feasibility study
(b)Maintenance
(c) Design
(d)None of the above
29. Which of the following is not a component of object oriented software engg.
(a)Process
(b)Method
(c) Architecture
(d)None of the above
1 Answer
(c) Keys
2 (d) 3 (d) 4 (b) 5 (d) 6 (a)
7 (c) 8 (a) 9 (c) 10 (b) 11 (d) 12 (b)
13 (d) 14 (b) 15 (a) 16 (c) 17 (a) 18 (b)
19 (b) 20 (b) 21 (b) 22 (c) 23 (c) 24 (c)
25 (b) 26 (c) 27 (c) 28 (a) 29 (c) 30 (b)
5. Life cycles and development / Software development / Compiler design (Minimum 30
Questions)
Questions
1. In an absolute loading scheme, which loader function is accomplished by programmer?
A.Allocation
B.Linking
C.Reallocation
D.both (A) and (B)
5. Terminal table
A.contains all constants in the program.
B.is a permanent table of decision rules in the form of patterns for matching with the uniform symbol
table to discover syntactic structure.
C.consist of a full or partial list of the token is as they appear in the program created by lexical analysis
and used for syntax analysis and interpretation.
D.is a permanent table which lists all keywords and special symbols of the language in symbolic form
6. Language which have many types, but the type of every name and expression must be calculated at
compile time are
A.strongly-type languages
B.weakly typed languages
C.loosely typed languages
D.none of these
7. An interpreter is a program that
A.places programs into memory and prepares them for execution
B.automates the translation of assembly language into machine language.
C.accesses a program written in a high level language and produces an object program.
D.appears to execute a source program as if it were machine language.
12. A system program that setup an executable program in main memory ready for execution is
A.assembler
B.linker
C.loader
D.load and go
13. Which of the following system program forgoes the production of object code to
generate absolute machine code and load it into the physical main storage location
from which it will be executed immediately upon completion of the assembly ?
A.Two pass assembler
B.Load-and-go-assembler
C.Macroprocessor
D.Linker
17. A simple two-pass assembler does which of the following in the first pass ?
A.It allocates space for the literals
B.It computes the total length of the program
C.It builds the symbol table for the symbols and their values.
D.All of these
18. A system program that set-up an executable program in main memory ready for execution is
A.assembler
B.linker
C.loader
D.text editor
20. A programmer, by mistake, writes an instruction to divide, instead of a multiply, such error can be
detected by a/an
A.Compiler
B.Interpreter
C.compiler or interpreter test
D.None of these
22. A system program that combines separately compiled modules of a program into a form suitable for
execution is
A.Assembler
B.linking loader
C.cross compiler
D.None of these
23. In which way a macro processor for assembly language can be implemented?
A.Independent two-pass processor
B.Independent one-pass processor
C.Processor incorporated into pass 1 of a standard two pass assembler
D.All of these
25. A shift reduce parser carries out the actions specified within braces immediately after reducing with
the corresponding rule of grammer
S----> xxW ( PRINT "1")
S----> y { print " 2 " }
S----> Sz { print " 3 " )
What is the translation of xxxxyzz using the syntax directed translation scheme described by the above rules
?
A.23131
B.11233
C.11231
D.33211
26. The symbol table implementation is based on the property of locality of reference is
A.linear list
B.search tree
C.hash table
D.self-organization list
1 Answer
(d) Keys
2 (a) 3 (d) 4 (d) 5 (d) 6 (a)
7 (d) 8 (c) 9 (a) 10 (d) 11 (a) 12 (c)
13 (b) 14 (c) 15 (b) 16 (a) 17 (d) 18 (c)
19 (c) 20 (d) 21 (a) 22 (b) 23 (d) 24 (a)
25 (a) 26 (c) 27 (a) 28 (c) 29 (c) 30 (c)
(a)virtual memory implements the translation of a program's address space into physical memory
address space
(b) virtual memory allows each program to exceed the size of the primary memory
(c) Virtual memory increases the degree of multi programming
(a) If a process makes a transition D, it would result in another process making transition A
immediately.
(b) A process P2 in blocked state can make transition E
while another process P1 is in running state.
(c) The OS uses preemptive scheduling.
(d) The OS uses non-preemptive scheduling.
6. The atomic fetch-and-set x, y instruction unconditionally sets the memory location x to 1 and
fetches the old value of x in y without allowing any intervening access to the memory location
x. consider the following implementation of P and V functions on a binary semaphore .
void P (binary_semaphore *s) {
unsigned y;
unsigned *x = &(s->value);
do {
fetch-and-set x, y;
} while (y);
}
7. Three concurrent processes X, Y, and Z execute three different code segments that access and
update certain shared variables. Process X executes the P operation (i.e., wait) on semaphores
a, b and c; process Y executes the P operation on semaphores b, c and d; process Z executes
the P operation on semaphores c, d, and a before entering the respective code segments.
After completing the execution of its code segment, each process invokes the V operation
(i.e., signal) on its three semaphores. All semaphores are binary semaphores initialized to one.
Which one of the following represents a deadlockfree order of invoking the P operations by
the processes?
(a) X: P(a)P(b)P(c) Y:P(b)P(c)P(d) Z:P(c)P(d)P(a)
(b) X: P(b)P(a)P(c) Y:P(b)P(c)P(d) Z:P(a)P(c)P(d)
8. Consider an OS capable of loading and executing a single sequential user process at a time.
The disk head scheduling algorithm used is FCFS. If FCFS is replaced by shortest seek time first
(SSTF), claimed by the vendor to give 50% better benchmark results, what is the expected
improvement in the IN/OUT performance of user programs?
(a) P-3, Q-2, R-1 (b)P-1, Q-3, R-2(c)P-2, Q-3, R-1(d) P-1, Q-3, R-2
19. A CPU generates 32-bit virtual addresses. The page size is 4 KB. The processor has a translation
look-aside buffer (TLB) which can hold a total of 128 page table entries and is 4-way set
associative. The minimum size of the TLB tag is:
(a)11 bits (b)13 bits (c)15 bits (d)20 bits
20. Thrashing occurs when
(a) When a page fault occurs
(b)Processes on system frequently access pages not memory
(c) Processes on system are in running state
(d)Processes on system are in waiting state
21. A computer uses 46–bit virtual address, 32–bit physical address, and a three–level paged page
table organization. The page table base register stores the base address of the first–level table
(T1), which occupies exactly one page. Each entry of T1 stores the base address of a page of
the second–level table (T2). Each entry of T2 stores the base address of a page of the
third–level table (T3). Each entry of T3 stores a page table entry (PTE). The PTE is 32 bits in
size. The processor used in the computer has a 1 MB 16 way set associative virtually indexed
physically tagged cache. The cache block size is 64 bytes. What is the size of a page in KB in
this computer?
(a) 2 (b)4 (c)8 (d)16
22. A computer uses 46–bit virtual address, 32–bit physical address, and a three–level paged page
table organization. The page table base register stores the base address of the first–level table
(T1), which occupies exactly one page. Each entry of T1 stores the base address of a page of
the second–level table (T2). Each entry of T2 stores the base address of a page of the
third–level table (T3). Each entry of T3 stores a page table entry (PTE). The PTE is 32 bits in
size. The processor used in the computer has a 1 MB 16 way set associative virtually indexed
physically tagged cache. The cache block size is 64 bytes. What is the minimum number of
page colours needed to guarantee that no two synonyms map to different sets in the
processor cache of this computer?
(a) 2 (b)4 (c)8 (d)16
23. Let the page fault service time be 10ms in a computer with average memory access time being
20ns. If one page fault is generated for every 10^6 memory accesses, what is the effective
access time for the memory?
(a) 21ns (b)30ns(c)23ns (d)35ns
24. A processor uses 36 bit physical addresses and 32 bit virtual addresses, with a page frame size
of 4 Kbytes. Each page table entry is of size 4 bytes. A three level page table is used for virtual
to physical address translation, where the virtual address is used as follows • Bits 30-31 are
used to index into the first level page table • Bits 21-29 are used to index into the second level
page table • Bits 12-20 are used to index into the third level page table, and • Bits 0-11 are
used as offset within the page The number of bits required for addressing the next level page
table (or page frame) in the page table entry of the first, second and third level page tables are
respectively.
(a)20,20,20 (b)24,24,24 (c)24,24,20 (d)25,25,24
25. A virtual memory system uses First In First Out (FIFO) page replacement policy and allocates a
fixed number of frames to a process. Consider the following statements:
P: Increasing the number of page frames allocated to a process sometimes increases the page
fault rate.
Q: Some programs do not exhibit locality of reference.
Which one of the following is TRUE?
(a) Both P and Q are true, and Q is the reason for P (b)Both P and Q are true, but Q is not the
reason for P(c) P is false, but Q is true(d)Both P and Q are false
26. Suppose n processes, P1, …. Pn share m identical resource units, which can be reserved and
released one at a time. The maximum resource requirement of process Pi is Si, where Si > 0.
Which one of the following is a sufficient condition for ensuring that deadlock does not occur?
(a) a (b)b (c)c (d)d
27. A system has n resources R0,...,Rn-1,and k processes P0,....Pk-1.The implementation of the
resource request logic of each process Pi is as follows:
if (i % 2 == 0) {
if (i < n) request Ri
if (i+2 < n) request Ri+2
}
else {
if (i < n) request Rn-i
if (i+2 < n) request Rn-i-2
}
In which one of the following situations is a deadlock possible?
(a) n=40, k=26 (b)n=21,k=12 (c)n=20, k=10 (d)n=41,k=19
28. Consider a system with 4 types of resources R1 (3 units), R2 (2 units), R3 (3 units), R4 (2 units).
A non-preemptive resource allocation policy is used. At any given instance, a request is not
entertained if it cannot be completely satisfied. Three processes P1, P2, P3 request the
sources as follows if executed independently.
Process P1:
t=0: requests 2 units of R2
t=1: requests 1 unit of R3
t=3: requests 2 units of R1
t=5: releases 1 unit of R2
and 1 unit of R1.
t=7: releases 1 unit of R3
t=8: requests 2 units of R4
t=10: Finishes
Process P2:
t=0: requests 2 units of R3
t=2: requests 1 unit of R4
t=4: requests 1 unit of R1
t=6: releases 1 unit of R3
t=8: Finishes
Process P3:
t=0: requests 1 unit of R4
t=2: requests 2 units of R1
t=5: releases 2 units of R1
t=7: requests 1 unit of R2
t=8: requests 1 unit of R3
t=9: Finishes
Which one of the following statements is TRUE if all three processes run concurrently starting
at time t=0?
(a) All processes will finish without any deadlock(b) Only P1 and P2 will be in deadlock
(c) Only P1 and P3 will be in a deadlock. (d) All three processes will be in
deadlock
29. A system contains three programs and each requires three tape units for its operation. The
minimum number of tape units which the system must have such that deadlocks never arise is
_________.
(a)6 (b)7 (c)8 (d)9
30. An operating system uses the Banker’s algorithm for deadlock avoidance when managing the
allocation of three resource types X, Y, and Z to three processes P0, P1, and P2. The table
given below presents the current system state. Here, the Allocation matrix shows the current
number of resources of each type allocated to each process and the Max matrix shows the
maximum number of resources of each type required by each process during its execution.
There are 3 units of type X, 2 units of type Y and 2 units of type Z still available. The system is
currently in a safe state. Consider the following independent requests for additional resources
in the current state:
REQ1: P0 requests 0 units of X,
0 units of Y and 2 units of Z
REQ2: P1 requests 2 units of X,
0 units of Y and 0 units of Z
Which one of the following is TRUE?
(a)Only REQ1 can be permitted
(b)Only REQ2 can be permitted
(c) Both REQ1 and REQ2 can be permitted
(d)Neither REQ1 nor REQ2 can be permitted
Answer Keys
1 (a) 2 (b) 3 (c)
4 (a) 5 (c) 6 (a)
7 (b) 8 (d) 9 (d)
10 (d) 11 (a) 12 (b)
13 (c) 14 (c) 15 (a)
16 (b) 17 (b) 18 (a)
19 (c) 20 (b) 21 (c)
22 (c) 23 (b) 24 (d)
25 (b) 26 (c) 27 (b)
28 (a) 29 (b) 30 (b)
7. SQL/Normalization/ Transaction and Concurrency control/Database(30 Questions)
Questions
1. Consider the following relational schema.
Students(rollno: integer, sname: string)
Courses(courseno: integer, cname: string)
Registration(rollno: integer, courseno: integer, percent: real)
Which of the following queries are equivalent to this query in English?
"Find the distinct names of all students who score more than 90% in the course numbered 107"
(a) I, II,III and IV (b) I, II and IV only (c) II,III and IV only (d) II and III only
2. Suppose (A, B) and (C,D) are two relation schemas. Let r1 and r2 be the corresponding relation
instances. B is a foreign key that refers to C in r2. If data in r1 and r2 satisfy referential
integrity constraints, which of the following is ALWAYS TRUE?
A.
Table A
Id Name Age
----------------
12 Arun 60
15 Shreya 24
99 Rohit 11
Table B
Id Name Age
----------------
15 Shreya 24
25 Hari 40
98 Rohit 20
99 Rohit 11
Table C
Id Phone Area
-----------------
10 2200 02
99 2100 01
(a) 7 (b) 4 (c) 5 (d)9
4. Consider a join (relation algebra) between relations r(R)and s(S) using the nested loop
method. There are 3 buffers each of size equal to disk block size, out of which one buffer is
reserved for intermediate results. Assuming size(r(R)) < size(s(S)), the join will have fewer
number of disk block accesses if
(a) relation r(R) is in the outer loop
(b) relation s(S) is in the outer loop
(c) Join selection factor between r(R) and s(S) is more than 0.5.
(d)Join selection factor between r(R) and s(S) is less than 0.5.
5. Consider the relational schema given below, where eId of the relation dependent is a foreign
key referring to empId of the relation employee. Assume that every employee has at least one
associated dependent in the dependent relation.
employee (empId, empName, empAge)
dependent(depId, eId, depName, depAge)
Consider the following relational algebra query:
The
above query evaluates to the set of empIds of employees whose age is greater than that of
(a)Some dependent (b) all dependents (c) Some of his/her dependents (d) all of his/her
dependents
6. Let E1 and E2 be two entities in an E/R diagram with simple single-valued attributes. R1 and
R2 are two relationships between E1 and E2, where R1 is one-to-many and R2 is many-to-
many. R1 and R2 do not have any attributes of their own. What is the minimum number of
tables required to represent this situation in the relational model?
(a) 2 (b)3 (c)4 (d)5
7. A database of research articles in a journal uses the following schema.
(VOLUME, NUMBER, STARTPGE, ENDPAGE, TITLE, YEAR, PRICE)
The primary key is (VOLUME, NUMBER, STARTPAGE, ENDPAGE) and the following functional
dependencies exist in the schema.
(VOLUME, NUMBER, STARTPAGE, ENDPAGE) -> TITLE
(VOLUME, NUMBER) -> YEAR
(VOLUME, NUMBER, STARTPAGE, ENDPAGE) -> PRICE
The database is redesigned to use the following schemas.
(VOLUME, NUMBER, STARTPAGE, ENDPAGE, TITLE, PRICE)
(VOLUME, NUMBER, YEAR)
Which is the weakest normal form that the new database satisfies, but the old one does not?
(a) 1NF (b)2NF (c)3NF (d) BCNF
8. A Relation R with FD set {A->BC, B->A, A->C, A->D, D->A}. How many candidate keys will be
there in R?
(a) 1 (b)2 (c)3 (d)4
9. What is the min and max number of tables required to convert an ER diagram with 2 entities
and 1 relationship between them with partial participation constraints of both entities?
(a)Min 1 and max 2 (b) Min 1 and max 3 (c)Min 2 and max 3 (d)Min 2 and max 2
10. Consider a B+ tree in which the maximum number of keys in a node is 5. What is the minimum
number of keys in any non root node?
13. Relation R has eight attributes ABCDEFGH. Fields of R contain only atomic values. F = {CH -> G,
A -> BC, B -> CFH, E -> A, F -> EG} is a set of functional dependencies (FDs) so that F+ is exactly
the set of FDs that hold for R. How many candidate keys does the relation R have?
(a) 3 (b) 4 (c) 5 (d)6
14. Consider the following relational schema:
Suppliers(sid:integer, sname:string, city:string, street:string)
Parts(pid:integer, pname:string, color:string)
Catalog(sid:integer, pid:integer, cost:real)
Assume that, in the suppliers relation above, each supplier and each street within a city has a
unique name, and (sname, city) forms a candidate key. No other functional dependencies are
implied other than those implied by primary and candidate keys. Which one of the following is
TRUE about the above schema?
(a)The schema is in BCNF
(b) The schema is in 3NF but not in BCNF
(c)The schema is in 2NF but not in 3NF
(d)The schema is not in 2NF
15. Consider the relation scheme R = {E, F, G, H, I, J, K, L, M, M} and the set of functional
dependencies {{E, F} -> {G}, {F} -> {I, J}, {E, H} -> {K, L}, K -> {M}, L -> {N} on R. What is the key
for R?
(a) {E,F} (b){E,F,H} (c) {E,F,H,K,L} (d) {E}
16. Given the following two statements:
S1: Every table with two single-valued
Attributes is in 1NF, 2NF, 3NF and BCNF.
S2: AB->C, D->E, E->C is a minimal cover for
the set of functional dependencies
AB->C, D->E, AB->E, E->C.
Which one of the following is CORRECT?
(a) S1 is TRUE and S2 is FALSE
(b)Both S1 and S2 are true
(c)S1 is FALSE and S2 is TRUE
(d) Both S1 and S2 are FALSE
17. The maximum number of superkeys for the relation schema R(E,F,G,H) with E as the key is
(a)5 (b)6 (c)7 (d)8
18. Given the STUDENTS relation as shown below.
For (StudentName, StudentAge) to be the key for this instance, the value X should not be
equal to
(a) 18 (b)19 (c)20 (d)21
19. Which one of the following statements about normal forms is FALSE?
(a) BCNF is stricter than 3NF
(b)Lossless, dependency-preserving decomposition into 3NF is always possible
(c) Lossless, dependency-preserving decomposition into BCNF is always possible
(d) Any relation with two attributes is in BCNF
20. Let r be a relation instance with schema R = (A, B, C, D). We define r1 = ΠA, B, C (r) and r2 = ΠA.D (r).
Let s = r1 * r2 where * denotes natural join. Given that the decomposition of r into r1 and r2 is
lossy, which one of the following is TRUE?
(a) s ⊂ r (b) r ∪ s (c) r ⊂ s (d) r * s= s
Which one of the schedules below is the correct serialization of the above?
(a)T1->>T3->>T2 (b)T2->>T1->>T3 (c)T2->>T3->>T1 (d)T3->>T1->>T2
26. Consider the following four schedules due to three transactions (indicated by the subscript)
using read and write on a data item x, denoted by r(x) and w(x) respectively. Which one of
28. Which of the following statements are TRUE about an SQL query?
P : An SQL query can contain a HAVING clause even
if it does not have a GROUP BY clause
Q : An SQL query can contain a HAVING clause only
if it has a GROUP BY clause
R : All attributes used in the GROUP BY clause must
appear in the SELECT clause
S : Not all attributes used in the GROUP BY clause
need to appear in the SELECT clause
(a)P and R
(b) P and S
(c) Q and R
(d) Q and S
29. Consider a database table T containing two columns X and Y each of type integer. After the
creation of the table, one record (X=1, Y=1) is inserted in the table. Let MX and My denote the
respective maximum values of X and Y among all records in the table at any point in time.
Using MX and MY, new records are inserted in the table 128 times with X and Y values being
MX+1, 2*MY+1 respectively. It may be noted that each time after the insertion, values of MX
and MY change. What will be the output of the following SQL query after the steps mentioned
above are carried out?
SELECT Y FROM T WHERE X=7;
(a)127 (b)255 (c)129 (d)257
30. Database table by name Loan_Records is given below.
Borrower Bank_Manager Loan_Amount
Ramesh Sunderajan 10000.00
Suresh Ramgopal 5000.00
Mahesh Sunderajan 7000.00
What is the output of the following SQL query?
SELECT Count(*)
FROM ( (SELECT Borrower, Bank_Manager
FROM Loan_Records) AS S
NATURAL JOIN (SELECT Bank_Manager,
Loan_Amount
FROM Loan_Records) AS T );
(a) 3 (b)9 (c)5 (d)6
Answer Keys
1 (a) 2 (a) 3 (a)
4 (a) 5 (d) 6 (b)
7 (b) 8 (c) 9 (c)
10 (b) 11 (b) 12 (c)
13 (b) 14 (a) 15 (b)
16 (a) 17 (d) 18 (b)
19 (c) 20 (c) 21 (d)
22 (b) 23 (b) 24 (b)
25 (a) 26 (d) 27 (c)
28 (c) 29 (a) 30 (c)
int main()
{
char str[] = "GATE CS 2015 Mock Test";
printf("%s", fun(str));
return 0;
}
(a)GATE CS 2015 Mock Tes
(b)tseT kcoM 5102 SC ETAG
(c) No output is printed
(d) Segmentation fault
5. Consider the following function written in the C programming language. The output of the
above function on input “ABCD EFGH” is
void foo (char *a)
{
if (*a && *a != ` `)
{
foo(a+1);
putchar(*a);
}
}
(a) ABCD EFGH (b)ABCD (c) HGFE DCBA (d) DCBA
6. Consider the following C program segment.
# include <stdio.h>
int main( )
{
char s1[7] = "1234", *p;
p = s1 + 2;
*p = '0' ;
printf ("%s", s1);
}
What will be printed by the program?
(a) 12 (b)120400 (c)1204 (d)1034
7. Output of following program?
#include<stdio.h>
int main()
{
int a[] = {1, 2, 3, 4, 5, 6};
int *ptr = (int*)(&a+1);
printf("%d ", *(ptr-1) );
return 0;
}
(a)1 (b)2 (c)6 (d)Runtime error
8. Consider the following declaration of a ‘two-dimensional array in C:
char a[100][100];
Assuming that the main memory is byte-addressable and that the array is stored starting from
memory address 0, the address of a[40][50] is
(a) 4040 (b)4050 (c)5040 (d)5050
9. Predict the output of the below program:
#include <stdio.h>
#define SIZE(arr) sizeof(arr) / sizeof(*arr);
void fun(int* arr, int n)
{
int i;
*arr += *(arr + n - 1) += 10;
}
int main()
{
int arr[] = {10, 20, 30};
int size = SIZE(arr);
fun(arr, size);
printArr(arr, size);
return 0;
}
(a) 20 30 40 (b)20 20 40 (c)50 20 40 (d)Compile time error
10. For a C program accessing X[i][j][k], the following intermediate code is generated by a
compiler. Assume that the size of an integer is 32 bits and the size of a character is 8 bits.
t0 = i ∗ 1024
t1 = j ∗ 32
t2 = k ∗ 4
t3 = t1 + t0
t4 = t3 + t2
t5 = X[t4]
Which one of the following statements about the source code for the C program is CORRECT?
(a) X is declared as “int X[32][32][8]”
(b)X is declared as “int X[4][1024][32]"
(c) X is declared as “char X[4][32][8]”
(d) X is declared as “char X[32][16][2]”
11. In the worst case, the number of comparisons needed to search a singly linked list of length n
for a given element is
(a) log 2 n (b) n/2 (c) log 2 n-1 (d)n
12. Suppose each set is represented as a linked list with elements in arbitrary order. Which of the
operations among union, intersection, membership, cardinality will be the slowest?
(a) Union only (b)Intersection, membership (c) Membership, cardinality
(d) Union, intersection
13. Consider the function f defined below.
struct item
{
int data;
struct item * next;
};
(a) rear node (b)front node (c)not possible with a single pointer (d)node next to front
15. Let P be a singly linked list. Let Q be the pointer to an intermediate node x in the list. What is
the worst-case time complexity of the best known algorithm to delete the node x from the
list?
(a) O(n) (b) O(log 2 n) (c) O( logn) (d) O(1)
16. N items are stored in a sorted doubly linked list. For a delete operation, a pointer is provided
to the record to be deleted. For a decrease-key operation, a pointer is provided to the record
on which the operation is to be performed. An algorithm performs the following operations
on the list in this order: Θ(N) delete, O(log N) insert, O(log N) find, and Θ(N) decrease-key
What is the time complexity of all these operations put together
(a)O(Log2N) (b) O(N) (c) O(N2) (d) Θ(N2 Log N)
17. The concatenation of two lists is to be performed in O(1) time. Which of the following
implementations of a list should be used?
(a)Singly linked list (b) double linked list (c)Circular doubly linked list (d)array
implementations of lists
18. A scheme for storing binary trees in an array X is as follows. Indexing of X starts at 1 instead of
0. the root is stored at X[1]. For a node stored at X[i], the left child, if any, is stored in X[2i] and
the right child, if any, in X[2i+1]. To be able to store any binary tree on n vertices the minimum
size of X should be.
(a) log2n(b)n(c)2n+1 (d)2^n — 1
19. Postorder traversal of a given binary search tree, T produces the following sequence of keys
10, 9, 23, 22, 27, 25, 15, 50, 95, 60, 40, 29 Which one of the following sequences of keys can be
the result of an in-order traversal of the tree T?
(a)9, 10, 15, 22, 23, 25, 27, 29, 40, 50, 60, 95
(b)9, 10, 15, 22, 40, 50, 60, 95, 23, 25, 27, 29
(c)29, 15, 9, 10, 25, 22, 23, 27, 40, 60, 50, 95
(d) 95, 50, 60, 40, 27, 23, 22, 25, 10, 9, 15, 29
20. In a binary tree with n nodes, every node has an odd number of descendants. Every node is
considered to be its own descendant. What is the number of nodes in the tree that have
exactly one child? (a) 0 (b) 1 (c) (n-1)/2
(d) n-1
21. The height of a binary tree is the maximum number of edges in any root to leaf path. The
maximum number of nodes in a binary tree of height h is:
(a) 2h−1
(b)2h−1 -1
(c) 2h+1-1
(d) 2h+1
22. The height of a tree is the length of the longest root-to-leaf path in it. The maximum and
minimum number of nodes in a binary tree of height 5 are
(a) 63 and 6, respectively
(b)64 and 5, respectively
(c)32 and 6, respectively
(d) 31 and 5, respectively
23. A binary tree T has 20 leaves. The number of nodes in T having two children is
(a) 18 (b)19 (c)17 (d)Any number between 10 and 20
24. Consider a complete binary tree where the left and the right subtrees of the root are max-
heaps. The lower bound for the number of operations to convert the tree to a heap is
(a) Ω(logn) (b) Ω(n) (c) Ω(nlogn) (d)Ω(n2)
25. An array of integers of size n can be converted into a heap by adjusting the heaps rooted at
each internal node of the complete binary tree starting at the node (n - 1) /2 , and doing this
adjustment up to the root node (root node is at index 0) in the order (n - 1)/2 , (n - 3)/ 2 ,
....., 0. The time required to construct a heap in this manner is
(a)O(log n) (b) O(n)(c) O (n log log n) (d) O(n log n)
26. In a binary tree, for every node the difference between the number of nodes in the left and
right subtrees is at most 2. If the height of the tree is h > 0, then the minimum number of
nodes in the tree is:
(a) 2h - 1 (b) 2h - 1 + 1
(c) 2h - 1 (d)2h
27. Breadth First Search (BFS) is started on a binary tree beginning from the root vertex. There is a
vertex t at a distance four from the root. If t is the n-th vertex in this BFS traversal, then the
maximum possible value of n is ________
(a)15 (b) 16 (c) 31 (d)32
28. In a binary tree, the number of internal nodes of degree 1 is 5, and the number of internal
nodes of degree 2 is 10. The number of leaf nodes in the binary tree is
(a) 10 (b)11 (c)12 (d)15
29. A binary tree with n > 1 nodes has n1, n2 and n3 nodes of degree one, two and three
respectively. The degree of a node is defined as the number of its neighbors.
Starting with the above tree, while there remains a node v of degree two in the tree, add an
edge between the two neighbors of v and then remove v from the tree. How many edges will
remain at the end of the process?
(a)2 * n1 - 3
(b) n2 + 2 * n1 - 2
(c) n3 - n2
(d) n2 + n1 - 2
30. Suppose we have a balanced binary search tree T holding n numbers. We are given two
numbers L and H and wish to sum up all the numbers in T that lie between L and H. Suppose
there are m such numbers in T. If the tightest upper bound on the time to compute the sum is
O(nalogb n + mc logd n), the value of a + 10b + 100c + 1000d is ____.
(a) 60 (b) 110 (c)210 (d)50
Answer Keys
1 (c) 2 (d) 3 (c)
4 (b) 5 (d) 6 (c)
7 (c) 8 (b) 9 (c)
10 (a) 11 (d) 12 (d)
13 (b) 14 (a) 15 (d)
16 (c) 17 (c) 18 (d)
19 (a) 20 (a) 21 (c)
22 (a) 23 (b) 24 (a)
25 (b) 26 (b) 27 (c)
28 (b) 29 (a) 30 (b)
9. Regular language and Finite automata/ Context free language/Theory of computation(30
Questions)
Questions
1. Consider the languages L1 = and L2 = {a}. Which one of the following represents L1 L2* U L1*
Which of the following finite state machines is a valid minimal DFA which accepts the same
language as D?
(a) A (b) B (c) C (d)D
8. Let w be any string of length n is {0,1}*. Let L be the set of all substrings of w. What is the
minimum number of states in a non-deterministic finite automaton that accepts L?
(a) n-1 (b) n (c) n+1 (d)2n-1
9. Given the following state table of an FSM with two states A and B, one input and one output:
Next Next
Present Present
Input State State Output
State A State B
A B
0 0 0 0 0 1
0 1 0 1 0 0
1 0 0 0 1 0
1 1 0 1 0 0
0 0 1 0 1 0
0 1 1 0 0 1
1 0 1 0 1 1
1 1 1 0 0 1
If the initial state is A=0, B=0, what is the minimum length of an input string which will take
the machine to the state A=0, B=1 with Output = 1?
(a) 3 (b) 4 (c) 5 (d)6
10. Given below are two finite state automata (→ indicates the start state and F indicates a final
state)Which of the following represents the product automaton Z×Y?
(a)A
(b)B (c) C (d)D
11. Consider the following languages.
19.
Here, wr is the reverse of the string w. Which of these languages are deterministic Context-
free languages?
(a) None of the languages (b) Only L1 (c) only L1 and L2 (d) All the three languages
20.
(a) L1 only (b) L3 only (c)L1 and L2 (d) L2 and L3
21. Consider the following statements about the context free grammar
G = {S → SS, S → ab, S → ba, S → Ε}
I. G is ambiguous
II. G produces all strings with equal number of a’s and b’s
III. G can be accepted by a deterministic PDA.
Which combination below expresses all the true statements about G?
(a) I only (b) I and III only (c) II and III only (d) I, II an III
22. Which of the following statements is/are FALSE?
1. For every non-deterministic Turing machine,
there exists an equivalent deterministic Turing machine.
2. Turing recognizable languages are closed under union
and complementation.
3. Turing decidable languages are closed under intersection
and complementation.
4. Turing recognizable languages are closed under union
and intersection.
(a) 1 and 4 only (b) 1 and 3 only (c) 2 only (d) 3 only
23. Let L1 be a recursive language. Let L2 and L3 be languages that are recursively enumerable but
not recursive. Which of the following statements is not necessarily true? (A) L2 – L1 is
recursively enumerable. (B) L1 – L3 is recursively enumerable (C) L2 ∩ L1 is recursively
enumerable (D) L2 ∪ L1 is recursively enumerable
(a)A (b) B (c) C (d)D
25. Let L be a language and L' be its complement. Which one of the following is NOT a viable
possibility?
(a) Neither L nor L' is recursively enumerable (r.e.).
(b) One of L and L' is r.e. but not recursive; the other is not r.e
(c) Both L and L' are r.e. but not recursive
(d) Both L and L' are recursive
26. Let A ≤m B denotes that language A is mapping reducible (also known as many-to-one
reducible) to language B. Which one of the following is FALSE? a) If A ≤m B and B is recursive
then A is recursive. b) If A ≤m B and A is undecidable then B is undecidable. c) If A ≤m B and B is
recursively enumerable then A is recursively enumerable. d) If A ≤m B and B is not recursively
enumerable then A is not recursively enumerable.
(a)A (b) B (c)C (d)D
27. Which of the following is/are undecidable?
(a) 3 only (b) 3 and 4 only (c) 1,2 and 3 only (d) 2 and 3 only
28. Which of the following problems are decidable?
Answer Keys
1 (a) 2 (d) 3 (b)
4 (c) 5 (d) 6 (b)
7 (a) 8 (c) 9 (a)
10 (a) 11 (d) 12 (b)
13 (c) 14 (d) 15 (b)
16 (c) 17 (b) 18 (c)
19 (c) 20 (d) 21 (b)
22 (c) 23 (b) 24 (d)
25 (c) 26 (d) 27 (d)
28 (d) 29 (b) 30 (b)
B) for(i = 0; i < n; i += 2)
C) for(i = 1; i < n; i *= 2)
11. Which of the following algorithms is NOT a divide & conquer algorithm by nature?
(a) Euclidean algorithm to compute the greatest common divisor
(b) Heap Sort
(c)Cooley-Tukey fast Fourier transform
(d)Quick Sort
13. The secant method is used to find the root of an equation f(x) = 0. It is started from two
distinct estimates xa and xb for the root. It is an iterative procedure involving linear
interpolation to a root. The iteration stops if f(xb) is very small and then xb is the solution. The
procedure is given below. Observe that there is an expression which is missing and is marked
by? Which is the suitable expression that is to be put in place of? So that it follows all steps of
the secant method?
Initialize: xa, xb, ε, N // ε = convergence indicator
fb = f(xb) i = 0
while (i < N and |fb| > ε) do
i=i+1 // update counter
xt = ? // missing expression for
// intermediate value
xa = xb // reset xa
xb = xt // reset xb
fb = f(xb) // function value at new xb
end while
if |fb| > ε
then // loop is terminated with i = N
write “Non-convergence”
else
write “return xb”
end if
(a) xb – (fb– f(xa)) fb/ (xb – xa)
(b) xa– (fa– f(xa)) fa/ (xb – xa)
(c) xb – (fb – xa) fb/ (xb – fb(xa)
(d) xa – (xb – xa) fa/ (fb – f(xa))
14. Suppose you are provided with the following function declaration in the C programming
language.
int partition (int a[], int n);
The function treats the first element of a[] as a pivot, and rearranges the array so that all elements
less than or equal to the pivot is in the left part of the array, and all elements greater than the pivot is
in the right part. In addition, it moves the pivot so that the pivot is the last element of the left part.
The return value is the number of elements in the left part. The following partially given function in
the C programming language is used to find the kth smallest element in an array a[ ] of size n using
the partition function. We assume k ≤ n
int kth_smallest (int a[], int n, int k)
{
int left_end = partition (a, n);
if (left_end+1==k)
{
return a [left_end];
}
if (left_end+1 > k)
{
return kth_smallest (____________________);
}
else
{
return kth_smallest (____________________);
}
}
The missing argument lists are respectively
(a) (a, left_end, k) and (a+left_end+1, n–left_end–1, k–left_end–1)
(b) (a, left_end, k) and (a, n–left_end–1, k–left_end–1)
(c) (a, left_end+1, N–left_end–1, K–left_end–1) and(a, left_end, k)
(d) (a, n–left_end–1, k–left_end–1) and (a, left_end, k)
15. Consider the problem of computing min-max in an unsorted array where min and max are
minimum and maximum elements of array. Algorithm A1 can compute min-max in a1
comparisons without divide and conquer. Algorithm A2 can compute min-max in a2
comparisons by scanning the array linearly. What could be the relation between a1 and a2
considering the worst case scenarios?
(a) a1 < a2 (b) a1 > a2 (c) a1=a2 (d) Depends on the input
16. A sub-sequence of a given sequence is just the given sequence with some elements (possibly
none or all) left out. We are given two sequences X[m] and Y[n] of lengths m and n
respectively, with indexes of X and Y starting from 0. We wish to find the length of the longest
common sub-sequence(LCS) of X[m] and Y[n] as l(m,n), where an incomplete recursive
definition for the function l(i,j) to compute the length of The LCS of X[m] and Y[n] is given
below:
l(i,j) = 0, if either i=0 or j=0
= expr1, if i,j > 0 and X[i-1] = Y[j-1]
= expr2, if i,j > 0 and X[i-1] != Y[j-1]
(a) expr1 ≡ l(i-1, j) + 1
(b) expr1 ≡ l(i, j-1)
(c) expr2 ≡ max(l(i-1, j), l(i, j-1))
(d) expr2 ≡ max(l(i-1,j-1),l(i,j))
17. Consider two strings A = "qpqrr" and B = "pqprqrp". Let x be the length of the longest
common subsequence (not necessarily contiguous) between A and B and let y be the number
of such longest common subsequences between A and B. Then x + 10y = ___.
(a) 33 (b) 23 (c) 43 (d)34
18. Let A1, A2, A3, and A4 be four matrices of dimensions 10 x 5, 5 x 20, 20 x 10, and 10 x 5,
respectively. The minimum number of scalar multiplications required to find the product
A1A2A3A4 using the basic matrix multiplication method is
(a)1500 (b)2000 (c) 500 (d)100
19. The time complexity of the following C function is (assume n > 0 )
int recursive (mt n)
{
if (n == 1)
return (1);
else
return (recursive (n-1) + recursive (n-1));
}
(a) 0(n)
(b
0(nlogn)
)
(c
0(n^2)
)
(d
0(2^n)
)
20. Which one of the following correctly determines the solution of the recurrence relation with
T(1) = 1?
T(n) = 2T(n/2) + Logn
(a) Θ(n)
(b) Θ(nLogn)
(c) Θ(n*n)
(d) Θ(log n)
22. The solution to the recurrence equation T(2k) = 3 T(2k-1) + 1, T (1) = 1, is:
(a) 2k
(b) (3k + 1 - 1)/2
(c) 3log2k
(d) 2log3k
23. Select the correct asymptotic complexity of an algorithm with runtime T(n, n) where
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)
(a) Θ(nLogn)
(b) Θ(n2)
(c) Θ(n)
(d) Θ(n2Logn)
24. Let f(n) = n and g(n) = n(1+sin n), where n is a positive integer. Which of the following statements
is/are correct?
I. f(n) = O(g(n))
II. f(n) = Ω(g(n))
(a) Only I
(b) Only II
(c) Both I and II
(d) Neither I nor II
25. Consider a list of recursive algorithms and a list of recurrence relations as shown below. Each
recurrence relation corresponds to exactly one algorithm and is used to derive the time
complexity of the algorithm.
Recursive Recurrence
Algorithm Relation
P. Binary search I. T(n) = T(n-k) + T(k) + cn
Q. Merge sort II. T(n) = 2T(n-1) + 1
R. Quick sort III. T(n) = 2T(n/2) + cn
S. Tower of Hanoi IV. T(n) = T(n/2) + 1
P-II, Q-III, R-IV, S-
(a)
I
P-IV, Q-III, R-I, S-
(b)
II
P-III, Q-II, R-IV, S-
(c)
I
(d) P-IV, Q-II, R-I, S-II
26. Consider the recurrence relation a1 = 8, an = 6n2 + 2n + an-1. Let a99 = k x 104. The value of K is
_____ (a) 190 (b) 296 (c) 198 (d) 200
27. The given diagram shows the flowchart for a recursive function A(n). Assume that all
statements, except for the recursive calls, have O(1) time complexity. If the worst case time
complexity of this function is O(nα), then the least possible value (accurate up to two decimal
positions) of α is __________
(a) 2.2 to 2.4 (b) 3.2 to 3.4 (c) 0 to 1.8 (d)1
28. When n = 22k for some k ≥ 0, the recurrence relation
T(n) = √(2) T(n/2) + √n, T(1) = 1
evaluates to :
(a) √(n) (log n + 1)
(b) √(n) (log n )
(c) √(n) log √(n)
(d) n log √(n)
29. Consider the DAG with Consider V = {1, 2, 3, 4, 5, 6}, shown below. Which of the following is
30. Let G be a graph with n vertices and m edges. What is the tightest upper bound on the running
time on Depth First Search of G? Assume that the graph is represented using adjacency
matrix.
(a) O(n)
(b) O(m+n)
(c) O(n2)
(d) O(mn)
Answer Keys
1 (d) 2 (a) 3 (c)
4 (d) 5 (a) 6 (a)
7 (b) 8 (b) 9 (b)
10 (d) 11 (b) 12 (c)
13 (d) 14 (a) 15 (b)
16 (c) 17 (d) 18 (a)
19 (d) 20 (a) 21 (b)
22 (b) 23 (c) 24 (d)
25 (b) 26 (c) 27 (a)
28 (a) 29 (d) 30 (c)
Director (R&D)