Normalization is a process of decomposing the relations into relations with fewer
attributes.
Normalization is used to minimize the redundancy from a [Link] main reason
for normalizing the relations is removing these anomalies. Failure to eliminate
anomalies leads to data redundancy and can cause data integrity and other problems
as the database grows.
Types of Normal form:
[Link] First normal form attributes must be simple and single valued .It disallows
multi-valued attribute or composite attribute.
[Link] the 2NF, relation must be in 1NF and all non-prime attributes are fully and
functionally dependent on the primary key.
3.A relation is in third normal form if it holds atleast one of the following
conditions for every non-trivial functional dependency X → Y.
X is a super key.
Y is a prime attribute, i.e., each element of Y is part of some candidate key.
4.A table is in BCNF if for every functional dependency X → Y, X is the super key
of the table.
Transaction in DBMS
Transaction is a collection of data manipulation statements which is considered
as the smallest unit of execution by DBMS. If all the statements are executed
successfully then the transaction is said to be successful. A transaction has
ACID properties as follows.
Atomicity: Transaction is an atomic unit of processing. Either it will be
executed entirely or not at all.
Correctness/Consistency preserving: A transaction must be logically correct so
that execution of the transaction takes the database from one consistent state
to another.
Isolation: A transaction should appear as if it is being executed in isolation
from other transactions. In other words, it is not interfered by other
transactions executed concurrently.
Durability: If a transaction completely successfully (commits) then its effect
must persist in the database. Changes must not be lost due to any failure.
Example:
Suppose, certain amount of money has to be transferred between two
accounts. So, it is to be ensured that balance of source account will be reduced
and that of destination account will be increased. Both the changes are to be
made. So, both the updates together will form the transaction. Atomicity
ensures that either both are done or not. To ensure consistency accounts will
be incremented or decremented by the same amount. The logical correctness
has to be ensured by the programmer. If multiple transactions are running
concurrently and working with common data item then race condition (as you
have studied in OS) must not occur. Isolation property safeguards it. Once a
transaction completes successfully, it is to be guaranteed that the updates are
available in the database, even if certain failure occurs after that. That’s what
the durability is for.
Necessary Conditions for the Occurrence of a Deadlock
Let’s explain all four conditions related to deadlock in the context of the
scenario with two processes and two resources:
Mutual Exclusion
This condition requires that at least one resource be held in a non-shareable mode,
which means that only one process can use the resource at any given time. Both
Resource 1 and Resource 2 are non-shareable in our scenario, and only one process
can have exclusive access to each resource at any given time.
As an example:
Process A obtains Resource 1.
Process B acquires Resource 2.
Hold and Wait
The hold and wait condition specifies that a process must be holding at least one
resource while waiting for other processes to release resources that are currently
held by other processes. In our example,
Process A has Resource 1 and is awaiting Resource 2.
Process B currently has Resource 2 and is awaiting Resource 1.
Both processes hold one resource while waiting for the other, satisfying the hold
and wait condition.
No Preemption
Preemption is the act of taking a resource from a process before it has finished
its task. According to the no preemption condition, resources cannot be taken
forcibly from a process a process can only release resources voluntarily after
completing its task. In our scenario, neither Process A nor Process B can be forced
to release the resources in their possession. The processes can only release
resources voluntarily.
Circular Wait
This condition implies that circular processes must exist, with each process
waiting for a resource held by the next process in the chain. In our scenario,
Process A is waiting for Resource 2, which is being held by Process B.
Process B is awaiting Resource 1 from Process A.
This circular chain of dependencies causes a deadlock because neither process can
proceed, resulting in a system shutdown.
To summarise, in the context of two processes and two resources, all four
conditions (mutual exclusion, hold and wait, no preemption, and circular wait) must
be met at the same time. Deadlocks are a major concern in operating systems, and
various techniques are used to avoid them to prevent, detect, and recover from
them.
A class can be understood as a template or a blueprint, which contains some values,
known as member data or member, and some set of rules, known as behaviors or
functions.
An object refers to the instance of the class, which contains the instance of the
members and behaviors defined in the class template.
Encapsulation is the
process of binding data members and methods of a program together to do a specific
job, without revealing unnecessary details.
Polymorphism refers to the process by which an
object behaves differently under different circumstances or contexts. Compile-time
polymorphism and Run time polymorphism are the two types of polymorphisms.
[Link] time polymorphism, also known as Static
Polymorphism, refers to the type of Polymorphism that happens at compile [Link]
compiler looks at the method signature
and decides which method to invoke for a particular method call at compile time.
[Link] polymorphism, also known as Dynamic
Polymorphism, refers to the type of Polymorphism that happens at the run time.
Example:
class AnyVehicle{
public void move(){
[Link](“Any vehicle should move!!”);
}
}
class Bike extends AnyVehicle{
public void move(){
[Link](“Bike can move too!!”);
}
}
class Test{
public static void main(String[] args){
AnyVehicle vehicle = new Bike();
// In the above statement, as you can see, the object vehicle is of type AnyVehicle
// But the output of the below statement will be “Bike can move too!!”,
// because the actual implementation of object ‘vehicle’ is decided during runtime
v
vehicle = new AnyVehicle();
// Now, the output of the below statement will be “Any vehicle should move!!”,
[Link]();
}
}
C++ supports compile-time polymorphism with
the help of features like templates, function overloading, and default
arguments.
Runtime Polymorphism: C++ supports Runtime polymorphism with the help of
features like virtual functions.
Overloading is a compile-time polymorphism feature in which an entity has multiple
implementations with the same name. For example, Method overloading and
Operator overloading.
Whereas Overriding is a runtime polymorphism feature in which an entity has the
same name, but its implementation changes during execution. For example, Method
overriding.
Inheritance is the mechanism by
which an object or class (referred to as a child) is created using the definition
of
another object or class (referred to as a parent). It helps to facilitate code
reuse.
Constructors are special methods whose name is the same as the class name. The
constructors serve the special purpose of initializing the objects.
For example, suppose there is a class with the name “MyClass”, then when you
instantiate this class, you pass the syntax:
MyClass myClassObject = new MyClass();
Types:
[Link] constructor: The default constructor is the constructor which doesn’t
take
any argument. It has no parameters.
[Link] constructor: The constructors that take some arguments are known
as parameterized constructors.
[Link] constructor: A copy constructor is a member function that initializes an
object
using another object of the same class.
Example :
class ABC
{
int x;
ABC(int y)
{
x = y;
}
// Copy constructor
ABC(ABC abc)
{
x = abc.x;
}
}
Destructors are automatically called when an object
is being destroyed.
***Are class and structure the same? If not, what's the
difference between a class and a structure?
--->No, class and structure are not the same. Though they appear to be similar,
they have
differences that make them [Link] Abstraction
cannot be achieved with the help of structure, but with class, Abstraction is
majorly used.
An interface refers to a special type of class, which contains methods, but not
their
definition. Only the declaration of methods is allowed inside an interface. To use
an
interface, you cannot create objects. Instead, you need to implement that interface
and define the methods for their implementation.
The main difference between the abstract class and interface is that, when
an interface is implemented, the subclass must define all its methods and provide
its
implementation. Whereas when an abstract class is inherited, the subclass does not
need to provide the definition of its abstract method, until and unless the
subclass is
using it.
Also, an abstract class can contain abstract methods as well as non-abstract.