Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

Mindtree Interview Questions

TR Questions:

1.Explain HTTP and HTTPS protocol in the context of computer networks.

• HTTP: HTTP stands for Hypertext Transfer Protocol. HTTP is a set of rules and standards that
regulate how information can be sent across the Internet. HTTP establishes communication
standards for web browsers and servers. HTTP is a network protocol that runs on top of TCP
at the application layer. HTTP employs hypertext structured text to create a logical link
between text-containing nodes. It's also known as the "stateless protocol" since each
command is conducted separately, without using the last run command as a reference.
• HTTPS: HTTPS is the acronym for HyperText Transfer Protocol Secure. It is a highly advanced
and secure HTTP version. For data communication, it uses port 443. Encrypting all
communication using SSL, it provides for secure transactions. It's a hybrid of the SSL/TLS and
HTTP protocols. It allows a network server to be identified in an encrypted and safe manner.
HTTPS also enables the server and browser to establish a secure encrypted connection. It
provides data security in both directions. This assists you in preventing the theft of
potentially sensitive information.

2. Differentiate between Multiprogramming vs Multitasking.


Following are the differences between Multiprogramming and Multitasking:

Multiprogramming Multitasking

Multiprogramming is primarily used to maximise Multitasking, on the other hand,


CPU efficiency by arranging applications so that tries to improve reaction time by
only one programme is running at any given sharing computing resources
time. among multiple users.

The goal of multiprogramming is to make the Multitasking, on the other hand,


CPU work harder. The programs are designed in aims to enhance CPU reaction
such a way that the CPU is never idle; each time.
program is executed one after the other.

Multiprogramming is based on the concept of Multitasking, on the other hand,


context switching, which is a common operation is based on time-sharing, which
that allows a single processor machine's CPU to means that each activity or
switch from one task to another. The Process process is completed in the same
Control Block (PCB) keeps track of an active amount of time.
process's state so that the CPU can resume from
the same point.
3. What do you understand about Object Oriented Programming? Explain the major features of
object oriented programming.

Object-oriented programming (OOP) is a programming paradigm that organises software design


around data, rather than functions and logic. An object is a data field with its own set of properties
and behaviour. Object-oriented programming (OOP) focuses on the objects that developers desire
to handle rather than the logic that is required to manipulate them. This kind of programming is
ideally suited to big, complicated, and frequently updated or maintained projects. Inheritance,
hiding, polymorphism, and other real-world concepts are all part of object-oriented programming.
The basic goal of OOP is to connect data and the functions that operate on it so that no other part
of the code may access it except that function.

Following are the major features of Object-Oriented Programming:

• Encapsulation: The word "encapsulate" refers to the act of enclosing something.


Encapsulation works in OOP in a similar fashion to how a pill "encapsulates" or contains the
medication under its coating: by building a protective barrier around the information
contained within a class from the rest of the code. In OOP, we encapsulate data and methods
that operate on it by combining them into a single unit, the class. We can hide the private
information of a class from the outside world and only disclose functionality that is needed
to interact with it this way. We say a class is properly enclosed when it prevents calling code
from accessing its private data directly.
◦ For example, consider a multinational company. There are various sectors in a firm,
such as the accounts, finance, and sales departments. The finance department is in
charge of all financial transactions and keeps track of all financial data. Similarly, the
sales department is in charge of all sales-related activities and keeps track of all sales.
Now and then, a circumstance may arise in which a finance official requires complete
sales data for a specific month for some reason. In this instance, he is not permitted
to view the sales section's data directly. He must first contact another officer in the
sales department and request that he provide the requested information.
Encapsulation is what it is. The data from the sales area, as well as the employees
who can change it, are grouped together under the heading "sales section."

• Abstraction: Abstraction is the technique of hiding unnecessary details and displaying only
the necessary details. The practice of identifying only the required attributes of an object
while discarding the irrelevant information is known as data abstraction. The features and
behaviours of an object assist to distinguish it from other things of the same sort, as well as
classifying and grouping them.
◦ For example, consider an ATM machine. In our daily lives, we all utilise an ATM
machine for cash withdrawals, money transfers, retrieving minimum statements, and
so on. However, we have no idea what happens inside an ATM machine when you
insert an ATM card to execute any type of transaction.

• Inheritance: Inheritance is the technique in Object-Oriented Programming by which one


class can acquire all the properties of another class and can even add more properties to its
definition. Inheritance, therefore, enforces code reusability. The class whose properties are
being inherited is referred to as a base or parent class while the class which inherits the
properties of another class is referred to as sub or child class.
◦ For example, A child inherits a lot of physical features from his/ her parents. People
often compare whether a particular feature is the same as that of the father or the
mother. There are different types of vehicles such as cars, buses, trucks and so on.
All of these different types of vehicles can be believed to have inherited all the basic
properties of a Vehicle which includes an accelerator, brake and so on.

• Polymorphism: Polymorphism is the technique of using one thing in more than one form.
Polymorphism, in other terms, allows you to specify a single interface with various
implementations.
◦ For example, a person can have different relations with different people around
them. A person may be a father to a son, a brother to a sister, a son to a mother and
so on. Similarly, a person may behave differently depending on the situation. For
example, two people in an office are considered colleagues during work hours, but
they can be friends after office hours. When you're in class, you act like a student;
when you're in the store, you act like a customer; when you're at home, you act like
a son or daughter; here, one person exhibits a variety of behaviours.

4. What are the advantages of Object Oriented Programming?


Following are the advantages of Object-Oriented Programming:
• Instead of needing to start writing code from scratch, we can build programs from standard
functioning modules that communicate with one another, saving time and increasing
productivity.
• The Object-Oriented Programming language allows us to divide the program down into
small-sized problems that can be solved quickly (one object at a time).
• The Object-Oriented Programming Language increases programmer efficiency, improves
software quality, and reduces maintenance costs.
• OOPs, concepts can be applied from tiny to large systems.
• It is possible for numerous instances of objects to coexist without interfering with one other
• The data hiding principle aids programmers in creating secure programs that are not
vulnerable to code in other areas of the program.
• We can minimise duplicate code and increase the use of existing classes by using inheritance.
5. Differentiate between interface and abstract class in the context of Java.
The following table lists the differences between an interface and abstract class:

Interface Abstract class

Only abstract methods are allowed in an There are abstract and non-abstract
interface. It can also contain default and methods in an abstract class.
static methods with Java 8.

We cannot implement the concept of We cannot implement the concept of


multiple inheritances using interfaces. multiple inheritances using abstract
classes.

The implementation of an abstract class An abstract class can provide


cannot be provided by an interface. interface implementation.

Only static and final variables are used in the Variables in an abstract class can be
interface. final, non-final, static, or non-static.

To declare an interface, we use the interface To declare an abstract class, we use


keyword. the abstract keyword.

Only another Java interface can be extended An abstract class can implement
by an interface. numerous Java interfaces by
extending another Java class.

The keyword "implements" can be used to The keyword "extends" can be used
create an interface. to extend an abstract class.

By default, members of a Java interface are Private, protected, and other class
public. members can be found in a Java
abstract class.
6. Does Java allow a class to inherit from multiple classes? If not, how can a class achieve the
properties of more than one class (i.e., multiple inheritance)?
Multiple inheritances are not allowed by Java using classes. This is because dealing with the
complexity that multiple inheritances produce is quite difficult.

For example,
import java.io.*;
class Base1 {
void fun() {
System.out.println("Parent1");
}}
class Base2 {

void fun() {
System.out.println("Parent2");
}
}
class Child extends Base1, Base2 {
public static void main(String args[]) {
Child obj = new Child(); // object creation of the child class
obj.fun(); // it leads to compilation error since fun() is defined in both Base1 and Base2 and the
compiler gets in an ambiguous situation as to which fun() is being referred to.
}
}
In the above code, a compilation error is thrown. This is because both the classes Base1 and Base2
contain a definition for the function fun(). This confuses the compiler as to which fun() is being
referred to.
Multiple Inheritance causes issues during operations such as casting, constructor chaining, and so
on, and the main reason is that we only need multiple inheritances in a few cases, thus it's best to
leave it out to keep things simple and easy.
However, the main objective of multiple inheritances to inherit from multiple classes can be
obtained via interfaces in Java. An interface, like a class, has variables and methods, however, unlike
a class, the methods in an interface are abstract by default. The class that implements an interface
needs to define the member functions. If a class implements multiple interfaces, or if an interface
extends multiple interfaces, multiple inheritances via interface happen.
For example, the code for the above example using interfaces would be like this:
interface Base1
{
public void fun();
}
interface Base2
{
public void fun();
}
class Child implements Interface1, Interface2
{
public void fun()
{
System.out.println("Implementing the fun() of the interface.");
}
public static void main(String args[]){
Child obj = new Child();
obj.fun();
}}
In the above code, the fun() is not defined in the interfaces Base1 and Base2. They are defined by
the classes which implement the interfaces. This leads to no ambiguity and the purpose of multiple
inheritances has been solved.

7. Write a program to calculate the Least Common Multiple (LCM) of two numbers.
Example : Input : a = 10, b =15 Output : 30 a = 5, b = 7 Output : 35

Input :
a = 10, b =15
Output :
30
a = 5, b = 7
Output :
35

Approach:
Let us assume the two numbers are a and b. Then, the two numbers have the following
relationship :
a * b = LCM(a, b) * GCD(a, b)

or,
LCM(a, b) = (a * b) / GCD(a, b)
Let us take an example to understand better. For a = 10 and b = 15, a * b = 150, LCM(10, 15) = 30,
GCD(10, 15) = 5. So, a * b = LCM(a, b) * GCD(a, b).
Code :
#include <iostream>
using namespace std;
//Function to find the greatest common divisor of the two numbers
int findGCD(int a,int b)
{
if (b == 0)
return a;
return findGCD(b, a % b);
}
// Function to return LCM of two numbers
int findLCM(int a, int b)
{
return (a * b) / findGCD(a, b);
}
int main()
{
int a = 10, b = 15;
cout <<"The Least Common Multiple of the two numbers " << a << " and " << b << " is : " <<
findLCM(a, b);
return 0;
}
Output:
The Least Common Multiple of the two numbers 10 and 15 is : 30
Explanation:
In the above code, the function findGCD() finds the greatest common divisor of the two numbers a
and b. We use the Euclidean algorithm to find the greatest common divisor of the two numbers.
The function findLCM() finds the least common multiple of the two numbers.

8. Write a program to sort a given array of numbers. The sorting algorithm should give best
performance in every case (best, worst and average). Example : Input : arr = {3, 5, 7, 1, 2, 4, 6}
Output : {1, 2, 3, 4, 5, 6, 7}
Example:
Input :
arr = {3, 5, 7, 1, 2, 4, 6}
Output :
{1, 2, 3, 4, 5, 6, 7}
Approach:
Since we want the sorting algorithm to give the best time complexity in all three cases (that is,
best, worst and average), we will implement merge sort to sort the given array of numbers. In
merge sort, we divide an array into two halves recursively, sort each half and then merge them.
Code:
#include<bits/stdc++.h>
using namespace std;
//function to merge the two sorted halves of the array
void merge(int *arr, int start, int mid, int end) {
int temp[end - start + 1];// creating a temporary array to store the sorted array
int i = start;
int j = mid+1;
int k = 0;
while(i <= mid && j <= end) {
if(arr[i] <= arr[j]) {
temp[k] = arr[i];
i = i + 1;
}
else {
temp[k] = arr[j];
j = j + 1;
}
k = k + 1;
}
//If the first half still has elements, we add them to the temporary array
while(i <= mid) {
temp[k ++] = arr[i ++];
}
//If the second half still has elements, we add them to the temporary array
while(j <= end) {
temp[k ++] = arr[j ++];
}
// We store the sorted order of elements in the original array
for(i = start; i <= end; i ++) {
arr[i] = temp[i - start]
}
}
// function to sort an array of elements
void mergeSort(int *arr, int start, int end) {

if(start < end) {


int mid = (start + end) / 2;// finding the mid index
mergeSort(arr, start, mid);// sorting the left side of the array
mergeSort(arr, mid+1, end);// sorting the right side of the array
merge(arr, start, mid, end);// merging the left and right halves of the array
}
}
int main()
{
int arr[] = {3, 5, 7, 1, 2, 4, 6};
int n = sizeof(arr)/ sizeof(arr[0]);
mergeSort(arr, 0, n);
cout << "The sorted array is : ";
for(int i = 0; i < n; i ++)
cout << arr[i];
cout << "\n";
return 0;
}
Output:
The sorted array is : 1 2 3 4 5 6 7
9. You have 15 rupees on you. You enter a shop and the shopkeeper informs you that each
chocolate costs one rupee. He also informs you that in exchange for three wrappers, you will
receive a chocolate. How many chocolates can you eat in total?

We can eat a total of 22 chocolates for Rs. 15. First, we will buy 15 chocolates for 15 rupees since
each chocolate costs Re. 1. Now, we have 15 wrappers. We return all the 15 wrappers to the
shopkeeper which gives us 5 chocolates (15 / 3 = 5). We eat those five chocolates and return 3
wrappers to the shopkeeper and get 1 chocolate. We eat that chocolate and again give 3 wrappers
which give us one chocolate. So, in total, we can have 15 + 5 + 1 + 1 chocolates.

10. What do you understand by super key, candidate key, primary key and foreign key in the
context of database management systems?

• Super key: Super Key is a set of attributes that can be used to uniquely identify a tuple. The
super key is created by adding zero or more attributes to the candidate key. A candidate key
is a super key, but not the other way around.
• Candidate key: A candidate key is the smallest set of attributes that can uniquely identify a
tuple. For each tuple, the Candidate Key value is unique and non-null. In relation, there can
be more than one candidate key. The candidate key might be simple (only having one
attribute) or composite (containing multiple attributes).
• Primary key: In relation, there may be more than one candidate key, with one being chosen
as the primary key. This primary key is chosen by the database administrator based on the
requirements amongst the candidate keys.
• Foreign key: A foreign key is a column or set of columns in a relational database table that
connects data from two other tables. It serves as a cross-reference between tables by
referencing the primary key of another table and therefore creating a relationship between
them.

For example, let us consider tables with the following schema :


Teacher :
teacher_id (primary key), teacher_name, teacher_phone_number, teacher_aadhar,
teacher_department_id

Department :
department_id (primary key), department_name
Here, for the Teacher table, the following are the different types of keys present :
• The candidate keys can be teacher_id, teacher_phone_number and teacher_aadhar since
they all can uniquely identify a record of the table.
• Out of the above three candidate keys, any one of them can be chosen as the primary key.
We generally choose teacher_id as the primary key.
• Any of the above candidate keys when grouped with any other key form the super key. For
example, teacher_id, teacher_name can together form a super key.
• Teacher_department_id is a foreign key for the Teacher table since it is a
• primary key in the Department table and it links the two tables.
11. What are the different types of SQL commands?

Following are the different types of SQL commands :


• Data Definition Language (DDL): DDL commands are those commands that modify the
table's structure, such as by adding, deleting, or changing a table. All DDL commands are
auto-committed, which means they store all database changes permanently. Example -
Create, Drop, Truncate, Alter.
• Data Manipulation Language (DML): The database is modified using DML commands. It is in
charge of all database modifications of any kind. The DML command is not auto-committed,
which means it cannot preserve all database modifications permanently. They have the
potential to be rolled back. Example - Insert, Update, Delete.
• Data Control Language: Any database user can be granted or revoked authority using DCL
commands. Example - Grant, Revoke.
• Transaction Control Language (TCL): Transaction Control Language commands are
commands that are used to manage transactions in a database. Only DML commands like
INSERT, DELETE, and UPDATE can be used with TCL commands. Because these activities are
automatically committed to the database, they can't be used while creating or dropping
tables. Example - Commit, Rollback, Savepoint.
• Data Query Language (DQL): DQL commands are used to fetch data from the database.
Example - Select.

12. Differentiate between Delete and Truncate SQL commands.


The following table lists the differences between Delete and Truncate SQL commands:

Delete Truncate

The DELETE command is used This command is used to delete all of the rows in a
to remove specific rows from table.
a table (one or more).

It is a Data Manipulation It is a Data Definition Language (DDL) command.


Language (DML) command.

In order to filter the records, The TRUNCATE command may not use a WHERE
the DELETE command may clause.
include a WHERE clause.

The DELETE statement TRUNCATE TABLE deletes data by relocating the


deletes rows one by one and data pages that were used to hold the table data,
records each deleted row in and only the page deallocations are recorded in the
the transaction log. transaction log.

A tuple is locked before being Before removing the table data, the data page is
deleted with the DELETE locked in this command.
statement.

DELETE permission on the To use Truncate on a table, the table must have at
table is required to use least ALTER permission.
Delete.

The DELETE command is more The TRUNCATE command, on the other hand, is
time consuming than the faster than the DELETE command.
TRUNCATE command.

13. Differentiate between new and malloc() in the context of C++.


The following table lists the differences between new and malloc():

new malloc()

new is an operator. malloc() is a function.

When we use a new operator, it Usage of the malloc() function does not involve
calls the constructor. invoking constructors.

It returns the data type specified It returns a void * type which needs to be
while using the new operator. typecasted manually to the required data type.

When the new operator fails, it When the malloc() command fails, it returns
throws an error of bad_alloc NULL.
exception.

Here, the size of memory Here, the size of memory required needs to be
required is computed computed manually and provided at the time of
automatically by the compiler. using malloc().
14. Explain the Open Systems Interconnection (OSI) model in the context of computer networks.
Following are the different layers in the OSI model:

Physical Layer: The physical layer is the lowest layer in the OSI reference model. It is in charge of
establishing a physical connection between the devices. Bits of information are stored in the
physical layer. Following are the responsibilities of the physical layer :
• Bit synchronisation: A clock is provided by the physical layer, which allows the bits to be
synchronised. This clock controls both the sender and the receiver, ensuring bit-level
synchronisation.
• The transmission rate, or the number of bits transferred per second, is likewise defined by
the Physical layer.
• Physical topologies: The physical layer defines the arrangement of devices/nodes in a
network, such as bus, star, or mesh topologies.
• Transmission mode: The physical layer also specifies how data is passed between the two
linked devices. Simplex, half-duplex, and full-duplex transmission modes are available.

Data Link Layer (DLL): The data link layer is in charge of message transport from node to node. The
major purpose of this layer is to ensure that data transfers from one node to another through the
physical layer are error-free. Following are the responsibilities of data link layer :
• Framing: The data link layer is responsible for framing. It allows a sender to deliver a set of
bits to a receiver that are relevant to the receiver. This can be done by attaching unique bit
patterns to the frame's beginning and end.
• Physical addressing: After producing frames, the Data link layer adds the sender and/or
receiver's physical addresses (MAC addresses) to the header of each frame.
• Error control: The data link layer implements error control by detecting and retransmitting
broken or lost frames.
• Flow Control: Because the data rate on both sides must be consistent or the data would be
corrupted, flow control coordinates the amount of data that can be transferred before
acknowledgment.
• When many devices share a single communication channel, the MAC sub-layer of the data
link layer assists in determining which device has control over the channel at any particular
time.

Network Layer: The network layer is responsible for data transmission between hosts on different
networks. Following are the responsibilities of the network layer :
• Routing: From source to destination, the network layer protocols determine which path is
best. Routing is the name for this network layer function.
• The network layer defines an addressing scheme in order to uniquely identify each device
on the internetwork. The network layer places the IP addresses of the sender and receiver
in the header. An address like this recognises each gadget in a unique and universal way.

Transport Layer: The transport layer delivers services to the application layer while also receiving
services from the network layer. Segments are the units of data in the transport layer. Following are
the responsibilities of the Transport layer :
• This layer accepts the message from the (session) layer and splits it down into smaller parts.
A header is attached to each of the segments created. The message is reassembled by the
transport layer at the destination station.
• The transport layer header provides a form of address called service point address or port
address in order to deliver the message to the relevant process. The transport layer ensures
that the message is delivered to the relevant process by supplying this address.

Session Layer: The Session Layer is in charge of establishing connections, maintaining sessions,
authenticating users, and ensuring security. Following are the responsibilities of session layer :
• Establishing, maintaining, and terminating a session: The layer enables the two processes to
create, use, and terminate a connection.
• Synchronization: This layer allows a process to insert checkpoints into the data that serve as
synchronisation points. These synchronisation points aid in the detection of errors so that
data may be correctly resynchronized, message ends are not severed prematurely, and data
loss is avoided.
• Dialog Controller: The session layer enables two systems to communicate in half-duplex or
full-duplex mode.

Presentation Layer: The Presentation Layer is often referred to as the Translation Layer. The data
from the application layer is retrieved and processed here so that it may be transmitted across the
network in the proper format. Following are the responsibilities of the presentation layer :
• It is responsible for translations such as ASCII to EBCDIC.
• Encryption/decryption: Data encryption is the process of converting data into a different
form or coding. The ciphertext is the encrypted data, and the plain text is the decoded data.
When encrypting and decrypting data, a key-value is used.
• Compression: This technique reduces the amount of data that must be transmitted over the
network.

Application Layer: The Application layer, which is implemented by network applications, is at the
very top of the OSI Reference Model stack of levels. Following are the responsibilities of the
application layer :
• This layer also acts as a window for application services to connect to the network and show
the information they receive to the user.
• It is also responsible for file transfer access and management.
• It is responsible for mail services.
• It is also responsible for directory services.
15. Differentiate between WHERE clause and HAVING clause in SQL.
The following table lists the differences between the WHERE clause and the HAVING clause:

WHERE HAVING

The WHERE Clause is used to filter records The HAVING Clause is used to filter
from a table depending on a condition records from groups based on a
that is given. condition that is given.

You can use the WHERE Clause without The HAVING Clause is ineffective
the GROUP BY Clause. without the GROUP BY Clause.

The WHERE Clause is used in row The HAVING Clause is used to


operations. implement column operations.

The WHERE clause can be used in Only the SELECT statement can employ
conjunction with the SELECT, UPDATE, and the HAVING Clause.
DELETE statements.

The aggregate function cannot be used in The HAVING Clause is capable of


the WHERE Clause. containing aggregate functions.

With single-row functions such as UPPER, With multiple-row functions like SUM,
LOWER, and so on, the WHERE Clause is COUNT, and others, the HAVING
used. Clause is employed.

The WHERE Clause comes before the After the GROUP BY Clause, the
GROUP BY Clause. HAVING Clause is used.

16. Write a query in SQL to find the details of an employee having the nth highest salary from a
given table Employee. The value of n needs to be taken as user input. Assume that the table
Employee has the following schema.
name - denoting the name of the employee
salary - denoting the salary of the employee
Approach:
We use the dense_rank() function to display the details of the employee having the nth highest
salary. The function DENSE_RANK returns the rank of a row in an ordered collection of rows as a
NUMBER. The ranks are in ascending order, starting with 1. Based on the values of the value exprs
in the order by clause, DENSE RANK computes the rank of each row returned from a query in relation
to the other rows as an analytic function.

Query:
select name, salary from(
select name, salary, dense_rank()
over(order by salary desc)input from Employee)
where input = &n;
Explanation:
In the above query, we first sort the data according to the descending order of the salary and assign
a rank to each of the employees starting from 1. In case of an event where the salary of two
employees is the same, they both are assigned the same rank. Then we display the data whose rank
is equal to the given input.

17. What do you understand by subnetting in the context of computer networks?


Subnetting is the process of dividing a larger network into smaller networks in order to preserve
security. As a result, smaller networks are easier to maintain. To divide a network into two pieces,
select one bit from the host ID part for each Subnet. To divide a network into four subnets, two bits
from the host id component must be chosen for each subnet and so on.

18. What are the advantages and disadvantages of subnetting?


Following are the advantages of subnetting :
• It protects one network from the intrusion of another. For example, in an organisation, the
Developer department's code must not be accessible by any other department.
• It's possible that some subnets will require higher network priority than others. A sales
department, for example, may need to host webcasts or video conferences. Subnetting
makes it possible to treat networks with different priorities differently.
• Maintenance is simple in the case of small networks.

Following are the disadvantages of subnetting :


• To reach a Process in the case of a single network, only three steps are required: Source Host
to Destination Network, Destination Network to Destination Host, and lastly Destination
Host to Process. Subnetting, on the other hand, necessitates four phases for Inter-Network
Communication. Source Host to Destination Network, Destination Network to appropriate
Subnet, Subnet to Host, and lastly Host to Process are the steps. As a result, Time complexity
rises. More time is necessary for communication or data transfer in the case of Subnet.
• Only two IP addresses are spent for Network Id and Broadcast address in a single network,
while two IP addresses are wasted for each Subnet in subnetting.
19. Differentiate between preemptive and non-preemptive scheduling algorithms.
Following are the differences between preemptive and non-preemptive scheduling algorithms:

Preemptive Scheduling Non-Preemptive Scheduling

The CPU is assigned to the processes in In non-preemptive scheduling, the


preemptive scheduling for a limited time CPU is allocated to the processes
until they terminate or switch to
the waiting state.

In Preemptive scheduling, when a higher In non-preemptive scheduling, the


priority task arrives, the executing process in executing process is not disturbed
preemptive scheduling is halted in the middle in the middle of its execution and
of its execution. waits until it is completed.

The overhead of transitioning a process from Non-preemptive scheduling, on the


the ready state to the running state, and vice other hand, has no overhead of
versa, as well as maintaining the ready queue, transitioning the process from
exists in Preemptive Scheduling. running to ready state.

In the case of preemptive scheduling, if a high- If CPU is allotted to a process with


priority process repeatedly appears in the a long burst time in non-
ready queue, the low-priority process will preemptive scheduling, processes
have to wait for a long time, and it may have with shorter burst times may be
to starve. forced to starve.

Preemptive scheduling achieves flexibility by Non-preemptive scheduling is


granting important processes access to the referred to as stiff because even if
CPU as soon as they enter the ready queue, a crucial process joins the ready
regardless of what task is already running. queue, the process's CPU is
unaffected.
20. Differentiate between SQL and NoSQL databases.

Following are the differences between SQL and NoSQL databases:

SQL Database NoSQL Database

SQL databases are referred to NoSQL databases are referred to as non-relational


as Relational Database or distributed databases.
Management Systems
(RDBMS).

SQL databases have fixed and NoSQL databases can have dynamic schema.
static predefined schema.

SQL databases are vertically NoSQL databases, on the other hand, are
scalable in almost all cases. horizontally scalable. By sharding, or adding
This means that by boosting multiple servers to your NoSQL database, you can
RAM, CPU, or SSD, you may handle greater traffic. It's the difference between
increase the demand on a adding more storeys to a single building and
single server. adding more buildings to a neighbourhood. NoSQL
databases can grow in size and power, making
them the best solution for huge or constantly
changing data sets.

SQL databases are table- Key-value pairs, document-based, graph


based. As a result, relational databases, and wide-column stores are all types of
SQL databases are a NoSQL databases.
preferable choice for
applications that require
multi-row transactions, such
as accounting systems, or for
legacy systems that were
designed with a relational
structure in mind.

The ACID characteristics The Brewers CAP theorem is followed by NoSQL


(Atomicity, Consistency, databases (Consistency, Availability and Partition
Isolation, and Durability) are tolerance).
followed by SQL databases.
21. Given two unsorted arrays. Check if the second array is a subarray of the first array.
Example:
Input :
arr1 = {2, 3, 0, 5, 1, 1, 2}
arr2 = {3, 0, 5, 1}
Output :
True
Input :
arr1 = {3, 4, 5, 1, 2, 7}
arr2 = {4, 1, 2}
Output :
False

Approach:
We use two pointers to explore both the array and the subarray. We maintain the pointer of array
arr2[] and increase the pointer of both arrays if any element of arr1[] matches the first element of
arr2[], otherwise set the pointer of arr1 to the next element of the previous starting point and reset
the pointer of arr2 to 0. If all of arr2's elements match, print True; otherwise, print False.
The following is how the above strategy is put into action:

Code:
#include <bits/stdc++.h>
using namespace std;
//function to check if the second array is a subarray of the first array
bool checkSubArray(int arr1[], int arr2[], int n, int m)
{
int i = 0, j = 0;
while (i < n && j < m) {
// If element matches
// increment both pointers
if (arr1[i] == arr2[j]) {
i++;
j++;

// checking if we have reached the end of the second array


if (j == m)
return true;
}

else {
i = i - j + 1;// setting the pointer of the first array to the next element of the previous starting
point
j = 0; // resetting the pointer of the second array to 0.
}
}
return false;
}
int main()
{
int arr1[] = { 2, 3, 0, 5, 1, 1, 2 };
int arr2[] = { 3, 0, 5, 1 };
int n = sizeof(arr1) / sizeof(arr1[0]);
int m = sizeof(arr2) / sizeof(arr2[0]);
bool res = checkSubArray(arr1, arr2, n, m);
if (res)
cout << "True\n";
else
cout << "False\n";
return 0;
}

Explanation:
In the above code, the function checkSubArray checks whether the second array is a sub array of
the first array or not and returns the output correspondingly. We maintain two pointers, one for the
first array and the other for the second array. If the elements match, we increment both the
pointers; otherwise, we reset the pointers.

22. Given a string as an input, write a program to reverse the words in the given string and display
the new string.
Example:
Input:
str = “Talentio Academy”
Output :
Academy Talentio
Approach:
We maintain a vector of strings. We traverse the given string and keep forming the word until a
space is encountered. When space is encountered we add the word formed to the vector of strings.
In the end, we print the vector of strings in reverse format.
Code :
#include <bits/stdc++.h>
using namespace std;
// function to reverse the words in an inputted string
void displayModifiedString(string str)
{
// vector to store all the words of the inputted string
vector<string> arr;
string temp = ""; // variable to form each word of the string
for (int i = 0; i < str.length(); i++)
{

// if space is encountered, we push the formed word to the vector


if (str[i] == ' ')
{
arr.push_back(temp);
temp = "";// resetting the temp variable
}
// we keep forming the word
else
temp += str[i];
}
arr.push_back(temp);// we push back the last formed word
// we print the vector in the reverse order
for (int i = arr.size() - 1; i > 0; i--)
cout << arr[i] << " ";
cout << arr[0] << endl;
}
int main()
{
string str = “talentio is best";
displayModifiedString(str);
return 0;
}

Output :
best is talentio
Explanation :
In the above code, the function displayModifiedString takes a string input and displays the modified
string with words in reverse order. We keep forming a word until a space character is found. Once
space is found, we push back the word to the vector. Lastly, we display the vector in reverse order.
HR Question :
1. Tell me about yourself in a few words.
2. Would you consider relocating to another part of India?
3. What do you hope to get out of this job?
4. What drew you to MindTree in the first place?
5. In five years, where do you see yourself?
6. Tell me about your internships and projects.
7. What prompted you to look for a new job? (Many seasoned professionals on the lookout for a
new job ask this question.)
8. Tell me about a moment when you faced a challenge and how you dealt with it.
9. Let's pretend you're in charge of a group. One of your team members is underperforming and,
despite many warnings, refuses to modify his or her attitude. What will you do if you find yourself
in this situation?
10. Describe a circumstance in which you tried your hardest but failed.

You might also like