Understanding Computer Network Topologies
Understanding Computer Network Topologies
● Network : A network is a set of devices that are connected with a physical media link. In
a network, two or more nodes are connected by a physical link or two or more networks
are connected by one or more nodes. A network is a collection of devices connected to
each other to allow the sharing of data.
● Ring :
1. Ring topology is a network topology in which nodes are exactly connected to two
or more nodes and thus, forming a single continuous path for the transmission.
2. It does not need any central server to control the connectivity among the nodes.
3. If the single node is damaged, then the whole network fails.
4. Ring topology is very rarely used as it is expensive, difficult to install and
manage.
5. Examples of Ring topology are SONET network, SDH network, etc.
● Bus :
1. Bus topology is a network topology in which all the nodes are connected to a
single cable known as a central cable or bus.
2. It acts as a shared communication medium, i.e., if any device wants to send the
data to other devices, then it will send the data over the bus which in turn sends
the data to all the attached devices.
3. Bus topology is useful for a small number of devices.
4. As if the bus is damaged then the whole network fails.
● Mesh :
1. Mesh topology is a network topology in which all the nodes are individually
connected to other nodes.
2. It does not need any central switch or hub to control the connectivity among the
nodes.
3. Mesh topology is categorized into two parts: Fully connected mesh topology:
In this topology, all the nodes are connected to each other. Partially connected
mesh topology: In this topology, all the nodes are not connected to each other.
4. It is robust as a failure in one cable will only disconnect the specified computer
connected to this cable.
5. Mesh topology is rarely used as installation and configuration are difficult when
connectivity gets more.
6. Cabling cost is high as it requires bulk wiring.
● Tree :
1. Tree topology is a combination of star and bus topology. It is also known as the
expanded star topology.
2. In tree topology, all the star networks are connected to a single bus.
3. Ethernet protocol is used in this topology.
4. In this, the whole network is divided into segments known as star networks which
can be easily maintained. If one segment is damaged, there is no effect on other
segments.
5. Tree topology depends on the "main bus," and if it breaks, then the whole
network gets damaged
● Hybrid :
1. A hybrid topology is a combination of different topologies to form a resulting
topology.
2. If star topology is connected with another star topology, then it remains a star
topology. If star topology is connected with different topology, then it becomes a
Hybrid topology.
3. It provides flexibility as it can be implemented in a different network environment.
● Different Types of Networks : (Imp) - Networks can be divided on the basis of area of
distribution. For example:
● PAN (Personal Area Network): Its range limit is up to 10 meters. It is created for
personal use. Generally, personal devices are connected to this network. For example
computers, telephones, fax, printers, etc.
● LAN (Local Area Network): It is used for a small geographical location like office,
hospital, school, etc.
● HAN (House Area Network): It is actually a LAN that is used within a house and used to
connect homely devices like personal computers, phones, printers, etc.
● CAN (Campus Area Network): It is a connection of devices within a campus area which
links to other departments of the organization within the same campus.
● MAN (Metropolitan Area Network): It is used to connect the devices which span to
large cities like metropolitan cities over a wide geographical area.
● WAN (Wide Area Network): It is used over a wide geographical location that may range
to connect cities and countries.
● GAN (Global Area Network): It uses satellites to connect devices over the global area.
● VPN (Virtual Private Network) : VPN or the Virtual Private Network is a private WAN
(Wide Area Network) built on the internet. It allows the creation of a secured tunnel
(protected network) between different networks using the internet (public network). By
using the VPN, a client can connect to the organization’s network remotely.
● Advantages of VPN :
2. VPN is used for secure transactions and confidential data transfer between
multiple offices located in different geographical locations.
4. VPN encrypts the internet traffic and disguises the online identity.
● Types of VPN :
● Access VPN: Access VPN is used to provide connectivity to remote mobile users and
telecommuters. It serves as an alternative to dial-up connections or ISDN (Integrated
Services Digital Network) connections. It is a low-cost solution and provides a wide
range of connectivity.
● Site-to-Site VPN: A Site-to-Site or Router-to-Router VPN is commonly used in large
companies having branches in different locations to connect the network of one office to
another in different locations. There are 2 sub-categories as mentioned below:
● Intranet VPN: Intranet VPN is useful for connecting remote offices in different
geographical locations using shared infrastructure (internet connectivity and servers)
with the same accessibility policies as a private WAN (wide area network).
● Extranet VPN: Extranet VPN uses shared infrastructure over an intranet, suppliers,
customers, partners, and other entities and connects them using dedicated connections.
2. DataLink Layer
● It is used for transferring the data from one node to another node.
● It receives the data from the network layer and converts the data into data frames
and then attaches the physical address to these frames which are sent to the
physical layer.
● It enables the error-free transfer of data from one node to another node.
● Frame synchronization: Data-link layer converts the data into frames, and it ensures
that the destination must recognize the starting and ending of each frame.
● Flow control: Data-link layer controls the data flow within the network.
● Error control: It detects and corrects the error occurred during the transmission from
source to destination.
● Addressing: Data-link layers attach the physical address with the data frames so that
the individual machines can be easily identified.
● Link management: Data-link layer manages the initiation, maintenance and termination
of the link between the source and destination for the effective exchange of data.
3. Network Layer
● Network layer converts the logical address into the physical address.
● The routing concept means it determines the best route for the packet to travel from
source to the destination.
Functions of network layer :
● Routing: The network layer determines the best route from source to destination. This
function is known as routing.
● Logical addressing: The network layer defines the addressing scheme to identify each
device uniquely.
● Packetizing: The network layer receives the data from the upper layer and converts the
data into packets. This process is known as packetizing.
● Internetworking: The network layer provides the logical connection between the
different types of networks for forming a bigger network.
4. Transport Layer
● It delivers the message through the network and provides error checking so that no error
occurs during the transfer of data.
5. Session Layer
● The main responsibility of the session layer is beginning, maintaining and ending the
communication between the devices.
● Session layer also reports the error coming from the upper layers.
● Session layer establishes and maintains the session between the two users.
6. Presentation Layer
● The presentation layer is also known as a Translation layer as it translates the data from
one format to another format.
● At the sender side, this layer translates the data format used by the application layer to
the common format and at the receiver side, this layer translates the common format into
a format used by the application layer.
Functions of presentation layer:
○ Data conversion
○ Data compression
○ Data encryption
7. Application Layer
● Application layer protocols are file transfer protocol, simple mail transfer protocol,
domain name system, etc.
● The most widely used application protocol is HTTP(Hypertext transfer protocol ). A user
sends the request for the web page using HTTP.
● TCP/IP Reference Model : It is a compressed version of the OSI model with only 4
layers. It was developed by the US Department of Defence (DoD) in the 1860s. The
name of this model is based on 2 standard protocols used i.e. TCP (Transmission
Control Protocol) and IP (Internet Protocol).
1. Link : Decides which links such as serial lines or classic Ethernet must be used
to meet the needs of the connectionless internet layer. Ex - Sonet, Ethernet
2. Internet : The internet layer is the most important layer which holds the whole
architecture together. It delivers the IP packets where they are supposed to be
delivered. Ex - IP, ICMP.
3. Transport : Its functionality is almost the same as the OSI transport layer. It
enables peer entities on the network to carry on a conversation. Ex - TCP, UDP
(User Datagram Protocol)
4. Application : It contains all the higher-level protocols. Ex - HTTP, SMTP, RTP,
DNS.
HTTP is the HyperText Transfer Protocol which defines the set of rules and standards
on how the information can be transmitted on the World Wide Web (WWW). It helps the
web browsers and web servers for communication. It is a ‘stateless protocol’ where each
command is independent with respect to the previous command. HTTP is an
application layer protocol built upon the TCP. It uses port 80 by default.
● DNS (Imp) :
1. DNS is an acronym that stands for Domain Name [Link] was introduced
by Paul Mockapetris and Jon Postel in 1983.
2. It is a naming system for all the resources over the internet which includes
physical nodes and applications. It is used to locate resources easily over a
network.
3. DNS is an internet which maps the domain names to their associated IP
addresses.
4. Without DNS, users must know the IP address of the web page that you wanted
to access.
● Working of DNS (Imp): If you want to visit the website of "shaurya", then the user will
type "[Link] into the address bar of the web browser. Once the
domain name is entered, then the domain name system will translate the domain name
into the IP address which can be easily interpreted by the computer. Using the IP
address, the computer can locate the web page requested by the user.
● DNS Forwarder : A forwarder is used with a DNS server when it receives DNS queries
that cannot be resolved quickly. So it forwards those requests to external DNS servers
for resolution. A DNS server which is configured as a forwarder will behave differently
than the DNS server which is not configured as a forwarder.
● SMTP Protocol : SMTP is the Simple Mail Transfer Protocol. SMTP sets the rule for
communication between servers. This set of rules helps the software to transmit emails
over the internet. It supports both End-to-End and Store-and-Forward methods. It is in
always-listening mode on port 25.
● Difference Between TCP (Transmission Control Protocol) and UDP (User Datagram
Protocol):
1. TCP is a connection-oriented protocol, whereas UDP is a connectionless
protocol. A key difference between TCP and UDP is speed, as TCP is
comparatively slower than UDP. Overall, UDP is a much faster, simpler, and
efficient protocol, however, retransmission of lost data packets is only possible
with TCP
2. TCP provides extensive error checking mechanisms. It is because it provides
flow control and acknowledgment of data. UDP has only the basic error
checking mechanism using checksums.
Important Protocols
A protocol is a set of rules which is used to govern all the aspects of information
[Link] main elements of a protocol are:
● Syntax: It specifies the structure or format of the data. It also specifies the order in which
they are presented.
● Timing: Timing specifies two characteristics: When data should be sent and how fast it
can be sent.
2. The main difference between MAC and IP address is that MAC Address is used to
ensure the physical address of a computer. It uniquely identifies the devices on a
network. While IP addresses are used to uniquely identify the connection of a network
with that device taking part in a network.
● Firewall : The firewall is a network security system that is used to monitor the incoming
and outgoing traffic and blocks the same based on the firewall security policies. It acts as
a wall between the internet (public network) and the networking devices (a private
network). It is either a hardware device, software program, or a combination of both. It
adds a layer of security to the network.
Important Key Points
1. What happens when you enter [Link] in the web browser? (Most Imp)
Steps :
● Check the browser cache first if the content is fresh and present in the cache display the
same.
● If not, the browser checks if the IP of the URL is present in the cache (browser and OS)
if not then requests the OS to do a DNS lookup using UDP to get the corresponding IP
address of the URL from the DNS server to establish a new TCP connection.
● A new TCP connection is set between the browser and the server using three-way
handshaking.
● An HTTP request is sent to the server using the TCP connection.
● The web servers running on the Servers handle the incoming HTTP request and send
the HTTP response.
● The browser processes the HTTP response sent by the server and may close the TCP
connection or reuse the same for future requests.
● If the response data is cacheable then browsers cache the same.
● Browser decodes the response and renders the content.
2. Hub: Hub is a networking device which is used to transmit the signal to each port
(except one port) to respond from which the signal was received. Hub is operated on a
Physical layer. In this packet filtering is not available. It is of two types: Active Hub,
Passive Hub.
3. A subnet is a network inside a network achieved by the process called subnetting which
helps divide a network into subnets. It is used for getting a higher routing efficiency and
enhances the security of the network. It reduces the time to extract the host address
from the routing table.
4. The reliability of a network can be measured by the following factors:
● Downtime: The downtime is defined as the required time to recover.
● Failure Frequency: It is the frequency when it fails to work the way it is intended.
● Catastrophe: It indicates that the network has been attacked by some unexpected event
such as fire, earthquake.
5. There are mainly two criteria which make a network effective and efficient:
● Performance : performance can be measured in many ways like transmit time and
response time.
● Robustness: robustness specifies the quality or condition of being strong and in good
condition.
● Security: It specifies how to protect data from unauthorized access and viruses.
6. Node and Link : A network is a connection setup of two or more computers directly
connected by some physical mediums like optical fiber or coaxial cable. This physical
medium of connection is known as a link, and the computers that it is connected to are
known as nodes.
7. Gateway and router : A node that is connected to two or more networks is commonly
known as a gateway. It is also known as a router. It is used to forward messages from
one network to another. Both the gateway and router regulate the traffic in the
network. Differences between gateway and router: A router sends the data between
two similar networks while gateway sends the data between two dissimilar networks.
8. NIC (Imp) : NIC stands for Network Interface Card. It is a peripheral card attached to
the PC to connect to a network. Every NIC has its own MAC address that identifies the
PC on the network. It provides a wireless connection to a local area network. NICs were
mainly used in desktop computers.
9. POP3 stands for Post Office Protocol version3. POP is responsible for accessing the
mail service on a client machine. POP3 works on two models such as Delete mode and
Keep mode.
10. Private IP Address - There are three ranges of IP addresses that have been reserved
for IP addresses. They are not valid for use on the internet. If you want to access the
internet on these private IPs, you must use a proxy server or NAT server.
12. Netstat : It is a command line utility program. It gives useful information about the
current TCP/IP setting of a connection.
13. Ping : The "ping" is a utility program that allows you to check the connectivity between
the network devices. You can ping devices using its IP address or name.
14. The processes on each machine that communicate at a given layer are called
peer-peer processes. (P2P).
15. Unicasting: If the message is sent to a single node from the source then it is known as
unicasting. This is commonly used in networks to establish a new connection.
Anycasting: If the message is sent to any of the nodes from the source then it is known
as anycasting. It is mainly used to get the content from any of the servers in the Content
Delivery System.
Multicasting: If the message is sent to a subset of nodes from the source then it is
known as multicasting. Used to send the same data to multiple receivers.
Broadcasting: If the message is sent to all the nodes in a network from a source then it
is known as broadcasting. DHCP and ARP in the local network use broadcasting.
DBMS & SQL NOTES
Database: A database is a collection of related data which represents some aspect of the real
world. A database system is designed to be built and populated with data for a certain task.
Database Management System (DBMS) is a software for storing and retrieving users' data while
considering appropriate security measures. It consists of a group of programs which manipulate
the database. The DBMS accepts the request for data from an application and instructs the
operating system to provide the specific data. In large systems, a DBMS helps users and other
third-party software to store and retrieve data.
ER diagram:
● It shows all the constraints and relationships that exist among the different components.
Entity Set:
Relationship:
Cardinality Constraint:
Cardinality constraint defines the maximum number of relationship instances in which an entity
can participate.
● One-to-One Cardinality - An entity in set A can be associated with at most one entity in
set B. An entity in set B can be associated with at most one entity in set A.
● One-to-Many Cardinality - An entity in set A can be associated with any number (zero or
more) of entities in set B. An entity in set B can be associated with at most one entity in
set A.
● Many-to-One Cardinality - An entity in set A can be associated with at most one entity in
set B. An entity in set B can be associated with any number of entities in set A. ●
Many-to-Many Cardinality - An entity in set A can be associated with any number (zero or
more) of entities in set B. An entity in set B can be associated with any number (zero or
more) of entities in set A.
Attributes:
Attributes are the descriptive properties which are owned by each entity of an Entity Set.
Types of Attributes:
● Simple Attributes - Simple attributes are those attributes which cannot be divided
further. Ex. Age
● Composite Attributes - Composite attributes are those attributes which are composed
of many other simple attributes. Ex. Name, Address
● Multi Valued Attributes - Multi valued attributes are those attributes which can take
more than one value for a given entity from an entity set. Ex. Mobile No, Email ID ●
Derived Attributes - Derived attributes are those attributes which can be derived from
other attribute(s). Ex. Age can be derived from DOB.
● Key Attributes - Key attributes are those attributes which can identify an entity uniquely
in an entity set. Ex. Roll No.
Constraints:
Relational constraints are the restrictions imposed on the database contents and
operations. They ensure the correctness of data in the database.
● Domain Constraint - Domain constraint defines the domain or set of values for an
attribute. It specifies that the value taken by the attribute must be the atomic value from
its domain.
● Tuple Uniqueness Constraint - Tuple Uniqueness constraint specifies that all the tuples
must be necessarily unique in any relation.
● Key Constraint - All the values of the primary key must be unique. The value of the
primary key must not be null.
● Entity Integrity Constraint - Entity integrity constraint specifies that no attribute of
primary key must contain a null value in any relation.
● Referential Integrity Constraint - It specifies that all the values taken by the foreign key
must either be available in the relation of the primary key or be null.
Keys:
A key is a set of attributes that can identify each tuple uniquely in the given relation.
Types of Keys:
● Super Key - A superkey is a set of attributes that can identify each tuple uniquely in the
given relation. A super key may consist of any number of attributes.
● Candidate Key - A set of minimal attribute(s) that can identify each tuple uniquely in the
given relation is called a candidate key.
● Primary Key - A primary key is a candidate key that the database designer selects while
designing the database. Primary Keys are unique and NOT NULL.
● Alternate Key - Candidate keys that are left unimplemented or unused after
implementing the primary key are called as alternate keys.
● Foreign Key - An attribute ‘X’ is called as a foreign key to some other attribute ‘Y’ when its
values are dependent on the values of attribute ‘Y’. The relation in which attribute ‘Y’ is
present is called as the referenced relation. The relation in which attribute ‘X’ is present
is called as the referencing relation.
● Composite Key - A primary key composed of multiple attributes and not just a single
attribute is called a composite key.
● Unique Key - It is unique for all the records of the table. Once assigned, its value cannot
be changed i.e. it is non-updatable. It may have a NULL value.
Functional Dependency:
In any relation, a functional dependency α → β holds if- Two tuples having same value
of attribute α also have same value for attribute β.
Decomposition of a Relation:
The process of breaking up or dividing a single relation into two or more sub relations is called
the decomposition of a relation.
Properties of Decomposition:
Types of Decomposition:
Normalization:
In DBMS, database normalization is a process of making the database consistent by-
● Reducing the redundancies
● Ensuring the integrity of data through lossless decomposition
Normal Forms:
● First Normal Form (1NF) - A given relation is called in First Normal Form (1NF) if each cell
of the table contains only an atomic value i.e. if the attribute of every tuple is either
single valued or a null value.
● Second Normal Form (2NF) - A given relation is called in Second Normal Form (2NF) if
and only if
o Relation already exists in 1NF.
o No partial dependency exists in the relation.
A → B is called a partial dependency if and only if- A is a subset of some
candidate key and B is a non-prime attribute.
● Third Normal Form (3NF) - A given relation is called in Third Normal Form (3NF) if and
only if
o Relation already exists in 2NF.
o No transitive dependency exists for non-prime attributes.
A → B is called a transitive dependency if and only if- A is not a super key and B
is a non-prime attribute.
● Boyce-Codd Normal Form - A given relation is called in BCNF if and only if
o Relation already exists in 3NF.
o For each non-trivial functional dependency ‘A → B’, A is a super key of the
relation.
Transaction:
Transaction is a single logical unit of work formed by a set of operations.
Operations in Transaction:
● Read Operation - Read(A) instruction will read the value of ‘A’ from the database and
will store it in the buffer in main memory.
● Write Operation – Write(A) will write the updated value of ‘A’ from the buffer to the
database.
Transaction States:
● Active State –
o This is the first state in the life cycle of a transaction.
o A transaction is called in an active state as long as its instructions are getting
executed.
o All the changes made by the transaction now are stored in the buffer in main
memory.
● Partially Committed State –
o After the last instruction of the transaction has been executed, it enters into a
partially committed state.
o After entering this state, the transaction is considered to be partially committed.
o It is not considered fully committed because all the changes made by the
transaction are still stored in the buffer in main memory.
● Committed State –
o After all the changes made by the transaction have been successfully stored into
the database, it enters into a committed state.
o Now, the transaction is considered to be fully committed.
● Failed State –
o When a transaction is getting executed in the active state or partially committed
state and some failure occurs due to which it becomes impossible to continue
the execution, it enters into a failed state.
● Aborted State –
o After the transaction has failed and entered into a failed state, all the changes
made by it have to be undone.
o To undo the changes made by the transaction, it becomes necessary to roll back
the transaction.
o After the transaction has rolled back completely, it enters into an aborted state.
● Terminated State –
o This is the last state in the life cycle of a transaction.
o After entering the committed state or aborted state, the transaction finally
enters into a terminated state where its life cycle finally comes to an end.
ACID Properties:
To ensure the consistency of the database, certain properties are followed by all the
transactions occurring in the system. These properties are called as ACID Properties of a
transaction.
● Atomicity –
o This property ensures that either the transaction occurs completely or it does not
occur at all.
o In other words, it ensures that no transaction occurs partially.
● Consistency –
o This property ensures that integrity constraints are maintained.
o In other words, it ensures that the database remains consistent before and after
the transaction.
● Isolation –
o This property ensures that multiple transactions can occur simultaneously
without causing any inconsistency.
o The resultant state of the system after executing all the transactions is the same
as the state that would be achieved if the transactions were executed serially one
after the other.
● Durability –
o This property ensures that all the changes made by a transaction after its
successful execution are written successfully to the disk.
o It also ensures that these changes exist permanently and are never lost even if
there occurs a failure of any kind.
Schedules:
The order in which the operations of multiple transactions appear for execution is called as a
schedule.
● Serial Schedules –
o All the transactions execute serially one after the other.
o When one transaction executes, no other transaction is allowed to execute.
o Serial schedules are always- Consistent, Recoverable, Cascadeless and Strict. ●
Non-Serial Schedules –
o Multiple transactions execute concurrently.
o Operations of all the transactions are inter leaved or mixed with each other.
o Non-serial schedules are not always- Consistent, Recoverable, Cascadeless and
Strict.
Serializability –
Non-Serializable Schedules –
● A non-serial schedule which is not serializable is called a non-serializable schedule. ● A
non-serializable schedule is not guaranteed to produce the same effect as produced by
some serial schedule on any consistent database.
● Non-serializable schedules- may or may not be consistent, may or may not be
recoverable.
● Irrecoverable Schedules –
If in a schedule,
o A transaction performs a dirty read operation from an uncommitted transaction
o And commits before the transaction from which it has read the value then such a
schedule is known as an Irrecoverable Schedule.
● Recoverable Schedules –
If in a schedule,
o A transaction performs a dirty read operation from an uncommitted transaction
o And its commit operation is delayed till the uncommitted transaction either
commits or roll backs
then such a schedule is known as a Recoverable Schedule.
Types of Recoverable Schedules –
X (Cross Product) Cross product of relations, returns m*n rows where m and n
are number of rows in R1 and R2 respectively.
U (Union) Return those tuples which are either in R1 or in R2. Max no.
of rows returned = m+n and Min no. of rows returned =
max(m,n)
−(Minus) R1-R2 returns those tuples which are in R1 but not in R2.
Max no. of rows returned = m and Min no. of rows
returned = m-n
∩ (Intersection) Returns those tuples which are in both R1 and R2. Max no.
of rows returned = min(m,n) and Min no. of rows returned
=0
⟖(Right Outer Join) When applying join on two relations R and S, some tuples of R
or S do not appear in the result set which does not satisfy the
join conditions. But Right Outer Joins gives all tuples of S in
the result set. The tuples of S which do not satisfy the join
condition will have values as NULL for attributes of R.
⟗(Full Outer Join) When applying join on two relations R and S, some tuples of R
or S do not appear in the result set which does not satisfy the
join conditions. But Full Outer Joins gives all tuples of S and all
tuples of R in the result set. The tuples of S which do not
satisfy the join condition will have values as NULL for
attributes of R and vice versa.
/(Division Operator) Division operator A/B will return those tuples in A which are
associated with every tuple of B. Note: Attributes of B should
be a proper subset of attributes of A. The attributes in A/B will
be Attributes of A- Attribute of B.
File Structures:
● Primary Index: A primary index is an ordered file, records of fixed length with two fields.
First field is the same as the primary key as a data file and the second field is a pointer to
the data block, where the key is available. The average number of block accesses using
index = log2 Bi + 1, where Bi = number of index blocks.
● Clustering Index: Clustering index is created on data file whose records are physically
ordered on a non-key field (called Clustering field).
● Secondary Index: Secondary index provides secondary means of accessing a file for
which primary access already exists.
B Trees
At every level , we have Key and Data Pointer and data pointer points to either block or record.
Properties of B-Trees:
Root of B-tree can have children between 2 and P, where P is Order of tree.
Order of tree – Maximum number of children a node can have.
Searching time will be less in B+ trees, since it doesn’t have record pointers in non-leaf because
of which depth will decrease.
SQL
DDL:
DDL is short name of Data Definition Language, which deals with database schemas and
descriptions, of how the data should reside in the database.
● CREATE - to create a database and its objects like (table, index, views, store procedure,
function, and triggers)
● ALTER - alters the structure of the existing database
● DROP - delete objects from the database
● TRUNCATE - remove all records from a table, including all spaces allocated for the
records are removed
● RENAME - rename an object
DML:
DML is short name of Data Manipulation Language which deals with data manipulation and
includes most common SQL statements such SELECT, INSERT, UPDATE, DELETE, etc., and it is
used to store, modify, retrieve, delete and update data in a database.
TCL:
TCL is short name of Transaction Control Language which deals with a transaction within a
database.
SQL is a standard language for storing, manipulating and retrieving data in databases.
SELECT:
Syntax -
Ex –
SELECT DISTINCT:
The SELECT DISTINCT statement is used to return only distinct (different) values.
Syntax –
● SELECT DISTINCT column1, column2, ...
FROM table_name;
Ex –
● SELECT DISTINCT Country FROM Customers;
WHERE:
Syntax –
Ex –
= Equal
<> Not equal. Note: In some versions of SQL this operator may be written as !=
The WHERE clause can be combined with AND, OR, and NOT operators.
The AND and OR operators are used to filter records based on more than one condition:
● The AND operator displays a record if all the conditions separated by AND are TRUE.
● The OR operator displays a record if any of the conditions separated by OR is TRUE.
Ex –
● SELECT * FROM Customers
WHERE Country='Germany' AND City='Berlin';
● SELECT * FROM Customers
WHERE Country='Germany' AND (City='Berlin' OR City='München');
ORDER BY:
The ORDER BY keyword is used to sort the result-set in ascending or descending order.
The ORDER BY keyword sorts the records in ascending order by default. To sort the records in
descending order, use the DESC keyword.
Syntax –
Ex –
● SELECT * FROM Customers
ORDER BY Country;
● SELECT * FROM Customers
ORDER BY Country ASC, CustomerName DESC;
INSERT INTO:
*In the second syntax, make sure the order of the values is in the same order as the columns in
the table.
Ex –
NULL Value:
It is not possible to test for NULL values with comparison operators, such as =, <, or
<>. We will have to use the IS NULL and IS NOT NULL operators instead.
Syntax –
● SELECT column_names
FROM table_name
WHERE column_name IS NULL;
● SELECT column_names
FROM table_name
WHERE column_name IS NOT NULL;
Ex –
● SELECT CustomerName, ContactName, Address
FROM Customers
WHERE Address IS NULL;
UPDATE:
● UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
Ex –
● UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;
DELETE:
In 2ndsyntax, all rows are deleted. The table structure, attributes, and indexes will be intact
Ex –
SELECT TOP:
The SELECT TOP clause is used to specify the number of records to return.
Syntax –
MIN():
The MIN() function returns the smallest value of the selected column.
Syntax –
● SELECT MIN(column_name)
FROM table_name
WHERE condition;
Ex –
● SELECT MIN(Price) AS SmallestPrice
FROM Products;
MAX():
The MAX() function returns the largest value of the selected column.
Syntax –
● SELECT MAX(column_name)
FROM table_name
WHERE condition;
Ex –
● SELECT MAX(Price) AS LargestPrice
FROM Products;
COUNT():
The COUNT() function returns the number of rows that matches a specified criterion.
Syntax –
● SELECT COUNT(column_name)
FROM table_name
WHERE condition;
Ex –
● SELECT COUNT(ProductID)
FROM Products;
AVG():
The AVG() function returns the average value of a numeric column.
Syntax –
● SELECT AVG(column_name)
FROM table_name
WHERE condition;
Ex –
● SELECT AVG(Price)
FROM Products;
SUM():
The SUM() function returns the total sum of a numeric column.
Syntax –
● SELECT SUM(column_name)
FROM table_name
WHERE condition;
Ex –
● SELECT SUM(Quantity)
FROM OrderDetails;
LIKE Operator:
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
There are two wildcards often used in conjunction with the LIKE operator:
Syntax –
● SELECT column1, column2, ...
FROM table_name
WHERE columnN LIKE pattern;
LIKE Operator Description
WHERE CustomerName LIKE 'a%' Finds any values that start with "a"
WHERE CustomerName LIKE '%a' Finds any values that end with "a"
WHERE CustomerName LIKE '%or%' Finds any values that have "or" in any position
WHERE CustomerName LIKE '_r%' Finds any values that have "r" in the second position
WHERE CustomerName LIKE 'a_%' Finds any values that start with "a" and are at
least 2 characters in length
WHERE CustomerName LIKE 'a__%' Finds any values that start with "a" and are at
least 3 characters in length
WHERE ContactName LIKE 'a%o' Finds any values that start with "a" and ends with "o"
IN:
Syntax –
● SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1, value2, ...);
● SELECT column_name(s)
FROM table_name
WHERE column_name IN (SELECT STATEMENT);
Ex –
● SELECT * FROM Customers
WHERE Country IN ('Germany', 'France', 'UK');
● SELECT * FROM Customers
WHERE Country IN (SELECT Country FROM Suppliers);
BETWEEN:
The BETWEEN operator selects values within a given range. The values can be numbers, text, or
dates.
The BETWEEN operator is inclusive: begin and end values are included.
Syntax –
● SELECT column_name(s)
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
Ex –
● SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;
Joins:
A JOIN clause is used to combine rows from two or more tables, based on a related column
between them.
INNER JOIN:
The INNER JOIN keyword selects records that have matching values in both tables.
Syntax –
● SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
Ex –
Syntax –
● SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
Ex –
The RIGHT JOIN keyword returns all records from the right table (table2), and the matching
records from the left table (table1). The result is 0 records from the left side, if there is no
match.
Syntax –
● SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
Ex –
● SELECT [Link], [Link], [Link]
FROM Orders
RIGHT JOIN Employees ON [Link] = [Link]
ORDER BY [Link];
Syntax:
● SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name
WHERE condition;
Ex –
UNION:
The UNION operator is used to combine the result-set of two or more SELECT statements.
● Every SELECT statement within UNION must have the same number of columns
● The columns must also have similar data types
● The columns in every SELECT statement must also be in the same order
The UNION operator selects only distinct values by default. To allow duplicate values,
use UNION ALL
Syntax –
Ex –
● SELECT City FROM Customers
UNION
SELECT City FROM Suppliers
ORDER BY City;
GROUP BY:
The GROUP BY statement groups rows that have the same values into summary rows, like "find
the number of customers in each country".
The GROUP BY statement is often used with aggregate functions
(COUNT(), MAX(), MIN(), SUM(), AVG()) to group the result-set by one or more
columns. Syntax –
● SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
ORDER BY column_name(s);
Ex –
The HAVING clause was added to SQL because the WHERE keyword cannot be used with
aggregate functions.
Syntax –
● SELECT column_name(s)
FROM table_name
WHERE condition
GROUP BY column_name(s)
HAVING condition
ORDER BY column_name(s);
Ex –
● SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
HAVING COUNT(CustomerID) > 5;
CREATE DATABASE:
DROP DATABASE:
CREATE TABLE:
DROP TABLE:
The DROP TABLE statement is used to drop an existing table in a database.
Syntax –
TRUNCATE TABLE:
The TRUNCATE TABLE statement is used to delete the data inside a table, but not the table itself.
Syntax –
ALTER TABLE:
The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
The ALTER TABLE statement is also used to add and drop various constraints on an existing
table.
Syntax –
Ex –
● ALTER TABLE Customers
ADD Email varchar(255);
● ALTER TABLE Customers
DROP COLUMN Email;
● ALTER TABLE Persons
ALTER COLUMN DateOfBirth year;
OBJECT ORIENTED PROGRAMMING
● Class is a user-defined data type which defines its properties and its
functions. Class is the only logical representation of the data. For
example, Human being is a class. The body parts of a human being are its
properties, and the actions performed by the body parts are known as
functions. The class does not occupy any memory space till the time an
object is instantiated.
APNI KAKSHA
● Inheritance
Inheritance is a process in which one object acquires all the properties and
behaviors of its parent object automatically. In such a way, you can reuse,
extend or modify the attributes and behaviors which are defined in other
classes.
In C++, the class which inherits the members of another class is called
derived class and the class whose members are inherited is called base class.
The derived class is the specialized class for the base class.
C++ Syntax :
Types of Inheritance :
1. Single inheritance : When one class inherits another class, it is known
as single level inheritance
2. Multiple inheritance : Multiple inheritance is the process of deriving
a new class that inherits the attributes from two or more classes.
3. Hierarchical inheritance : Hierarchical inheritance is defined as the
process of deriving more than one class from a base class.
4. Multilevel inheritance : Multilevel inheritance is a process of deriving a
class from another derived class.
5. Hybrid inheritance : Hybrid inheritance is a combination of
simple, multiple inheritance and hierarchical inheritance.
● Encapsulation
APNI KAKSHA
● Abstraction
● Polymorphism
APNI KAKSHA
Method Overloading : Method overloading is a technique which allows you
to have more than one function with the same function name but with
different functionality. Method overloading can be possible on the
following basis:
Example :
#include<bits/stdc++.h>
using namespace std;
class Add {
public:
int add(int a,int b){
return (a + b);
}
int add(int a,int b,int c){
return (a + b + c);
}
};
int main(){
Add obj;
int res1,res2;
res1 = [Link](2,3);
res2 = [Link](2,3,4);
cout << res1 << " " << res2 << endl;
return 0;
}
/*
Output : 5 9
add() is an overloaded function with a different number of parameters. */
APNI KAKSHA
● Runtime Polymorphism : Runtime polymorphism is also known as dynamic
polymorphism. Function overriding is an example of runtime
polymorphism. Function overriding means when the child class contains
the method which is already present in the parent class. Hence, the child
class overrides the method of the parent class. In case of function
overriding, parent and child classes both contain the same function with a
different definition. The call to the function is determined at runtime is
known as runtime polymorphism.
#include <bits/stdc++.h>
using namespace std;
class Base_class{
public:
virtual void show(){
cout << "Apni Kaksha base" << endl;
}
};
int main(){
Base_class* b;
Derived_class d;
b = &d;
b->show(); // prints the content of show() declared in derived
class return 0;
APNI KAKSHA
}
#include <bits/stdc++.h>
using namespace std;
class go {
public:
int x;
go(int a){ // parameterized constructor.
APNI KAKSHA
x=a;
}
go(go &i){ // copy constructor
x = i.x;
}
};
int main(){
go a1(20); // Calling the parameterized constructor.
go a2(a1); // Calling the copy constructor.
cout << a2.x << endl;
return 0;
}
// Output : 20
Example :
#include<bits/stdc++.h>
using namespace std;
class A{
public:
// constructor and destructor are called automatically,
once the object is instantiated
A(){
cout << "Constructor in use" << endl;
}
~A(){
cout << "Destructor in use" << endl;
}
};
int main(){
APNI KAKSHA
A a;
A b;
return 0;
}
/*
Output: Constructor in use
Constructor in use
Destructor in use
Destructor in use
*/
● ‘this’ Pointer : this is a keyword that refers to the current instance of the
class. There can be 3 main uses of ‘this’ keyword:
1. It can be used to pass the current object as a parameter to
another method
C++ Syntax :
struct node{
int data;
node *next;
node(int x){
this->data = x;
this->next = NULL;
}
}
● Friend Function : Friend function acts as a friend of the class. It can access
the private and protected members of the class. The friend function is not
APNI KAKSHA
a member of the class, but it must be listed in the class definition. The
non-member function cannot access the private data of the class.
Sometimes, it is necessary for the non-member function to access the data.
The friend function is a non-member function and has the ability to
access the private data of the class.
Note :
1. A friend function cannot access the private members directly, it has
to use an object name and dot operator with each member name.
2. Friend function uses objects as arguments.
Example IMP :
#include <bits/stdc++.h>
using namespace std;
class A{
int a = 2;
int b = 4;
public:
// friend function
friend int mul(A k){
return (k.a * k.b);
}
};
int main(){
A obj;
int res = mul(obj);
cout << res << endl;
return 0;
}
// Output : 8
APNI KAKSHA
any entity reference. It is another way to reuse the class. It is a form of
association that represents the HAS-A relationship.
2. When we use the same function name in both base and derived
class, the function in base class is declared with a keyword
virtual.
Key Points :
1. Virtual functions cannot be static.
2. A class may have a virtual destructor but it cannot have a virtual
constructor.
C++ Example :
#include <bits/stdc++.h>
APNI KAKSHA
using namespace std;
class base {
public:
// virtual function (re-defined in the derived class)
virtual void print(){
cout << "print base class" << endl;
}
void show(){
cout << "show base class" << endl;
}
};
void show(){
cout << "show derived class" << endl;
}
};
int main(){
base* bptr;
derived d;
bptr = &d;
/*
output :
APNI KAKSHA
print derived class // (impact of virtual function)
show base class
*/
C++ Syntax :
C++ Example :
#include<bits/stdc++.h>
using namespace std;
class Base{
public:
virtual void show() = 0;
};
class Derived : public Base {
public:
void show() {
cout << "You can see me !" << endl;
}
};
int main(){
Base *bptr;
APNI KAKSHA
Derived d;
bptr = &d;
bptr->show();
return 0;
}
Example :
#include<bits/stdc++.h>
using namespace std;
// abstract class
class Shape{
public:
virtual void draw()=0;
};
class Rectangle : Shape{
public:
void draw(){
cout << "Rectangle" << endl;
}
};
class Square : Shape{
public:
void draw(){
cout << "Square" << endl;
}
};
int main(){
Rectangle rec;
Square sq;
APNI KAKSHA
[Link]();
[Link]();
return 0;
}
/*
Output :
Rectangle
Square
*/
● Namespaces in C++ :
1. The namespace is a logical division of the code which is designed to
stop the naming conflict.
2. The namespace defines the scope where the identifiers such as
variables, class, functions are declared.
3. The main purpose of using namespace in C++ is to remove the
ambiguity. Ambiguity occurs when a different task occurs with the
same name.
4. For example: if there are two functions with the same name such as
add(). In order to prevent this ambiguity, the namespace is used.
Functions are declared in different namespaces.
5. C++ consists of a standard namespace, i.e., std which contains
inbuilt classes and functions. So, by using the statement "using
namespace std;" includes the namespace "std" in our program.
C++ Example :
#include <bits/stdc++.h>
using namespace std;
// user-defined namespace
namespace Add {
int a = 5, b = 5;
int add() {
return (a + b);
}
}
APNI KAKSHA
int main() {
int res = Add :: add(); // accessing the function inside namespace
cout << res;
}
// output : 10
● Access Specifiers IMP : The access specifiers are used to define how functions
and variables can be accessed outside the class. There are three types of
access specifiers:
Key Notes
● Virtual inheritance facilitates you to create only one copy of each object
even if the object appears more than one in the hierarchy.
APNI KAKSHA
Operator overloading: Operator overloading is defined as the standard
operator can be redefined so that it has a different meaning when applied to
the instances of a class.
APNI KAKSHA
Operating Systems
1. Batch OS – A set of similar jobs are stored in the main memory for execution. A job gets
assigned to the CPU, only when the execution of the previous job completes.
2. Multiprogramming OS – The main memory consists of jobs waiting for CPU time. The
OS selects one of the processes and assigns it to the CPU. Whenever the executing
process needs to wait for any other operation (like I/O), the OS selects another process
from the job queue and assigns it to the CPU. This way, the CPU is never kept idle
and the user gets the flavor of getting multiple tasks done at once.
3. Multitasking OS – Multitasking OS combines the benefits of Multiprogramming OS
and CPU scheduling to perform quick switches between jobs. The switch is so quick
that the user can interact with each program as it runs.
4. Time Sharing OS – Time-sharing systems require interaction with the user to instruct
the OS to perform various tasks. The OS responds with an output. The instructions are
usually given through an input device like the keyboard.
5. Real Time OS – Real-Time OS are usually built for dedicated systems to accomplish a
specific set of tasks within deadlines.
● Process : A process is a program under execution. The value of the program counter
(PC) indicates the address of the next instruction of the process being executed.
Each process is represented by a Process Control Block (PCB).
Apni Kaksha 1
● Process Scheduling:
1. Arrival Time – Time at which the process arrives in the ready queue.
2. Completion Time – Time at which process completes its execution.
3. Burst Time – Time required by a process for CPU execution.
4. Turn Around Time – Time Difference between completion time and arrival time.
Turn Around Time = Completion Time - Arrival Time
5. Waiting Time (WT) – Time Difference between turn around time and burst time.
Waiting Time = Turnaround Time - Burst Time
● Thread (Important) : A thread is a lightweight process and forms the basic unit of
CPU utilization. A process can perform more than one task at the same time by including
multiple threads.
● A thread has its own program counter, register set, and stack
● A thread shares resources with other threads of the same process: the code section,
the data section, files and signals.
Note : A new thread, or a child process of a given process, can be introduced by using
the fork() system call. A process with n fork() system call generates 2^n – 1 child
processes.
There are two types of threads:
● User threads (User threads are implemented by users)
Apni Kaksha 2
● Scheduling Algorithms :
Apni Kaksha 3
● The Critical Section Problem:
1. Critical Section – The portion of the code in the program where shared variables
are accessed and/or updated.
2. Remainder Section – The remaining portion of the program excluding the Critical
Section.
3. Race around Condition – The final output of the code depends on the order in
which the variables are accessed. This is termed as the race around condition.
A solution for the critical section problem must satisfy the following three conditions:
● Synchronization Tools:
1. Semaphore : Semaphore is a protected variable or abstract data type that is
used to lock the resource being used. The value of the semaphore indicates the
status of a common resource.
Apni Kaksha 4
Mutex (A mutex provides mutual exclusion, either producer or consumer can
have the key (mutex) and proceed with their work. As long as the buffer is filled
by the producer, the consumer needs to wait, and vice versa.
At any point of time, only one thread can work with the entire buffer. The concept
can be generalized using semaphore.)
● Deadlocks (Important):
A situation where a set of processes are blocked because each process is holding a
resource and waiting for another resource acquired by some other process. Deadlock
can arise if following four conditions hold simultaneously (Necessary Conditions):
1. Mutual Exclusion – One or more than one resource is non-sharable (Only one
process can use at a time).
2. Hold and Wait – A process is holding at least one resource and waiting for
resources.
3. No Preemption – A resource cannot be taken from a process unless the process
releases the resource.
4. Circular Wait – A set of processes are waiting for each other in circular form.
● Methods for handling deadlock: There are three ways to handle deadlock
1. Deadlock prevention or avoidance : The idea is to not let the system into a
deadlock state.
2. Deadlock detection and recovery : Let deadlock occur, then do preemption to
handle it once occurred.
3. Ignore the problem all together : If deadlock is very rare, then let it happen and
reboot the system. This is the approach that both Windows and UNIX take.
Apni Kaksha 5
● Banker's algorithm is used to avoid deadlock. It is one of the deadlock-avoidance
methods. It is named as Banker's algorithm on the banking system where a bank
never allocates available cash in such a manner that it can no longer satisfy the
requirements of all of its customers.
1. First Fit – The arriving process is allotted the first hole of memory in which it fits
completely.
2. Best Fit – The arriving process is allotted the hole of memory in which it fits the best
by leaving the minimum memory empty.
3. Worst Fit – The arriving process is allotted the hole of memory in which it leaves the
maximum gap.
Apni Kaksha 6
Note:
● Best fit does not necessarily give the best results for memory allocation.
● The cause of external fragmentation is the condition in Fixed partitioning and
Variable partitioning saying that the entire process should be allocated in a
contiguous memory [Link] Paging is used.
1. Paging – The physical memory is divided into equal sized frames. The main memory
is divided into fixed size pages. The size of a physical memory frame is equal to the
size of a virtual memory frame.
2. Segmentation – Segmentation is implemented to give users a view of memory. The
logical address space is a collection of segments. Segmentation can be implemented
with or without the use of paging.
● Page Fault:
A page fault is a type of interrupt, raised by the hardware when a running program accesses a
memory page that is mapped into the virtual address space, but not loaded in physical memory.
Apni Kaksha 7
Belady’s anomaly proves that it is possible to have more page faults when increasing
the number of page frames while using the First in First Out (FIFO) page
replacement algorithm. For example, if we consider reference string ( 3 2 1 0
3 2 4 3 2 1 0 4 ) and 3 slots, we get 9 total page faults, but if we
increase slots to 4, we get 10 page faults.
2. Optimal Page replacement –
In this algorithm, pages are replaced which are not used for the longest duration of
time in the future.
Apni Kaksha 8
● Disk Scheduling: Disk scheduling is done by operating systems to schedule I/O
requests arriving for disk. Disk scheduling is also known as I/O scheduling.
1. Seek Time: Seek time is the time taken to locate the disk arm to a specified track
where the data is to be read or written.
2. Rotational Latency: Rotational Latency is the time taken by the desired sector of
disk to rotate into a position so that it can access the read/write heads.
3. Transfer Time: Transfer time is the time to transfer the data. It depends on the
rotating speed of the disk and number of bytes to be transferred.
4. Disk Access Time: Seek Time + Rotational Latency + Transfer Time
5. Disk Response Time: Response Time is the average of time spent by a request
waiting to perform its I/O operation. Average Response time is the response time of
all requests.
1. FCFS: FCFS is the simplest of all the Disk Scheduling Algorithms. In FCFS, the
requests are addressed in the order they arrive in the disk queue.
2. SSTF: In SSTF (Shortest Seek Time First), requests having the shortest seek time
are executed first. So, the seek time of every request is calculated in advance in a
queue and then they are scheduled according to their calculated seek time. As a
result, the request near the disk arm will get executed first.
3. SCAN: In SCAN algorithm the disk arm moves into a particular direction and
services the requests coming in its path and after reaching the end of the disk, it
reverses its direction and again services the request arriving in its path. So, this
algorithm works like an elevator and hence is also known as elevator algorithm.
4. CSCAN: In SCAN algorithm, the disk arm again scans the path that has been
scanned, after reversing its direction. So, it may be possible that too many requests
are waiting at the other end or there may be zero or few requests pending at the
scanned area.
Apni Kaksha 9
5. LOOK: It is similar to the SCAN disk scheduling algorithm except for the difference
that the disk arm in spite of going to the end of the disk goes only to the last request
to be serviced in front of the head and then reverses its direction from there only.
Thus it prevents the extra delay which occurred due to unnecessary traversal to the
end of the disk.
6. CLOOK: As LOOK is similar to SCAN algorithm, CLOOK is similar to CSCAN disk
scheduling algorithm. In CLOOK, the disk arm in spite of going to the end goes only
to the last request to be serviced in front of the head and then from there goes to the
other end’s last request. Thus, it also prevents the extra delay which occurred due to
unnecessary traversal to the end of the disk.
Apni Kaksha 10
Key Terms
● Real-time system is used in the case when rigid-time requirements have been
placed on the operation of a processor. It contains well defined and fixed time
constraints.
● A monolithic kernel is a kernel which includes all operating system code in a
single executable image.
● Micro kernel: Microkernel is the kernel which runs minimal performance
affecting services for the operating system. In the microkernel operating system
all other operations are performed by the processor.
Apni Kaksha 11
● Fragmentation is a phenomenon of memory wastage. It reduces the capacity
and performance because space is used inefficiently.
3. Economical
Apni Kaksha 12