Technical Subjects
Technical Subjects
Object-Oriented Programming
Class
• 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.
class student {
public:
int mobile;
string name;
return x + y;
};
Object
• Object is a run-time entity. It is an instance of the class. An object can represent a person,
place or any other item. An object can operate on both data members and member
functions.
Note:
• When an object is created using a new keyword, then space is allocated for the variable in a
heap, and the starting address is stored in the stack memory. When an object is created
without a new keyword, then space is not allocated in the heap memory, and the object
contains the null value in the stack.
Inheritance
• Inheritance is a process in which one object acquires all the properties and behaviors ofits
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 :
1. Single inheritance :
o When one class inherits another class, it is known as single level inheritance.
2. Multiple inheritance :
o Multiple inheritance is the process of deriving a new class that inherits the attributes
from two or more classes.
3. Multilevel inheritance :
4. Hierarchical inheritance :
o Hierarchical inheritance is defined as the process of deriving more than one class
from a base class.
5. Hybrid inheritance :
Encapsulation
• Encapsulation is the process of combining data and functions into a single unit called class.
In Encapsulation, the data is not accessed directly; it is accessed through the functions
present inside the class. In simpler words, attributes of the class are kept private and public
getter and setter methods are provided to manipulate these attributes. Thus, encapsulation
makes the concept of data hiding possible.(Data hiding: a language feature to restrict access
to members of an object, reducing the negative effect due to dependencies. e.g. "protected",
"private" feature in C++).
Abstraction
• We try to obtain an abstract view, model or structure of a real life problem, and reduce its
unnecessary details. With definition of properties of problems, including the data which are
affected and the operations which are identified, the model abstracted from problems can
be a standard solution to this type of problems. It is an efficient way since there are nebulous
real-life problems that have similar properties.
Data binding :
• Data binding is a process of binding the application UI and business logic. Any change made
in the business logic will reflect directly to the application UI.
Polymorphism
• Polymorphism is the ability to present the same interface for differing underlying forms
(data types). With polymorphism, each of these classes will have different underlying data.
Apoint shape needs only two coordinates (assuming it's in a two-dimensional space of
course). Acircle needs a center and radius. Asquare or rectangle needs two coordinates for
the top left and bottom right corners and (possibly) a rotation. An irregular polygon needs a
series oflines. Precisely, Poly means ‘many’ and morphism means ‘forms’.
Types of Polymorphism
o 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:
#include<bits/stdc++.h>
class Add {
public:
return (a + b);
}
int add(int a,int b,int c){
return (a + b + c);
};
int main(){
Add obj;
int res1,res2;
res1 = obj.add(2,3);
res2 = obj.add(2,3,4);
cout << res1 << " " << res2 << endl;
return 0;
Runtime Polymorphism :
#include <bits/stdc++.h>
class Base_class{
public:
};
public:
void show(){
};
int main(){
Base_class* b;
Derived_class d; b = &d;
class return 0;
Constructor :
i. Default constructor :
▪ It is of two types :
#include <bits/stdc++.h>
public:
int x;
x=a;
x = i.x;
};
int main(){
return 0;
// Output : 20
Destructor :
#include<bits/stdc++.h>
class A{
public: // constructor and destructor are called automatically, once the object is instantiated
A(){
}
~A(){
};
int main(){
Aa; Ab;
return 0;
‘this’ Pointer :
• this is a keyword that refers to the current instance of the class. There can be 3 main uses
of ‘this’ keyword:
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 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. Afriend function cannot access the private members directly, it has to use an object name
and dot operator with each member name.
#include <bits/stdc++.h>
class A{
int a = 2;
int b = 4;
int mul(Ak){
};
int main(){
Aobj;
return 0;
// Output : 8
Aggregation :
• It is a process in which one class defines another class as any entity reference. It is another
way to reuse the class. It is a form of association that represents the HAS-Arelationship.
i. A virtual function is a member function which is present in the base class and
redefined by the derived class.
ii. When we use the same function name in both base and derived class, the function
in base class is declared with a keyword virtual.
iii. When the function is made virtual, then C++ determines at run-time which function
is to be called based on the type of the object pointed by the base class
pointer. Thus, by making the base class pointer to point to different objects, we can
execute different versions of the virtual functions.
Key Points :
2. Aclass may have a virtual destructor but it cannot have a virtual constructor.
#include <bits/stdc++.h>
class base {
public:
void show(){
};
public:
void print(){
cout << "print derived class" << endl;
void show(){
};
int main(){
base* bptr;
derived d;
bptr = &d;
bptr->print();
bptr->show();
PureVirtual Function :
• Apure virtualfunction is not used for performing any task. It only serves as a placeholder.
• Apure virtualfunction is a function declared in the base class that has no definition relative to
the base class.
• Aclass containing the pure virtualfunction cannot be used to declare the objects ofits own,
such classes are known as abstract base classes.
• The main objective of the base class is to provide the traits to the derived classes and to
create the base pointer used for achieving the runtime polymorphism.
C++ Syntax :
#include <bits/stdc++.h>
using namespace std;
class Base{
public:
};
public:
void show() {
};
int main(){
Base *bptr;
Derived d;
bptr = &d;
bptr->show();
return 0;
Abstract Classes :
• In C++ class is made abstract by declaring at least one of its functions as a pure virtual
function. Apure virtualfunction is specified by placing "= 0" in its declaration. Its
implementation must be provided by derived classes.
#include <bits/stdc++.h>
// abstract class
class Shape{
public:
};
};
public:
void draw(){
};
int main(){
Rectangle rec;
Square sq;
rec.draw();
sq.draw();
return 0;
Namespaces in C++ :
• The namespace is a logical division of the code which is designed to stop the naming conflict.
• The namespace defines the scope where the identifiers such as variables, class,functions are
declared.
• The main purpose of using namespace in C++ is to remove the ambiguity. Ambiguity occurs
when a different task occurs with the same name.
• 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.
• 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.
#include <bits/stdc++.h>
// user-defined namespace
namespace Add {
int a = 5, b = 5;
int add() {
return (a + b);
int main() {
// output : 10
• The access specifiers are used to define how functions and variables can be accessed outside
the class. There are three types of access specifiers:
i. Private:
▪ Functions and variables declared as private can be accessed only within the
same class, and they cannot be accessed outside the class they are declared.
ii. Public:
iii. Protected:
Key Notes
• Delete :
• Virtual inheritance :
o Virtual inheritance facilitates you to create only one copy of each object even if the
object appears more than one in the hierarchy.
• Function overloading :
o Function overloading is defined as we can have more than one version of the same
function. The versions of a function will have different signatures meaning that they
have a different set of parameters.
• Operator overloading :
• Overloading :
OPERATING SYSTEM
Operating System :
• Batch OS –
o 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
• Multiprogramming OS –
o 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.
• Multitasking OS –
• Time Sharing OS –
o 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.
• Real Time OS –
o 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).
Process Scheduling :
• Arrival Time –
• Completion 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.
o A thread has its own program counter, register set, and stack
o 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.
Scheduling Algorithms :
o Processes which have the shortest burst time are scheduled first.
o The period of time for which a process or job is allowed to run in a pre-emptive
method is called time quantum.
o In this scheduling, processes are scheduled according to their priorities, i.e., highest
priority process is scheduled first.
o If priorities of two processes match, then scheduling is according to the arrival time.
o In this scheduling, processes with the highest response ratio are scheduled. This
algorithm avoids starvation.
o According to the priority of the process, processes are placed in the different
queues. Generally high priority processes are placed in the top level queue. Only
after completion of processes from the top level queue, lower level queued
processes are scheduled.
o It allows the process to move in between queues. The idea is to separate processes
according to the characteristics of their CPU bursts. If a process uses too much CPU
time, it is moved to a lower-priority queue.
• Critical Section –
o The portion of the code in the program where shared variables are accessed and/or
updated.
• Remainder Section –
o 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:
• Mutual Exclusion –
• Progress –
• Bounded Waiting –
o There exists a bound on the number of times other processes can enter into the
critical section after a process has made a request to access the critical section and
before the request is granted.
Synchronization Tools:
• Semaphore :
o 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.
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):
o Mutual Exclusion – One or more than one resource is non-sharable (Only one
process can use at a time).
o Hold and Wait – A process is holding at least one resource and waiting for resources.
o Circular Wait – A set of processes are waiting for each other in circular form.
▪ If deadlock is very rare, then let it happen and reboot the system.
This is the approach that both Windows and UNIX take
• Memory Management:
▪ Overlays –
▪ The memory should contain only those instructions and data that
are required at a given time.
▪ Swapping –
• Techniques :
▪ The memory is divided into two parts. One part is kept to be used by the OS
and the other is kept to be used by the users.
▪ Fixed Partition –
▪ Variable Partition –
▪ Note :
▪ First Fit –
▪ Best Fit –
▪ Worst Fit –
o Note:
▪ Best fit does not necessarily give the best results for memory allocation.
▪ Paging –
▪ Segmentation –
• Page Fault:
o 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
o This is the simplest page replacement algorithm. In this algorithm, the operating
system keeps track of all pages in the memory in a queue, the oldest page is in the
front of the queue. When a page needs to be replaced, the page in the front of the
queue is selected for removal.
o For example, consider page reference string 1, 3, 0, 3, 5, 6 and 3 page slots. Initially,
all slots are empty, so when 1, 3, 0 come they are allocated to the empty slots —> 3
Page Faults. When 3 comes, it is already in memory so —> 0 Page Faults. Then 5
comes, it is not available in memory so it replaces the oldest page slot i.e 1. —> 1
Page Fault. Finally, 6 comes, it is also not available in memory so it replaces the
oldest page slot i.e 3 —> 1 Page Fault.
o Belady’s anomaly:
▪ 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.
o In this algorithm, pages are replaced which are not used for the longest duration of
time in the future.
o In this algorithm, the page will be replaced with the one which is least recently used.
Let say the page reference string 7 0 1 2 0 3 0 4 2 3 0 3 2 . Initially, we had 4-page
slots empty. Initially, all slots are empty, so when 7 0 1 2 are allocated to the empty
slots —> 4 Page faults. 0 is already there so —> 0 Page fault. When 3 comes it will
take the place of 7 because it is least recently used —> 1 Page fault. 0 is already in
memory so —> 0 Page fault. 4 will take place of 1 —> 1 Page Fault. Now for the
further page reference string —> 0 Page fault because they are already available in
the memory.
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.
• Seek Time:
o Seek time is the time taken to locate the disk arm to a specified track where the data
is to be read or written.
• Rotational Latency:
o 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.
• Transfer Time:
o 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.
o 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
• FCFS:
o 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.
• SSTF:
o 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.
• SCAN:
o 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.
• CSCAN:
o 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.
• LOOK:
o 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.
• CLOOK:
KEY Terms:
• Real-time System:
o 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.
• Monolithic Kernel:
o A monolithic kernel is a kernel which includes all operating system code in a single
executable image.
• Micro kernel:
o 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.
o Macro Kernel:
• Re-entrancy:
o It is a very useful memory saving technique that is used for multi-programmed time
sharing systems. It provides functionality that multiple users can share a single copy
of a program during the same period. It has two key aspects:The program code
cannot modify itself and the local data for each user process must be stored
separately.
• Demand Paging:
o Demand paging specifies that if an area of memory is not currently being used, it is
swapped to disk to make room for an application's need.
• RAID:
o RAID stands for Redundant Array of Independent Disks. It is used to store the same
data redundantly to improve the overall performance. There are 7 RAID levels.
• Logical Address:
o Logical address space specifies the address that is generated by the CPU. On the
other hand, physical address space specifies the address that is seen by the memory
unit.
• Fragmentation:
▪ Internal fragmentation:
▪ It occurs when we deal with the systems that have fixed size
allocation units.
▪ External fragmentation:
• Spooling:
• Starvation:
o Economical
• Thrashing:
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.
Database management systems were developed to handle the following difficulties of typical File-
processing systems supported by conventional operating systems.
4. Integrity problems
5. Atomicity of updates
7. Security problems
ER diagram:
• ER diagram or Entity Relationship diagram is a conceptual model that gives the graphical
representation of the logical structure of the database.
• It shows all the constraints and relationships that exist among the different components.
• An ER diagram is mainly composed of following three components- Entity Sets, Attributes
and Relationship Set.
Entity Set:
o A strong entity set is an entity set that contains sufficient attributes to uniquely
identify all its entities.
o A weak entity set is an entity set that does not contain sufficient attributes to
uniquely identify its entities.
o In other words, a primary key does not exist for a weak entity set.
Relationship:
o Unary relationship set is a relationship set where only one entity set participates in a
relationship set.
o Binary relationship set is a relationship set where two entity sets participate in a
relationship set.
o Ternary relationship set is a relationship set where three entity sets participate in a
relationship set.
o N-ary relationship set is a relationship set where ‘n’ entity sets participate in a
relationship set.
Cardinality Constraint:
Cardinality constraint defines the maximum number of relationship instances in which an entity can
participate.
• One-to-One Cardinality -
o 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 -
o 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 -
o 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 -
o 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:
o Simple Attributes -
▪ Simple attributes are those attributes which cannot be divided further. Ex.
Age
o Composite 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
o Derived Attributes -
▪ Derived attributes are those attributes which can be derived from other
attribute(s). Ex. Age can be derived from DOB.
o 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.
o Domain Constraint -
▪ Tuple Uniqueness constraint specifies that all the tuples must be necessarily
unique in any relation.
o Key Constraint -
▪ All the values of the primary key must be unique. The value of the primary
key must not be null.
▪ 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.
• The set of all those attributes which can be functionally determined from an attribute set is
called a closure of that attribute set.
Keys:
• A key is a set of attributes that can identify each tuple uniquely in the given relation.
Types of Keys:
• Super Key -
o 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 -
o A set of minimal attribute(s) that can identify each tuple uniquely in the given
relation is called a candidate key.
• Primary Key -
o 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 -
o Candidate keys that are left unimplemented or unused after implementing the
primary key are called as alternate keys.
• Foreign Key -
o 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 -
o A primary key composed of multiple attributes and not just a single attribute is called
a composite key.
• Unique Key -
o 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 β. Types of Functional Dependency:
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:
o When the sub relations are joined back, the same relation is obtained that was
decomposed.
o None of the functional dependencies that hold on the original relation are lost.
o The sub relations still hold or satisfy the functional dependencies of the original
relation.
Types of Decomposition:
o Consider there is a relation R which is decomposed into sub relations R1, R2, …., Rn.
o This decomposition is called lossless join decomposition when the join of the sub
relations results in the same relation R that was decomposed.
o Consider there is a relation R which is decomposed into sub relations R1, R2, …., Rn.
o This decomposition is called lossy join decomposition when the join of the sub
relations does not result in the same relation R that was decomposed.
Normalization:
Normal Forms:
o 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.
Transaction:
Operations in Transaction:
• Read Operation -
o Read(A) instruction will read the value of ‘A’ from the database and will store it in the
buffer in main memory.
• Write Operation –
o Write(A) will write the updated value of ‘A’ from the buffer to the database.
Transaction States:
• Active State –
o All the changes made by the transaction now are stored in the buffer in main
memory.
o After the last instruction of the transaction has been executed, it enters into a
partially committed state.
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.
• 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 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.
o Atomicity –
o Consistency –
▪ In other words, it ensures that the database remains consistent before and
after the transaction.
o Isolation –
▪ 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.
o Durability –
▪ This property ensures that all the changes made by a transaction after its
successful execution are written successfully to the disk.
▪ 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.
o Serial Schedules –
o Non-Serial Schedules –
▪ Operations of all the transactions are inter leaved or mixed with each other.
• Serializability –
o Serializable Schedules –
Types of Serializability –
o Conflict Serializability -
o View Serializability -
• Non-Serializable Schedules –
Irrecoverable Schedules –
o If in a schedule,
o If in a schedule,
▪ 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.
o Cascading Schedule -
o Cascadeless Schedule -
▪ If in a schedule, a transaction is not allowed to read a data item until the last
transaction that has written it is committed or aborted, then such a schedule
is called as a Cascadeless Schedule.
o Strict Schedule -
Relational Algebra:
• Relational Algebra is a procedural query language which takes a relation as an input and
generates a relation as an output.
Basic
Semantic
Operator
X (Cross Cross product of relations, returns m * n rows where m and n are number of
Product) rows in R1 and R2 respectively.
Return those tuples which are either in R1 or in R2. Max no. of rows returned
U (Union)
= m+n and Min no. of rows returned = max(m,n)
R1-R2 returns those tuples which are in R1 but not in R2. Max no. of rows
− (Minus)
returned = m and Min no. of rows returned = m-n
Extended
Semantic
Operator
∩ Returns those tuples which are in both R1 and R2. Max no. of rows returned
(Intersection) = min(m,n) and Min no. of rows returned = 0
⋈c
Selection from two or more tables based on some condition (Cross product
(Conditional
followed by selection)
Join)
Division operator A/B will return those tuples in A which are associated with
/ (Division
every tuple of B. Note: Attributes of B should be a proper subset of attributes
Operator)
of A. The attributes in A/B will be Attributes of A- Attribute of B.
File Structures:
• Primary Index:
o 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:
o Clustering index is created on data file whose records are physically ordered on a
non-key field (called Clustering field).
• Secondary Index:
o 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.
B+ Trees
• In B+ trees, the structure of leaf and non-leaf are different, so their order is. Order of non-
leaf will be higher as compared to leaf nodes.
• Searching time will be less in B+ trees, since it doesn’t have record pointers in non-leaf
because of which depth will decrease.
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.
o CREATE
▪ to create a database and its objects like (table, index, views, store procedure,
function, and triggers)
o ALTER
o DROP
o TRUNCATE
▪ remove all records from a table, including all spaces allocated for the records
are removed
o 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.
o SELECT
o INSERT
o UPDATE
o DELETE
DCL:
• DCL is short name of Data Control Language which includes commands such as GRANT and
mostly concerned with rights, permissions and other controls of the database system.
o GRANT
o REVOKE
TCL:
• TCL is short name of Transaction Control Language which deals with a transaction within a
database.
o COMMIT
▪ commits a Transaction
o ROLLBACK
SQL:
• SQL is a standard language for storing, manipulating and retrieving data in databases.
SELECT:
Syntax:-
o Here, column1, column2, ... are the field names of the table you want to select data
from.
o If you want to select all the fields available in the table, use the following syntax:
Example:-
FROM Customers;
SELECT DISTINCT:
• The SELECT DISTINCT statement is used to return only distinct (different) values.
Syntax –
Example –
FROM Customers;
WHERE:
Syntax –
Example -
SELECT *
FROM Customers
WHERE Country='Mexico';
Operator Description
= 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.
Syntax –
• SELECT column1, column2, ... FROM table_name WHERE condition1 AND condition2 AND
condition3 ...;
• SELECT column1, column2, ... FROM table_name WHERE condition1 OR condition2 OR
condition3 ...;
Example –
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 –
• SELECT column1, column2, ... FROM table_name ORDER BY column1, column2, ... ASC|DESC;
Example –
ORDER BY Country;
INSERT INTO:
Syntax –
• INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3,
...);
o In the second syntax, make sure the order of the values is in the same order as the
columns in the table.
Example –
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 –
Example –
FROM Customers
UPDATE:
Syntax –
• UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
Example –
UPDATE Customers
WHERE CustomerID = 1;
DELETE:
Syntax –
• In 2nd syntax, all rows are deleted. The table structure, attributes, and indexes will be intact
Example –
DELETE
FROM Customers
SELECT TOP:
• The SELECT TOP clause is used to specify the number of records to return.
Syntax –
• In case the interviewer asks other than the TOP, rest are also correct. (Diff. DB Systems)
Example –
LIMIT 3;
Aggregate Functions:
MIN():
• The MIN() function returns the smallest value of the selected column.
Syntax –
Example –
FROM Products;
MAX():
• The MAX() function returns the largest value of the selected column.
Syntax –
Example –
FROM Products;
COUNT():
• The COUNT() function returns the number of rows that matches a specified criterion.
Syntax –
Example –
SELECT COUNT(ProductID)
FROM Products;
AVG():
Syntax –
Example –
SELECT AVG(Price)
FROM Products;
SUM():
Syntax –
Example –
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;
• 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 –
Example –
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 –
Example –
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 –
Example –
FROM Orders
• The LEFT JOIN keyword returns all records from the left table (table1), and the matching
records from the right table (table2). The result is 0 records from the right side, if there is no
match.
Syntax –
Example –
FROM Customers
ORDER BY Customers.CustomerName;
• 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 –
Example –
FROM Orders
ORDER BY Orders.OrderID;
• The FULL OUTER JOIN keyword returns all records when there is a match in left (table1) or
right (table2) table records.
Syntax –
Example –
FROM Customers
UNION:
• The UNION operator is used to combine the result-set of two or more SELECT statements.
o Every SELECT statement within UNION must have the same number of columns
o 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 –
• SELECT column_name(s) FROM table1 UNION ALL SELECT column_name(s) FROM table2;
Example –
UNION
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 –
Example –
FROM Customers
GROUP BY Country
HAVING:
• The HAVING clause was added to SQL because the WHERE keyword cannot be used with
aggregate functions. *WHERE is given priority over HAVING.
Syntax –
• SELECT column_name(s) FROM table_name WHERE condition GROUP BY column_name(s)
HAVING condition ORDER BY column_name(s);
Example –
FROM Customers
GROUP BY Country
CREATE DATABASE:
Syntax –
DROP DATABASE:
Syntax –
CREATE TABLE:
Syntax –
• CREATE TABLE table_name ( column1 datatype, column2 datatype, column3 datatype, .... );
DROP TABLE:
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 –
Example –
COMPUTER NETWORK
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.
Network Topology :
• Network topology specifies the layout of a computer network. It shows how devices and
cables are connected to each other.
• Star :
o Star topology is a network topology in which all the nodes are connected to a single
device known as a central device.
o Star topology is very easy to install, manage and troubleshoot. It is commonly used
in office and home networks.
• Ring :
o 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.
o It does not need any central server to control the connectivity among the nodes.
o Ring topology is very rarely used as it is expensive, difficult to install and manage.
• Bus :
o Bus topology is a network topology in which all the nodes are connected to a single
cable known as a central cable or bus.
o 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.
• Mesh :
o Mesh topology is a network topology in which all the nodes are individually
connected to other nodes.
o It does not need any central switch or hub to control the connectivity among the
nodes.
o 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.
o It is robust as a failure in one cable will only disconnect the specified computer
connected to this cable.
o Mesh topology is rarely used as installation and configuration are difficult when
connectivity gets more.
• Tree :
o Tree topology is a combination of star and bus topology. It is also known as the
expanded star topology.
o In tree topology, all the star networks are connected to a single bus.
o 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.
o Tree topology depends on the "main bus," and if it breaks, then the whole network
gets damaged
• Hybrid :
o A hybrid topology is a combination of different topologies to form a resulting
topology.
o 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.
• For Example:
▪ It is used for a small geographical location like office, hospital, school, etc.
▪ It is actually a LAN that is used within a house and used to connect homely
devices like personal computers, phones, printers, etc.
▪ It is used to connect the devices which span to large cities like metropolitan
cities over a wide geographical area
▪ It is used over a wide geographical location that may range to connect cities
and countries
• 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 :
o VPN is used to connect offices in different geographical locations remotely and is
cheaper when compared to WAN connections.
o VPN is used for secure transactions and confidential data transfer between multiple
offices located in different geographical locations.
o VPN encrypts the internet traffic and disguises the online identity
• Types of VPN :
o Access VPN:
o Site-to-Site VPN:
▪ Intranet VPN:
▪ Extranet VPN:
IPv4 Address:
• An IP address is a 32-bit dynamic address of a node in the network. An IPv4 address has 4
octets of 8-bit each with each number with a value up to 255. IPv4 classes are differentiated
based on the number of hosts it supports on the network. There are five types of IPv4
classes and are based on the first octet of IP addresses which are classified as Class A, B, C, D,
or E
• It is a network architecture model based on the ISO standards. It is called the OSI model as it
deals with connecting the systems that are open for communication with other systems. The
OSI model has seven layers. The principles used to arrive at the seven layers can be
summarized briefly as below:
• Seven Layers :
i.Physical Layer :
▪ The physical layer is mainly used for the physical connection between the
devices, and such physical connection can be made by using twisted-pair
cable, fibre-optic or wireless transmission media.
ii.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:
▪ Error control:
▪ Addressing:
▪ Link management:
iii.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.
▪ Routing:
▪ Logical addressing:
▪ Packetizing:
▪ The network layer receives the data from the upper layer
and converts the data into packets. This process is known as
packetizing.
▪ Internetworking:
▪ Fragmentation:
▪ It is a process of dividing the packets into fragments
iv.Transport Layer :
▪ It delivers the message through the network and provides error checking so
that no error occurs during the transfer of data.
▪ Connection-oriented transmission:
▪ Connectionless transmission:
v.Session Layer :
▪ Session layer also reports the error coming from the upper layers.
▪ Session layer establishes and maintains the session between the two users
vi.Presentation Layer :
▪ 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.
▪ Data conversion
▪ Data compression
▪ Data encryption
vii.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.
• 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.
o 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
o 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.
o 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)
o Application :
• 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.
• HTTPS is the HyperText Transfer Protocol Secure or Secure HTTP. It is an advanced and
secured version of HTTP. On top of HTTP, SSL/TLS protocol is used to provide security. It
enables secure transactions by encrypting the communication and also helps identify
network servers securely. It uses port 443 by default. ●
DNS Imp :
• DNS is an acronym that stands for Domain Name akashsingh3031.DNS was introduced by
Paul Mockapetris and Jon Postel in 1983.
• 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.
• DNS is an internet which maps the domain names to their associated IP addresses.
• Without DNS, users must know the IP address of the web page that you wanted to access.
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):
• 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
communication.The main elements of a protocol are:
o Syntax:
▪ It specifies the structure or format of the data. It also specifies the order in
which they are presented.
o Semantics:
o Timing:
▪ Timing specifies two characteristics: When data should be sent and how fast
it can be sent.
o DHCP:
o FTP :
o ICMP :
o ARP :
o RIP :
• Both MAC (Media Access Control) Address and IP Address are used to uniquely define a
device on the internet. NIC Card’s Manufacturer provides the MAC Address, on the other
hand Internet Service Provider provides IP Address.
• 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.
• Ipconfig :
• Ifconfig :
o Interface Configuration, It is a command used in MAC, Linux, UNIX operating systems
to view and configure network interfaces
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
1. What happens when you enter google.com in the web browser? Most Imp :
• Steps
o Check the browser cache first if the content is fresh and present in the cache display
the same.
o 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.
o A new TCP connection is set between the browser and the server using three-way
handshaking.
o The web servers running on the Servers handle the incoming HTTP request and send
the HTTP response.
o The browser processes the HTTP response sent by the server and may close the TCP
connection or reuse the same for future requests.
2. Hub:
o 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.
• Switch:
o Switch is a network device which is used to enable the connection establishment and
connection termination on the basis of need. Switch is operated on the Data link
layer. In this packet filtering is available. It is a type of full duplex transmission mode
and it is also called an efficient bridge.
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.
o Downtime:
o Failure Frequency:
o 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:
o Performance :
▪ performance can be measured in many ways like transmit time and response
time.
o Reliability:
o Robustness:
o Security:
▪ A router sends the data between two similar networks while gateway sends
the data between two dissimilar networks.
8. NIC Imp :
o 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.
• 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.
• Public IP Address :
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 :
o 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 :
o 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 :
o 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