You are on page 1of 10

EY Technical Interview Questions: Freshers and

Experienced
1. What do you mean by “normalization”?

 Normalization is a way to keep data in the database in an organized manner.


In this process, tables are created and relationships are established
according to the rules designed to protect the data and to make the
database flexible by removing redundancy and inconsistent dependency.
Normalization is crucial for many reasons.
 But more specifically, it is important because it enables databases to take up
less disk space resulting in increased performance.

2. What is an object-oriented model?

An object-oriented model is a way to apply object-oriented concepts to all the


stages of the software development cycle. In an object-oriented model, we think
about the problems using models organized around real-world problems.

The main objective of the object-oriented model is the following:

 Testing an entity before actually starting building it.


 Coordination with the customers.
 Visualization.
 Reducing complexity that leads to scalable products.

3. Define RDBMS?

RDBMS is an acronym for relational database management systems. Most


database management systems like SQL, MY-SQL, and ORACLE are based on
RDBMS. The name relational database management system is given because RDMS
is based upon the relational model introduced by E.F. Codd. It is one of the most
commonly used databases. It includes several tables or relations and each table has
its own primary key.

The set of tables is stored in an organized manner in RDBMS, therefore data can be
accessed easily in RDBMS.

4. Explain the need for a lock and also explain the difference between
a shared lock and an exclusive lock?

To ensure the isolation of property holds in transactions, we need to make sure that
data items be accessed in a mutually exclusive manner. It basically means that when
one transaction is accessing a data item then no other transaction can make
changes to that data item.

Thus, to fulfil this requirement, we can allow transactions to access the data item
only if it holds a lock on that item.

Shared lock vs Exclusive lock:

Shared lock Exclusive lock


It allows ready and writing
It allows read-only operation. operations.
Protect others from reading as well
Protect others from updating the data. as updating the data.
There is no limitation on the number of
transactions that can hold a shared lock on an Exclusive lock can be held by only
item. one transaction
A shared lock is requested using a shared lock An exclusive lock is requested using
operation. exclusive lock operation.

5. What is the difference between primary key and foreign key?

Primary Key Foreign Key


Primary key ensures that data in Foreign key is a column or group of columns
the specific column is unique. used to link between data present in two tables.
One primary key is possible for a More than one foreign key is possible for a
table. table.
The primary key value cannot be
null. Primary key values can be null.
It is used to uniquely identify a It refers to the column in a table that is the
record in relation to or table. primary key of that table.
Unique and not-null constraints
together make the primary key. It can contain duplicate values.

6. What is a transparent DBMS?

A transparent DBMS is one that keeps its physical structure hidden from the users.

7. What is a deadlock?

Deadlock is a condition in which more than one process is blocked because it is


holding a resource but also requires another resource that is currently acquired by
some other process. This can be understood with the help of a real-life example:
 Consider two trains passing through a railway track in opposite directions.
Each waits for the other to pass but none of them can go across the other.

8. Why is DML provided?

Data manipulation language (DML) is provided for the manipulation and processing
of databases.

9. What is meant by the interface?

An interface is a blueprint for a class. It has static constants and abstract methods.
It is a way to achieve abstraction. In other words, we can say that an interface can
have variables and abstract methods but no method body.

10. Differentiate between abstract class and interface.

Abstract Class Interface


Abstract class can contain abstract as well An interface can contain abstract methods
as non-abstract methods. only.
There is a way using which multiple
Abstract class doesn’t support multiple inheritances are possible through an
inheritances. interface.
An abstract class can provide the An interface cannot provide the
implementation of the interface. implementation of the abstract class.
An abstract class can contain static and An interface can contain final and static
non-static, final and non-final members. variables.

11. Where do we generally create an index?

The index is generally created at the time of the table creation in the database. For
example, in MySQL, we can use the following statements to create a table with an
index that holds two columns column1 and column2.

mysql> CREATE TABLE t_index


( column1 INT PRIMARY KEY, column2 INT NOT NULL, column3 INT NOT NULL, co
lumn4 VARCHAR(20), INDEX (column1,column2) );

If want to add an index to the table, we can use the following statement:

mysql>
CREATE INDEX [index] ON [table] (column)

Here:

 index: It represents the name of the index,


 table: It represents the name of the table to which the index belongs, and
 column: It represents the list of columns.

12. What are the advantages of using the stored procedures?

Store procedure specifies a type of code in SQL that can be stored by the user for
later use and can be used many times.

Syntax:

CREATE PROCEDURE name_of_the_procedure


AS
sql_statement
GO;

The advantages of stored procedures are the following:

 Increased productivity: The same piece of code is used again and again
which results in higher productivity.
 Better performance: The calls made to the procedure are quick and
efficient as stored procedures are compiled once and stored in the
executable form which leads to better performance.
 Easily maintainable: Maintaining a procedure on a server is quite easier
than maintaining its replica on a different client machine.
 Security: We can restrict access to the oracle data by allowing the users to
use stored procedures within specific privileges.

13. Problem statement: You are given the head of two linked lists and
you need to determine the data present at the intersection of linked
lists. If there is no intersection between the lists then return -1.

Input Format:

You need to complete findIntersection(ListNode *headA, ListNode *headB)


function.

Output:

Return the data present at the intersection.

If there is no intersection then return -1

Constraints:

1 <= Number of node in both the lists <= 10^5


-10^9 <= data <= 10^9 and data != -1

Time Limit: 1 sec

Sample Input 1:

Sample Output 1:

Sample Input 2:

Sample Output 2:

-1

Approach

We can first determine the lengths of both lists by traversing through the lists. Note
that after the intersection the number of nodes remains the same for both the lists.
Let the lengths come out to be equal to len1 and len2. If len1 exceeds len2 then we
move the head pointer of ListNode1 by (len1 - len2) times forward otherwise len2
exceeds len1 so we will move the head pointer of ListNode2 by (len2 - len1) times
ahead.

Now we will iterate unless either of them (head1 or head2) becomes NULL or head1
and head2 pointing to the same node.
At the end of the iteration, we will check whether either of the head of lists is NULL,
if it is so then we will return -1 otherwise we will return value (data) stored at head1
or head2.

Source Code:

/**
* Definition for singly-linked list.
* struct ListNode {
* int data;
* ListNode *next;
* ListNode(int x) : val(x), next(NULL) {}
* };
*/
class Solution {
public:
ListNode *findIntersection(ListNode *headA, ListNode *headB) {

// Variables to store the length


// of both the lists

int lenA = 0;
int lenB = 0;

ListNode* currA = headA;


ListNode* currB = headB;

/*
Find the length of both the lists
*/

while(currA || currB)
{
if(currA)
{
lenA++;
currA = currA -> next;
}
else
{
lenB++;
currB = currB -> next;
}
}

if(lenA > lenB)


{
currA = headA;
currB = headB;
int difference = lenA - lenB;
while(difference > 0)
{
currA = currA -> next;
difference--;
}
}

else
{
currB = headB;
currA = headA;
int difference = lenB - lenA;
while(difference > 0)
{
currB = currB -> next;
difference--;
}

while(currA != NULL && currB != NULL && currA != currB)


{
currA = currA -> next;
currB = currB -> next;
}

return ((currA == NULL || curB == NULL) ? -1 : currA -> data);

}
};

14. Discuss memory management.

In a computer that supports multiprogramming, the operating system stays in


some part of the memory and the rest is used by different processes. This task of
dividing the memory among different processes is known as memory management.

Why memory management is required:

 Efficient utilization of the memory.


 To minimize fragmentation.
 To ensure data integrity when a process is being executed.
 To keep the track of the memory space used by different processes.

15. Differentiate between compiler and interpreter.


Compiler Interpreter
Scans the program and translates the At a time only a single statement is
entire program into machine code in translated into machine code i.e., line-by-
one go. line translation.
Object code is generated by a No object code is generated by the
compiler. Therefore, they are less interpreter. Therefore, they are more
memory efficient. memory efficient.
A compiler takes more time to analyze Interpreter takes less time to analyze the
the entire program. entire program.
Execution time is faster in the case of Execution time is not very fast in the case of
compilers. interpreters.

16. Explain malloc() and calloc() in C.

1. malloc() function:

The malloc() function also known as the memory allocation function is used to
dynamically allocate a block of memory by specifying the size.

 Syntax:

ptr = (cast-type*) malloc(byte-size)

 For example,

ptr = (int*) malloc(100 * sizeof(int));

Since the size of int is 4 bytes. Therefore, this statement allocates 400 bytes of
memory and ptr holds the address of the first byte.

If allocation fails then it returns NULL.

2. calloc() function:

The calloc() function also known as the contiguous allocation function is used to
dynamically allocate specified blocks of memory of a specific size.

 Syntax:

ptr = (cast-type*) calloc(n, size)

 For example,

ptr = (int*) calloc(10, sizeof(int));


Since, the size of int is 4 bytes. Therefore, this statement allocates contiguous space
of memory for 10 elements each of size 4.

If allocation fails then it returns NULL.

17. SQL question: Problem Statement: Find the second largest value
in a specified column of a relation or table.

Input:

Employee Name Salary


Rajesh 34000
Amit 20000
Harshit 24000
Mukul 31000

Output:

31000

Method 1:

SELECT MAX (name_of_column) FROM name_of_table WHERE name_of_column NOT I


N (SELECT MAX (name_of_column) FROM name_of_table);

Explanation:

Here, firstly we are finding the maximum value in the specified column and then we
are searching again by excluding the found maximum value.

Method 2:

SELECT name_of_column
FROM name_of_table p
WHERE 2 = (SELECT COUNT (DISTINCT name_of_column) FROM name_of_table q WH
ERE p.column_name <= q.column_name)

We have used a nested sub-query above. Note that this is a generic SQL query that
prints the nth largest value. For each record processed by the outer query, the inner
query would be executed and it will return how many records have a value lesser
than the current value. As our task here is to determine the second largest value,
therefore we will stop as soon as the inner returns 2.

18. What is a thread? Also, explain how a thread is different from the
process.
 A thread represents a path of execution within a process. A process can
contain more than one thread.
 Threads present in a process share a common memory space whereas
processes run in different memory spaces.

You might also like