0% found this document useful (0 votes)
17 views

Computer Science & Engineering Information Theory English Medium

The document provides an overview of computer organization and architecture, focusing on the Von Neumann architecture, bus arbitration methods, and various types of registers and micro-operations. It discusses instruction formats, addressing modes, and CPU organization types, as well as cache memory concepts including hit/miss ratios and replacement algorithms. Additionally, it covers the Arithmetic Logic Unit (ALU) and the execution phases of instructions in a CPU.

Uploaded by

sonu90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Computer Science & Engineering Information Theory English Medium

The document provides an overview of computer organization and architecture, focusing on the Von Neumann architecture, bus arbitration methods, and various types of registers and micro-operations. It discusses instruction formats, addressing modes, and CPU organization types, as well as cache memory concepts including hit/miss ratios and replacement algorithms. Additionally, it covers the Arithmetic Logic Unit (ALU) and the execution phases of instructions in a CPU.

Uploaded by

sonu90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 190

Search on TG: @apna_pdf

01. Computer Organization and


Architecture
Von Neumann Architecture (Stored Memory Bus Arbitration–The overall control which decides
Program) who will control the master bus line.

There are two approaches to bus arbitration.


• Centralization bus arbitration
• Distributed bus arbitration
Register–
Logic 1. Memory Address Register (MAR) hold on
address of the memory unit.
2. PC–Program Counter
3. IR–Instruction Register
4. R–Processor Register
Computer register are designated by capital letters.
Various General Purpose Registers– Register Transfer– R2 ← R1
• Address Register 5. DR – Data Register
• Data Register Bus and Memory Transfers–
• Accumulator Common Bus- It consists of a set of common lines
one for each bit of a register through which binary
• Program Counter information is transfered one at a time.
Control Signal–Determine which register is
• Instruction Register selected by the bus during each particular register
• Temporary Register transfer.
• Input Register Bus System for four Register–
• In general bus system will multiplex K register
• Output Register
of n bits each to produce an n-line common bus.
Type of Bus– There are three type of Bus.
• The number of multiplexers needed to construct
• Address Bus the bus is equal to n, the number of bits in each
• Data Bus register.
• Control Bus • The size of each multiplexer must be K×1 since it
multiplexer K data lines.

• The address bus, which is a unidirectional path


way that allows information to travel in only one
direction, carries information about where data
will be stored in memory.
• The data bus is a bidirectional path way that
carries the actual data (information) to and from
the main memory.
• The control bus carries the control and timing Bus Transfer–
signals needed to coordinate the activities of the Bus ← R2, R1 ← BUS
entire computer. Think of this as a traffic cop. ⇒ R1 ← R2
Computer Organization and Architecture 3 YCT
Search on TG: @apna_pdf
Memory Transfer– Read : DR ← M[AR] • Right shift
Write : M[AR] ← R1
Where, DR → Data Register
AR → Address Register
Micro-operations– Micro-operations classified into
four categories Address Register ← Program Arithmetic shift– Applied on signed number after
counter the shift sign of the number should remain same.
1. Register Transfer Micro-operations Left shift– It is same as logical left shift but it is
allowed only when sign is not going to change.
2. Arithmetic Micro-operation
3. Logic Micro-operation Example–
4. Shift Micro-operation
Register Transfer Micro-operations- These type
of micro operations are used to transfer from one
register to another binary information.
Arithmetic Micro-operation
1. Addition – R3 ← R1 + R2
Right shift–
2. Subtraction – R3 ← R1 – R2
R 3 ← R1 + R 2 + 1
3. 1's complement – R 2 ← R 2
4. 2's complement – R 2 ← R 2 + 1 Instruction format–
• A group of bits which instructs computer to
5. Increment – R1 ← R1 + 1 perform some operation.
6. Decrement – R1 ← R1 − 1 ISA (Instruction Set Architecture) Collection of
Arithmetic shift – The increment and decrement all instruction CPU supports.
micro operations are implemented with a binary up- Type of Instruction (Based on Operation)
down counter. • Data Transfer – MOV, LDI, LDA
Logic micro operation– • Arithmetic & Logic – ADD, SUB, AND, OR
1. OR – R1 ← R1 ∨ R 3 • Machine Control – EI, DI, PUSH, POP
2. AND – R1 ← R 2 ∧ R 3 • Iterative – LOOP, LOOPE, LOOPZ
• Branch – JMP, CALL, RE T, JZ, JNZ
3. XOR – R1 ← R 2 ⊕ R 3 Type of Instruction (Based on Operand
4. Compliment – R1 ← R Information)
• 4-Address Instruction
5. X-NOR – R1 ← R 2 ⊙ R 3
• 3-Address Instruction
Shift Micro operation– • 2-Address Instruction
• Logical shift • 1-Address Instruction
• Circular shift (Rotation) • 0-Address Instruction
• Arithmetic shift
Logical Shift– There are two types
• Left shift Types of CPU Organization– The number of
Example– address fields in the instruction format of a
computer depends on the internal organization of
1011 → 1 0 1 1 0 = 0 1 1 0 the registers.
× There are three types of organization.
• Right shift. 1. Single Accumulator Organization
Example– 2. General Register Organization
3. Stack Organization (LIFO)
1011 → 0 1 0 1 1 = 0 1 0 1
1. Single Accumulator Organization– The
×
instruction format in this type of computer user one
Circular shift– There are two types address field.
• Left shift Example–
ADD × AC ← AC + M[X];
AC → Accumulator Register
2. General Register Organization uses three and two
address instructions.
Computer Organization and Architecture 4 YCT
Search on TG: @apna_pdf
Example– Example– LD@ADR ⇒ AC ← M[M[ADR]]
ADD R1, R2, R3 = R1 ← R2 + R3 • Relative Address Mode– In this mode the
ADD R1, R2 = R1 ← R1 + R2 content of the program counter (PC) is added to
3. Stack Organization uses zero and one address the address part of the instruction in order to
instruction. obtain the effective address.
Example–(i) PUSH (ii) ADD Example– LD$ADR ⇒ AC ←M[PC + ADR]
In a general register CPU organization there are # Relative addressing is often used with
eight general purpose register and ALU can perform branch-type instruction.
32-different operation. • Base Register Mode– Used in program
The number of selection line of each multipliers for relocation of programs in memory.
selecting the operand = 3 (23 =8) Indexed Addressing Mode–
The number of bits in operation code= 5(25 = 32) → Use to access or implement array efficiently.
The length of the control word = 5 + 3 + 3 + 3 = 14 → Multiple Registers required to implement.
(for 3-address instruction) → Any element can be accessed without changing
Addressing Mode instruction.
The way of operand are choosen during program Example– LD AD R(x) ⇒ AC ← M [ADR + X]
execution is dependent on the addressing mode of
instruction. Arithmetic Logic Unit (ALU)
The addressing mode may reduce the number of bits Inside a computer, there is an (ALU) which is
in the addressing field of the instruction. capable of performing logical operations (e.g AND,
Instruction Cycle– CPU performs 6 phases to OR, Ex-OR, Invert etc.) in addition to arithmetic
execute an instruction. operation (Addition, Subtraction etc.). The control
unit supplies the data required by the ALU from
memory or from input devices and directs the ALU
to perform a specific operation based on the
Fetch cycle – Instruction fetch instruction fetched from memory.
Execution cycle – from decode ...... to write back
Type of addressing mode–
• Implied Mode– Operand is specified Implied
in the definition of instruction.
Used for zero address and one address instruction.
• Immediate Mode– Operand is directly
provided as constant.
No computation required to calculate effective
address.
• Register Mode– Operand is present in the
register.
Example– LDR1 ⇒ AC ← R1
Register number is written in instruction.
• Register Indirect Mode– Register contains
address of operand rather than operand itself.
Example– LD (R1) ⇒ AC ← M[R1]
• Auto Increment or Auto Decrement
Addressing Mode– Special case of register
indirect addressing mode.
Example–
LD(R1) + ⇒ AC ←M[R1], R1 ← R1 + 1
• Direct Addressing Mode (Absolute
addressing mode)– Actual address is given in
instruction. Cache Memory
Use to access variables Cache memory faster than main memory.
Cache hit– It required element present in cache that
Example– LD ADR ⇒ AC ← M[ADR]
called cache hit.
• Indirect Addressing Mode– Hit latency– Time taken to find out whether
Using to implement pointers and passing element present on the cache or not that is called hit
parameters. latency.
2 memory access required. Where the effective Cache miss– It required element not present in
address is stored in memory. cache, that is called 'Cache miss'.
Computer Organization and Architecture 5 YCT
Search on TG: @apna_pdf
Miss latency– Time taken to get something from Block size = 256 B = 28 B
main memory and then place it into the cache and 217
then read that's called miss latency. No. of Block = 8
= 29 bit
Page hit– It required element present in main 2
memory. Cache size = 16 KB = 214 b
Page fault– It required element not present in main
memory.
Tag directory– Tag directory say that required
element present in tag on not.
Introduction to Direct mapping–
Offset
• Taking about disk and main memory we talking
about paging. Cache size 214
• Talking about Cache and main memory we talking Number of line = = = 26 bit
Block size 28
about blocks.
Tag directory size = (Tag size * No. of lines)
• Block size = lines size.
= (3*26) bit
Fully Associative– The associative memory stores
both the address and content (data) of the memory
word. This permits any location in cache to store
any word from main memory.

=0111

• Smallest addressable unit in the memory called


word.
Let's
1w = 1B (means system is byte addressable)
Block size = 4 word Offset
No. of black in main memory = 128/4 = 32 block
No. of Lines in Cache = 16/4 = 4 lines Block no. = 32 = 25 = 5 bit
Physical address contain = 128 = 27 = 7 bits Block offset = 4 = 22 = 2 bit
Processure generate address = Set-Associative Mapping– The set associative
mapping is an improvement over the direct mapping
in that each word of cache can store two or more
word of memory under the same index address.
No.of lines
Offset Total number of set =
K
00 20 K is number of way
01 21 Example–
10 22 4 way set associative cache lines = 128
Lines size = 64 word
11 23
Physical address = 20 bits
Example– Main memory size = 128 KB
Tag, set and word field are?
Cache size = 16 KB
Solution–
Block size = 256 B
Tag bits = 3 bit
Tag directory size = ?
Solution – Main memory size 128 KB
= 210 *128 B
Cache size
= 210 *27 B Number of lines =
= 217 B Lines size
Computer Organization and Architecture 6 YCT
Search on TG: @apna_pdf
Cache size = 26 * 27 = 213 word  5  100 1
7
Hit ratio =  × 100  = = 33
Lines 2  15  3 3
Sets = = 2 = 25
Set size 2  10  2 2
Miss =  ×100  = ×100 = 66
Tag = 9, Set = 5, Word = 6  15  3 3
Locality of Reference– M M M M M H H H M H
1. Spatial locality (ii) LRU  5, 12, 13, 17, 4 , 12, 13, 17, 2 , 13,
2. Temporal locality 
M H M M H
• If a word is accessed now then the word adjacent 19, 13, 43, 61, 19 
to it (close proscimity) will be accessed next. 
• Keeping more words in a block affects spatial
locality (block size). ( 5 , 12 , 13 , 17 , 4 , 12 , 13 , 17 , 2 , 13 , 19 , 13,

• If a word is referenced now then the same word 43, 61, 19)
will be referenced again in future. 6 
Hit ratio =  ×100  = 40
• LRU is used in temporal locality.  15 
Cache Replacement Algorithms– 9 
Miss =  ×100  = 60
• Replacement policy is required for associative  15 
mapping and set associative mapping but not for (iii) Direct mapping
direct mapping.  
M M M M M M M M M M M
• Replacement policies are aimed to minimize miss 5,   5, 12, 13, 17, 4, 12, 13, 17, 2, 13,
Penalty for future references.
 
M H M M M
19, 13, 43, 61, 19 

Line number = B.No mode 4


Example– Consider the cache has 8 blocks for the 1 
Cache hit ratio =  × 100  = 6.66
memory reference (5, 12, 13, 17, 4, 12, 13, 17, 2,  15 
13, 19, 13, 43, 61, 19). What is the hit ratio for the
 14 
following cache replacement algorithms. Miss ratio =  × 100  = 93.333
 15 
(i) FIFO
(iv) 2-way set associate
(ii) LRU
(iii) Direct mapping  5 12 13 17 4 12 13 17 2 13
 M, M, M, M, M, H, H, H, M, H,
(iv) 2-way set associate 
M M M M M H H H M H 19 13 43 61 19 
(i) FIFO  5, 12, 13, 17, 4, 12, 13, 17, 2, 13, M, H, M, M, M 

 
M M M M H 
19, 13, 43, 61, 19 

Line no. = (i mod 2) i → Block number


5 
Hit ratio =  ×100  = 33.33
 15 
 10 
Miss ratio =  ×100  = 66.66
 15 
Computer Organization and Architecture 7 YCT
Search on TG: @apna_pdf
Control Processing Unit Difference between Horizontal Micro
CPU Control Design– There are two major types Programming and Vertical Micro Programming
of control organization. Horizontal Micro Vertical Micro
(i) Hardwired Control Programming Programming
(ii) Micro programmed control 1. Control Word Large Control word is
small
Hardwired Control Unit– Control logic is
implemented with gates, flip-flops, decoders and 2. Parallelism is high No parallalism
other digital circuits. 3. Faster Slower
Advantage– Can be optimized to produce a faster Difference between Hardwired Control Unit and
mode of operation. Micro Programming Unit
Disadvantage– Rearranging the wires among Hardwired Micro Programming
various components is difficult. Control Unit Unit
1. Fixed Instruction Instruction can flexible
2. High speed Slower compared to
hardwired instruction
3. Expensive Relatively cheap
4. Complex Simple
Example– Intel Example– INTEL 8080,
8085, Motorola Motorola 68000 and any
6802 Tilog 80 and complex instruction set
any Reduce computer.
Instruction Set
Computer (RISC)
Micro-Programmed Control Unit– Control Logic
is implemented with micro programmed. Difference between RISC and CISC
Advantage– Updating the control logic is easy. RISC CISC
Disadvantaged– Slower than hardwired control Less number of More number of
unit. instruction instruction
Control Word Sequencing Fixed length instruction Variable length
instruction
Simple Instruction Complex Instruction
Limited addressing More & complex
addressing modes
Easy to implement using Difficult to implement
hardwired control unit using hardwired
Example– CPU has 64 distinct instructions each
instruction takes 8 micro operation micro- One cycle per instruction Multiple cycle per
instruction– instruction
(i) Signals (128 bits) Register to register Register to memory &
(ii) Mux select [16 mux inputs] arithmetic operation only memory to register
(iii) Address arithmetic operations
possible
What is size of control memory?
More number of registers Less number of registers
Solution– Total micro operations = 64*8
= 26 * 23 = 29 Example– Consider the following processor design
characteristics.
Memory address = 9 bits
(i) Register to register arithmetic operation only
MUX (ii) Fixed length instruction format
Signals Address
select (iii) Hardwired control unit
Which of the characteristics above are used in the
128 4 9
design of a RISC processor?
Total micro Instruction = 128 + 4 + 9 = 141 bit (a) i and ii only (b) ii and iii only
so size of control memory = 29 *141 bits (c) i and iii only (d) i, ii and iii
Computer Organization and Architecture 8 YCT
Search on TG: @apna_pdf
IO Organization Example-
Peripheral Device– Devices connected to processor How many 8 bit characters can be transmitted per
externally are known as peripherals. There are three second over 9600 baud (bits/sec) serial
type– communication link using a parity synchronous
mode of transmission with 1 start bit, 8 data bits, 2
• Input Devices stop bits and 1 parity bit.
• Output devices Solution– For 1 char = 1 + 8 + 2 + 1 = 12 bits
• Storage devices 9600
Input/Output Subsystem Of Computer– Provides Characters transmitted = = 800 char / sec
12
an efficient mode of communication between
Mode of transfer– 3-way to perform I/O
control system & outside word.
• Programmed I/O
Input/Output Interface– Provides a method for
• Interrupt driven I/O
transferring information between internal storage
(memory & registers) & external I/O devices. • DMA
Programmed I/O
{1. Read the status flag.
2. It data is not available (status = 0) then go to step
• Serial and Parallel Transmission 1.
(i) Serial Transmission 3. Move the data}
• Waste time processor
(ii) Parallel Transmission • Mostly devices time to transfer 1 byte.
Interrupt Initiated IO–
• IO device has a provision (interrupt signal) to
Difference between Serial and Parallel inform to CPU about communication
Serial Parallel When CPU receives interrupt–
Need of shift register No need of shift • It completes execution of current instruction
register • Saves the status (PC, PSW etc.) of current process
onto the stack
• Branches to service the interrupt
• Resumes the previous process by taking out the
values from stack.
DMA (Direct Memory Access)
Burst errors Bit errors
• Enables data transfer between I/O and memory
Cheaper Costless without CPU intervention.
Less reliable More reliable • Need a hardware : DMAC
Used to more distance Used to less Starting Address – Memory Address starting from
distance where data transfer should be perform.
Asynchronous Transmission– Data is sent in Data Count– No of bytes or word to be transferred.
form of byte or character. This transmission is the
half-duplex type transmission. In this transmission
start bits and stop bits are added with data.
Example–
• Email
• Forums
• Letters
Synchronous Transmission– Data is sent in form
of blocks or frames. This transmission is the full- Modes of DMA Transfer
duplex type. Between sender and receiver, • Burst mode (all data transfer at the same time)
synchronization is compulsory.
• Cycle stealing (it happen word by word)
Example–
• Interleaving DMA (Whenever CPU does not
• Chat rooms require system buses (doing internal work) then
• Telephonic conversations only control of the buses given to DMAC).
Computer Organization and Architecture 9 YCT
Search on TG: @apna_pdf
Flynn's Classification of computer n = 500, K = 5, tp = 15
• SISD– Single Instruction Stream, Single Data processing time of pipeline = (K + n – 1)tp
Stream = (5 + 500 – 1)15
Example– Von-neamann = 504 × 15
• SIMD– Single Instruction Stream, Multiple Data = 7560 n sec
Stream Instruction Pipeline
Example– Pipeline processor If pipeline processing is implemented on instruction
• MISD– Multiple Instruction Stream, Single Data cycle.
Stream only hypothetical IF : Instruction fetch
• MIMD – Multiple Instruction Stream, Multiple ID : Instruction decode & Address calculation
Data Stream
OF : Operand Fetch
Example– Multiple Pipelines (Super Scalar
EX : Execution
Computer (ILP))
WB : Write Back
Pipelining
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
• Pipelining is useful, when same processing is I1 IF ID OF EX WB
applied over multiple inputs. I2 IF ID OF EX WB

• Technique to decompose a sequential process into I3


I4
IF ID
IF
OF
ID
EX WB
OF EX WB
sub-operations. I5 IF − −
• Sub-operations performed in all segments. I6

• Task: one operation performed in all segments. I7


I8 IF ID OF EX WB
General Consideration about pipeline I9 IF ID OF EX WB

• Consider a K segment pipeline with clock cycle Assume in cycle number 5, I4 decoded as branch
time = tp to perform n tasks. instruction.
Time required to perform 1st task = K*tp
By standard ⇒ Branch decision is made in
Time required to perform remaining (n –1) tasks =
'Execution' phase.
(n–1)tp
Time required for all n tasks = (K+n–1)tp • After execution phase next instruction can be
(K + n – 1) is total cycle. fetched.
• Consider a non-pipeline system that takes tn time Actually only instruction executed (n = 6) K = 5 for
to perform a task n input, no. of cycles = K+ n – 1
Time required for n task = n*tn =5+6–1
• Performance of a pipeline is given by speed up = 10
ratio. 3 cycles are extra (stall cycles because of branch)
Non − pipeline time Total = 10 + 3 = 13 cycles
Speed up ratio =
Pipeline time Total execution time = cycle * tp
n * tn Pipeline Hazards– Situations that prevent the next
S= instruction from being executing its designated
( K + n − 1) t p clock cycle.
as the number of task increases, n>>K (Ignore K–1) • Hazard lead to have stall cycles
tn There are three type–
Sideal =
tp 1. Structural Hazard/Resource Conflict
2. Data Hazard/Data Dependency
Latency– Time after machine takes next input.
3. Control Hazard/Branch difficulty
• Latency in non-pipeline = tn
Structural Hazard– When multiple instruction
• Latency in pipeline = tp
need same resource.
Throughput– No of input processed per unit of
Control Hazard– All Instruction who change the
n
time = program counter leads to control hazard because of
( K + n − 1) t p branch instruction.
Ideal case– Data Hazards Classification–
1 • RAW (Read After Write) [Flow/true data
Throughput =
tp dependency]
Example– Consider a 5 stage pipeline with cycle time • WAR (Write After Read) [Anti Data dependency]
of 15 ns. Calculate processing time of pipeline • WAW (Write After Write) [Output data
for 500 tasks. dependency]
Computer Organization and Architecture 10 YCT

Powered by TCPDF (www.tcpdf.org)


Search on TG: @apna_pdf

02. DATA STRUCTURE AND


ALGORITHM
Merging- Combining the data of two different sorted
DATA STRUCTURE files into a single sorted.
Data- Data is a collection of raw, unorganized facts and
Example-
details like text, observations figures, symbols, and
descriptions of things etc.
Data can be record and does not have any meaning
unless processed.
Information- Information is processed, organized, and
Traversing- Accessing Each data Exactly one in the
structured data.
data structure so that Each data item is traversed or
Definition of data structure – A data structure is a
visited.
collection of data, generally organized so that items can
be stored and retrieved by some fixed techniques. Example-

Arrays in Data structure


Array- Array is a fixed size sequenced collection of
data items of same type.
• Access a particular element = array name [index]
= Int a [ ]
• data items are stored in continuous locations.
How the data is to be accessed, how you can calculate
the address.

Data structure operation


Insertion- Add a new data in the data structure.
Example–
a[0]=6, a[1]=2, a[2]=4, a[3]=3, a[4]=0
Formula-
Address of a[i] = Base +i * (size of data type)
i = 0, 1, 2……..(n - 1)
n = size of array
Deleting- Remove a data from the data structure. so if want to, i = 2;
Example- Int size = 4 bit
10 20 30 40 50 = 100+2×4
Deleting = 108
20 10 30 40 • Random Access taking Constant time.
Sorting- Arrange data in increasing or decreasing order.
Example-
data- 20, 30, 10, 5, 6
5 6 10 20 30
Searching- Final the location of data in data structure.
Example-
5 6 10 20 30 • Name [LB:UB] LB ≤ UB
a[0] a[1] a[2] a[3] a[4] LB = Lower Bound
Search = 10 → a[2] UB = Upper Bound
Data Structure and Algorithm 11 YCT
Search on TG: @apna_pdf

Operation On Linked List-


1. Creation - This operation are used to created a linked
Size of array = UB-LB+1
list in this node is created and linked to the Another
Consider an array A [6:18]. node.
Total number of element in array 2. Insertion- This operation is used to insert a new node
By formula in the linked list.
Size of array = UB – LB+1 3. Deletion- In this operation, elements can be deleted
= 18 – 6 + 1 at the starting of the list.
= 13
4. Traversing- It is a process of going through all the
Searching Array– nodes of linked list from one End to the other end.
• Searching an array means to find a particular element
in the array. The search can be used to return the Type of Linked List
position of the element or check if it exists in the • Singly Linked List- A singly linked list is a
array. unidirectional linked list. It is the simplest type of
• Linear Search Time complexity linked list in which every node contains some data and a
Average O (n) pointer to the next node of the same data type.
Best O (1)
Worst O (n)
• Binary search Time complexity
Average O (log n)
Best O (1)
Worth O (n) •
• Pointer is an address of another variable Doubly Linked List- A doubly linked list is a
Example– bidirectional linked list that contains a pointer to the
int b = 10; next as well as the previous node in sequence.
int* P; b P
10 200
P = & b; 200 204
2-D Array
The two-dimensional array can be defined as an array of • Circular Linked List- A circular linked list is that in
array. which the last node contains the pointer to the first node
2D array syntax– of the list.
data type array_name [row][columns];
Representation of 2-D Arrays in memory
Row major order-
a [i][j] = B+((i*n)+ j)*size.
IF start (0,0)
A [i][j] = [((i-1)*n+(j-1))*size + Base if start (1,1)
Colom major • Circular Doubly Linked List- A circular doubly
A [i][j] = ((i*m) + i)*size + Base linked list is a mixture of a doubly linked list and a
circular linked list.
Linked List
A Linked list is a Linear data structure in which the
elements are not stored at contiguous memory location.
• A liked list is a dynamic data structure.
• Each element is called a node which has two part,
info part stores the information and pointer part
which point to the next element.
Data Structure and Algorithm 12 YCT
Search on TG: @apna_pdf
Representation of Linked List– Stack Notation- There are three stack notation.
• A data item • Infix Notation- Where the operator is written in
• An address of another node between the operands.
We wrap both the data item and the next reference in a Example- A+B + operator
struct as. A, B operands
Syntax– • Prefix Notation- In this operator is written before
Struct node the operands. It is also know as polish Notation.
Example- +AB
{ Int data;
Struct node*next; • Post fix Notation- In this operator is written After
the operands. It is also know as suffix Notation.
};
Example- AB+
Linked list Applications
• Convert the following Infix to prefix and postfix
• Dynamic memory allocation.
for (A + B)* C/D+E ∧ F/G
• Implemented in stack and queue.
Prefix –
• In undo functionality of software.
(A+B)* C/D + E ∧ F/G
• Hash tables, graphs.
+ AB* C/D + E ∧ F/G
STACKS Let + AB = R1R1
Stack is a non-primitive linear data structure. * C/D + E^F/G
It is an ordered list in which addition of new data item R1 * C/D+^ EF/G
and deletion of already existing data item is done from Let ^ EF = R2
only one End know as Top of Stack (TOS). R1 * C/D+R2/G
R1 */CD + R2/G
Let /CD = R3
R1*R3 + R2/G
R1*R3 + /R2G
Let /R2G = R4
R1*R3 + R4
• It follows the LIFO pattern, which means the last *R1R3 + R4
added element will be the first to be Removed from the Let *R1R3 = R5
stack. R5 + R4
Stack has two operation– 1. PUSH Operation +R5R4
2. POP Operation Now enter the value of R5, R4, R3, R2, R1
PUSH Operation- Every PUSH operation TOP is +*R1R3/R2G
incremented by one. +*+AB/CD/AEFG
TOP = TOP + 1 Post fix-
In case the Array is full no new Element is added. This (A+B)*C/D+E ∧ F/G
condition is called stack full or stack over flow AB+*C/D+E ∧ F/G
condition. Let AB+=R1
• The process of adding a new element of the TOP of ∧
R1*C/D+EF /G
stack is called PUSH operation.
Let EF ∧ =R2
POP Operation- The process of Deleting an element
R1*C/D+R2/G
from the top of stack is called POP.
R1*CD/+R2/G
After Every POP operation the stack TOP is
Let CD/ = R3
decremented by one.
R1*R3+R2/G
TOP = TOP-1
R1*R3+R2G/
(This is called operation stack underflow).
Let R2G/=R4
R1*R3+R4
R1R3*+R4
Let R1R3*=R5
R5+R4+
Data Structure and Algorithm 13 YCT
Search on TG: @apna_pdf
Now Enter the value of R5,R4,R3,R2,R1 • Get highest priority ( ): Returns the highest priority
R5R4+ item. operation implemented by linear searching the
R1R3*R4+ highest priority item in array. O(1).
AB+CD*R2G/+ • Delete highest priority (): Removes the highest
AB+CD* EF ∧ G/+ priority operation can be implemented by first
linearly searching an item, the removing the item by
QUEUE moving all subsequent items one position back. (time
• Queue is a Non primitive Linear data structure. O(logn)).
• The first added Element will be the first to be remove • Heap is generally preferred for priority queue
from the queue that is the reason queue is called implementation because heaps provide better
(FIFO) type list. performance compared array or linked list.
• In queue Every insert operation Rear is incremented Circular Queue- A circular queue is one in which the
by one. (R = R + 1) and every delete operation front insertion of a new element is done at very first location
is increment by one. of queue is full.

• A circular queue overcome the problem of utilized


space in linear queues implemented as arrays.

BINARY TREE
• Binary tree is a finite set of data item which is either empty
of consists of a single item called root and two disjoint
binary tree called the left sub tree and right sub tree.
BASIC OPERATION OF QUEUE
• In Binary tree, every node can have maximum of two
• Enqueue: Add an element to the end of the queue. children which are known as left child and right child.
• Dequeue: Remove an element from the front of the
queue.
• Is Empty: Check if the queue is Empty.
• Is full: Check if the queue is full.
• Peek: Get the value of the front of the queue without
removing it.
Application of Queue-
• CPU scheduling, Disk scheduling
• Handling of interrupts in real time system
• Call center phone system use Queues to hold people Types of Binary Tree
calling them in order. Full Binary Tree- A Binary tree is full if every node
• Unlike stack, Queue is also considered as the ordered has 0 or 2 child.
list of the data the ordered list of the data that has a
similar data type.
Priority Queue- Priority Queue is an Extension of
queue with following properties. An element with high
priority is dequeued before an element with low
priority.
Operations-
• Insert (item, priority): Inserts an item with given
priority time (O(logn)).
Data Structure and Algorithm 14 YCT
Search on TG: @apna_pdf
Complete Binary Tree- A Binary tree is complete m 
Internal nodes =  
Binary tree if all level are completely filled. 2
• Every node has max. (m-1) keys
• Min key:- root node → 1
m
all other =   − 1
2
GRAPH
Graph in data structure are non linear data structure
made up of a finite number of vertices and the edges
Perfect Binary Tree- A Tree in which all internal that connect them. Graph in data structure are used to
nodes has two children and all leaves are at the same address real problem in which it represents the real
level in which all level has 2n children. problem in which it represents the problem area as a
network like telephone networks, circuit network and
social network.

Traversal of Binary Tree This graph has a set of vertices


1. Preorder traversal (NLR) Node left Right V = { 1, 2, 3, 4, 5} and a set of edges
2. In order traversal (LNT) Left Node Right E = {(1,2), (1,3), (2,3), (2,4), (2,5), (3,5), (4,5)}
3. Post order traversal (LRN) Left Right Node Operation Of Graph In Data Structure
Example- • Creating graphs
• Insert vertex
• Delete vertex
• Insert edge
B-Tree • Delete edge
B-Tree is a self-balancing tree. in most of the other self- Graph Traversal Algorithm–
balancing searching ( like AVL and Red-Black tree). It Graph traversal is a subset of tree traversal. There are
assumed that everything is in the main memory. two techniques to implement a graph traversal
Algorithm.
Time complexity of B-Tree
1. Breadth - first Search or BFS
Algorithm Time complexity
2. Depth – first – search or DFS
Search O (logn) BFS- Two data structure for traversing the graph.
Insert O (logn) • Visited array (size of the graph)
Delete O (logn) • Queue data structure
Properties of B-Tree • Using the FIFO concept.
• Until the queue is not empty and no vertex is left to
• All nodes of the leaf must be on the same level.
be visited.
• At least two root nodes are required.
• Each B-Tree node a maximum of m children.
• Each node in a B- tree includes at least m/2 children,
except the root and the leaf node.
• Maintains sorted data.
• Minimum children:
leaf = 0
BFS 1 2 3 4 5 6
root = 2
Data Structure and Algorithm 15 YCT
Search on TG: @apna_pdf
DFS- The (DFS) algorithm traverses or explores data The data element The data element connect to
structure such as trees and graphs. The DFS algorithm connect to each other each other sequentially.
begins at the root nodes and examines each branch as hierarchically.
for feasible before backtracking. It is not easy to traverse You can traverse in a single
• Examine any two data structures for traversing the graph. in multiple runs run.
• Visited array (size of the graph) It is memory friendly. It is not very memory friendly.
• Stack data structure Map, Graph, Tree List, Array, Stack, Queue
• Using the FIFO principle. Array Linked list
• Stack data structure is not empty. Array is a collection Linked-list is a collection
of Homogeneous of node (data & address)
(same) data type.
Size of an Array is Size of list is not fixed.
fixed
Memory is allocated Memory is allocated from
from stack. heap.
Work with static data Work with dynamic data
structure structure.
DFS 1 2 4 5 3 6
Array Element are Linked list Element are
Application of graph independent to each depend to each other.
• The friend suggestion system on facebook is based other.
on graph theory. Array take more time Linked- list take less time
• Graph transformation system manipulate graph in memory (Insertion & Deletion) (Insertion & Deletion)
using rules. Graph databases store and query graph–
structure data in a transaction–safe permanent manner. Tree Graph
Difference between stack and Queue There is a unique node There is no unique node.
called root in tree.
Stack Queue
Tree is a collection of Graph is a collection of
The collection of element The collection of Element
node and edges. vertices/nodes and edges.
in last in first out (LIFO). in first in first out (FIFO)
Ex- T{node, Edges} Ex G = {V,E}
Objects are inserted and Objects are inserted and
removed at the same end removed from different ends There will not be any There can be loops/cycle.
called TOP of sack. called Front and Rear end. cycle/loops.

Insert operation is called Insert operation is called In this Pre-order, In- In this BFS and DFS
PUSH operation. Enqueue operation. order and post order traversal.
Traversal.
Delete operation is called Delete operation is called
POP operation. Dequeue operation. HEAP DATA STRUCTURE
In stack There is no In Queue there is a wastage A Heap is a special Tree-based structure in which the
wastage of memory space. of memory space. tree is complete binary tree.
Plate counter at marriage Students standing in a line
Reception is an Example at fees counter is an
of stack. Example of Queue.

Non-Linear Data Linear Data structure


structure
The non- linear data The linear data structure are
structure are comparatively easier to
comparatively difficult implement
implement and
understand as compared A B C D E F G
to linear data structure. 1 2 3 4 5 6 7
Data Structure and Algorithm 16 YCT
Search on TG: @apna_pdf
Formula- • Search key (24, 52, 91, 67, 48, 8 3)
if a Node is at index i • Hash Table
its left child is at = 2*i • Hash Function (K mod 10, K mod n, Mid, Square )
its right child is at = 2*i+1 folding method.
i K mod n = (n-1)
it parent is at =  
2 ↓
(This is true when your heap is starting from index 1.) 24 mod 10 =4
If you represent a binary tree in an array then they 52 mid 10= 2
should not be any empty locations or gaps in between 91 mod 10=1
the elements bins from first element to last element in 67 mod 10=7
between anywhere. 48 mod 10=8
• Height of a complete binary tree will be minimum 83 mod 10=3
only that is log n.
HEAP

B-Tree & B+Tree


Max Heap- A max heap is a complete binary tree in
which the value in each internal node is greater than or Data is stored in leaf Data is stored only in leaf
equal to the values in the children of the node. Max as well as internal nodes.
heap data structure is useful for sorting data using heap nodes
sort. Leaf nodes not linked Linked together like
50 > 30, 20 30 > 15, 10 20 > 8, 16 together Linked list.
Min Heap- A min heap is a heap where every single Searching is slower Searching is faster,
parent node including the root, is less than or equal to deletion complex deletion easy (directly
the value of its children nodes. The most important from leaf node)
property of a min heap is that the node with the
smallest, or minimum value, will always be the root
node.
10 < 30, 20 30 < 35, 40 20 < 32, 25
Operations of Heap
• Heapify– a process of creating a heap from an array.
• Insertion– time complexity O (log N)
• Deletion – time complexity O (log N) ALGORITHM
• Peek–To check or find the most prior element in the Analysis of Algorithms
heap. • A well defined procedure to solve a specific problem
HASHING is called Algorithm.
Hashing is a technique or process of mapping keys and • Data structure + Algorithm = Programming
values into the hash table by using a hush function. It is • Algorithms Criteria
done for faster access to elements.
• Hashing storing and Retrieving data in O (1) time.
Data Structure and Algorithm 17 YCT
Search on TG: @apna_pdf
Asymptotic Notations
Asymptotic notations are abstract notation for describe
the behavior of Algorithm and determine the rate of
growth of a function.

f(n) = θ(g(n))
Worst Case Analysis– The case that causes a
maximum number of operation to be executed.
Best Case Analysis– The case that causes a minimum
number of operations to be executed .
Average Case Analysis– We take all possible inputs
and calculate the computing time for all of the inputs,
1. Big O Notation sum all calculate values and divide the sum by the total
• The Big O Notation defines an upper bound of an number of inputs.
algorithm. Therefore, it gives the worst-case
complexity of an algorithm.
• O (g(n)) = {f(n): there exist positive constants C
and n0 such that
O ≤ f (n) ≤ Cg(n) for all n > n0

BUBBLE SORT
Algorithm–
1. Start with an array of unsorted numbers
2. Defines a function called 'bubblesort" that takes in
the array and the length of the array as parameters.
3. In the function, create a variable called "sorted" that
2. Omega (Ω) Notation:
is set to false.
Omega notation represents the lower bound of the 4. Create a for loop that iterates through the array
running time of an algorithm. thus, it provides the best starting at index 0 and ending at the length of the
case complexity of an algorithm. array –1
5. Within the for loop, compare the current element
with the next element in the array.
6. If the current element is greater than the next elements,
swap their positions and set "sorted" to true.
7. After the for loop, check if "sorted" is true.
8. If "sorted" is true, call the "bubblesort" function
again with the same array and length as parameters.
9. If "sorted" is false, the array is now sorted and the
3. Theta (θ) Notation: function will return the sorted array.
Theta notation encloses the function from above and 10. Call the "bubbleSort" function with the initial
unsorted array and its length as parameters to befin
below. It is used for analyzing the average case
the sorting process.
complexity of an algorithm.
• It is stable sorting techniques.
C1g ( n ) ≤ f ( n ) ≤ C 2 g ( n )
• Recursive relation in Bubble sort.
C1C 2 ≥ 0, n ≥ n 0 , n 0 ≥ 1 T(n) = T (n-1) +n
Data Structure and Algorithm 18 YCT
Search on TG: @apna_pdf
• It is In place sorting = θ (n2)
• Time complexity = θ (n2) space = θ(n)
Space complexity = 1 + n • Stable sorting
= θ (n) QUICK SORT
Best case = θ (n) • It is Divide and conquer technique.
Worst case = θ (n2) • It is unstable sorting
Average case = θ (n2) • Best case = θ (n logn) = Average case
SELECTION SORT Worst case = θ (n2)
Algorithm– • Recursive
1. Initialize minimum value(min_idx) to location 0. T(n) = 2T(n/2)+n
2. Traverse the array to find the minimum element in Using master theorem
the array. θ (n logn)
3. While traversing if any element smaller than min_idx n(n − 1)
• Number of comparison =
is found then swap both the values. 2
4. Then, increment min_idx to point to the next Merge Sort
element. Algorithm–
5. Repeat until the array is sorted. MergeSort(arr[],l,r)
• Recursive relation If r > 1
T(n) = T (n - 1) +(n - 1) 1. Find the middle point to divide the array into two
• Max swap = (n-1) Complexity θ(n) halves.
• Min swap = 0 middle m = l + (r – 1)/2
2. Call mergeSort for first half:
Call mergeSort(arr, l, m)
3. Call mergeSort for second half:
Call mergeSort(arr, m + 1, r)
4. Merge the two halves sorted in steps 2 and 3:
Call merge(arr, l, m, r)
• It is stable sorting.
• It is pure divide & conquer.
• It is unstable sorting • Recursive–
T(n)= 2T(n/2)+n
INSERTION SORT
• Complexity–
Algorithm– To sort an array of size N in ascending Best case = Average case = Worst case = θ(n logn)
order:
RADIX SORT
1. Iterate from arr[1] to arr[N] over the array.
• It is counting Based sorting.
2. Compare the current element (key) to its predecessor.
3. If the key element is smaller than its predecessor, • It is outplace sorting
compare it to the elements before. Move the greater • Q (n k)
elements before. Move the greater elements one
position up to make space for the swapped element.
n ( n − 1) • Q (n*R) space complexity.
• Number of comparison– max =
2 RECURSION
min = n – 1 A recurrence is an equation or inequality that describes a
function in terms of its values on smaller inputs. To solve a
• Best case = θ(n)
Recurrence Relation means to obtain a function defined on
Worst case & Average case = θ(n2) the natural numbers that satisfy the recurrence.
• Insertion sort = Position +Shifting • There are four methods for solving Recurrence
• It is highly affected due to order of input. (i) Substitution method (iii) Iteration method
• Recursive time T (n) = T (n-1)+n (ii) Recursion tree (vi) Master method
Data Structure and Algorithm 19 YCT
Search on TG: @apna_pdf
(i) Substitution method– T(n)=T(n-2)+n-1]+n…...(ii)
1 n = 0 T(n)=T(n-3)+(n-2)+(n-1)+n……(iii)
T(n) =  
 T(n − 1) + 1 n >o :
∵ T(n) = T(n − 1) + 1......(i)  : Continue of k time
T(n) = T(n − 1) + 1   :
∴ T(n − 1) = T(n − 2) + 1.......(ii) 
Substitution T(n − 1) T(n)=T(n-k)+(n-(k-1))+(n-(k-2)+……+(n-1)+n
Assume n-k=0
T(n) = [T(n − 2) + 1] + 1 {From equ x
(ii)}
∴n = k
T(n) = T(n − 2) + 2
T(n)=T(0)+1+2+3+…..n-1+n
T(n) = T(n − 3) + 3
n(n + 1)
⋮ =1+
⋮ Continue for k time 2
⋮ n(n + 1)
T(n)=1+ = θ(n) 2
T(n) = T(n − k) + k Assume n − k = 0 2
T(n) = T(n − n) + n ∴n = k • T(n) = 2T(n − 1) + 1
T(n) = T(0) + n By solving recursion tree
T(n) = 1 + n ∴ θ(n) 1+2+23+…..+2K = 2k+1 (This is GP series)
= θ(2n)
(ii) Recursion Tree – (iv) Master theorem for Decreasing function
T(n)= aT(n-b)+f(n)
1 n = 0
T(n)=   a>0, b>0 and f(n)=O(nK) where K≥0
T(n − 1) + n n > 0
Case
• If a<1 • If a=1 • If a>n
O(nk) O(nK+1) O(nKan/b)
O(f(n)) O(n*f(n)) O(f(n)an/b)
• Master Theorem for Dividing function
(i) logba T(n)=a T(n/b)+f(n)
a≥1
(ii) b> f(n)=θ(nklogPn)
Case1: if logba>k them θ(nlogba)
Case2: if logba=k
If P>-1 θ(nklogp+1n)
If P=-1 θ(nklog log n)
If P<-1 θ(nk)
Case3: If logba<K If P ≥ 0 θ(nklogpn)
If P < 0 O(nk)
T(n) = 2T(n/2) + 1
n(n + 1) a = 2, b = 2, f(n) = O(1) = θ(n0log0n)
0+1+2…….n-1+n= log22 = 1 > K = 0
2
Case1: θ(n1)
n(n + 1)
T(n) = Recurrence Relation
2
T(n) = T(n − 1) + 1 O(n)
θ(n 2 )
T(n) = T(n − 1) + 1 O(n 2 )
(iii) Iteration Method– T(n) = T(n − 1) + log n O(n logn)
1 n = 0 T ( n ) = T ( n − 1) + n 2 O(n 3 )
T(n)=  
T(n − 1) + n n > 0  T(n) = T(n − 2) + 1
n
O (n)
T(n)=T(n-1)+n {∵ T(n) = T(n − 1) + 2 2
T(n)=[T(n-1)+n-1]+n…..(i) {T(n-1)=T(n-2)+n-1 T(n) = T(n − 100) + n O(n 2 )

Data Structure and Algorithm 20 YCT


Search on TG: @apna_pdf
HUFFMAN CODING KNAPSACK PROBLEM
• Huffman Coding is a famous greedy Algorithm. • A Knapsack (kind of shoulder bag) with limited
• It is used for the lossless compression of data. weight capacity.
• It used variable length in encoding. • Few items each having some weight and value.
• It assigns variable length code to all the Characters. • There are two knapsack problem.
Prefix rule– 1. Fractional knapsack problem.
• Huffman coding implements a rule know as a prefix 2. 0/1 Knapsack problem.
coding Fraction knapsack problem
• This is to prevent the ambiguities while decoding • As the name suggest, items are divisible here.
• It ensures that the code assigned to any character is • For each item, compute its value/ weight.
not a prefix of the code assigned to any other • Arrange all the items in decreasing order of their
character. value/weight ratio.
• There are two major steps in Huffman Coding. Put as many items as you can into the knapsack.
1. Building a Huffman tree from the input characters Time Complexity–
2. Assigning code to the characters by traversing the • If the items are already arranged in the required order
Human tree. then while loop takes O (n) time.
Huffman Tree- • Average time complexity of Quick sort is O (n logn)
Step.1 Create a leaf node for each Character of the test. Example–
• Leaf node of a character contains the Occurring Object : O 1 2 3 4 5 6 7
frequency of the character. Profits : P 10 5 15 7 6 18 3
Step.2 Arrange all the nodes in increasing order of their Weights : W 2 3 5 7 1 4 1
frequency value. P
5 1.3 3 1 6 4.5 3
• Considering the first two nodes having considering W
the first two nodes having minimum frequency. x (1 2/3 1 0 1 1 1)
• The frequency of this new node is the sum of x1 x2 x3 x4 x5 x6 x7
frequency of those two nodes. n = 7, M= 15
Step.3 Make the first node as a left child and the other 2
node as right child of the newly created node. ∑x W i i = 1× 2 + × 3 +1 × 5 + 0 × 7 + 1× 4 + 1 × 1
3
Step.4 Keep repeating step 2 and step 3 until all the = 2 + 2 + 5 + 0 + 1 + 4 + 1 = 15
nodes from a single tree. 2
Time complexity-
∑ x P = 1×10 + 3 × 5 + 1×15 + 1× 6 + 1× 18 + 1× 3
i i

• Extract Min( ) is called 2*(n-1) times if there are n nodes. = 54.6


• As extract Min( ) cells min Heapify, it take O (logn) time. Constraint
Thus, Overall time complexity of Huffman coding ∑x W ≤ m i i

become O(n logn).


Objective
Example- ABBCDBCCDAABBEEEBEAB
max ∑ x i Pi

OPTIMAL MERGE PATTERN


Given n number of sorted files, the task is to find the
minimum computations done to reach the optimal
merge pattern, when two or more sorted files are to be
merged altogether to form a single file, the minimum
computation are done to reach this file are known as
Optimal merge pattern.

Data Structure and Algorithm 21 YCT


Search on TG: @apna_pdf

fun(Si +1 , K) + C(Vj , K) 
Example- List– x1, x2, x3, x4, x5
Size– 20 30 10 5 30 Fun (Si, Vj)= min  
C(Vj , D) if Si = Sfi − 1 

Where, S=stage, V = Vertex, F= final stage

Total cost of merging =∑di*xi


di = distance of each node Minimum cost = 11
The size of each node = xi
So, Path
Total number of merging
= 3×5+3×10+2×20+2×30+2×30 = 205 Time Complexity = O (V + E) (E is edge)
DYNAMIC PROGRAMMING
FLOYD-WARSHALL
• It is used to solve optimization solution .
• Breaks down the complex problem into simpler sub- The strategy adopted by the Floyd-Warshall algorithm
problems. is Dynamic programming. The running time of the
• Find optimal solution to these sub-problems.
Floyd-Warshall algorithm is determined by the triply
• Store the results of sub-problems. (memorization)
• Reuse then so that same sub-problem is not nested for loops of lines 3-6. Each execution of line 6
calculated more than once. takes O(1) time. The algorithm thus runs in time θ (n3).
• Finally calculate the result of complex problem.
• Overlapping sub problems & Optimal Substructure.
Type of Dynamic Programming–
• Multistage Graph
• Floyd Warshall
• Bellman Ford Algorithm
• 0/1 Knapsack Example–
• Optimal Binary Tree
• Reliability Design
• Longest common subsequence (LCS)
• Matrix chain Multiplication
MULTISTAGE GRAPH
Multistage graph is a data structure that is used to
represent a graph in which the vertices are divided into
a number of levels. The edges of the graph are also
divided into a number of levers. The multistage graph is
also called a Hierarchical graph.

A K −1[i, j] 
Ak[i, j] = min  k −1 K −1 
A [i, k] + A [k, j]
Time Complexity = O(n3)
Space Complexity = O(n3)
K∀Si +1
Data Structure and Algorithm 22 YCT
Search on TG: @apna_pdf
Bellman Ford Algorithm • On encountering an entry whose value is not same as
the value stored in the entry immediately about it,
mark the row label of that entry.
• After all the entries are scanned the marked labels
represent the items that must be put into the
knapsack.
Example-
O/1 Knapsack problem
m = 8 P = {1, 2, 5, 6}
n = 4 w = {2, 3, 4, 5}
Value of V
V[4, 5] = max[V[3, 5], {V[3, 5-5]+6]}
= max[5, 0] = 5
V[4, 6] = max[V[3, 6], {V[3, 6-5]+6]}
go on relaxing all the edges(n − 1) times
= max[6, 6] = 6
n = number of verites
V[4, 7] = max[V[3, 7], {V[3, 2]+6]}
if ([u] + c(u, v) < d[v]) = max[7, 7] = 7
d[v] = d[u] + c(u, v) V[4, 8] = max[V[3, 8], {V[3, 3]+6]}
= max[7, 8] = 8
Edges- 0 1 2 3 4 5 6 7 8
(A, B), (A, C), (A, D), (B, E), (C, E), (D, C), (D, F), (E,
Pi Wi 0 0 0 0 0 0 0 0 0 0
F), (C, B)
We are done algorithm 5 time. 1 2 1 0 0 1 1 1 1 1 1 1
A-0, B-1, C-3, D-5, E-0, F-3 2 3 2 0 0 1 2 2 3 3 3 3
Single Source Shortest Path 5 4 3 0 0 1 2 5 5 6 7 7
Time Complexity = O(E(|v|-1) 6 5 4 0 0 1 2 5 6 6 7 8
= O(E.V)
= O(n2)
 x1 x2 x3 x4 
0/1 Knapsack Problem Solution   = {2, 6}
0 1 0 1
• Consider– Knapsack weight capacity = w
Number of items each having some weight Optimal Binary Search Tree
and value = n A set of integers are given in the sorted order and
another array to frequency count. Our task is to create a
• Problem solving steps–
binary search tree with those data to find the maximum
(i) Draw a table say 'T' with (n+1) number or row and
cost for all searches.
(w+1) number of column.
Example-
(ii) Fill all the boxes of 0th row and 0th column with
1 2 3 4
zeroes as
Key 10 20 30 40
(iii) Start filling the table row wise top to bottom from
left to right. frequency 4 2 6 3
Using formula
V[i, w]=max{v(i-1, w), v[i-1, w-w[i]]+P[i]} Formula–
Here V [i, w]= maximum value of the selected items [i, j]= min{C[i, k-1]+C[k, j]}+w(i, j) i<k≤j
if we can take items 1 to i and weight restrictions of w.
• This step leads to completely filling the table.
• Then value of the last box represents the maximum
possible value that can be put into the knapsack.
• The knapsack to obtain that maximum profit.
• Consider the last column of the table.
• Start scanning the entries from bottom to top.

Data Structure and Algorithm 23 YCT


Search on TG: @apna_pdf
C[0,1] = 4 DIVIDE AND CONQUER
l = j−i = 0 C[1, 2] = 2 • Divide: In this step, we will break the problem into
l = j−i =1 C[2, 3] = 6 sub-parts by recursion.
C[3, 4] = 3 • Conquer: We will solve the smaller subparts
So, recursively. It the sub problem is small, then we can
l = j−i = 2 solve it instantly.
• Application of divide and conquer Algorithm
C[0, 2] = 8, C[1,3] = 103 , C[2, 4] = 123
(i) Binary search
Using formula
4
(ii) Merge sort
w(0, 4)= ∑ f (i) (iii) Quick sort
i =1
(iv) Strassen's Matrix Multiplication.
l=j–i=3
(v) Karatsuba Algorithm
C[0, 3] = 203, C[1, 4] = 163
(vi) Stassen's Algorithm.
l=j–i=4
C[0, 4] = 263 GREEDY ALGORITHM
Matrix Chain Multiplication • A greedy algorithm is a problem solving approach
A1 A2 A3 like subtract and conquer and dynamic programming,
A2×5 B5×10 C10×3 which is used for solving optimality problem(one
P0×P1 P1×P2 P2×P3 solution), out of all feasible solution.
• Minimum spanning tree
• Single source shortest path
• Huffman coding
Left side • Optimal merge pattern
(BC)5×3 = B5×10 C10×3 = 5×10×3 = 150 KRUSKAL'S ALGORITHM
M [2, 3] = M [2, 2] + M [3, 3] + 5×10×3=150 • Kruskal's Algorithm is a famous greedy Algorithm.
(ABC)2×3 = A2×5(BC) = 2×5×3 = 30
• It is used for finding the Minimum spanning tree
M [1, 3] = M [1, 1] + M [2, 3] + P0×P1×P3
(MST) of a given graph.
= 0+150+30 = 180
• The given graph must be weighted, connected and
Right side
undirected.
(AB)2×10 = A2×5 .B5×10 = 2×5×10 = 100
M [1, 2] = M [1, 1] + M [2, 2] + 2×5×10 =100 • Simple draw all the vertices on the paper.
(ABC)2×3 = (AB)2×10 C = 2×10×3 = 60 • Connect these vertices using edges with minimum
M [1, 2] = M [1, 2] + M [3, 3] + P0×P1×P3 = 160 weights such that no cycle gets formed.
Formula using Example-
M (i, j) = min {M [i, k] + M [k + 1, j] + Pi-1 Pk Pj
i≤k<j
Example- A2×1 B1×3 C3×4 D4×5
M [1, 2] = M [1, 1] + M [2, 2] + 2×1×3 = 6
M [2, 3] = M [2, 2] + M [3, 3] + 1×3×4 = 12
M [3, 4] = M [3, 3] + M [4, 4] + 3×4×5 = 60
Weight of the MST
So by formula
= Sum of all edge weights
1 2 3 4 1 2 3 4
= 1+2+4+5+6=18 units
1 0 6 20 42 1 1 1 1 Worst case time complexity
2 0 12 32 2 2 3 = O(E logV) or O(E logE)
3 0 60 3 3
SINGLE SOURCE SHORTEST PATH
4 0 4
• Dijkstra Algorithm is a very famous greedy
A (B(CD)) Algorithm.
Time Complexity = O (n) • It is used for solving the single source shortest path
= O (n3) problem.
Data Structure and Algorithm 24 YCT
Search on TG: @apna_pdf
• Dijkstra algorithm work only for connected graphs. • It is employed to identify the shortest path.
• Dijkstra algorithm work only for those graphs that do • It is very popular in the Geographical Maps.
not contain any negative weight edge. • The telephone network makes use of it.
• The actual Dijkstra algorithm does not output the Application–
shortest paths • To determine the quickest route.
• Dijkstra algorithm works for directed as well as • In application for social networking
undirected graphs. • Within a phone network.
Dijkstra Algorithm Steps– Time complexity is O(E log V)
Step-01 In the first step. two set are defined . Space complexity is O(V)
• One set contains all those vertices which have been
BACK TRACKING
included in the shortest path tree.
Back tracking uses brute force approach to solve
• In the beginning, this set is empty.
problem. Brute force approach say that for any given
• In the beginning, this set contains all the vertices of problem generate all possible solution and pich up
the given graph. decided solution . Back tracking uses Depth- first-
Step-02 Two variables are defined as search to generate state space tree.
• ∏[v] which denotes the predecessor of vertex 'v) Brute force Approach–
• d [v] which denotes the shortest path estimate of Example–
vertex 'V' from the source vertex. Let B1 B2 G1 {B=Boy
Initially, the value of these variables in set as– Seating arrangement {G=Girl
• The value of variable '∏ ' for each vertex is set to State space tree – n=3
NIL. i.e. ∏[v] = NIL.
• The value of variable 'd ' for source vertex is set to 0
i.e. d[s] = 0
The value of variable 'd 'for remaining vertices is set
to ∞ i.e. d[v]∞
Step-03
• Among unprocessed vertices, a vertex with minimum
value of variable d is chosen.
• Its outgoing edges are relaxed.
• After relaxing the edges for that vertex, the sets
Created in step-01 are updated.
Edge relaxation– N-Queens Problem
edge(a, b)- The N Queen is the problem of placing N chess queens
on an N×N Chessboard so that no two queens attack
each other.
Formula–
Maximum number of nodes
n  i 
= 1 + ∑ ∏ (N − j) 
i = 0  j= 0 
• Time complexity: O(N!) which represent the
Here, d[a] and d[b] denotes the shortest path estimate maximum number of queens placed.
for vertices a and b respectively from the source vertex • Space complexity: O(N2) for the board.
'S'
Graph Coloring
Now
If d[a]+w<d[b]
then d[b]= d[a]+w and ∏[b]=a
this is called as edge relaxation.
Advantages–
• It is used in google map • How many number of nodes = Cn+1
Data Structure and Algorithm 25 YCT
Search on TG: @apna_pdf
• Coloring of graph constitutes coloring vertices edges Using formula
of the graph. g(i, S)= min{Cik + g(k,S − {k}}
k ←S
• Coloring all the vertices of a graph is the property
that no two adjacent vertices have same color. So

[Always try to color with minimum colors] g(1{2, 3,4})= min {C1k g(k{2,3, 4)} − {k}}
k ←{2, 3, 4}

HAMILTONIAN CYCLE g=Cost


The Hamiltonian cycle is the cycle. graph which visits
g(2, φ)=5, g(3, φ)=6 [φ is null value]
all the vertices in graph exactly once and terminates at
g(4, φ)=8, g(2,{3})=15
the staring node. It may not include all the edges.
g=(2, {4})=8, g(3,{3})=5
Step
g(3, {4})=5, g(4, {2})=5
• In any path, vertex i and (i+1) must be adjacent.
g=(4,{3})=6, g(4, {2})=25
• 1st and (n-1)th vertex must be adjacent.
g=(4,{2, 3})=23
• Vertex i must not appear in the first (i-1) vertices of
Last values
any path.
g = (1,{2,3, 4} = min{C12 + g(2,{3, 4}, C13 + g(3,{2, 4}}
• With the adjacency matrix representation of the
C14 + g(4,{2,3})}
graph, the adjacency of two vertices can be verified = min{10 + 25,15 + 25, 20 + 23}
in constant time. = min{35, 40, 43}
g(1,{2,3, 4}) = 35
• Maximum number of nodes

(n − 1)! BRANCH AND BOUND


=
2
• An algorithm design technique, primarily for solving
• Complexity hard optimization problem.
T(n) = O(n2)
• Guarantees that the optimal solution will be found
Traveling Salesman Problem using Dynamic
• Does not necessarily guarantee worst case
Programming
polynomial time complexity.
1 2 3 4
• But tries to ensure faster time on most instances
1 0 10 15 20 
2  5 0 9 10  Basic Idea.
3 6 13 0 12  • Model the entire solution space as a tree.
 
4 8 8 9 0
Search for a solution in the tree systematically,
eliminating parts of the tree from the search intelligently.
• Important technique for solving many problems for
which efficient algorithms (worst case polynomial
time) are not know.
Optimization problems–
• Set of input variables I
• Set of output variables O
• Values of the output variables define the solution space.
Minimum Cost = 35 • Set of constrains cover the variables.
Data Structure and Algorithm 26 YCT
Search on TG: @apna_pdf
• Set of feasible solutions. Techniques–
• Set of solutions that satisfy all the constraints. • Comparisons tree
• Objective function F:S →R (also called cast function) • Oracle and adversary argument
• Gives a value F(s) for each solution S ∈ S. • State space method
Optimal solution– Non –Deterministic Algorithm–
• A Solution S ∈ S for which F(S) is maximum among Outcome of Non deterministic Algorithm will be
all S ∈ S(for a maximization problem) or
restricted to specific set of possibilities.
minimum(for a minimization problem).
(1) Choice (S): Arbitrarily choose one element from set S.
Job searching–
(2) Failure ( ): Signal an unsuccessful solution.
Using problem solving
(3) Success ( ): Signal an successful solution.
1. FIFO – Queue
2. LIFO – Stack Example- Searching x on A [1:n], n≥1 on success
3. Least – Cost returns of it A[j]=x or returns 0 otherwise.
• Job sequencing with deadline (1) j=Choice (1,n);
Upper = sum of all penalties except that included (2) If (A [j]==x) then {write (j); success}
solution (3) Write (0); Failure();
Cost= sum of penalties till that last job considered
NP-Hard and NP–Complete
job 1 2 3 4
Polynomial time Exponential time
Penalty 5 10 6 3
linear search-n 0/1 Knapsack- 2n
deadline 1 3 2 1
time 1 2 1 1 Binary search-logn Traveling SP-2n
Insertion sort-n2 Sum of subsets-2n
U = ∑ Pi
i∈s
Marge sort-n logn Graph coloring cycle-2n
C= ∑ Pi Upper = ∞ 19 14 9 8
i∈SK Matrix mullipliction-n3 Hamiltonian cycle-2n
NP-Hard- If every problem in NP can be polynomial
time reducible to a problem 'A' is called NP Hard. If 'A'
Could be solved in polynomial time then every problem
in NP is 'P'.
NP- complete: A problem, if it is in NP and NP-Hard,
then it is said to be.
NP-Complete problem.

Solution– Ĉ=5
u=8
J2, J3=16
Note–If NP-Hard or NP-Complete is solved in
J1J4=8
polynomial time, then NP=P
LOWER BOUND THEORY • If NP-Hard or NP- Complete problem is proven to be
L(n) to be the running time of an algorithm A, then g(n) not solvable in polynomial time, then P!=NP
is the lower bound of the algorithm A. It there are two But, till date it is not possible to find out whether
constants C and N such that
NP= P or not.
L(n)>=C*g(n), for n>n
• Status of NP is still unknown.

Data Structure and Algorithm 27 YCT

Powered by TCPDF (www.tcpdf.org)


Search on TG: @apna_pdf

03. DISCRETE MATHEMATICS


LOGIC Derived Operators & Properties
Propositional Logic– A declarative sentence to
why we can assign one and only one truth value. (↑, ↓, ⊕, →, ↔)
i,e. True or False Truth Table
Example– P Q P ↑ Q P ↓ Q P⊕Q P → Q P ↔ Q
• London is a city. True  F F T T F T T
 Propositional
• 2 × 3 = 5 ..False  F T T F T T F
• x+2=5  Not T F T F T F F
th  T T F F F T T
•15 August is independence day  Propositional
Logical Connective or Operators Example– P→Q ≡ Q' → P + Q ≡ Q + P this is true.
The following symbols are used to represent the Tautology– An atomic proposition cannot be
logical connectives. tautology. So a compound proposition which is
AND ∧ (Conjunction) always true is called as 'tautology.'
OR ∨ (Disjunction) Primary Example– P∨( P)
NOT ¬ (NOT) Contradiction– A compound proposition which is
EX-OR ⊕ always false is called a contradiction.
NAND ↑ Example– P∧( P) ≅ F
NOR ↓ Contigency– A compound position which is neither
Secondary
If.....then → (Implication) a tautology nor a contradiction is called contigency.
If and only if ↔ (Biconditional) Example– P → q, P ∨ q, P ∧ q, P ↔ q
Truth Table of primary operator AND (∧) OR (∨) ¬ Satisfiable function of satisfiability–
(not) • A compound proposition which is not a
A B A∧B A∨B ¬A ¬B contradiction is called satisfiable function.
• A satisfiable function can be a tautology also.
F F F F T T
F T F T T F
Arguments
The argument is a set of statements or propositions
T F F T F T
which contains premises and conclusion. The end of
T T T T F F
last statement is called a conclusion and the rest
Properties statements are called premises.
Commutative Law Associative Law An argument is denoted by the following expression
p∨q = q∨p p ∨ (q ∨ r ) = (p ∨ q) ∨ r as follows.
P1, P2 ........ Pn $ Q
p∧q = q∧p p ∧ (q ∧ r ) = (p ∧ q) ∧ r
Where P1, P2 ........ Pn is the premises and Q is the
Distributive Law Identity Law conclusion.
p ∨ (q ∧ r) = (p ∨ q) ∧ ( p ∨ r ) P∨F = P Example–
p ∧ (q ∨ r) = (p ∧ q) ∨ ( p ∧ r ) P∧T = P • Every mother is a woman.
• All women is caring
Compliment • Therefore, every mother is caring.
p∨ P' = T Rules of Inferences
p ∧ P' = F In logical reasoning (an argument or proof), a
Example– certain number of propositions are assumed to be
(i) P + Q + P' = P + P' + Q = 1 + Q = 1 true and based on that assumption some other
(ii) P ∨ (P' ∨ Q) = (P ∨ P') ∨ Q propositions are derived. There are some important
= 1 + Q = 1 Tautology reasoning or rules of inferences.

Discrete Mathematics 28 YCT


Search on TG: @apna_pdf
Sr. Rules of Implicant form can be verified that, it is indeed a tautology &
No. Inference therefore the given argument is valid.
1. Addition P → (P ∨ Q) Rules of inference for quantified
P propositions
1. (US) Universal instantiation → (specification)
∴P ∨ Q
∀xP ( x )
2. Conjunction P P∧Q→P∧Q valid for any element
∴ P (a )
Q 'a' in the universe of discourse.
2. (ES) Existential specification (Instantiation)
∴P ∧ Q

3. Simplification (P ∧ Q) → Q ∃ xP ( x )
P∧Q valid for some elements 'c' in the
∴ P (c)
∴Q
universe of discourse.
4. Modus ponens (P ∧ (P → Q))→ Q 3. (UG) Universal Generalization → If P(a) is
P true for all elements in the universe of discourse
P (a )
P→Q
∴∀xP ( x )
∴Q
4. (ES) Existential Generalization → If P(c) is
5. Modus tollens (¬ Q ∧ (P → Q)) → ¬ P valid true for some element in universe of
¬Q discourse.
P (c)
P→Q
∴∃ x P ( x )
∴¬ P
Equivalences →
6. Disjunctive (¬ P ∧ (P ∨ Q)) → Q (1) ∀x{P(x) ∧ Q(x)} ⇔ {∀x(P(x))}∧{∀xQ(x)}
syllogism ¬ P If we replace ∀x with ∃x, the above statement
P∨Q does not hold good.
∴Q i.x ∃x{P(x) ∧Q(x)} ⇔ ∃xP(x)∧∃xP(x)
It is a tautological implication
7. Hypothetical ((P→Q)∧(Q→R))→(P→R ∃x{P(x)∧Q(x)} ⇒ {∃xP(x)}∧{∃xQ(x)}
syllogism P → ) Properties of quantifiers–
Q (1) ∀xP(x) →∃xP(x)
Q→R (2) ∀x∀y P(x, y) ↔ ∀ y ∀xP(x, y)
∴P ⇒ R (3) ∃ x ∃ yP(x, y) ↔ ∃y ∃x P(x, y)
8. Constructive (P→Q)∧(R→S)∧(P∨R)→( (4) ∃ x∀y P(x, y) → ∀y ∃x P(x, y)
Dilemma Q∨S)
(P→Q)∧(R→S
)
P∨R
∴Q ∨ S
9. Destructive (P→Q)∧(R→S)∧(¬Q∨¬S
Dilemma ) → (¬ P ∨ ¬R)
(P→Q)∧(R→S Graphical Representation of Relation between
) Sentences Involving two quantifiers.
¬Q ∨ ¬S TRANSLATIONS
∴¬P ∨ ¬R ∀ ⇒ "For all", "Every", "Any", "All", (→) ∃ ⇒
Example– If you study hard you will pass the exam. I "Their exist", "Same", "a", "an" (∧)
studied hard. Therefore I will pass the exam, can Example–
be translated as Birds can fly
P : I study hard Assumption
Q : I will pass the exam (P → Q, P) ⊣ Q B(x) : x is bird
This argument is valid if the well-formed F(x) : x can fly
formulas (P → Q) ∧ (P) → Q is a tautology. It Domain : Univers
Discrete Mathematics 29 YCT
Search on TG: @apna_pdf
Solution: (iv) combination without repetition
∀ x (B(x) →F(x)) n!
n
Example– Cr =
r!( n − r ) !
Some birds can fly
Assumption (v) Combination limited repetition
B(x) : x is Birds Generating function
F(x) : x can fly
(vi) Combination unlimited repetition
Domain : Universe
Solution: n – 1 + r Cr
∃ x(b(x) ∧F(x)) (vii) Distribution
Combinatorics (viii) Principle of Inclusion Exclusion
Fundamental Principle of counting (ix) Pigeon Hole Principle
• Sum Rule– Let an event occur thru process-1 in Recurrence Relations– Let a0,a1,a2 ... an be a
'm'-way and thru process-2 in 'n'-ways 'non-over sequence of real number.
lapping' then total number of ways of occurrences an = f(an–1, an–2, .....)
of event will be 'm + n'. Arithmetic sequence
• Product Rule → If event ε1 can occur thru m- {a, a + d, a + 2d, .....}
ways and another independent event E2 can occur the recurrence relation is an = an–1 + d (n≥1)
thru n-way then total number of ways of occurrence where a0 = a
of E1 and E2 will be 'm.n'. Geometric sequence
Note– It between two processes order is possible then it {a, ar, ar2, ar3 ......}
will be considered by itself in multiplication. The recurrence relation
• Bijection Rule– Number of favorable way of an = an–1.r (n≥1) a0 = a
occurrence of an event There are two type of recurrence relation
= total number of ways unfavorable – number of ways • Linear • Non-linear
Permutations Generating Function–
An arrangement of (or) ordered selection of Let {a0, a1, a2......an} be a sequence of real
objects is called a permutation. number, then a function f(x) defined by
The formula of counting this is f(x) = a0, a1x, a2x2 +..... + an.x12 + ... is called
generating function of the sequence.
n!
n
Pr = = n × ( n − 1) × ( n − 1) × ( n − 2 ) .....(n–r +1) It the sequence contains infinitely many terms
( n − r )!
then
Combinations– Let n, r integers. If n ≥ r for the ∞
set of n elements a sub set of r element is called a f (x) = ∑ ( a n .x n )
n =0
"combination".
Formula–
Set Theory
Set→ A set can be defined as a well-defined
n n!
Cr = unordered collection of distinct element.
r!( n − r ) !
Example– A = {1, 2, 3, 4, ......, ∞}
Nine categories of problem
S = {x/(x is a positive integer)} and 1≤x≤10
(i) Permutation without repetition
S = {1, 2, 3, ....., 10}
n n! Null set (empty set)– A set with no elements is
Pr =
( n − r )! called a "Null/empty set" denoted as 'φ'.,{}.
(ii) Permutation limited repetition Example– A = {x/x is a prime number and 8≤x≤10}
n! Subset– If every element of A is also an element
n1!* n2!*..... of B then A is subset of B.
(iii) Permutation unlimited repetition Example– A = {a, b, c} so A ⊆ B
nr B = {a, b, c}
Discrete Mathematics 30 YCT
Search on TG: @apna_pdf
Proper Subset– Any subset of A which is not a (iii) (B – A) = (B ∩ AC)
trivial subset of A is called proper subset of A. It (iv) (A ∪ B)C = (AC ∩ BC)
is denoted by 'C'.
Power set of a Set– If A is a finite set then set (c) For any 3 set → A, B, C the following
of all subsets of it is denoted by P(A). properties hold good.
Example– If A = {a, b, c}, then P(A) = {φ}, {a}, {b}, (1) If A ⊆ B, then A∪ B = B and A ∩ B = A
{c}, {a,b}, {b,c}, {c,a},{a, b, c}} (2) (AC)C = A
Note– If |A| = n the |P(A) | = 2n. (3) Commutative laws
Universal Set– Set of all objects under (i) (A ∪ B) = (B ∪ A)
discussion. It is denoted by 'U'. (ii) (A ∩ B) = (B ∩ A)
Example:- Let A={1,2,3,}, B={4,5,6} (iii) (A ⊕ B) = (B ⊕ A)
A∪B ={1,2,3,4,5,6,} (4) Associative laws
(i) (A ∪ B) ∪ C = A ∪ (B ∪ C)
(ii) (A ∩ B) ∩ C = A ∩ (B ∩ C)
(iii) (A ⊕ B) ⊕ C = A ⊕ (B ⊕ C)
(5) Distributive law
Complement of a set– If A is any set then (i) A ∪ (B ∩ C) = (A ∪ B) ∩ (A ∪ C)
C
complement of A, denoted by A or A defined (ii) A ∩ (B ∪ C) = (A ∩ B) ∪ (A ∩ C)
as (6) Demorgans laws
AC = {x/x∉A and x ∈ ∪} (i) (A ∪ B)C = (AC ∩ B C)
Set Difference– If A and B are two set, then A – (ii) (A ∩ B) C = (AC ∪ BC)
B = {x/x ∈ A and x∉ B} (iii) A – (B ∪ C) = (A – B) ∩ (A – C)
(iv) A – (B ∩ C) = (A – B) ∪ (A – C)
(7) Idempotent property
(i) A ∪ A = A
(ii) B ∩ B = B
(8) Absorption laws
Example:- (i) A ∪ (A ∩ B) = A
A= {1, 2, 3}, B = {2, 4, 6} (ii) A ∩ (A ∪ B) = A
then A – B = {1, 3} (9) Modular laws
Set Union– If A and B are two sets then,
(i) (A ∪ B) ∩ C = A∪ (B ∩ C) iff A ⊆ C
A∪B = {x/x∈ A or x ∈ B or x ∈ A∩B}
(ii) (A ∩ B) ∪ C = A ∩ (B ∪ C) iff C ⊆ A
Set Intersection → If A and B are two set then,
(10) A ∪ φ A , A ∩ φ = φ
A∩B = {x/x∈ A and x ∈ B}
A ∪ U = U, A ∩ φ = φ
Note– If A∩B is empty set, then A and B are called
A ∪ AC = U, A ∩ AC = φ
disjoint sets.
Relation– Let A & B be two sets and some
Symmetric Difference/Boolean sum– elements of A be in certain correspondence with
A∆B/A⊕B = {x/x ∈ A or x ∈ B but x ∉ A∩B} some elements of B then that correspondence
Note– The symmetric difference of A and B defines a relation between those element of the
(a) two set.
A ⊕ B = ( A − B) ∪ ( B − A ) Domain and Range of Relation– Let R be a
= ( A ∪ B) − ( B ∩ A ) relation from A to B then the elements of A
which are in relation are said to be domain and
(b) (i) (A – B) = (A ∩ BC)
the element of B which occur in R constitute in
(ii) (A ∩ B) range of R.
Discrete Mathematics 31 YCT
Search on TG: @apna_pdf
Example– If R = {(1, p), (1, q), (2, q)} be a relation
then
Domain = {1, 2}, Range = {p, q}
Properties of Relation–
(1) Reflexive relation– A relation R is reflexive
if for all x∈ A, (x, x) ∈ R
Example– Let A = {1, 2}& B = {1, 2, 3}
R = {(1, 2), (2, 2), (1, 3)}
Note– A relation R is not reflexive then it is called
irreflexive. LATTICE
(2) Symmetric Relation– A relation R is Maximal element– In a poset, if an element is not
symmetric if (a, b) ∈ R then (b, a) ∈ R related to any other element.
Example– A = {1, 2} & B = {1, 2, 3} Minimal element– In a poset, if no element is
R = {(1, 2), (2,1), (2, 2)} related to an element.
(3) Transitivity of a relation– A relation R is Example– Let (P, R) be a poset and P = {1, 2, 3, 4,
transitive if (x, y)∈R & (y, z)∈R then (x, 5}and R is relation of division.
z)∈R We know that 3, 4 & 5 are not related to any
element. So, 3, 4 & 5 are maximal element but no
Example– The relation "less then or equal to (≤) i.e. 1 <
element is related to 1. So, 1 is minimal element.
2 & 3 < 4 then 1 < 4.
LOWER BOUND AND UPPER BOUND
Equivalence Relation– A relation R is called
Upper Bound– Let (P, R) be a poset and B be a
equivalence relation in A, if
subset of P element x∈A is a upper bound of B if B
(1) R is reflexive
if y is related to x for every y∈B.
(2) R is symmetric
Lower Bound– An element x∈A is a lower bound
(3) R is transitive
of B if x is related to y for every y∈B.
Partial Order Relation– A relation R, defined
Function– Let X and Y are two set. a rule in which
on a set A is called a partial order relation if it is
every element of X assigned to unique element of Y,
(i) Reflexive (ii) Anti symmetric
then this rule is called Function.
(iii) Transitive
It is written as f:X→Y.
Anti symmetric– If a ≤ b & b ≤ a are true iff a = Domain And Range of the function– If f is a
b so relation is anti-symmetric. The set A with function from A to B then A is called domain and B
the partial order relation R is called POSET. is co-domain.
So (R, ≤) is POSET. Range of Function– The set of all those elements of
Total Order Relation– A partial order relation B which are related with elements of A is called the
R in a set A is called total order relation if for range of f. Evidently Range f⊆ B.
every element a, b, ∈ A either a R b or b R a or a Kind of Function
= b. (i) One-one Function– Let f:A→B be a function it
To Set– A set with total order relation is called is called one-one if x ≠ y ⇒ f(x) ≠ f(y) for x, y ∈ A
To Set. or if f(x) = f(y) ⇒ x = y.
HASSE DIAGRAM Example– Let f : R→R s.t f(x) = ax+b, a≠0
A graphical representation of a partial order relation f(x) = f(y)
in which all arrowhead are understood to be ⇒ f(ax + b) = ay + b
pointing upward is known as the Hasse Diagram. ⇒ ax = ay
Example– Let A = {1, 2, 3, 4, 6, 8} be ordered by the ⇒x=y
relation "a divides b". Note– If f is not one-one then it is called many one.
Discrete Mathematics 32 YCT
Search on TG: @apna_pdf
Onto Function– A function f : A → B is called onto Cyclic Groups– A group (G, *) is said to be cyclic
if Range f = B. if there exists an element a ∈ G such that every
Bijective– Let f: A → B be a function and it is element of G can be written as 'an' for some integer
called bijective if f is one-one and onto. "n"; then a is called generating element.
INVERS AND COMPOSITION OF FUNCTION Example– G = {1, –1} is a cyclic group of order 2
Inverse function– If f : X → Y is a bijection then with respect to multiplication.
there always exist pre image f–1(a) of each element a The generator of G = –1.
of y and this will be a unique element of y. GRAPH THEORY
Composition function– If f : A → B and g : B → C Graph– A Graph G is mathematical structure
be two function then the function gof : A → C ; consisting of two sets V and E share V is a non-
empty set of vertices and E is a non-empty set of
where gof(x) = g[f(x)] for all x ∈ A is the
edges.
composition function of f and g.
V1 e1 V2
Groups
Algebraic structure– A non-empty set S is called Basic Termenology–
an algebraic structure with respect to the binary (1) Trivial Graph– A graph consisting only one vertex
operation '*'. and no edge.
then (S, *) is an algebraic structure (N, +) (Z ,+), (Z– Example– 0
1), (R, +, x) are all examples of algebraic structures. (2) Null Graph– A graph consisting n vertices and no
Semi-Groups– An Algebraic structure (S, *) is edge.
called a semi group. Example– 0000
(a*b)*c = a*(b*c) ∀ a, b, c ∈ S (3) Directed Graph– A graph consist the direction of
* is associative on S. edges then is called directed graph.
Monoid– An Semigroup (S, *) is called a monoid. V1 e1 V2
(i) '*' is closed on G.
(ii) '*' is associative &
e5 e2
(iii) e ∈ G such that ∀ a∈M, e*a = a = a*e
e3
such an element 'e' is unique and is called the
identity element for the monoid. V4 e4 V3
Note– Every monoid is a semigroup the converse is not
(4) Undirected graph– A graph which is not directed
true. then it is called undirected graph.
Group– An algebraic structure (G, *) is called a (5) Self loop in a graph– If edge having the same.
group. If the binary operation satisfies the following Vertex as both its end vertexes is called self loop.
postulates.
Example–
1. Closure property: a * b ∈ G ∀ a, b ∈ G
2. Associativity : (a*b)*c = a*(b*c)∀a, b, c ∈ G e1 V
3. Existence of identity: There exists an element
e∈G such that e*a = a = a*e ∀ a ∈ G. the element e (6) Proper edge– An edge which is not self loop is
is called identity for '*' is G. called proper edge.
4. Existence of inverse: (7) Multi edge–A collection of two or more edge
–1 –1 –1 having identically end point.
Thus a is an element of G, such that a*A = a *a = e
Example–
Abelian Group or Commutative group– A group
G is said to be abellan.
Commutative: a * b = b * a ∀ a, b ∈ G.
Subgroup– Let (G*) be a group. A subset H of G is
called a sub group of G if (H, *) is a group. e1, e2, e3 are multi edge
Discrete Mathematics 33 YCT
Search on TG: @apna_pdf
(8) Simple graph– A graph does not contain any self (13) Isolated Vertex & Pendant Vertex– A Vertex
loop and multi edge. having 0 is called isolated vertex and a vertex
(9) Multi graph– A graph does not contain any self having degree 1 is called pendant vertex.
loop but contain multi edge is called multi graph. (14) Finite and Infinite Graph– A graph with a finite
V1 number of vertices as well as edge is called finite
graph otherwise is infinite graph.
Some Important Graph–
e1 e2
e4 (i) A simple connected graph is said to be complete
if each vertex is connected to every other vertex.
V2 V4 Example–
e3 V3 e5
(ii) Regular Graph– A graph G is said to be regular
(10) Pseudo graph– A graph contain both self loop and
if every vertex has the same degree. If degree of
multi edge is called pseudo graph.
each vertex of graph G is K, then it is called K-
V1 regular graph.
e1 V2
e2
e7
V6 V3
e3
e6
e5
e4 (iii) Bipartite– If the vertex set V of a graph G can
V5 V4 be partilioned into two non-empty disjoint subset X and
(11) Incidence and Adjacency– Let ek be an edge Y in such a way that edge of G has one end in X and
joining two vertices V1 & V2 then ek is said to be one end in Y. Then G is called bipartite.
incident of V1 & V2. Note– If a graph is connected then it will not bipartite.
Two vertices are said to be adjacent if there exist (4) Sub graph– Let G(V, E) be a graph. Let V be a
and edge joining this vertices. subset of V and let E be a subset of E whose end
Example– point belong to V: The G(V, E) is a graph and called
V1 a sub graph of G(V, E).
Decomposition of Graph– A graph is said to be
e1
e2 decomposition into two sub graph G1 and G2 if G1 ∪
G2 & G1 ∩ G2 = null graph.
V2 e3 V3 HAND SHAKING THEOREM
Here e1 is incident of V1 & V2 and V1 & V2 are The sum of the degree of the vertices of a graph G is
adjacent but V3 & V4 are not adjacent. equal to twice the number of edges in G.
(12) Degree of Vertex– The degree of vertex V in a n
graph G written as d(V) is equal to number of edges ⇒ ∑ deg ( V1 ) = 2 × Number of edges
i =1
which are incident on V with self loop counted
twice. MATRIX REPRESENTATION OF GRAPH
Example– (1) Adjacency Matrix– Let a1 denote the number of
edges (Vi, Vj) then A = [aij]m×n is called adjacency
matrix of G if

( )
1 if vi , v j is an edges
a ij = 
 0 other wise
if (V1, Vj) is an edges otherwise
(2) Incidence Matrix– Let G be a graph with m
Here d(V1) = 2, d(V2) ,= 4, d(V3) = 2, d(V4) = 3, vertices V1, V2, ..... Vm and n edges e1, e2,e3 ..... en
d(V5) = 2, d(V6) = 2, d(V7) = 1, d(V8) = 0 Let a matrix M = [Mij]m×n defined by
Discrete Mathematics 34 YCT
Search on TG: @apna_pdf
1 If the vertex Vi is incident on the ij WEIGHTED GRAPH– A graph is called weighted
 graph if a non-negative integer W(e) associate to each
m ij = 0 If Vi is not incident on ij
 2 If V is an end of the loop ij edge and this W(e) is a weight of corresponding edge.
 i
GRAPH COLORING– Painting all the vertices of a
Path Matrix– Suppose G is a simple directed graph with graph with colours such that no two adjacent vertices
m vertices then path matrix P and Bm have same non zero have the same color is called coloring of graph.
entries where Bm = A1 + A2 + A3...... Am. CHROMATIC NUMBER– The least number of
Where A is adjacency matrix colors required for coloring of a graph G is called its
ISOMORPHISM OF GRAPH chromatic number.
Definition– Two graphs G1 & G2 are isomorphic if Note–1. The chromatic number of graph G is denoted by
X(G).
(i) Number of vertices are same.
2. If X(G) = K, then the graph is called K-chromatic.
(ii) Number of edges are same.
3. Chromatic number of null graph is 1.
(iii) An equal number of vertices with given degree
4. Chromatic number of complete graph Kn of n
(iv) Vertex correspondence & edge correspondence valid.
vertices is n.
Homeomorphic Graph 5. If a graph is circuit with n vertices then.
Two graph G and G' are said to be homeomorphic if they (i) It is 2-chromatic if n is even
can be obtained from the same graph. (ii) If is 3-chromatic if n is odd.
Note–If G & G' are homeomorhpic they need not be TREE AND ITS PROPER TIES
insomorphic. TREE– A tree is a connected graph without any
WALK, TRAIL and PATH loop or circuits.
(1) Walk– A walk is a finite alternating sequence v1 Rooted Tree– A rooted tree is a tree in which one
e1 v2 e2 v3 e3 ... vn en of vertices and edges beginning vertex is root.
and ending with same or different vertices. SPANNING TREE–If G is any connected graph a
(i) Length of the walk– The number of edge is called spanning tree in G is a subgroup T of G, which is a tree.
length of the walk. Minimal Spanning Tree– Let G be a weighted
(ii) Closed & open walk– A walk is said to be closed if graph. A minimal spanning with minimum weight.
its origin & terminus vertex (V0 = Vn) is equal Algorithms For Minimal Spanning Tree
otherwise it is called open walk. KRUSHKAL's Algorithm
Trail: Any walk having different edges called trail. Working Rule
Cycle– A closed trail is called circuit. (i) Choose an edge of minimal weight
Path: A walk is called path if all vertices are not (ii) Al each step, choose the edge whose inclusion
repeated. will not create a circuit.
(iii) If G has n vertices stop after (n–1) edges.
Cycle– A closed path is called cycle.
Example–
EULERIAN PATH– A path in a graph is said to be
an Eulerian path if it traverses each edge in the
graph once and only once.
EULERIAN GRAPH– A connected graph which
contain a Eulerian circuit is called Eulerian graph.
HAMILTONIAN PATH– A path which contain
every vertex of a graph G exactly once is called
Hamiltonian graph. Weight = 3+1+2+1=7
HAMILTONIAN CIRCUIT– A circuit that passes (2) PRIM'S ALGORITHM
through each of the vertices in a graph G exactly one Working Rule–
except the starting vertex & end vertex is called (i) Select any vertex & choose the edge and smallest
Hamiltonian circuit. weight from G
HAMILTONIAN GRAPH– A connected graph (ii) At each stage, choose the edge of smallest weight joining
which contain Hamiltonial circuit is called a vertex already included to vertex not yet included.
Hamiltonian Graph. (iii) Continue until all vertices are included.
Discrete Mathematics 35 YCT

Powered by TCPDF (www.tcpdf.org)


Search on TG: @apna_pdf

04. DIGITAL LOGIC


Number System
Decimal System–
It is a positional number system that uses 10 as a base to represent different values. Therefore, this number system is
also known as base 10 number system. In this system, 10 symbols are available for representing the value. These
symbols include the digits from 0 to 9.
Example, the value 237 which comes before the decimal point, is called integer value and the value 25, which
comes after the decimal point, is called fraction value.

Binary System– The binary system uses base 2 to represent different value. Therefore, the binary system is also
known as base-2 system. As this system used base2, only two symbols. are available for representing the different
values in this system. These symbols are 0 and 1, Which are also known as bits in computer terminology. Using
binary system, the computer systems can store and process each type of data in terms of 0s and 1s only.
Example, the binary number 11001.101 represents the decimal value 25.625.

Technical terms Used in Binary System.


Bit ♦ It is the smallest unit of information used in a computer system.
♦ It can either have the value 0 or 1.
♦ Derived from the words 'Binary digit'.
Nibble It is a combination of 4 bits.
Byte ♦ It is combination of 8 bits.
♦ Derived from words 'by eight'.
Word It is a combination of 16 bits.
Double word. It is a combination of 32 bits.
Kilobyte (KB) It is used to represent the 1024 bytes of information.
Megabyte (MB) 1024 KBs
Gigabyte (GB) 1024 MBs
Terrabyte (TB) 1024 GBs
Petabyte (PB) 1024 TBs
Exabyte (EB) 1024 PBs
Zettabyte (ZB) 1024 EBs
Yottabyte (YB) 1024 ZBs

Digital Logic 36 YCT


Search on TG: @apna_pdf

Octal system– The octal system is the positional number system that used base 8 to represent different values.
Therefore, this number system is also known as base-8 system. As this system uses base 8, eight symbols are a
available for representing the value in this system. These symbols are the digits 0 to 7.
Example, The octal number 215.43 represents the decimal value 141.5469.

Hexadecimal system– The hexadecimal system is a positional number system that uses base 16 to represent
different values. Therefore, this number system is known as base-16 system. As this system uses base 16, 16
symbols are available for representing the value in this system. These symbols are the digits 0-9 and the letters A, B,
C, D, E and F. The digits 0-9 are used to represent the decimal value 0 through 9 and The letters A, B, C, D, E and F
are used to represent the decimal value 10 through 15.
Example, the hexadecimal number 4A9.2B represents the decimal value 1193.1679.

Decimal to non-decimal conversions


The decimal to non-decimal (binary, octal or hexadecimal), conversions use the step given below.
Step 1: Divide the given number by the base value of the number system in which It is to be converted.
Step 2 : Note the remainder.
Step 3: Keep on dividing the quotient by the base value and note the remainder till the quotient is Zero.
Step 4 : Write the noted remainders in the reverse order (from bottom to top).
(i) Decimal to Binary conversion–
Let us now convert a decimal value to its binary representation and verify that the binary equivalent of (65)10 is
(1000001)2.

Digital Logic 37 YCT


Search on TG: @apna_pdf
(ii).Decimal to Octal conversion–
The following example illustrate the method of converting decimal number 98 into its equivalent octal number.

(iii).Decimal to Hexadecimal conversion– The following example illustrate the method of converting decimal
number to its hexadecimal equivalent.

Non-decimal to Decimal Conversions


The non-decimal to decimal conversions can be implemented by taking the concept of place values not
consideration we can use the following steps to convert the given number with base value to its decimal
equivalent, where base value can be 2, 8 and 16 for binary, octal and hexadecimal number system, respectively.
Step 1 : Write the position number for each alphanumeric symbol in the given number.
Step 2 : Get positional value for each symbol by raising its position number to the base value symbol in the given
number.
Step 3 : Multiply each digit with the respective positional value to get a decimal value.
Step 4 : Add all these decimal values to get the equivalent decimal number.
(i). Binary Number to Decimal Number conversion– The following example illustrate the method of
converting binary number (1101)2 to decimal number.

Digit→ 1 1 0 1
Positional value→ 23 22 21 2º
Decimal Number→ 1× 23 + 1×22 + 0×21 + 1× 2º
8 + 4 + 0 + 1 = (13)10
Therefore, (1101)2 = (13)10

(ii). Octal number to Decimal number conversion– The following example shows how to compute the decimal
equivalent of an octal number (257)8.
Digit→ 2 5 7
Positional value→ 83 82 81
Decimal Number→ 2× 82 + 5×81 + 7×80
128 + 40 + 7 = (175)10
Therefore, (257)8 = (175)10
Digital Logic 38 YCT
Search on TG: @apna_pdf
(iii). Hexadecimal Number to Decimal number conversion– The following example Shows how to compute the
decimal equivalent of an Hexadecimal (3A5)16.
Digit→ 3 A 5
Positional value→ 162 161 16º
Decimal Number→ 3× 162 + 10×161 + 5×160
768 + 160 + 5 = (933)10
Therefore, (3A5)16 = (933)10
Conversion from Binary number to Octal number and Vice-versa
(i) Binary number to Octal Number- Given a binary number, an equivalent octal number representation by 3
bits is computed by grouping 3 bits from right to left and replacing each 3-bit group by the corresponding octal
digit. In case number of bits in a binary number is not multiple of 3, then add required, number of 0s on most
significant position of the binary number
Example – Convert (10101100)2 to octal number.
Make group of 3-bits of the
given binary number (Right to left) 010 101 100
Write octal number for each 3- bit group. 2 5 4
Therefore, (10101100)2 = (254)8
(ii) Octal number to Binary number– Each octal digit is an encoding for a 3-digit binary number. Octal number
is converted to binary by replacing each octal digit by a group of three binary digits.
Example– Convert (705)8 to binary number.
Octal digit → 7 0 5
Write 3-bits binary
value for each digit → 111 000 101
Therefore, (705)8 = (111000101)2
Conversion from Binary number to Hexadecimal number and vice-versa
(i) Binary Number to Hexadecimal Number– Given a binary number, its equivalent hexadecimal number is
computed by making a group of 4 binary digits from right to left and substituting each 4-bit group by its
corresponding computed by making a group of 4 binary digits from right to left and substituting each 4-bit group
by its corresponding hexadecimal alphanumeric symbol. If required, add 0 bit on to have number of bit in a binary
number as multiple of 4.
Example– Convert (0110101100)2 to hexadecimal number.
Make group of 4-bits of
the given binary number (Right to left) 0001 1010 1100
Writ hexadecimal symbol for each group→1 A C
Therefore, (0110101100)2 = (1AC)16
(ii). Hexadecimal number to Binary number– Each hexadecimal symbol is an encoding for a 4-digit binary
number. Hence, the binary equivalent of a hexadecimal number is obtained by substituting 4-bit binary equivalent
of each hexadecimal digit and combining them together.
Example. Convert (23D)16 to binary number.
Hexadecimal digits→ 2 3 D
Write 4-bit binary for each digit→ 0010 0011 1101
Therefore, (23D)16 = (001000111101)2
Conversion from octal number to hexadecimal number
The given octal number can be converted' into its equivalent hexadecimal number in two different steps. Firstly,
We need to convert the given octal number into its binary equivalent. After obtaining the binary equivalent, we
need to making a group of 4 binary digits from Right to left and substituting each 4-bit group by its corresponding
hexadecimal alphanumeric symbol. In this type of conversion, we need to represent each digit in the octal number
to its equivalent 3-bit binary number.
Example– Convert the octal number (365)8 into its hexadecimal number.
Octal digits→ 3 6 5
Write 3-bits binary value
for each digit→ 011 110 101
Regrouping into 4-bits of
the binary number (Right to left)→ 0000 1111 0101
Write hexadecimal symbol
for each group→ 0 F 5
Therefore, (365)8=(F5)16
Digital Logic 39 YCT
Search on TG: @apna_pdf

Conversion of a Number with Fractional Part.

(i) Fractional part of Decimal number to Binary number.

Example. Convert decimal number (0.25)10 to binary.

Since the fractional part is 0, the multiplication is stopped. Write the integer part from top to bottom to get binary
number for the fractional part.
Therefore, (0.25)10 = (0.01)2
Example– Convert (0.675)10 to binary.

Since the fractional part (.400) is the repeating value in the calculation, the multiplication is stopped, write the
integer part from top to bottom to get binary number for the fractional part.
Therefore, (0.675)= = (0.1010110)2
(ii) Fractional part of Decimal number to Octal Number.
Example– Convert (0.625)10 to Octal Number.

Since the fractional part is 0, the multiplication is stopped, write the integer part from top to bottom to get octal
number for the fractional part .
Therefore, (0.625)10 = (0.50)8
(iii) Fractional part of Decimal number to hexadecimal number.

Example– Convert (0.675)10 to hexadecimal.

Since the fractional part (.800) is repeating, the multiplication is stopped, Write the integer part from top to bottom
to get hexadecimal equivalent for the fractional part.
Therefore, (0.675)10 = (0.AC)16

Non-decimal Number with Fractional part to Decimal Number System

(i) Fractional part of Binary number to Decimal number.


Convert (0.111)2 into decimal number.
Digit→ 0. 1 1 1
Fractional value→ 2-1 2-2 2-3
Decimal value→ 1×2-1 + 1×2-2 + 1×2-3
0.5 + 0.25 + 0.125 = 0.875
Therefore, (0.111)2 = (0.875)10
Digital Logic 40 YCT
Search on TG: @apna_pdf
(ii) Fractional part of octal number to Decimal number.
⇒ Convert (0.12)8 into decimal number.
Digit→ 0. 1 2
Fractional value→ 8-1 8-2
Decimal value→ 1×8-1 + 2×8-2
0.125 + 0.03125 = 0.15625
Therefore (0.120)8 = (0.15625)10

(iii) Fractional part of Hexadecimal number to Decimal number


⇒ Convert (0.58)16 into decimal number.
Digit→ 0. 5 8
Fractional value→ 16-1 16-2
Decimal value→ 5×16-1 + 8×16-2
0.3125 + 0.03125 = 0.34375
Therefore, (0.58)16 = (0.34375)10

Fractional Binary Number to Octal or Hexadecimal Number

Example– Convert (10101100.01011)2 to octal number.


Make perfect group of 3-bits→ 010 101 100 . 010 110
Write octal symbol for each group → 2 5 4 . 2 6
Therefore, (10101100.01011)2 = (254.26)8
Note– Make 3-bit groups from right to left for the integer part and left to right for the fractional part.

Example– Convert (10101100.010111)2 to hexadecimal number.


make perfect group of 4-bits→ 1010 1100 . 0101 1100
Write hexadecimal symbol for each group→ A C . 5 C
Therefore, (10101100.010111)2 = (AC.5C)16
Binary coded Decimal (BCD) systems

Weighted 4-bit BCD code-


Example– Represent the decimal number 5327 in
weighted BCD code.
⇒ The given decimal number is 5327
The corresponding 4-bit 8421 BCD representation of
decimal digit. Therefore, The 8421 BCD representation of decimal
number (87.34)10 is (1000 0111.0011 0100)2.
Excess-3 BCD Code–
Example– Convert the decimal number 85 to XS-3 BCD
code.
⇒ The given decimal number is 85. now, add 3 to each
digit of the given decimal number as–
8 + 3 = 11
5+3=8
Therefore, The 8421 BCD representation of decimal The corresponding 4-bit 8421 BCD representation of the
number (5327)10 is (0101001100100111)2 decimal digit–
Example– Convert the decimal number (87.34)10 to
weighted BCD code.
⇒ The given decimal number is 87.34
The corresponding 4-bit 8421 BCD representation of
decimal digit Therefore, the XS-3 BCD representation of the decimal
number 85 is 1011 1000.
Digital Logic 41 YCT
Search on TG: @apna_pdf
Gray Code One's complement system
The Gray code or reflected binary code is an ordering 1's complement of a binary number is another binary
of the binary number system such that two successive number obtained by toggling all bits in it, i.e.
values differ in only one bit. Gray cods are very useful transforming the 0 bit to 1 and the 1 bit to 0.
in the normal sequence of binary number generated by Example- 1's complement of '1100' is '0011'
the hardware that may cause an error or ambiguity
during the transition from one number to the next. The
Two's complement system
Gary code is not weighted that means it does not 2's complement of a binary number is 1, added to the 1's
depends on positional value of digit. This cyclic complement of the binary number.
variable code that means every transition from one Exmaple- 2's complement of 1100 is ?
value to the next value involves only one bit change. 1's complement of 1100 is 0011 added 1, to the is
Binary to Gray code conversion– We can convert a complement.
number represented in the binary form to the Gray we
need to remember the following two rules:-
(i) The most significant Bit (MSB) of the Gray code is
always equal to the MSB of the given binary code. 2's complement of '1100' is '0100'
(ii) Other Bits of the output gray code can be obtained Boolean Algebra
by XORing binary code but at that index and Commutative • A+B = B+A • A.B = B.A
previous index. Law
Example- Convert the Binary number 1011 to its Associative Law • A+(B+C) = (A+B)+C
equivalent Gray coded number.
• A.(B.C) = (A.B)C = ABC
Distributive • A(B+C) = AB + AC
Law • A+(B.C) = (A+B).(A+C)
• (A+B)(C+D) =AC+AD+BC+BD
• A + (A.B) = A + B
Hence, the Gray coded equivalent of the binary number Absorption law • A + AB = A • A(A+B) =A
1011 is 1110. • A + AB = A + B
Gray to binary conversion- We can convert the gray
coded number to its binary equivalent by remembering • A + AB = A + B
the following two major rules. Idempotence • ORing-A+A+A + ........ = A
(i) The most significant bit (MSB) of the binary code is Law • ANDing- A.A.A ....... = A
always equal to the MSB of the given gray code. AND • A.0 = 0 • A.1 = A
(ii) Other bits of the output binary code can be obtained Operation
by checking gray code bit at that index. If current gray Theorem • A.A = A • A.A = 0
code bit is 0, then copy previous binary code bit, else OR Operation • A+A = A • A+0 = A
copy invert of previous binary code bit. Theorem
Example- Convert the Gray coded number 11010011 • A+1 = 1 • A + A =1
to its binary equivalent. Transposition • (A+B).(A+C) = A + BC
Theorem
Consensus or • AB + AC + BC = AB + AC
Redundancy
Theorem
Demorgan’s • A.B = A + B • A + B = A.B
Theorem
Duality
Theorem
AND ↔ OR
• Taking all literals as it is.
Complementary
Theorem
• Complement literals individually
Involution
Theorem
• A=A
Note :-
Maximum possible minterm or maxterm = 2n
Hence, the binary equivalent of gray coded number n
11010011 is 10011101. Maximum possible logical expression = 2 2
Digital Logic 42 YCT
Search on TG: @apna_pdf

Maximum possible self dual expression = 22


n −1
AND, OR, XOR, and X-NOR- Gate follow
associative law
AND, OR, NAND, NOR, XOR and X-NOR- Gate
follow commutative law NAND and NOR-Gate does not follow associative
law
Logic Gates
Logic Gate is a electronics switch which performs the arithmetic and logic function.
Basic Gates
Gate Symbol Diode circuit Transistor Truth table Switch table
NOT

AND

OR

Universal Gate
NAND
Gate

NOR
Gate

Digital Logic 43 YCT


Search on TG: @apna_pdf
FET as a Switch
Gate Diagram Truth Table
JFET as
NOT Gate

MOSFET as
NOT Gate

Special Purpose Gates AND Gate is also called all or nothing gate
Gate Symbol Truth Table AND Gate works as a series switch
OR Gate is also called any or all Gate
EX- OR Gate works as a parallel switch
OR EX-OR gate acts as odd number of “1’s detector”.
EX-OR gate is used for even parity generator and
In EXOR operation
detector.
• For BUFFER
EX-OR gate is known as stair case switch.
CIRCUIT ⇒ Logic '0'
EX-NOR gate acts as even number of “1’s detector”.
• For INVERSION EX-NOR gate is used for odd parity generator.
CIRCUIT ⇒ Logic '1' XOR-Gate is also called anti-incidental logic gate.
EX- A ⊕ 0 = A → work as buffer
NOR
A ⊕ 1 = A → work as inverter
In EXNOR operation
• For BUFFER X-NOR-Gate is also called equivalence gate or
CIRCUIT ⇒ Logic '1' equality detector or co-incident logic gate.
• For INVERSION A ⊙ 0 = A → work as inverter
CIRCUIT ⇒ Logic '0' A ⊙ 1 = A → work as Buffer
NOR and NAND are special logic gates
Logic gates No. of NAND No. of NOR
Gate required Gate required A ⊕ B⊕C = A ⊙ B⊙C
NOT 1 1 A⊕A⊕A⊕ ………n times = 0, (if n = even)
= A, (if n = odd)
AND 2 3
OR 3 2 A⊙A⊙A⊙ …………n times = 1, (if n = even)
EX-OR 4 5 = A, (if n = odd)
EX-NOR 5 4 A⊕B= A⊕B= A⊙B A⊕B= A⊙B
NAND 1 4 A⊙B= A⊙B= A⊕B
NOR 4 1 Positive logic Negative logic Bubbled logic
Remember point AND- Gate OR- Gate NOR- Gate
OR- Gate AND- Gate NAND- Gate
NAND- Gate NOR- Gate OR- Gate
NOR- Gate NAND- Gate AND- Gate
Positive logic and Negative logic system
Positive logic
Logic ‘1’ voltage level is higher than logic ‘0’
voltage level
Digital Logic 44 YCT
Search on TG: @apna_pdf
Logic ‘0’ voltage level is lower than logic ‘1’ Karnaugh Map (K - Map]
voltage level A systematic & simple way of minimization of
Negative logic Boolean algebra.
Logic ‘0’ voltage level is higher than logic ‘1’ Minimization using K-map, the solution is not unique.
voltage level “Gray Code” is used in K-map.
Logic ‘1’ voltage level is lower than logic ‘0’ Number of cells = 2n, n = Number of variables.
voltage level Don’t Care - Considered when this is helping in
Representation of Boolean functions minimization of Boolean algebra.
Implicants = Number of minterms/maxterms
Prime implicants = Number of pairs
Essential Prime Implicants= Number of prime
implicants without redundant terms
n
Digital Logic Circuits
Maximum no. of Boolean expression or function = 2 2 Combinational Circuit Sequential Circuit
Sum of Product (SOP) : Each product term is Present output depends only Present output
known as minterm. SOP form (Σm) is used when on present input. depends on both
output is logic 1. Ex.- ( ABC ) + ( ABC ) + ( ABC ) present input as well
as past output.
Product of Sum (POS) : Each product term is
known as maxterm. POS form (ΠM) is used when No memory present. Memory is present.
output is logic ‘0’. Faster. Slower.
Ex.- ( A + B + C ) . ( A + B + C ) . ( A + B + C ) Easy to design. Harder to Design.
No feedback present. Feedback present.
Remember point No clock pulse required. Clock pulse required.
Maximum possible minterm or maxterm = 2n Arithmetic operation and Data storing system.
Maximum possible self dual function = 22
n –1
Boolean operation.
AND-OR logic = NAND-NAND logic (Used in Ex.- Adder, Substractor, Ex.- Flip-flop, Latch,
SOP). Decoder, Encoder, Comparator Counter, Register,
OR-AND Logic = NOR-NOR logic (Used in POS). MUX, D-MUX, parallel adder, serial adder etc.
ROM, RAM etc.
Combinational Circuits
Circuit Diagram Formula Implement by
Half Adder S = AB + AB = A ⊕ B • 5- NAND gates
C = A.B • 5- NOR gates
• 3- (2 × 1) MUX
• 2- (4×1) MUX
Full Adder S=A⊕B⊕C • 2- H.A+ 1 OR
= ABC + ABC + ABC + ABC gate
• 9- NAND gate
Co = ( A ⊕ B ) .C + AB • 9- NOR gate
• 7- (2 × 1) MUX
= AB + BC + CA

Half D = AB + AB = A ⊕ B • 5- NAND gates


subtractor • 5- NOR gates
Bo = AB
• 3- (2 × 1) MUX
• 2- (4×1) MUX

Full D = A ⊕ B⊕C • 2- H.S + 1 OR


subtractor gates
= ABC + ABC + ABC + ABC • 9- NAND gates
• 9- NOR gates
B0 = ( A ⊙ B ) .C + AB • 7- (2 × 1) MUX

= AB + AC + BC

Digital Logic 45 YCT


Search on TG: @apna_pdf
• In parallel adder for two n-bits numbers requires-
n Full Adder
(n–1) F⋅A + 1 H⋅A
(2n–1) H⋅A + (n–1) OR Gate
Circuit Diagram Specification
MUX Named as-
Data Selector circuit Many to One circuit
Universal logic circuit Parallel to serial converter
Wave form generator Data Routing
m =2n = no. of input lines, no. of output line = 1
n = number of select lines
D-MUX Named as -
Data Distributor circuit One to many circuit
Serial to Parallel Converter
Single Input to multiple output
No. of input line =1, no. of output lines = 2n
No. of select lines = n
Decoder It is a combinational logic circuit that converts
binary information from n bit input lines to a
maximum 2n o/p lines
Decoders are used to convert a particular code-
• Binary to octal (3×8 lines decoders)
• Binary to Hexadecimal (4×16 line decoders)
• BCD to decimal (4×10 line decoders)
• BCD to 7-Segment display.
• The total number of output line m ≤ 2n
• Decoders are widely used memory system of computer.
Encoder Inversion of Decoder circuit is known as Encoder.
Encoder is used to convert other codes to binary
such as -
• Octal to Binary encoder (8×3 lines)
• Decimal to BCD encoder (10×4 lines)
• Hexadecimal to Binary encoder (16×4 lines)

Sequential Circuits Triggering Triggering is used to initiate the


Latch Flip-flop operation of latches or flip-flops.
Latches use level Flip-flops use edge Level trigger
triggering triggering.
Edge trigger
No clock pulse Clock pulse
Clock In Flip-Flop
Build from gates Build from latch
Setup Time : The time period required to hold the
The output changes as per The output changes as
incoming data before the arrival of clock pulse.
the input till enable is per the input only at
This is of the order of 50ns.
high. triggering point.
Hold Time : The time period required to hold the
Buffer • 1 bit memory element.
incoming signal information after the arrival of
• 2 Stable states clock pulse.
• Bi-stable Multi-vibrator This is in order of 10-20 ns.
Output cannot predict Output can predict (0/1) Setup Time > Hold Time.
Digital Logic 46 YCT
Search on TG: @apna_pdf
Flip- Logic Diagram Graphical Diagram Characteristics Truth Table
Flop Equation
SR Q n+1 = S + R Q n

JK Qn+1 = JQn + KQ n

D Flip- Qn+1 = D
flop

T flip- Qn +1 = TQn + TQ n
flop
= T ⊕ Qn

Conversion of Flip-flop To Avoid Race Around -


tpw < tpd (FF) < T Edge triggering
Master-Slave FF
Registers
Register is a memory device, which is used for data
storage & shifting.
Register is a group of flip-flops & gates.
For n-bit data, the n-flip-flops are required.
Shift Register
Data can be shifted by single bit.
Four types of shift Registers
Excitation table
Qn Qn+1 S R J K D T Register Presentation Clock pulse
0 0 0 x 0 x 0 0 Input Output
0 1 1 0 1 x 1 1 SISO n (n–1)
1 0 0 1 x 1 0 1
SIPO n 0
1 1 X 0 x 0 1 0
Applications of Flip-flops
Serial and Parallel data storage, Data Transfer,
Serial to Parallel Converter, Parallel to serial converter PISO 1 (n–1)
Latch, Counter, Frequency division, memory
Remember point
PIPO 1 0
Race-around condition occurs in JK-FF to store 1-
bit of Information. [J = K = 1], tpd (FF) << tpw.
Race-around Condition always arises in
“Asynchronous circuits.”
Digital Logic 47 YCT
Search on TG: @apna_pdf
Time delay for SISO shift register- Modulus of counter
1 Known as MOD or MOD number
∆t = N × T = N ×
fc MOD ≤ 2 n
N = Number of FFs. fc = Clock frequency Where n = Number of flip-flop
T = Time period of Clock pulse
All shift Registers made of JK-FFs.
In storage registers mostly D flip-flops are used.
f in
Counters f out =
N
Counter is formed by the cascading of FFs.
Counter are basically used for – Binary Counter
Counting of the number of clock pulses. If the sequence of the states is either ascending or
Frequency division Timers In RADAR descending order than the counter is called binary
Frequency Measurement Wave form generation counter. It is also called as (2n:1) scalar counter
In each count the binary data is known as “State of Variable modulus counter
counter.” It is counter in which the maximum number of state
Number of states counted by a counter is known as can be changed.
‘modules of counter’. Note: The final state of the counter sequence is called
If M = Modules = Mod = Total Number of states the terminal counter.
n = Number of bits or flip-flop then M ≤ 2 n Application of counter
M = 2n ⇒ Binary Counter or ripple counter It is used as frequency divider circuit
M < 2n ⇒ Non-Binary Counter or BCD counter It create time delay
Counters are classified in two categories. It generate a required sequence bit
i. Asynchronous Counter [Ripple Counter/Series
Output Frequency of two Cascaded Counters
Counter]
Overall Mod of Counters = M.N
ii. Synchronous Counter [Parallel Counter]
fi
Synchronous counter Asynchronous counter Overall Output frequency = f o =
M.N
Same clock pulse is Clock Signal is applied
For n-bits counter if delay for each Flip-flop is tpd
applied to individual flip- only the first flip-flop.
flop. then total clock period –

Any sequence can be Fixed sequence [Upper or 1 1


TCLK ≥ n.t pd ( ff ) , f CLK ≤ f max =
generate. Down] n.t pd( ff ) n.t pd( ff )
Faster Slower
Synchronous counter
No Decoding Error Due to propagation delay
decoding error exist.
Design is complex, as Design easy, even more
number of bits increases. number of bits.
Types: Types:
i. Ring Counter / End i. Ripple Up Counter
Carry Counter ii. Ripple Down
ii. Twisted Ring Counter
Counter / Johnson Ring Counter
iii. BCD Counter (Non-
Counter Binary)
iii. Synchronous-series iv. Up counter
carry counter v. Down counter
iv. Synchronous-parallel
carry counter

Digital Logic 48 YCT


Search on TG: @apna_pdf
Ring counter works as SISO Trick to Identify Counter (Ripple counter)
It is also called n:1 counter Clock (Triggering) Output Counter

Johnson Counter Q Down-counter


Positive edge Q Up-counter

Q Up-counter
Negative edge Q Down-counter

Maximum count value = (2n–1) 3-bit up-down ripple counter


Synchronous-series carry counter,

1
f CLK ≤
t pd (FF) + ( n – 2 ) t pd ( AND Gate )

Synchronous-parallel carry counter,

1
f CLK ≤
t pd(FF) + t pd ( AND Gate ) If M = 1 up counter, If M = 0 down counter

It is the ‘fastest counter”.


Remember point
Counter Number Unused Output
of states, state frequency The Ring counter and Johnson counter are not use

M for counting purpose.


fo
Johnson Counter also known as-
BCD/Mod-10 10 6, f
fo = i Twisted Ring counter
10
counter (2n – M)
Mobies Counter
n
Ring counter n 2 –n fi Switch tail Ring Counter
fo =
n
Creeping counter
n
Johnson/Ring 2n 2 – 2n fi Walking counter
fo =
2n
Twisted counter In ring counter all flip-flops output frequency
Asynchronous counter remain same but phase shift is different and equal to

3-bit binary ripple up counter 3600/n, (where, n= number of state)


“Lock out” problem occurs in non-binary counter.
JK, SR, D and T are called synchronous Input.
Reset and Set are called Asynchronous Input.
“Preset” always make the output to ‘1’.
3-bit binary ripple down counter
“Clear” always make the output to ‘0’.
“Glitch” is an unwanted spike in the signal.
MOD-16 counter could also be called a “divide-by-
16 counter”.

Digital Logic 49 YCT

Powered by TCPDF (www.tcpdf.org)


Search on TG: @apna_pdf

05. DATABASE MANAGEMENT


SYSTEMS
Introduction to DBMS Characteristics of DBMS

It user a digital repository established on a server to


store and manage the information.
It can provide a clear and logical view of the
process that manipulates data.
Database management system is the combination of DBMS contain automatic backup and recovery
two words. procedures.
Database + Management System = DBMS It contain ACID properties which maintain data in a
Data base healthy state in case of failure.
It is a collection of related data. It is used to provide security of data.
Data base management system is a collection of Application of DBMS
programs that enables users to create and maintain 1. Banking– for maintaining customer information,
the database. loans and banking transactions.
Structured Database 2. Universities– for maintaining, student records,
Structured data is highly specific and is stored in registration etc.
predefined format. 3. Railway Reservation– for checking the availability
Structured data store in relation form of reservation in different trains, tickets etc.
Example– IRCTC, University 4. Sales–for customer, product and purchase
information.
Unstructured– Unstructured data is information
that either does not have a predefined data model or 5. Hospital system– the hospital system which deals
with in patients as well as out-patients.
is not organised in a pre-defined manner. Example-
Web pages.

DBMS can also be define as a interface between the


application program and the operating system to
access and manipulate that database. Advantages of DBMS
Database management system is a software which is
used to manage the database for example–
• Control database redundancy– It can control
data redundancy because it stores all the data in
MYSQL, ORACLE etc. are a very popular
one single database file and that recorded data is
commercial database which is used in different
placed in the database.
applications.
Database Management Systems 50 YCT
Search on TG: @apna_pdf
• Data sharing– In DBMS, the organization users Basic DBMS File System
of an organization can share the data among
multiple users. Sharing of Data sharing is So, it is not easy
• Easily maintenance– It can be easily Data easy to share data
maintenance due to the centralized nature of the
database system. Security and DBMS provides The file system
• Multiple user Interface– It provides different protection good protection does not have a
types of user interface like graphical user
interface, application program interfaces. mechanism crash
Disadvantages of DBMS mechanism
• Cost of Hardware and Software– It requires a
high speed of data processor and large memory Cost The database The file system
size to run DBMS software. system is approach is
Size– It occupies a large space of disks and large
memory to run them efficiently. expensive to cheaper to
• Complexity– Database system creates additional design design
complexity and requirements.
File System Vs DBMS Data Due to the There exists a
File based system were an early attempt to Redundancy Centralization lot of
computerize the manual system.
Example– and the database, the duplication of
Inconsistency problems of data which may
data redundancy lead to
and inconsistency
inconsistency
are controlled
Structure The database The file system
structure is approach has a
Consider an example of students file system.
The student file will contain information regarding complex to simple structure
the student (rollno., studentName etc.).
design
We have subject file that contain information about
the subject and result regarding the result. File 2 tier layer
which contains the information regarding the result.
DBMS
A data base is a well-organized collection of data
that are related in a meaningful.
Different users but stored only one in a system.
The various operation performed by the DBMS
system are Insertion, Deletion, Selection etc.

2 tier architecture also called client server


architecture.
direct communicates
example– Indian Railway
The application on client side interact directly with
Figure, duplication of data is reduced due to the data base present at the server side.
centralization of data.
Database Management Systems 51 YCT
Search on TG: @apna_pdf
3 tier architecture Network Model– The network database model
allows each child to have multiple parents.

Relational Model– Relational DBMS is the most


widely used DBMS model because it is one of the
easiest.
ER Model– ER model is based on the notion of
real-world entities and relationship among them.
ER Model creates entity set, relationship set;
All the web application are kind of 3 tier general attributes and constraints.
architecture. DBMS LANGUAGES
There is no direct communication between client Data base languages are used to read update and
and server. store data in a database.
Application Server– This called business layer. It
act as a middle layer between the client and the
database server and exchange partially processed
data.
Data base layer– The data or information is stored. • DDL – Data Definition Language. (CREATE,
Client layer– The main purpose is to communicate DROP, ALTER, TRUNCATE, COMMENT,
with the application layer. RENAME)
Schema– Schema is actually a logical • DML – Data Manipulation Language. (INSERT,
representation of the database. UPDATE, DELETE, SELECT)
There can be multiple tables in a schema. • DCL–Data Control Language (GRANT, REVOKE)
• TCL – Transaction Control Language (COMMIT,
DATA MODELS
ROLLBACK)
Data model is the modeling of the data description,
data semantics and consistency constraints of the
DDL (Data Definition Language)
data. DDL actually consists of the SQL commands that can
be used to define the database schema.
Four Types of DBMS System are–
CREATE– It is used to create the database or its
• Hierarchical data base
objects (Like table, Index, function views store
• Network data base procedure and triggers).
• Relational data base There are two CREATE statements available in SQL.
• ER model data base 1. CREATE DATABASE
Hierarchical DBMS – In a Hierarchical database, 2. CREATE TABLE
model data is organized in a tree-like structure. Data CREATE DATABASE– The CREATE DATABASE
is stored Hierarchically (top down or bottom up) statement is used to create a new data base in SQL.
format. Syntax–
CREATE DATABASE database_name;
Example–
SQL>CREATE DATABASE Employee;
In order to get the list of all the database, you can
use SHOW databases statement.
SQL > SHOW DATABASE;
CREATE TABLE– The CREATE TABLE
statement is used to create table in SQL we know
that a table comprises of rows and columns.
Database Management Systems 52 YCT
Search on TG: @apna_pdf
Syntax– • ALTER (ADD, DROP, MODIFY)
CREATE TABLE table_name ALTER TABLE is used to add, delete/drop or
( modify columns in the existing table. It is also used
Column1 data_type(size), to add and drop various constraints on the existing
Column2 data_type(size), table.
Column3 data_type(size), ALTER TABLE_ADD–
....... • ADD is used to add columns into the existing table.
);
Syntax–
Example Query– This query will create a table
ALTER TABLE table_name;
students with three columns, RoLL_No, NAME and
SUBJECT. ADD(Columnname1 datatype,
CREATE TABLE students Columnname2 datatype,
( .......
RoLL_No int(3) columnnamen datatype);
NAME Varchar (20), ALTER TABLE_DROP–
SUBJECT Varchar (20), • DROP COLUMN is used to drop column in a table.
); Syntax–
DROP– ALTER TABLE table_name;
• DROP is used to delete a whole database or just a DROP COLUMN column_name;
table.
ALTER TABLE_MODIFY– It is used to modify
• A DROP statement in SQL removes a component
the existing columns in a table.
from a relational database management system
syntax–
(RDBMS).
Syntax– ALTER TABLE table_name;
DROP object object_name; MODIFY Column_name column_type;
Example– QUERY:
DROP TABLE table_name; TO ADD 2columns AGE and COURSE to table
table_name: Name of the table to be deleted. student.
DROP DATABASE database_name; ALTER TABLE student ADD (AGE number (3),
database_name: Name of the data base to be COURSE Varchar(40));
deleted.
DML
TRUNCATE– It is used to remove all records from
a table, including all spaces the TRUNCATE The SQL commands that deals with the manipulation of
TABLE my table statement is logically equivalent data present in the database belong to DML and this
to the DELETE FROM my table (without a includes most of the SQL statements.
WHERE clause). SELECT statement– select statement is used to fetch
Syntax– data from relational database. SQL select statement or
TRUNCATE TABLE table_name; SQL select query is used to fetch data from one or more
DROP Vs TRUNCATE– than one tables.
• Truncate is normally ultra fast and its ideal for Syntax– One Column:
deleting data from a temporary table. Here column_name is the name of the column for
• Table or database deletion using DROP statement which we need to fetch data and table_name is the
cannot be rollback so it must used wisely. name of the table in the database.
To delete the whole database Select column_name FROM table_name;
DROP DATABASE student_data; To fetch the entire table or all the fields in the table.
After running the above query whole database will SELECT * FROM table_name;
be deleted.
SELECT EMP_NAME FROM EMPLOYEES;
To truncate student_details table from student_data
database. To fetch the entire EMPLOYEES table;
TRUNCATE TABLE student_details; SELECT * FROM EMPLOYEES;
Database Management Systems 53 YCT
Search on TG: @apna_pdf
INSERT INTO statement– operation. You either execute it entirely or do not
INSERT INTO student of SQL is used to insert a execute it at all. There cannot be partial execution.
new row in a table. Consistency– Once the transaction is executed, it
INSERT INTO table_name VALUES (value1, should move from one consistent state to another.
value2, value3 .......); Durability– After successful completion of a
transaction, the changes in the database should
Example–
persist. Even in the case of system failures.
method1 (Inserting only values):
INSERT INTO student values ('5' 'HARSH' WEST Relational Model Concepts
BENGAL; 19;) 1. Attribute– Each column in a table. Attributes are
Method2 (Inserting values in only specified the properties which define a relation e.g.
columns); students_Rollno, Name, etc.
INSERT INTO student(Roll_NO, Name, Age) 2. Tables– In the Relational model the relations are
VALUES ('5' PRATIK, '19'); saved in the table format.
Tuple– It is nothing but a single row of a table,
UPDATE statement–
which contains a single record.
The UPDATE statement in SQL is used to update
the data of an existing table in database. Relation schema– A relation schema represents the
name of the relation with its attributes.
Basic syntax–
Degree– The total number of attributes which in the
UPDATE Table Name
relation is called the degree of the relation.
SET Column_name1 = value, column_names2 =
Cardinality – Total number of rows present in the
value ......
Table.
WHERE condition;
Relation key – Every row has one, two or multiple
Example-
attributes, which is called relation key.
SQL > update EMPLOYEES
ER Model
SET EMP_SALARY = 10000
ER Model stands for an entity-Relationship model.
WHERE EMP_AGE > 25;
It is a high-level data model.
Example-
Example– Suppose we design a school database.
SQL > UPDATE EMPLOYEES
SET EMP_SALARY = 120000
WHERE EMP_NAME = 'APOORV';
DELETE statement– The DELETE statement in
SQL is used to delete existing records from a table.
Syntax–
ER Diagram
DELETE FROM table_name WHERE
some_condition;
DCL (Data Control Language)
GRANT– Give users access privileges to database.
REVOKE– Withdraw users access privileges given by
using the GRANT command.
TCL (Transaction Control Language)
COMMIT – Commit a Transaction
ROLLBACK– rollback a transaction in case of any
error occurs.
SAVE POINT– Set a save point with in a transaction.
1. Entity– An entity many be any object, class, person
ACID Properties
or place.
ACID properties are used for maintaining the
Ex– Manager, product, employee etc.
integrity of database during transaction processing.
ACID in DBMS stands for atomicity, consistency,
Isolation and Durability.
Atomicity– A transaction is a single unit of
Database Management Systems 54 YCT
Search on TG: @apna_pdf
(a) Weak entity– An entity that depends on another (a) One-to-one relationship– When only one
entity called a weak entity. instance of an entity is associated with the
relationship.
Loan Installment Example– A female can marry to one male and a
male can marry to one female.
2. Attribute– The attribute is used to describe the
property of an entity.
For example– Id, age, contact number, name etc.
(b) One-to-many relationship
Example– Scientist can invent many inventions,
but the invention is done by the only specific
scientist.

(a) Key attribute– The key attribute is used to


represent the main characteristics of an entity
represent a primary key. (c) Many-to-one relationship
Example– Student enrolls for only one course, but a
course can have many students.

(d) Many-to-many relationship


(b) Composite attribute– An attribute that Example– Employee can assign by many projects
composed of many other attributes is known as a and project can have many employees.
composite.
The composite attribute is represented by an ellipse.

Notation of ER Diagram

(c) Multivalued Attribute– An attribute can have


more than one value.
A student can have more than one phone number.

(d) Derived attribute– It can be represented by a


dashed ellipse. An attribute that can be derived from
other attribute.
Integrity Constraint

3. Relationship– Diamond or rhombus is used to


represent the relationship. A relationship is used to
describe the relation between entities.

Database Management Systems 55 YCT


Search on TG: @apna_pdf
1. Domain Constraints– Defined of a valid set of 4. Key constraints– Its entity set uniquely.
values of an attribute. ID NAME SEMESTER AGE
Example– 1000 Tom 1 st
17
1001 Johnson 2nd 24
1002 Kate 3rd 21
th
1001 Morgan 8 22

Not allowed because all row must be unique.


KEY IN DBMS
2. Entity Integrity– The entity integrity state that Key is dbms is an attribute or set of attributes which
primary key value can't be null. helps you to identify a row (tuple) in a relation
Example– (table).
Key help you to identify any row of data in a table.
In a real world application, a table could contain
thousands of records.
There are mainly seven different types of key.
Super Key– A super key is a group of single or
multiple keys which identifies row in a table.
Primary Key– Primary key is a column or group of
columns in a table that uniquely identify every row
3. Referential Integrity– Referential integrity in in that table.
DBMS is based on primary and foreign key. the rule Candidate Key– Candidate key is a set of attributes
defines that a foreign key have a matching primary that uniquely identify tuples in a table Candidate
key. key is a super key with no repeated attributes.
Example–
<Employee> Alternate Key– Alternate key is a column or group
of columns in a table that uniquely identify every
EMP_ID EMP_NAME DEPT_ID row in that table.
<Department> Foreign Key– Foreign key is a column that creates
DEPT_ID DEPT_NAME DEPT_ZONE a relationship between two tables the purpose of
foreign key is to maintain data integrity and allow
The rule states that the DEPT_ID in the employee
navigation between two different instances of an
table has a matching valid DEPT_ID in the
entity.
Department table.
Compound Key– Compound key has two or more
To allow join Primary Key and
Foreign Key have same data types. attributes that allow you to uniquely recognize a
specific record.
Surrogate Key– An artificial key which aims to
EMP_ID EMP_NAME DEPT_ID
uniquely identify each record is called surrogate
01 Rahul D01 key.
02 Kumar D02 Primary Key Example–
03 Raj D03 CREATE TABLE PERSONS (
Foreign Key ID int Not NuLL
LastName varchar(255),
Primary Key first Name varchar(255),
DEPT_ID DEPT_NAME DEPT_ZONE Age int,
D01 Computer East PRIMARY Key (ID)
D02 Science West );
D03 Art South Create Primary Key (ALTER TABLE statement)

Database Management Systems 56 YCT


Search on TG: @apna_pdf
Syntax– Syntax: σp(r).
the syntax to create a primary key using the ALTER • σ is the predicate.
TABLE statement in SQL is; • r stands for relation which is the name of the table.
ALTER TABLE table_name; • p is prepositional logic.
ADD CONSTRAINT constraint_name, Example: σ age>17(student)
PRIMARY Key (column1, column2, ...... This will fetch the tuples (rows) from table student,,
column_n); for which age will be greater than 17.
FOREIGN KEY ON CREATE TABLE σage>17 and gender = 'Male' (student)
the following SQL creates a FOREIGN KEY on This will return tuples (rows) from table student
the "personID" column when the "orders" table is with information of male students, of age more than
created. 17.
CREATE TABLE ORDERS ( BRANCH_NAME LOAN_NO AMOUNT
order ID int NOT NuLL, Down town L-17 1000
orderNumber int NoT NuLL,
Redwood L-23 2000
personID int,
Perryride L-15 1500
PRIMARY KEY (orderID),
Downtown L-14 1500
Foreign KEY (person ID) REFERENCES
Mianus L-13 500
persons (person ID)
); Roundhill L-11 900

Relational Algebra Perryride L-16 1300


Relational Algebra is procedural query language, Input:
which take relation as input and generates relation σBRANCH_NAME="Perryride"(LOAN)
as output. Output:
Relational Algebra works on the whole table at BRANCH _ NAME LOAN _ NO AMOUNT
once, so we do not have to use loops etc to iterate Perryride L − 15 1500
over all the rows of data one by one.
Perryride L − 16 1300
2. Project Operation (π)
• Project operation is used to project only a certain
only a certain set of attributes of a relation.
• In simple words, if you want to see only the names
all of the students in the student table, then you can
use project operation.
Syntax of project Operator (π)–
π column_name1, column_name2, ______
column_nameN(table_name)
Example–
πName,Age(student)
Basic/Fundamental Operations– Above statement will show as only the Name and Age
1. Select (σ) columns for all the rows of data in student table.
2. Project (π) 3. Union Operation (∪): This operation is used to
3. Union (∪) fetch data from two relation (tables) or temporary
4. Set difference (–) relation (result of another operation).
5. Cartesian product (×) Syntax: A∪B
6. Rename (P) π student (Regular class) ∪ πstudent (extraclass)
1. Select operation (σ)– This is used to fetch rows 4. Set difference (–): This operation is used to find
(tuples) from table (relation) which satisfies a given data present in one relation and not present in the
condition. second relation.
Database Management Systems 57 YCT
Search on TG: @apna_pdf
Syntax– Syntax–
A–B where A and B are relations. SELECT tables1.column1, table1.column2
Example– If we want to find name of student who FROM table1 INNER JOIN table2
attend the regular class but not the extra class, then ON
we can use the below operation. table1.matching_column=table2.matching_columns
Query–
πstudent (Regular class) – πstudent (Extra class)
SELECT EMPLOYEE.EMP_NAME,
5. Cartesian product (×)– This is used to combine
PROJECT.DEPARTMENT
data from different relation (tables) into one and
FROM EMPLOYEE INNER JOIN PROJECT
fetch data from the combined relation.
ON PROJECT.EMP_ID = EMPLOYEE_ID
Syntax– (A×B) Output–
6. Rename operation (P)–
EMP _ NAME DEPARTMENT
• This operation is used to rename the output
Angelina Testing
relation for any query operation which returns result
Robert Development
like select, project etc.
Syntax– P(Relation New, Relation old) Christian Designing
the rename operation is used to rename the output Kristen Development
relation. It is denoted by rho (ρ). 2. LEFT JOIN– The SQL Left JOIN returns all the
JOIN in DBMS values from left table and the matching values from
the right table.
• A JOIN clause is used to combine rows from two or • If there is no matching join value, it will return
more tables, based on a related column between them. NULL.
• Join in DBMS is a binary operation which allows
you to combine Join product and selection in one
single statement.
Syntax–
Types of SQL JOIN SELECT table1.column1, table1.column2 FROM
1. INNER JOIN table1 LEFT JOIN table2
2. LEFT JOIN ON
3. RIGHT JOIN table1.matching_column=table2.matching_column:
4. FULL JOIN QUERY–
SELECT EMPLOYEE.EMP_NAME,
Example– EMPLOYEE
PROJECT.DEPARTEMENT
EMP _ ID EMP _ Name CITY SALARY AGE FROM EMPLOYTEE LEFT JOIN PROJECT
1 Angelina Chicago 200000 30 ON PROJECT.EMP_ID=EMPLOYEE.EMP_ID;
2 Robert Austin 300000 26 Output–
3 Christain Denver 100000 42
EMP _ NAME DEPARTMENT
4 Kristen Wash int on 500000 29
5 Russell Losangels 200000 36
Angelina Testing
Robert Development
PROJECT–
Christian Designing
PROJECT _ NO EMP _ ID DEPARTMENT
Kristen Development
101 1 Testing
Russell NULL
102 2 Development
Marry NULL
103 3 Designing
3. RIGHT JOIN– IN SQL, RIGHT JOIN returns all
104 4 Development
the values from the values from the rows of right
1. INNER JOIN– In SQL INNER JOIN selects and the matched values from the left table. If there
records that have matching values in both tables as is no matching in both tables, it will return NULL.
long as the condition is satisfied.

Database Management Systems 58 YCT


Search on TG: @apna_pdf
Syntax– Example–
SELECT table1. column1, table1.column2 Consider the CUSTOMERS table having the following
FROM table1 RIGHT JOIN table2 records–
No table1.matching_column = The following code is an example which would fetch
table2.matching_column_, the ID, Name and salary fields from the CUSTOMERS
4. FULL JOIN– In SQL, FULL JOIN is the result table, where the salary is greater than 2000–
of a combination of both left and right outer join. This would produce the following result.
Join table have all the records from both tables. It ID NAME SALARY
puts NULL on the place of matches not found. 4 Chaitali 6500.00
5 Hardik 8500.00
6 Komal 4500.00
7 Mufty 1000.00

Syntax– • From Clause


SELECT table1.column1, table1.column2 • From clause can be used to specify a sub query
FROM table1 FULL JOIN table2 expression in SQL.
ON • Sub queries in the from clause are supported by
table1.matching_column=table2.matching_column; most of the SQL implementation.
Syntax–
SQL Basic Structure
SELECT column1, column2 FROM
1. Basic structure of an SQL expression consists of
(SELECT column_x as C1, column_y FROM table
select, from and where clauses.
WHERE PREDICATE_x) as table2 WHERE
• From clause corresponds to cartesian product lists
PREDICATE;
relation to be used.
SET Operations
• Where clause corresponds to seclection predicate
1. UNION
in relational algebra.
2. UNION ALL
To fetch the entire table or all the fields in the
3. INTERECT
table.
4. MINUS
• SELECTFROM table_name;
Functional Dependency
WHERE SQL Clause
Functional dependency (FD) is a set of constraints
WHERE clause s used to specify/apply any
between two attributes in a relation functional
condition while retrieving, updating or deleting data
dependency says that if two tuples have same values
from a table. This clause is used mostly with
for attributes A1, A2, ..... An then those two tuples
SELECT, UPDATE and DELETE query.
must have to have same values for attributes B1,
The basic syntax of the SELECT statement with the
B2, ....... Bn.
WHERE clause is as shown below–
Functional dependency is represented by an arrow
SELECT column1, column2, columnN FROM
sign (→) that is,
table_name;
X→Y
ID NAME AGE ADDRESS SALARY
Trivial– If a functional dependency (FD) X→Y
1 Ramesh 32 Ahmadabad 2000.00 holds where Y is a subset of X, then it is called a
2 Khilan 25 Delhi 500.00 trivial FD. Trivial FDs always hold.
3 Kaushik 23 Kota 2000.00 Non-Trivial– If an FD X → Y holds, where Y is
4 Chaitali 25 Mumbai 6500.00 not a subset of x, then it is called a non-trivial FD.
5 Hardik 21 Bhopal 8500.00 Completely non-trivial– If an FD X→Y holds,
6 Komal 22 MP 4500.00 where X intersect Y = φ, it is said to be a
completely non-trivial FD.
7 Mufty 24 Indore 1000.00
Armstrong's Axioms– If F is a set of functional
SQL > SELECT ID, NAME, SALARY
dependencies then the closure of F, denoted as F+, is
FROM CUSTOMERS the set of all functional dependencies logically
WHERE SALARY > 2000; implied by F.
Database Management Systems 59 YCT
Search on TG: @apna_pdf
• Armstrong rules– First Normal Form
1. Reflexive Rule First Normal form is defined in the definition of
2. Augmentation Rule relations (table) itself.
3. Transitivity Rule Course Content
Aggregate function in SQL Programming Java,C + +
SQL aggregation function is used to perform the Web HTML, PHP
calculations on multiple rows of a single column of
We rearrange the relation (table) as below to
a table.
convert it to first normal form.
• Aggregate functions
Course Content
1. count()
Programming Java
2. sum()
Programming C++
3. avg()
Web HTML
4. min()
Web PHP
5. max()
Trigger– A trigger is a stored procedure in database Each attribute must contain only a single value from
its pre-defined domain.
which automatically invokes whenever a special
event in the database occurs. Second Normal Form
Syntax– Create trigger [Trigger_name] [before/after)
Second normal form, we need to understand the
{insert|update|delete}on [table_name] following–
[for each row] Prime attribute– An attribute which is a part of the
[trigger_body] candidate key, is known as a prime attribute.
Normalization– Non loss decomposition and functional Non-prime attribute– An attribute which is not a
dependencies, first, second and third normal forms part of the prime-key, is said to be a non-prime
dependency preservation, Boyce/codd normal form. attribute.
Decomposition– The process of breading up or • If we follow second normal form, then every non-
prime attribute should be fully functionally
dividing a single relation into two or more sub
dependent on prime key attribute.
relations is called as decomposition of a relation.
• That is, if X→ A holds, then there should not be
any proper subject Y of X, for which Y-A also
holds true.
Student_project

Student-
Stu_ID Stu_Name Proj_ID
Update anomalies– If data items are scattered and Project-
are not linked to each other properly, then it could Proj_ID Proj_Name
lead to strange situations. Third Normal Form
Deletion anomalies– We tried to delete a record,
For a relation to be in third normal form, it must be
but parts of it was left undeleted because of
in second normal form and the following must
unawareness, the data is also saved somewhere else. satisfy.
Insert anomalies– We tried to insert data in a No non-prime attribute is transitively dependent on
record that does not exist at all. prime key attribute.
Normalization is a method to remove all these Student_Detail–
anomalies and bring the database to a consistent
state.

Database Management Systems 60 YCT


Search on TG: @apna_pdf
Student_Detail– Active state–
• The active state is the first state of every
Zip codes– transaction. In this state, the transaction is being
executed.
For Example– Insertion or deletion or updating a
Boyce-Codd Normal form record is done here. But all the records are still not
• BCNF is an extension of third normal form on saved to the database.
strict terms. Partially committed– In the partially committed
• For any non-trivial functional dependency, X → A state, a transaction executes its final operation but
X, must be a super key. the data is still not saved to the database.
• In above image Stu_ID is the super key in the Committed– A transaction is said to be in a
relation student_Detail and zip is the super key in committed state if it executes all its operations
the relation zip codes. successfully.
Stu_ID → Stu_Name, Zip Failed state– If any of the checks made by the
and zip → city (which conforms that both the database recovery system fails, then the transaction
relation are in BCNF). is said to be in the failed state.
Fourth normal form (4NF) Aborted– If the transaction fails in the middle of
A relation will be 4NF if it is Boyce/codd normal the transaction then before executing the
and has no multi valued dependency. transaction, all the executed transaction are rolled
for a dependency A → B, if for single value of back to its consistent state.
multiple value of B exists, then the relation will be a Two operation–
multi-valued dependency. 1. Re-start the transaction
Fifth normal form (5NF) 2. Kill the transaction
A relation in 5NF if it is in 4NF and not contains Transaction property
any join dependency and joining should be lossless. The transaction has the four properties. These are
5NF is also known as project-join normal form used to maintain consistency in a database, before
(PJ/NF). and after the transaction.
Transaction Management In DBMS– Property of transaction
• A transaction is set of logically related operation. 1. Atomicity
• Now that we understand what is transaction we 2. Consistency
should understand what are the problems 3. Isolation
associated with it. 4. Durability
• To solve this problem, we have the following two 1. Atomicity– It states that all operation of the
operations. transaction take place at once if not the transaction
• Commit– If all the operations in a transaction are is aborted.
completed successfully then commit those 2. Consistency– A transaction must after the database
changes to the database permanently. from one steady state to another steady state. This is
• Rollback– If any the operations fails then the responsibility of both the DBMS and the
rollback all the changes does by pervious application developers to make certain consistency.
operations. 3. Isolation– Transactions that are executing
States of transaction– Transaction can be implemented independently of one another is the primary concept
using SQL queries and sever. followed by isolation.
4. Durability– The durability property is used to
indicate the performance of the database consistent
state.
Implementation of Atomicity and durability–
The recovery management component of a database
system can support atomicity and durability by a
variety of schemes.
Database Management Systems 61 YCT
Search on TG: @apna_pdf
Shadow copy– In this schedule,
In the shadow copy scheme, a transaction that wants • W1(A) and R2(A) are called as conflicting
to update the database first creates a complete copy operations.
of the database.
• This is because all the above conditions hold ture
Figure below depicts the scheme, showing the
for them.
database state before and after the update.
VIEW Serializability– View serializability is a
process to find out that a given schedule is view
serializable is not.
Two schedules S1 and S2 are said to be view
equivalent if they satisfy the following conditions.
1. Initial Read– An Initial read of both schedules
must be the same suppose two schedule S1 and S2.
IN schedule S1, if a transaction T1 is reading the
data item A, then in S2, transaction T1 should also
Schedule– A series of operation from one read A.
transaction to another transaction is known as
schedule. T1 T2 T1 T2

Read ( A ) Write ( A )
Write ( A ) Read ( A )
Schedule S1 Schedule S2
2. Update Read–
T1 T2 T3 T1 T2 T3
Serializability in DBMS
Some non-serial schedules may lead to Write ( A ) Write ( A )
Write ( A )
Read ( A ) Write ( A )
inconsistency of the database. Serializability is Read ( A )
mainly of two types– ScheduleS1 Schedule S2

3. Final write–
T1 T2 T3 T1 T2 T3

Read ( A )
Write ( A ) Write ( A )
Re ad ( A )
Write ( A ) Write ( A )

Transaction Isolation Levels in DBMS


The SQL standard defines four isolation levels.
Conflict serializability– If a given non-serial 1. Read uncommitted
schedule can be converted into a serial schedule by 2. Read committed
swapping its non-conflicting operations, then it is
3. Repeatable Read
called as a conflict serializable schedule.
4. Serializable
Conflict operations– Two operations are called as
conflicting operations if all the following conditions Failure Classification–
hold true for them. 1. Transaction Failure
• Both the operation belong to different transaction. 2. System Crash
• At least one of the two operations is a write 3. Disk Failure
operations. 1. Transaction failure– Transaction failure occurs
Example– Consider the following schedule when it fails to execute or when it reaches a point
Transaction T1 Transaction T2 from where it can't go any further.
R1( A ) 1. Logical error 2. Syntax error
W1( A ) R2 ( A ) 2. System Crash– System failure can occur due to
power failure or other Hardware or Software failure.
R1( B )
Example- Operating system error
Database Management Systems 62 YCT
Search on TG: @apna_pdf
3. Disk Failure– It occurs where hand-disk drives or CONCURRENCY CONTROL– Concurrency
storage drives used to fail frequently. control is the working concept that is required for
Problems with Concurrent Execution– In a database controlling and managing the concurrent execution
transaction, the two main operation are READ and of database and thus avoiding the in consistencies in
WRITE operations. the database.
(i) Lost Update Problem (W-W Conflict) Two-PHASE LOCKING (2PL)– The Two-Phase
locking protocol divides the execution phase of the
(ii) Dirty Read Problems (W-R Conflict)
transaction into three parts.
(iii) Unrepeatable Read Problem (W-R Conflict)
Lost Update Problem (Write-Write Conflict)– Let's
take the value of A is 100
Time Transaction T1 Transaction T2
t1 Read ( A )
t2 A = A − 50 There are two phases of 2PL–
t3 Read ( A ) 1. Growing phase 2. Shrinking phase
t4 A = A + 50 Example–
t5 Write ( A ) T1 T2
t6 Write ( A ) 0 LOCK − S ( A )
1 LOCK − S ( A )
• At t1 times, T1 Transaction reads the value of A i.e.
2 LOCK − X ( B )
100.
3 − −
• At t2 Time, T1 Transaction deducts the value of A
4 UNLOCK ( A )
by 50.
5 LOCK − X ( C )
Dirty Read Problem (W-R Conflict)– This type of
6 UNLOCK ( B )
problem occurs when one transaction T1 update a data
7 UNLOCK ( A )
item of the database, and then that transaction falls due
to some reason but its updates are accessed by some 8 UNLOCK ( C )
other transaction. 9 − −
Example– Lets value A is 100. The following way shows how unlocking and
locking work with 2-PL.
Time Transaction T1 Transaction T2
Transaction T1
t1 Read ( A )
• Growing phase from step 1-3
t2 A = A + 20
t3 Write ( A ) • Shrinking phase from step 5-7
t4 Read ( A ) • Lock point at = 3
t5 A = A + 30 Transaction T2
t6 Write ( A ) • Growing phase from step 2-6
t7 Write ( B ) • Shrinking phase from step 8-9
• Lock point at 6
Unrepeatable Read Problem (R-W Conflict)–
Strict two-phase locking (strict-2PL)
Example– Let take value A is 100
The first phase of strict-2PL is similar to 2PL.
Time Transaction T1 Transaction T2
Strict-2PL protocol does not have shrinking phase
t1 Read ( A ) of lock release.
t2 Read ( A )
t3 A = A + T30
t4 Write ( A )
t5 Read ( A )

Database Management Systems 63 YCT


Search on TG: @apna_pdf
Basic Time stamp ordering protocol works as 1. Database 2. Area 3. File 4. Record
follows–
1.Check the following condition whenever a
transaction Ti issues a Read (X) operation.
• If W_Ts (X) > Ts(Ti) then the operation is
rejected.
• If W_Ts(X) < = Ts(Ti) then the operation is
executed.
2. Check the following condition whenever a
transaction Ti issues a write (X) operation.
• If Ts (Ti) < R_Ts (X) then the operation is Recovery and Atomicity
rejected. • When a system crashes, it may have several
• If Ts(Ti) < W_Ts(X) the operation is rejected and transaction being executed and various file opened
Ti is rolled back other waise the operation is for them to modify the data items.
executed. • But according to ACID properties of DBMS
Where, atomicity of transaction as a whole must be
Ts(Ti) denotes the time tap of the transaction Ti. maintained, that is, either all the operations are
R_Ts(X) denotes the Read time_stamp of executed or none.
data_itemX. Log-Based Recovery– The log is a sequence
W_Ts(X) denotes the write time_stamp of of records. Log of each transaction is maintained in
data_itemX. some stable so that if any failure occurs, then it can be
Validation Based Protocol– Validation phase is also recovered from there.
known as optimistic concurrency control technique the There we two approach to modify the database
transaction is executed in the following three phase. 1. Deferred database modification
1. Read phase 2. Immediate database modification
2. Validation phase Recovery with concurrent transactions
3. Write phase Concurrency control means that multiple
THOMAS WRITE RULE– Thomas write rule provides transactions can be executed at the same time and then
the guarantee of serializability order for protocol. the inter leaved logs occur.
The Basic Thomas Write rules as follows. Recovery with concurrent transactions can be
• If Ts(T) < R+Ts(X) then transaction T is aborted and done in the following four ways.
rolled back and operation is rejected. 1. Interaction with concurrency control
• If Ts(T)<W_Ts(X) then don't execute the 2. Transaction rollback
W_item(X) operation of the transaction and 3. Check point
continue processing. 4. Restart recovery
• If neither condition 1 nor condition 2 occurs, then BUFFER Management– The buffer manager is the
allowed to execute write operation by transaction Ti software layer that is responsible for bringing pages
and set W_Ts(X) to Ts(T). from physical disk to main memory as needed. The
buffer manages the available main memory by dividing
MULTIPLE GRANULARITY
the main memory into a collection of pages, which we
Granularity– It is the size of data item allowed to called as buffer pool the main memory pages in the
lock. buffer pool are called frames.
Multiple Granularity– It can be defined as ARIES Algorithm– Algorithm for recovery and
liearachically breaking up the database into blocks isolation exploiting semantics (ARIES) is based on the
which can be locked. write Ahead Log (WAL) protocol. Every update
Hence, the levels of the tree starting from the top operation writes a log record which is one of the
level are as follow. following–
Database Management Systems 64 YCT
Search on TG: @apna_pdf
1. Undo-only log record– Only the before image is NoSQL Database
logged. We know that MongoDB is a NoSQL database, so it
2. Redo-only log record–Only the after image is logged. is very necessary to know about NoSQL database to
3. Undo-redo log record– Both before image and understand MongoDB throughly.
after images are logged. NoSQL database is used to refer a non-SQL or non
The recovery process actually consists of 3 phases. relational database.
1. Analysis 2. Redo 3. Undo Advantages of NoSQL–
1. It supports query language
Remote Backup
2. It provides fast performance
Remote backup provides a sense in case the primary
3. It provides horizontal scalability
location where the database is located gets
MongoDB advantages over RDBMS– MongoDB is a
destroyed. Remote backup can be offline or real-
new and popularly used database it is a document
time or online.
based, non relational database provider.
MongoDB Advantages
• MongoDB is schema less.
• There may be difference between number of fields,
content and size of the document from one to other.
• Structure of a single object is clear in MongoDB.
• There are no complex joins in MongoDB.
• Distinctive features of MongoDB.
Easy to use
Light weight
File– A file is named collection of related
Extremely faster than RDBMS
information that is recorded on secondary storage
Where MongoDB should be used–
such as magnetic disks, magnetic tables and optical
• Big and complex data
disks.
• Mobile and social infrastructure
S. SQL No SQL
• Content management and delivery
No.
• User data management
1. RELATIONAL No-relational or
• Data hub
DATABASE distributed database
MANAGEMENT system. MongoDB Datatypes
SYSTEM Following is a list of usable data types in MongoDB.
(RDBMS) Data type Description
2. These databases They have dynamic String String is the most commonly used
have fixed or static schema. data type. It is used to store data.
or predefined Integer Integer is used to store the numeric
schema. value. It can be 32 bit or 64 bit
3. These data bases These database are depending on the server you are using.
are not suited for best suited for Boolean This data type is used to store Boolean
hierarchical data hierarchical data values. It just shows yes/no values.
storage. storage. Double Double data type stores floating point
4. Follows ACID Follows CAP values
property (Consistency, Arrays This data type is used to store a list or
Example– MySQL, availability, partition multiple values into a single key.
Oracle, MS-SQL tolerance) Object Object data type is used for embedded
Server etc. Example– MongoDB, documents.
GraphQL, HBase, ect. Null It is used to store null values.

Database Management Systems 65 YCT

Powered by TCPDF (www.tcpdf.org)


Search on TG: @apna_pdf

06. THEORY OF COMPUTATION


Theory of Computation(TOC)- = {∈} ∪ {a, b} ∪ {aa, ab, ba, bb}..........
It is the mathematical study of computing machine = Infinite
and their capabilities.
= Complete language
OR
It is the study of automata theory and formal Finite Automata
languages.
Finite automata is the mathematical model which
Ambiguity problem–(undecidable). contains finite number of state and transition defined
• The general problems are two types known as- between the states.
1. Decidable problem
2. Undecidable problem
• To estimate the Nature of problem some
mathematical tools are used which is known as
Automata.
• Automata is mathematical model in which are
study practical situation of computer science.
Alphabet 'Σ'– Finite non-empty set of symbols.
Example– {0, 1}, {a,b,c,d}
String– Finite sequence of symbols over the given alphabet 'Σ'. Deterministic Finite Automata (DFA)
n Finite Automata can be represented by following
Example– {0, 1} repetition allowed. two methods.
{0, 1, 0, 1} {0, 1, 0, 1, 0, 1} • Transition diagram
Length → 4 6 • Transition table
Epsilon (∈) – Length will be zero. DFA: It is finite Automata in which from each and
Language – Any set of strings over the given alphabet. every state on every input symbol exactly one
L1: set of all string of length transition exist.
{0,1} DFA is formally define as five tuple :
Q = Finite Number of state
L = {0,1,10, 01........}
Input alphabet
• The set can finite, infinite, empty. q 0 = Initial state
• Finite language : (strings are finite) F = Final state
• Infinite Language : (strings are Infinite) δ = Transition function
• Empty Language : L = {∈}, finite length DFA (Q, , q 0 , F, δ)
L = {∈}→ Valid String Transition Function → Q × Q
L = {∈, 0, 1, 00, 11, 01, 10 ..........}

Complete Language = Σ*
Substring– Consecutive sequence of symbols over
the given string known as substring.
Ex. Mode → 4 length
N(N+1)
Hence, Total Number of Substring = +1
2 {q0.q1}× (a, b)
Power of Σ : Σ = {a, b} {q0.a}
1
Set of all string of length 1, = {a, b} {q0.b}
2
{aa, ab, ba, bb} {q1.a}
{q1.b}
3
8 Acceptance of DFA: By reading string from left to
0
Set of all string of length zero = {∈} or ∈ right end of the string the DFA enter into secure
* 0 1 2
final state than the given string accepted otherwise
.......... rejected.
Theory of Computation 66 YCT
Search on TG: @apna_pdf
The set of string accepted by given DFA is known as •
Language of the DFA, Hence Every DFA represents
exactly one language.

|ω| ≤ n
(n + 2) state
Minimal DFA: ω ∈ {a, b}
Empty Language accepted: |ω| mod 2 = 0
In any DFA, if no final state exist, or final state are
L = {∈, aa, ab, ba, bb} aaaa, .....}
not reachable from initial state than the language
accepted by DFA is Empty Language.
In any DFA if initial state is also final state then '∈'
is also accepted by DFA.
Dead State: If any non-final state having self loop |ω| mod 2 = 1
on input symbol than that state is known as dead
state.
By reading any input, if automata in DFA and if we
don't reach to final state then that input is rejected.
|ω| mod 3 = 0
C-programming language = set of all valid program.
Program void main ( )
{
int a, b;
{ ≅ | ω | ≅ 1mod 3
|ω| mod n = 0
'n' length string
3→3
4→4
.
.
n→n
• Minimal DFA– ω ∈ {a, b}*
A Finite Automata is said to accept a language if all na(ω) = 2 (exactly two a's)
the strings in the language are accepted and all the
L = {aa, aba, baa, aab, ......}
string are rejected which are not presented in the
language.
DFA (Minimal)–
ω = {a, b}, |ω| ≤ 2 • na(ω) ≥ 2 (at least two a's)
L = {∈, a, b, aa, ab, ba, bb}

• na (ω) ≤ 2 (at most two a's)


• ω ∈ {a, b}*
na(ω) mod 2 = 0
na(ω) ≅ 0 mod 2

|ω| = n |ω| ≥ n
(n + 2) state, (n + 1) state
Theory of Computation 67 YCT
Search on TG: @apna_pdf
• The language for which TM is possible know as
REL.
Note– FA → Finite Automata
PDA → Push Down Automata
CFL → Context-Free Language
CSL → Context Sensitive Language
TM → Turing Machine
REL → Recursively Enumerable Language
LBA → Linear Bounded Automata

• ω ∈ {a, b}*
na(ω) ≅ o mod 2
and
nb(ω) ≅ o mod 2
∈, aa, bb, aabb 
 
 abab  Power Sequence = [TM > LBA > PDA > FA]
L= 
 baba ....... Expressive Power–
 bbbb 
• Number of language accepted by particular
na( ω) nb( ω) automata know as expressive power of that
even even ∈, aa, bb Automata.
even odd aab • It is important to note that DFA and NFA are of
odd odd ab same power because every NFA can be converted
odd even abb into DFA and every DFA can be converted into
Compliment of DFA– By interchanging final state NFA.
into non-final state and non-final state, then we can • The turning machine i.e. TM is more powerful
get the compliment of DFA.
than any other machine.
Minimization of DFA
Equivalent state- Two state q1 and q2 are equivalent
∨ x ∈ ∑ * both δ ( q1 , x ) and δ ( q 2 , x ) result either
• If language accepted by DFA is '1' then final state or non-final state otherwise they are not
compliment of DFA accept "Σ* – 1". equivalent.
• Compliment is applicable only for DFA. State Equivalence Algorithm– To detect equivalent
Note– We cannot get the compliment of NFA and e- state for two algorithm exist know as-
NFA.
• State equivalence algorithm
Chomskey Hirarchy–
• Marking algorithm
• Finite automata having one stack memory element
know as push down automata. There minimization algorithm application for only
• The comparison element remember the stack to for DFA (Non-applicable for NFA and ∈-NFA)
perform validation of string in push down After apply minimization algorithm for any DFA
automata. then the language accepted by DFA remains same.
• Hence language L2 is accepted by push down
Before apply minimization algorithm all not
automata but not finite automata.
reachable state one eliminated first.
• To accept language L3 finite automata phase and
push down automata phase hence turning machine Minimum Number of State of following–
is constructed.
• The language for which FA is possible know as
Regular language.
• The language for which PDA is possible know as
CFL.
• The Language for which LBA is possible know as
CSL.
Theory of Computation 68 YCT
Search on TG: @apna_pdf
Construction of NFA
1. Construct NFA that accept all string of a'b and b's
where each string ending with abab.

2. With aba or abb


Construct the Minimal DFA–
L = {an bn/n, m ≥ 1}
L = {ab, aabb, aaab, abb .......}

NFA to DFA conversion–


Subset construction algorithm (Equivalence
algorithm)
• Construct the minimal DFA for the language. • Construct DFA equivalent to solving NFA.
L = {1, 2, 4 ...... 2n}
all these number are in unary.
L = {1, 11, 1111 ........}
L = {12n/n>0} not possible
• NFA:

∈-closer– ∈-closer state of which starting by


reading only ∈-reachable state. The initial state of
DFA is ∈-closer initial state of NFA.
• Construct a minimal DFA that accept all the Properties of FA–
strings of 0's and 1's which contains. 1. Emptyness problem
(i) 0 1 as substring 2. finiteness problem
L = {01, 010, 011, 101, 001 .....} 3. Equivalence problem
4. Membership problem
1. Emptyness problem– It means, checking whether
language accepted by the given FA is empty or not.
Non-Deterministric Finite Automata (NFA)
Step-1 → Eliminate all non-reachable state form
In NFA from the given state and the given input DFA.
signal there may be '0' transition or '1' transition or
(ii) To resultant automata at least one. Final item
more than '1' transition exist.
exist and we accept non-empty language other
• NFA is formally different (Q, Σ δ, q0, F) empty language.
Q → Finite no. of state
Σ → Input alphabet
q0 → Initial state
F → Set of final state
δ → Transition function
• Minimization algorithm not applicable for NFA.
• Complementation is not applicable for the NFA.
• In NFA for valid string also Non-final paths or 2. Finiteness problem– It means checking whether
transition may exist. language accepted by given automata is finite or not.
Theory of Computation 69 YCT
Search on TG: @apna_pdf
Converstion
Regular Expression  → Finite Automata
(RE ⇒ ∈-NFA) Thomson construction
Regular ∈-NFA
Expression
1. φ
3. Equivalence problem– Checking whether given Basic R.E.
two automata accept same language. 2. ∈
4. Membership problem– It means checking whether Basic R.E.
the Exist 'x' in the given automata or not. 3. a
x, y, z. Σ = {a, b}
Basic R.E.
I/P alphabet (Σ = {a, b})
4. r1.r2

5. r1 + r2

Regular Expression
• The simplest way of represent regular languages
know as regular expression.
• Regular expression can be constructed by using 6. r1*
following '3' operand and input symbols as operands.
* → Kleene closer
+ → Union operator
. → Concatenation operation
7. r1+
1. L = { } φ
2. L = {∈} ∈
3. L = {a} a
4. L = {a, b} ab 8. φ+
5. L = (a, b) a + b
6. L = {∈, a, aa, aaa ......}a*
7. L = {a, aa, aaa ......}a+ Construct NFA for RE–
• For one regular language, there, may be possibility (a + b)* (aa + bb) (a + b)*
of having many regular expression by but one
regular expression represent only one regular
language only.
Identities of Regular Expression
1. R + φ = φ + R = R
2. R.φ = φ.R = φ
3. R.∈ = ∈.R = R
4. R* = (R*)* = (R+)* = (R*)+
5. RR* = R+ = R*R
6. R+ + ∈ = R*
7. a(ba)* = (ab)*a
8. a + b = b + a
9. ab ≠ ba
10. (a+b)* ≠ (ab)*
• Mealy– Mealy is mathematical model in which
11. (a+b)* ≠ (a*b*) output is associated with transition.
12. (a + b)* ≠ a* + b*
13. (a + b)* = (a* + b*)* = (a* + b)* = (a + b*)* =
(a*b*)*
14. ∈* = ∈; ∈+ = ∈
15. φ* = ∈, φ+ = φ
Theory of Computation 70 YCT
Search on TG: @apna_pdf
• Moore– Moore is mathematical model in which • Construct Mealy Machine that contain all the string
output is associated with state. of a's and b's and produces one as output if last two
symbol input are same otherwise produce.

Definition– (Q, Σ, q0, ∆, δ, λ )


Q → Infinite Number of states
Σ → Input alphabet
q0 → Initial state
∆ → Output state • Construct the Moore Machine that takes all strings
of 0's and 1's as input and produces A's output if
δ → Transition function input is ending with 10 or produces B's output if
λ → Output function input is ending with 11 otherwise C as output.
Mealy Machine ⇒ Q×Σ → ∆
Moore Machine ⇒ Q → ∆
• Mealy and Moore Machine are deterministic in
nature hence from each and every state input symbol
exactly one transition exist.
• There is no final state in Mealy and Moore Machine
because they are not acceptors, they are output
generators.
• Mealy and Moore Machine are practical use in Ckt
• Construct the Moore Machine that takes all binary
design.
number if input and produces residue modulo '3' as
• Mealy and Moore Machine can be represented output.
transition table or transition diagram.
Mealy Machine
• Construct Mealy Machine that represents behaviour
of 1's complement of binary number ckt.

• Construct the Moore Machine that takes all base '3'


as input and produces residue modulo 4 as output.

• Construct the Mealy Machine that represents 2's


complement of binary number Ckt behaviour.
(Assume that we are reading the string from LSB to Moore to Mealy Machine Conversion
MSB and carry is discarded) • Construct the Equivalent Mealy Machine to
While reading the string from LSB initially any following Moore Machine
number of zero replace them by zero until we get
first '1' replace as it is and then complement
remaining things.

Theory of Computation 71 YCT


Search on TG: @apna_pdf
• Mealy Machine– (v) Palindrome language has one symbol regular
and over more them one symbol are non-
regular.

Pumping Lemma
• Pumping Lemma is the theorem using to prove non-
regular language as non-regular.
• Pumping Lemma uses prove by contradiction
strategies.

Mealy Machine to Moore Machine Conversion–

Method steps– L = {an bn/n ≥ 1} non regular


1. Assume L is regular
2. L = FA = n state
3. |z| ≥ n
Moore Machine– 4. |z|

u|v|w
5. Loop string
6. uv, w ∈ ∀ i > 0
u, v w ∉ L, non regular.
Steps–
To prove language 'L' is non-regular
(i) Assume L is regular
(ii) If 'L' is regular than their exist finite Automata
• While converting from Mealy Machine to Moore
for 'L' assume 'n' states on their.
Machine number of state of Moore M/C may
(iii) Select some |z| string |z| from length whose
increases because there may be possibility of having
length is greater than or equal to n.
more than one output at one state hence splitting of
• Divide |z| string in three parts (u, v, w) such length
states happens.
of v is |v| ≥ 1.
• While converting from Mealy M/C to Moore M/C
Maximum number of state possible in Moore M/C • If L is regular for all ∀ i ≥ 1,
from the given 'n' state m-output symbol Mealy M/C u v, w ∈ L
is n*m. at least i value u v w ∉ L then L is non-regular.

Regular Language Detection Closure properties of Regular Language


(i) Finite language is always regular, but all regular 1. Union Operation–
language need not be finite. L1 = Regular Language = FA1
(ii) Finite Automata having finite memory, hence L2 = Regular Language = FA2
the language which requires finite comparison
can be recognized by FA.
(iii) Finite Automata fails to accept language, which
requires infinite memory.
(iv) Any infinite language having comparison
between symbol is non-regular. Hence regular language are closed under union.
Theory of Computation 72 YCT
Search on TG: @apna_pdf
2. Sub-set Operation– The subset of regular language • Whenever union and complement one closed then
may or may not regular, hence regular language are intersection is also closed. Hence finally Regular
not closed under subset operation. Language are closed under intersection.
an bn ⊆ a* b* ⊆ (a + b)* 8. Reversal Operation–
Non-regular Regular L = {an bm} ⇒ LR = {bm an}
3. Concatenation–
L1 = Regular Language = an = FA1
L2 = Regular Language = bn = FA2
• Reversal of Regular Language is always Regular
because Regular Language are closed under reversal.
Regular language are closed under concatenation. • Reversal operation on regular expression applied
Note– Let 'L1' and 'L2' are two Regular Language F1 and as follows–
F2 are finite Automata for L1 and L2 is always 1– (E + F)R = ER + FR (001 + 110)R ⇒ 100011
regular. Hence Regular Language are closed under 9. Init Operation–
concatenation.
Init (L)– Init of language 'L' is set of all prefix of all
4. Kleene Closure– string of the language.
L → Regular Language
10. Substitution operation–
the FA exist
L = {an bm/n, m ≥ 1}
S(L) = {0n1m/n, m ≥ 1}
Substitution (s) is a mapping from Σ → ∆ where
each symbol of Σ is replaced by a Regular
Language over the ∆.
5. Positive Kleene closure–
S(φ) = φ
S(∈) = ∈
S(a) = a
11. Homomorphism Operation– Homomorphism is a
(i) Let 'L' be a Regular Language and 'F' be the finite special case of substitution where each symbol of Σ
Automata for 'L' then the Kleene closure of it, can be replaced by A single string for the ∆.
always regular because FA exists as follows. 1. H(φ) = φ
(ii) Let 'L' is Regular Language F be the FA for 'L'
2. H(∈) = ∈
then the positive closure of it always regular because
3. H(a) = a
FA as follow.
4. H(a + b) = H(a) + H(b)
6. Complementation–
L - Regular Language Two DFA
Σ* – L ⇒ Regular
Compliment of Regular Language is always regular
because can construct complemented DFA by
interchanging final state as non-final and non-final
state as final.
7. Intersection– 2DFA → (Q, Σ, δ, q0, F)
L1 → Regular
δ : Q × E → Q × {L, R}
L2 → Regular
• 2-DFA is a DFA which is capable to move Left as
(
L1 ∩ L2 = L1 ∪ L 2 ) well as right side direction.
Intersection is closed under Regular Language. • 2-DFA is formally defined as follows.
Theory of Computation 73 YCT
Search on TG: @apna_pdf
Acceptance method– By reading the string starting Sentential Form–
from left if the 2DFA enter into. Final state • Every step in the derivation is one sentential form
whenever M/C is halted. Then the string is accepted sentential form may be collection of terminals and
otherwise string is rejected. non-terminals.
Equivalence classes– • The derivation is LMD then sentential form is left
• Equivalence class of state 'q' is set of string by sentential form.
which we can reach state 'q' from the initial state. • Every grammar represent one language.
• The number of equivalence for given Regular • For CFL their exist grammar context free
Language is number of states of minimal DFA grammar.
exist for that language. • For CSL their exist grammar context sensitive
grammar.
GRAMMARS
• Set of rules used for describe rules for the language.
• Grammar is following determines as:
N = Set of non-terminals [S, A, B]
T = Set of terminals [a, b]
P = Number of production S → ab/ba/c/∈
S = Starting symbol
Example– S → AB
A→a
B→ b
Every grammar is formed α → β
where β is replacement of 'α'
Derivation– The process of generating string from
the given grammar know as derivation.
• The derivation can be either left most derivation
(LMD) or completely right most derivation (RMD).

• All grammar is of the form of α, β, α should


contain at least order.
LMD– It is process of derivation in which left most Linear Grammar– In any grammar their exist
non-terminal is replaced by its right hand side part. exactly one non-terminal on LHS and almost one
RMD– It is process of derivation in which right non terminal (A) on RHS.
most non-terminal is replaced by its RHS part at • The linear grammar can be left linear or Right
every set. grammar or middle linear.
Parse Tree or Derivation Tree–Tree representation • Regular grammars are not one class of linear
of the derivation know as parse tree all heaf node of grammar hence all regular grammar are linear
parse tree know as yield of the parse tree. grammar but all linear grammar need not be
regular.
Regular Grammar– Grammar is called a type 3 or
regular grammar if all its production are type 3
production. A production S → ∧ is allowed in type
3 grammar, but in this case S does not appear on the
right-hand side of any production.
S → bs/aA
A → bA/aS/∈
Theory of Computation 74 YCT
Search on TG: @apna_pdf
Context Free Grammar S → S1/S2
Context-free languages are applied in parser design. S1 → AB
They are also useful for describing block structures A → aAb/ab
in programming languages. It is easy to visualize B → CB/C
derivations in context-free languages as we can SL → PQ
represent derivations using tree structures. P → aP/Q
The language generate by context-free grammar are Q → bQC/bc
known as CFL. Simplification of context free grammar–
(i) Useless Variable
(ii) Unit Production
(iii) Null Production
• Elimination of useless variable– It means
• Checking whether the given CFG is Regular or elimination of variable from the grammar which are
not, is undecidable. not deriving any string and also eliminate variable
Ambiguity Problem which are not required for derivation.
A terminal string ω ∈ L (G) is ambiguous if there • Variable not reachable from S (Starting Symbol).
exist two or more derivation tree for ω (or these (ii) Unit Production– Any production of the form
exist two or more left most derivation of ω). "A→B" known as unit production.
(iii) Null Production (A→∈)– Any production like
"A→∈" known as Null production.

Unambiguous Grammar
The grammar is said to be unambiguous for all string
(i) Normal form of CFG means applying condition
if the grammar exist only one parse tree or only one on RHS of the production.
LMD or one RMD or if one LMD and one RMD (ii) To normalize the grammar, it should be
ever exist but both produces the same parse tree. simplified.
1. a = b + c * d; (iii) There are mainly two normal forms known as
S → id/E Chomsky and Greibach normal form.
E → E + E/ E*E |id; GNF Normal Form– A → av*
E→E+E (a) Convert into GNF?
→E+E*E S → AB
→ id + E * E A → aA|bB|b
B→b
→ id + id*E
• The grammar is left recursive grammar, then
→ id + id * E
eliminate the left recursion to convert into GNF.
Inherently Ambiguous Grammar
Decision Properties of CFG–
• In ambiguous grammar from which elimination of
(i) Emptyness 
ambiguity is not possible. 
(ii) Finiteness  Decidable
Example–The following language is inherently
(iii) Membership 
ambiguous CFL Means, all of its grammar are
ambiguous and elimination of ambiguity is not (i) Emptyness– Checking whether CFG generate
possible for each grammar. empty language or not.
Theory of Computation 75 YCT
Search on TG: @apna_pdf
Algorithm– • PDA is only one type only, but recognize or are
(a) Eliminate useless variable from the given two types, DPDA, NDPDA.
grammar. Definition–
(b) Starting symbol is also useless then that grammar (i) There is only one type of PDA, that is language
generates empty language otherwise non-empty. recognizer (No output generator).
(ii) Finiteness problem– It means checking whether (ii) Expressive power of NPDA is more than
given CFG generates finite language or not. DPDA.
Algorithm– (iii) By default PDA means N-PDA.
(a) Convert the given grammar into CNF grammar. (iv) There are two type of acceptance methods to
(b) Construct CNF graph. accept a string in PDA, they are–
(iii) Membership Problem or Parsing Algorithm– • Empty Stack Method
(a) Checking whether string 'x' is generated from • Final State Method
given CFG or not.
(b) Checking whether given string is member of
{
Example– L = b n a n / n ≥ 1 }
given grammar or not, know as parsing. (a) Empty Stack Method– By reading the string

(c) The algorithm which performs parsing, know as from left to right, end of the string. If the stack is

parsing algorithm or membership algorithm. empty then the given string is accepted and irrelative
about number of final state.
Push Down Automata (PDA)
(b) Final State Method– By reading the starting
from left to right, end of the string, the PDA enters
into final state, then given string is accepted and
irrelative about stack symbol.
Parsing and Push Down Automata
(i) Top-Down Parsing– We present certain
techniques for top-down parsing which can be
applied to a certain subclass of context free
PDA(Q, Σ, q0, F, δ, z0, )
languages. We discuss LL(1) parsing, LL(K)
Q → Finite number of state
parsing, Left factoring and the technique to remove
Σ → Input alphabet left reversion.
q0 → Initial state (ii) Bottom up Parsing– In bottom-up parsing we
F → Set of final states have to reverse the productions to gets finally. This
z0 → Initial stack element suggests the following moves for a PDA acting as

 → Stack element bottom up parser.

δ → Transition function (a) δ(P, ∧ , αT) = {(P, A)| there exists a production
A → α}
Q × Σ ∪ {∈} ×  → Q × *
(b) δ ( P, σ, ∧ ) = {( P, σ )} for all σ in ∑ .

Using (i) we replace αT on the basis by A when


A→α is a production the input symbol σ is moved
on to the stack using (ii) for acceptability we require
some moves when the PDS has S or z0 on the top.
Theory of Computation 76 YCT
Search on TG: @apna_pdf
Turing Machine Model Recursive Enumerable (RE) or Type-0
Turing's Aim– Language– RE language or type-0 language are
Design a model that is- generated by type-0 grammars. It means TM can
loop for ever for the string which are not a part of
(i) simple (ii) Intuitive (iii) Generic
the language. RE languages are also called as Turing
recognizable languages.
Recursive Language (REC)– REC language are
also called as Turing decidable languages the
relationship between RE and REC language can be
shown in figure.

• The Turing Machine can be thought of as finite


control connected to a R/W (read/write) head. It
has one tape which is divided into a number of
cells. Closure Properties of Recursive Languages
• A Turing machine M is a 7-tuple, namely (Q, Σ, ,
• Union– If L1 and if L2 are two recursive languages,
δ, q0, b, F)
their union L1 ∪ L2 will also be recursive because if
1. Q is finite nonempty set of states.
TM halts for L1 and halts for L2, it will also halt for
2.  is a finite nonempty set of tape symbols.
L1 ∪ L2.
3. b∈  is the blank
• Concatenation– If L1 and if L2 are two recursive
4. Σ is a non-empty set of input symbols and is a languages, their concatenation L1, L2 will also be
subset of  and b ∉ Σ, recursive.
5. δ is transition function mapping (q, x) on to (q, y, • Kleene Closure– If L1 is recursive, its Kleene
D) where D denotes the direction of movement of closure L1* will also be recursive.
R/W head; D=L or R according as the movement is
• Intersection and complement– If L1 and if L2 are
to the left or right.
two recursive languages, their intersection L1 ∩ L2
6. q0 ∈ Q is the initial state.
will also be recursive.
7. F ⊆ Q is the set of final states.
Linear Bounded Automata
Representation of Turing Machines
• A linear bounded Automata is a multi-track non-
(i) instantaneous descriptions using move-relations.
deterministic Turing machine with a tape of some
(ii) transition table
bounded finite length.
(iii) transition diagram
Length = function
Nondeterministic Turing Machines
(length of the initial input string, constant C)
• A non-deterministic Turing machine is a 7-tuple A linear bounded automata can be defined as an 8-
(Q, Σ, , δ, q0, b, F) tuple (Q, X, Σ, q0, ML, MR, δ, F)
(i) Q is a finite nonempty set of states (i) Q is a finite set of states
(ii)  is a finite nonempty set of tape symbols (ii) X is the tape alphabet
(iii) b∈  is called the blank symbol. (iii) Σ is the input alphabet
(iv) Σ is a nonempty subset of , called the set of (iv) q0 is the initial state
input symbols. (v) ML is the left end marker
(v) q0 is the initial state. (vi) MR is the right end marker were MR ≠ ML
(vi) F⊆ Q is the set of final states.
(vii) δ is a transition function which maps each pair
(vii) δ is a partial function from Q ×  into the power (state, tape symbol) to (state, tape symbol,
set of Q ×  × {L, R}. constant 'C') where C can be o or +1 or –1
Theory of Computation 77 YCT
Search on TG: @apna_pdf
(viii) F is the set of final state • A decision problem is decidable if there exists a
decision algorithm for it otherwise it is
undecidable.
Decidability properties of regular languages–
(i) DFA membership–
A deterministic linear bounded automaton is always
Instance : ADFAM = {Q,Σ, δ,q0, F} and string ω ∈
context sensitive and the linear bounded automaton
with empty language is undecidable. Σ*.

Context Sensitive Language (ii) DFA emptiness–

• A context sensitive grammar is an unrestricted ADFA m = {Q, Σ, δ, q0, F}


grammar in which all the productions are of form. Undecidable problems–
α→β We will now discuss the notion of undecidability.
Where α, β ∈ (V∪T)* and |α| ≤ |β|
where α and β are strings of non-terminals and
terminals.
• Context-sensitive grammars are more powerful
than context free grammars because there are
some languages that can be described by CSG but
not by context free grammars and CSL are less
powerful than unrestricted grammar. A decider for the Language L
• All computations of a decider TM must halt.
Decidable language are often called also recursive
language.
• A language is Turing recognizable if it is
• Context sensitive grammar has 4-tuples. recognized by a TM.
G = {N, Σ, P, S} Theorem– LTM accept is undecidable the proof (to
N = Set of non-terminal symbols be gone through in class) show that in fact the more
Σ = Set of terminal symbols restricted language.
S = Start symbol of the production Lsel accept = {< M, < M >> M is a TM} is
P = Finite set of production
undecidable the crucial idea is diagonalization.
All rules in p are of the form α, α2 → α1 βα2
Complexity–
• The language that can be defined by context
sensitive grammar is called CSL. The classes P and NP- We introduce the classes P
Properties of CSL are– and NP of languages.
• Union, intersection and concatenation of two • A Turing Machine M is said to be of time
context sensitive languages is context sensitive. complexity T(n) if the following holds. Input w of
• Complement of a context-sensitive language is length n, M halts after making at most T(n)
context-sensitive. moves.
DECIDABILITY • A language L is in class P if there Exists come
• A decision problem is a function that associates polynomial T(n) such that L = T(m) for some
with each input instance of the problem a truth
value true or false. deterministic Tm m of time complexity T(n).

Theory of Computation 78 YCT

Powered by TCPDF (www.tcpdf.org)


Search on TG: @apna_pdf

07. COMPILER DESIGN


Overview of Language Processing System Loader/Linker– It converts the re-locatable code
into absolute code and tries to run the program
resulting in a running program or an error message.
Linker loads a variety of object files into a single
file to make it executable. Then loader loads it in
memory and executes it.
Structure of the compiler Design

Compiler– Compiler is a translator program that


translates a program written in (High Level
Language) the source program and translate it into LEXICAL ANALYSIS
equivalent in (Machine Level Language) the target Lexical analysis is the first phase of the compiler
program. As an important part of a compiler is error also known as a scanner. It converts the high level
showing to the programmer. input program into a sequence of Tokens.
• Lexical analysis can be implemented with the
Deterministic Finite Automata (DFA).
• The output is a sequence of tokens that is sent to the
parser for syntax analysis.
Assembler– Programmers found it difficult to write
or read programs in machine language. They begin
to use a mnemonic (symbols) for each machine
instruction, which they would subsequently
translate into machine language. Such a mnemonic
machine language is now called an assembly
language. Programs known as assembler were • Token– Token is a sequence of characters that can
written to automate the translation of assembly be treated as a single logical entity. Typical token
language in to machine language. are, (1) Identifiers (2) Keywords (3) Operators (4)
Special symbols (5) Constants.
Interpreter– An interpreter converts high level
• Pattern– A set of strings in the input for which the
language into low level machine language, just like
same token is produced as output. This set of strings
a compiler. But they are different in the way they is described by a rule called a pattern associated
read the input. The compiler in one go reads the with the token.
inputs, does the processing, and executes the source • Lexeme– A lexeme is a sequence of characters in
code whereas the interpreter does the same line by the source program that is matched by the pattern
line. A compiler scans the entire program and for a token. e.g- "float", "=", "273".
translates it as a whole into machine code whereas FLEX (Fast Lexical Analyzer Generator)– FLEX
an interpreter translates the program one statement is a computer program for generating lexical
at a time. Interpreted programs are usually slower analyzers written by Vern Paxson in C around 1987.
with respect to compiled ones. It is used together with Berkeley Yacc Parser
Compiler Design 79 YCT
Search on TG: @apna_pdf
generator or GNU Bison parser generator. FLEX a is an FIRST(Yi) and ε is in all of FIRST(Yi).....,
and Bison both are more flexible than Lex and Yacc FIRST(Yi–1); that is, Y1, ...., Yi–1 ⇒ *ε.
and produces faster code. Bison produces parser If ε is in FIRST(Yj) for all j = 1,2, ....., k then add ε
from the input file provided by the users. The to FIRST(X). For example, everything in
function yylex() is automatically generated by the FIRST(Y1) is surely in FIRST(X). If Y1 does not
flex when it is provided with a .l file and this derive ε, then add nothing more to FIRST(X), but if
yylex() function is expected by parser to call to Y1 ⇒*ε, then add FIRST(Y2) and so on.
retrieve tokens from this token stream. 2. FOLLOW(A)– To compute FOLLOW(A) for all
Note– The function yylex() is the main flex non-terminals A, apply the following rules until
function that runs the Rule section and extension (.l) nothing can be added to any FOLLOW set.
is the extension used to save the programs. 1. Place $ in FOLLOW(S), where S is the start
symbol and $ is input right end marker.
2. If there is a production A ⇒ α B β, then
everything in FIRST(β) except ε is placed in
FOLLOW(B).
Program Structure– In the input file, there are 3 3. If there is a production A → αB or a production
sections. A→αBβ, where FIRST(β) contains ε, then
(i) Definition Section– The definition section contains everything in FOLLOW(A) is in FOLLOW(B).
the declaration of variables, regular definitions, LR Parsers
manifest constants. In the definition section, text is
• In LR(K), L stands for Left to right scanning, R
enclosed in "%{%}" brackets. Anything written in
stands for Right most derivation, K stands for
this brackets is copied directly to the file lex.yy.c.
number of look ahead symbols.
(ii) Rules Section– The rules section contains a series
of rules in the form; pattern action and pattern must • LR parsers are table-driven, much like the non-
be unintended and action begin on the same line in recursive LL parsers. A grammar which is used in
{} brackets. The rule section is enclosed in construction of LR parser is LR grammar. For a
"%%%%". grammar to be LR it is sufficient that a left-to-right
shift-reduce parser be able to recognize handles of
(iii) User Code Section– This section contains C
right-sentential forms when they appear on the top
statements and additional functions. We can also
of the stack.
compile these functions separately and load with the
lexical analyzer. • The time complexity for such parsers is O(n3).
• LR parsers are faster than LL(1) parser.
Parsing • LR parsing is attractive because–
A program that performs syntax analysis is called a → The most general non-backtracking shift reduce
parser. A syntax analyzer takes tokens as input and parser.
output error message if the program syntax is wrong. → The class of grammars that can be passed using
Parser obtains a string of tokens from the lexical LR methods is a proper super set of predictive
analyzer and verifies that it can be generated by the parsers, LL(1) grammars CLR(1) grammars.
language for the source program. The parser should
report any syntax errors in an intelligible fashion. → LR parser can detect a syntactic error in the left
to right scan of the input.
The LR parsing algorithm–
• It consists of an input, an output, a stack, a driver
program and a parsing table that has two parts
(action and go to).
• The driver/parser program is same for all these LR
parsers, only the parsing table changes from parser
to another.

Constructing a parsing table– To construct a


parsing table, we have to learn about two functions:
1. FIRST() 2. FOLLOW()
1. FIRST(X)– To compute FIRST(X) for all grammar
symbols X, apply the following rules until no more
terminals or ε can be added to any FIRST set.
1. If X is a terminal, then FIRST(X) is {X}.
2. If X → ε is a production, then add ε to FIRST(X).
3. If X is non-terminal and X→ Y1Y2 .... YK is a
production, then place 'a' in FIRST(X) if for some i,
Compiler Design 80 YCT
Search on TG: @apna_pdf
Stack– To store the string of the form. [A → αβ, a]
S0 X1 S1 ..... XmSm where Where A → αβ is a production.
Sm : state a is terminal/right end marker ($). We will call it as
Xm: grammar symbol LR(1) item.
Each state symbol summarizes the information 'LR(1) item is a combination of LR(0) items along
contained in the stack below it. with look ahead of the item. Here 1 refers to look
Parsing Table– Parsing table consists of two parts- ahead of the item.'
(i) ACTION Part– Construction of the sets of LR(1) items
Let, Sm → top of the stack Function closure(I):
ai → current symbol Begin
Then action [Sm, ai] which can have one of four Repeat
values. For each item [A→ α.B.β, a] in I,
1. Shift S, where S is a state. Each production B → γ in G',
2. Reduce by a grammar production A→B And each terminal b in FIRST(β a)
3. Accept Such that [B→γ, b] is not in I do
4. Error Add [B → γ, b] to I;
(ii) GO TO Part– If goto (S, A) = X where End;
S→state, A → non-terminal, then GOTO maps Until no more items can be added to I;
state S and non-terminal A to state X.
Configuration– L. ALR Parsing Table
(S0x1S, x2S2 ... SmSm, aiai + 1 .. an $) • The tables obtained by it are considerably smaller
The next move of the parser is based on action [Sm, ai]. than the canonical LR table.
The configurations are as follows– • LALR stands for look ahead LR.
1. If action [Sm, ai] = Shift S • The number of states in SLR and LALR parsing
(S0x1S1, x2S2 ... xmSm, aiai + 1 ... an $) tables for a grammar G are equal.
2. If action [Sm, ai] = reduce A → B then • But LALR parsers recognize more grammars than
(S0x1S1 x2S2 ... xm–rSm–r, As aiai + 1 ... an $) SLR.
where S = goto [Sm–r, A] • YACC creates a LALR parser for the given
3. If action [Sm, ai] = accept, parsing is complete. grammar.
4. If action [Sm, ai] = error, it calls an error recovery • YACC stands for 'Yet another compiler compiler'.
routine. • An easy, but space-consuming LALR table
SLR parsing table construction construction is explained below:
1. Construct C = {I0, I1, ...., In}, the collection of sets
1. Construct the canonical collection of sets LR(0) items of LR(1) items.
for G'. Where G' the augmented grammar for G. 2. Find all sets having the common core; replace these
2. Create the parsing action table as follows: sets by their union.
(a) If a is a terminal and [A→ α aβ] is in Ii, go to 3. Let C' = {J0, J1, ....Jm} be the resulting sets of LR(1)
(Ii, a) = Ij then action (i, a) to shift j. Here 'a' must be items. If there is a parsing action conflict then the
a terminal. grammar is not a LALR(1).
(b) If [A →α] is in Ii, then set action [i, a] to 4. Let K be the union of all sets of items having the
'reduce A → α' for all a in FOLLOW(A); same core. Then goto (J, X) = K.
(c) If [S'→S] is in Ii then set action [i, $] to • If there are no parsing action conflicts then the
'accept'. grammar is said to LALR(1) grammar.
3. Create the parsing go to table for all non- • The collection of items constructed is called
terminals A, if go to (Ii, A) = Ij then go to [i, A] = j. LALR(1) collection.
4. All entries not defined by steps 2 and 3 are made Comparison of parsing methods–
errors.
5. Initial state of the parser contains S' → S.
The parsing table constructed using the above
algorithm is known as SLR(1) table for G.
Note–Every SLR(1) grammar is unambiguous, but every
unambiguous grammar is not a SLR grammar.
Canonical LR Parsing (CLR)
• To avoid some of invalid reductions, the states
need to carry more information.
• Extra information input into a state by including a
terminal symbol as a second component of an item.
• The general form of an item. Every LR(0) in SLR (1) but vice versa is not true.
Compiler Design 81 YCT
Search on TG: @apna_pdf
Syntax Directed Translation– To translate a L → En
programming language construct, a compiler may E → E1 + T
need to know the type of construct, the location of E→T
the first instruction, and the number of instructions
T → T1*F
generated etc so, we have to use the term 'attributes'
associated with constructs. T→F
An attribute may represent type, F → (E)
number of arguments, memory location, F → digit
compatibility of variables used in a statement which Let us consider synthesized attribute value with
cannot be represented by CFG alone. each of the non-terminals E, T and F Token digit
So, we need to have one more phase to has a synthesized attribute lexical supplied by
do this, i.e., 'semantic analysis' phase. lexical analyzer.

Production Semantic Rule


L → En print (E.val)
In this phase, for each production CFG, we will E → E1 + T E.val: = E1.val + T.val
given some semantic rule. E→T E.val: = T1.val
Syntax Directed Definition (SDD) T → T1*F T.val: = T1.val*F.val
It is high level specification for translation. They T→F T.val: = F.val
hide the implementation details, i.e., the order in F → (E) F.val: = E.val
which translation takes place. F → digit F.val: = digit.lexval
Attributes + CFG + Semantic rules = SSD Inherited Attributes– An attribute of a non-
A SDD is a generalization of a CFG in which each terminal on the right-hand side of a production is
grammar symbol is associated with a set of called an inherited attribute. The attribute can take
attributes. There are two types of set of attributes value either from its parent or form its siblings
for a grammar symbol. (variables in the LHS or RHS of the production).
1. Synthesized attributes For example, let's say A → BC is a production of a
2. Inherited attributes grammar and B's attribute is dependent on A's
Each production rule is associated with a set of attributes or C's attributes then it will be inherited
semantic rules. Semantic rules setup dependencies attribute.
between attributes which can be represented by a Types of SDD's– Syntax Directed Definitions
dependency graph. The dependency graph (SDD) are used to specify syntax directed
determines the evaluation order of these semantic translations. There are two types of SDD.
rules. Evaluation of a semantic rule defines the 1. S-attributed definitions
value of an attribute. But a semantic rule may also 2. L-attributed definitions
have some side effects such as printing a value.
S-attributed definitions–
Attribute grammar– An attribute grammar is a
• Only synthesize attributes used in syntax direct
syntax directed definition in which the functions in
definition.
semantic rules 'cannot have side effects'.
• S-attributed grammars interact well LR(K) parsers
Annotated parse tree– A parse tree showing the
since the evaluation of attributes is bottom-up. They
values of attributes at each node is called an
do not permit dependency graphs with cycles.
annotated parse tree. The process of computing the
attribute values at the nodes is called annotating (or L-attributed definitions–
decorating) of the parse tree. • Both inherited and synthesized attribute are used.
In a SDD, each production A → ∞ is • L-attributed grammar support the evaluation of
associated with a set of semantic rules of the form: attributes associated with a production body,
b = f(C1, C2, ......Cn) where dependency-graph edges can go from left to right
f : A function only.
b can be one of the following: • Each s-attributed grammar is also a L-attributed
grammar.
b is a 'synthesized attribute' of A and C1, C2,
...........Cn are attributes of the grammar symbols in • L-attributed grammars can be incorporated
A→∞ conveniently in top down parsing.
The value of a 'synthesized attribute' at a node is • These grammars interact will with LL(K) parsers
computed from the value of attributes at the (both table driven and recursive descent).
children of that node in the parse tree. A syntax directed definition is L-attributed if each
Synthesized Attribute– The value of a synthesized inherited attribute of Xj, 1 ≤ j ≤ n, on the right side
attribute at a node is computed from the value of of A→X1, X2 ..... Xn, depends only on–
attributes at the children of that node in a parse tree. 1. The attributes of symbols X1, X2, .... Xj–1 to the left
Consider the following grammar: of Xj in the production.
Compiler Design 82 YCT
Search on TG: @apna_pdf
2. The inherited attributes of A. Jump–
Every S-attributed definition is L-attributed, • Unconditional jump– goto L, jumps to L.
because the above two rules apply only to the • Conditional:
inherited attributes. if (x relop y)
Intermediate Code Generation goto L1;
In the analysis-synthesis model, the front end translates else
a source program into an intermediate representation {
(IR). From IR the back end generates target code. goto L2;
}
where relop is <, <=, >, >=, = or ≠
Procedure call–
Param x1;
Param x2;
There are different types of intermediate .
representations– .
• High level IR, i.e. AST (Abstract Syntax Tree). .
• Medium level IR, i.e. Three address code. Param xn;
• Low level IR, i.e. DAG (Directed Acyclic Graph) Call p, n, x; call procedure p with n parameters
and store the result in x.
• Postfix Notation (Reverse Polish Notation, RPN).
return x Use x as result from procedure.
Benefits of Intermediate Code Generation (ICG)–
1. We can obtain an optimized code. Implementation of three Address Statements–
Three address statements can be implemented as
2. Compilers can be created for the different machines
records with fields for the operator and the
by attaching different backend to existing front end
operands. There are 3 types of representations–
of each machine.
1. Quadruples
3. Compilers can be created for the different source
languages. 2. Triples
3. Indirect triples
Directed Acyclic Graphs (DAG) for expression–
1. Quadruples– A quadruple has four fields: op, arg1,
• A DAG for an expression identifies the common arg2, and result.
sub expressions in the given expression.
• Unary operators do not use arg2.
• A node N in a DAG has more than one parent if
N represents a common sub expression. • Param use neither arg2 nor result.
• DAG gives the compiler, important clues • Jumps put the target label in result.
regarding the generation of efficient code to • The contents of the fields are pointers to the
evaluate the expressions. symbol table entries for the names represented by
Three-Address Code– In three address codes, each these fields.
statement usually contains 3 addresses, 2 for • Easier to optimize and move code around.
operands and 1 for the result. • For the expression x = y * – z + y* – z, the
Example– x = y OP z quadruple representation is–
• x, y, z are names constants or compiler generated OP Arg1 Arg2 Result
temporaries. (0) Uminus z t1
• OP stands for any operator. any arithmetic (1) * y t1 t2
operator or logical operator. (2) Uminus z t3
Types of three address statement–
(3) * y t3 t4
Assignment–
(4) + t2 t4 t5
• Binary assignment : x = y OP z store the result of
y OP z to x. (5) = t5 x
• Unary assignment x = OP y store the result of 2. Triples– Triples have three fields: OP, arg1, arg2.
unary operation on y to x. • Temporaries are not used and instead references
Copy– to instructions are made.
• Simple copy x = y store y to x. • Triples are also known as two address code.
• Indexed copy x = y [i] store the contents of y[i] to • Triples takes less space when compared with
x. quadruples.
• x[i] = y store y to (x + i)th address. • Optimization by moving code around is difficult.
Address and pointer manipulation– • The DAG and triple representations of
x=&y store address of y to x expressions are equivalent.
x=*y store address of y to x • For the expression a = y* – z + y* – z the triple
*x = y store y to location pointed by x representation is–
Compiler Design 83 YCT
Search on TG: @apna_pdf
OP Arg1 Arg2 • High Level Intermediate representation. Example-
Abstract Syntax Tree (AST)
(0) Uminus z
• Medium-level intermediate representation.
(1) * y (0) Example-Control flow graph of complex operations.
(2) Uminus z • Low-Level Intermediate representation. Example-
(3) * y (2) Quadruples, DAGs.
(4) + (1) (3) • Code for abstract stack machine, i.e. postfix code.
2. Target Programs– The output of the code
(5) = a (4) generator is the target program. The output may
3. Indirect Triples– take on a variety of forms–
• In direct triples, pointers to triples will be there (i) Absolute machine language
instead of triples. (ii) Relocatable machine language
• Optimization by moving code around is easy. (iii) Assembly language
• Indirect triples takes less space when compared 3. Memory Management– Mapping names in the
source program to addresses of data objects in
with quadruples.
runtime memory is done by the front end and the
• Both indirect triples and quadruples are almost code generator.
equally efficient. • A name in a three address statement refers to a
• Indirect triple representation of 3-address code. symbol entry for the name.
Statement • Stack, heap, garbage collection is done here.
(0) (14) 4. Instruction selection– Instruction selection
depends on the factors like-
(1) (15)
• Uniformity
(2) (16) • Completeness of the instruction
(3) (17) • Instruction speed
(4) (18) • Machine idioms
(5) (19) • Choose set of instructions equivalent to intermediate
representation code.
• Minimize execution time used registers and code
OP Arg1 Arg2 size.
(14) Uminus z 5. Register allocation–
(15) * y (14) • Instructions with register operands are faster. So,
(16) Uminus z keep frequently used values in registers.
• Some registers are reserved.
(17) * y (16)
Example– SP, PC etc. minimize number of loads
(18) + (15) (17) and stores.
(19) = x (18) 6. Evaluation order–
Code Generation • The order of evaluation can affect the efficiency
of the target code.
Code generation is the final phase of the compiler
• Some orders require fever registers to hold
model.
intermediate results.
Runtime storage management– To run a compiled
program, compiler will demand the operating
system for the block of memory. This block of
memory is called runtime storage. This runtime
storage is subdivided into the generated target code,
Data objects and information which keeps track of
procedure activations.
The runtime storage contains stack and the heap.
Stack contains activation records and program
The requirement imposed on a code generator are– counter, data object within this activation record are
also stored in this stack with relevant information.
• Output code must be correct.
Activation Record– Information needed during an
• Output code must be of high quality. execution of a procedure is kept in a block of
• Code generator should run efficiently. storage called an activation record.
Issues in the design of a code generator– • Storage for names local to the procedure appears
1. Input to the code generator– Intermediate in the activation record.
representation with symbol table will be the input • Each execution of a procedure is refereed as
for the code generator. activation of the procedure.
Compiler Design 84 YCT
Search on TG: @apna_pdf
• If the procedure is recursive, several of its Leaves are labeled by unique identifiers, either
activation might be alive at a given time. variable names or constants.
• Runtime storage is subdivided into Interior nodes are labeled by an operator
1. Generated target code area symbol.
2. Data objects area Nodes are also optionally given as a sequence
3. Stack of identifiers for labels.
4. Heap Peephole Optimization
Code • Target code often contains redundant instructions
Static data and suboptimal constructs.
• Improving the performance of the target program by
Stack
examining a short sequence of target instructions
.......↓ (peephole) and replacing these instructions by a
.......↑ shorter or faster sequence is peephole optimization.
Heap • The peephole is a small, moving window on the
• Sizes of stack and heap can change during target program. Some well known peephole
program execution. optimizations are–
For code generation there are two standard storage (i) Elimination of Redundant Loads and Stores–
allocations: Example- (i) MOV R0, a
1. Static allocation– The position of an activation (ii) MOV a, R0
record in memory is fixed at compile time. We can delete instruction (ii), because the value of a
is already in R0.
2. Stack allocation– A new activation record is
pushed on to the stack for each execution of the (ii) Eliminating Unreachable Code– An unlabeled
procedure. instruction immediately following and
unconditional jump maybe removed.
Basic Blocks– Basic blocks are sequence of
• May be produced due to debugging code introduced
consecutive statements in which flow of control
during development.
enters at the beginning and leaves at the end without
a halt or branching. • May be due to updates in programs without
1. First determine the set of leaders. considering the whole program segment.
(iii) Flow of control optimizations– The
• First statement is leader
unnecessary jumps can be eliminated.
• Any target of goto is a leader. Jumps like:
• Any statement that follows a goto is a leader. Jumps to jumps,
2. For each leader its basic block consists of the Jumps to conditional jumps,
leader and all statements up to next leader. Conditional jumps to jumps:
Initial node: Block with first statement is leader. Example– We can replace the jump sequence
Once the basic blocks have been defined, a number goto L1
of transformations can be applied to them to .......
improve the quality of code. L1 : got L2
1. Global : Data flow analysis. By the sequence
2. Local : Structure preserving transformations, Got L2
Algebraic transformations L1: got L2
Basic Blocks compute a set of expressions. These ....
expressions are the values of the names live on exit It there are no jumps to L1 then it may be possible to
from the block. eliminate the statement L1 : goto L2.
Two basic blocks are equivalent it they compute the (iv) Reduction in strength–
same set of expressions. • x2 is cheaper to implement as x*x than as a call to
DAG Representation of Basic Blocks– exponentiation routine.
• DAGs are useful data structures for implementing • Replacement of multiplication by left shift.
transformations on basic blocks. Example– x*23 ⇒ x << 3
• Tells, how value computed by a statement is used • Replace division by right shift.
in subsequent statements. Example– x >> 2 (is x/22)
• It is a good way of determining common sub (v) Use of machine Idioms–
expressions. • Auto increment and auto decrement addressing
• A DAG for a basic block has following labels on modes can be used whenever possible.
the nodes: Example– replace add # 1, R by INCR.
Compiler Design 85 YCT

Powered by TCPDF (www.tcpdf.org)


Search on TG: @apna_pdf

08. OPERATING SYSTEM


Introduction Operating system Services–
Operating system acts as an interface between computer
hardware and user. It manages and controls all the
hardware and flow of data, instructions and information
to within the system. The operating system takes
instructions from the user and directs it to CPU, which
further passes the instructions to the hardware.

Process concept
Text Section– A process is more than the program
Operating system is one of the core software programs code, which is sometimes known as the text section.
that run on hardware and makes it usable. The user can It also includes the current activity, as represented
interact with hardware so that they can send commands by the value of the program counter.
and receive output. An operating system provides an Stack– The stack contains temporary data, such as
interface between user and machine. This interface can function parameters, returns addresses, and local
be Graphical User Interface (GUI) in which users. Click variables.
on screen elements to interact with operating system or Data Section– Contains the global variable.
a Command Line Interface (CLI) to tell the operating Heap– Dynamically allocated memory to process
system to do things, it also manages the computers
during its run time.
resource such as CPU, memory, disk drives and
printers. It provides services for application software.
Types of Operating System

Process state

Function of an Operating System–

• New– The process is being created.


• Running– Instructions are being executed.
• Waiting– The process is waiting for some event
to occur.
• Ready– The process is waiting to be assigned to a
processor.
• Terminated– The process has finished execution.
Operating System 86 YCT
Search on TG: @apna_pdf
Process Control Block (PCB)– Process in an Sr. Similarity between Difference between
operating system is represented by a data structure No. Threads and Threads and
called Process Control Block (PCB) also called a Processes Processes
task control block. 1. Only one thread or Threads are not
process is active at a independent of one
time. another but processes
are independent.
2. Within a processes, Unlike processes, all
both execute threads can access
sequentially. every address in the
task.
3. Both can create Threads are designed
children. to assist each other,
processes may or may
not do it.
4. If one thread or
• Pointer– It is a stack pointer which is required to be process is blocked,
saved when the process is switched from one state another thread or
to another to retain the current position of the process can run.
process.
• Process State– The state may be new, ready, Types of Threads
running, waiting, halted and so on.
Parameters 1. User Level 2. Kernel
• Process Number– Every process is assigned with Thread Level
unique ID known as process ID or PID which stores (ULT) Thread
the process identifier. (KLT)
• Program Counter– The counter indicates the Implemented User threads Kernel threads
address of the next instruction to be executed for by are are
this process. implemented implemented
• Registers– These are the CPU registers which by users. by operating
includes: accumulator, base, registers and general system.
purpose registers.
Recognize Operating Kernel threads
• Memory Limits– This field contains the system doesn't are recognize
information about memory management system
recognize user by operating
used by operating system. This may include the
level threads. system.
page tables, segment tables etc.
• Open Files List– This information includes the list Context Context switch Context switch
of files opened for a process. switch time time is less. time is more.
Threads Hardware Context switch Hardware
Thread is a single sequence stream within a process. support requires no support is
Threads have same properties as of the process so hardware needed.
they are called as light weight processes. Threads support.
are executed one after another but gives the illusion Blocking If one user If one Kernel
as if they are executing in parallel. Each thread has operation level thread thread perform
different states.
performs blocking
blocking operation then
operation then another thread
entire process can continue
will be execution.
blocked.

Operating System 87 YCT


Search on TG: @apna_pdf
Creation and User level Kernel level Disadvantages • Multi thread • Transferring
Management threads can be threads take applications control
created and more time to on user-level within a
managed move create and threads process from
quickly. manage. cannot one thread to
benefit from another
Operating Any operating Kernel level
multi necessitates a
system system can threads are processing. mode switch
support user- operating
• If a single to Kernel
level threads. system- user-level mode.
specific. thread • Kernel level
Thread The thread The application performs a threads takes
management library contains code does not blocking more time to
the code for contain thread operation, create and
thread creation management the entire manage than
message code. It is process is user level
passing, thread merely an API halted. threads.
scheduling data to the Kernel Multi-threading Models–
transfer and mode. The Many-to-One One-to-One Many-to-Many
thread windows Model Model Model
destroying. operating In this model, In this model, In this model,
system makes we have one to one we have
use of this multiple user relationship multiple user
feature. threads between threads
mapped to one Kernel and multiplex to
Example Example- Java Example–
Kernel thread. user thread. same or lesser
thread, POSIX Window When a user Multiple thread number of
threads. Solaris. thread makes a can run on Kernel level
Advantages • User level • Scheduling of blocking multiple threads.
threads are multiple system call processor. Number of
simple and threads that entire process Problem with Kernel level
blocks. As we this model is threads are
quick to belong to
have only one that creating a specific to the
create. same process
Kernel thread user thread machine,
• Can run on on different and only one requires the advantage of
any processors is user thread can corresponding this model is if
operating possible in access Kernel Kernel thread. a user thread is
system. Kernel level at a time, so As each user blocked we can
• In user level threads. multiple thread is schedule others
threads, • Multi threads are not connected to user thread to
threading can able access different. other Kernel
switching
multiprocessor Kernel, if any thread. Thus,
between be there for
at the same user thread system does not
threads does Kernel
time. makes a block if a
not need routines. blocking particular thread
Kernel mode • When a system call, the is blocked. It is
privileges. thread at the other user the best multi-
Kernel level threads would threading
is halted, the not be blocked. model.
Kernel can
schedule
another
thread for the
same process.

Operating System 88 YCT


Search on TG: @apna_pdf
fork() in C It controls the It provides lesser It reduces the
Fork() system call is used for creating a new degree of control over degree of
process, which is called child process, which is multi- degree of multi-
called process, which runs con-currently with the programming. multiprogramming programming.
process that makes the fork() call (parent It is almost It is also minimal It is a part of
process). After a new child process is created, absent or in time sharing Time sharing
both processes will execute the next instruction minimal in system. systems.
following the fork() system call. A child process time sharing
system.
uses the same program counter, same CPU
registers, same open files which use in the parent It selects It selects those It can re-
process. processes processes which introduce the
from pool are ready to process into
()
and loads execute. memory and
them into execution can
memory for be continued.
execution.
Categories of scheduling
Preemptive scheduling Non-Preemptive
scheduling
A processor can be Once the processor
preempted to execute starts its execution, it
the different processes must finish it before
in the middle of any executing the other. It
current process can't be paused in the
Note–
execution. Middle.
1. fork() is threading based function, to get the correct
CPU utilization is more CPU utilization is less
output run the program on a local system.
efficient compared to efficient compared to
2. Total number of processes = 2n, where n is number of
non-preemptive preemptive scheduling.
fork() system calls. scheduling.
Process Scheduling Preemptive scheduling When any process enters
The process scheduling is the activity of the is prioritized. The the state of running, the
process manager that handles the removal of the highest priority process state of that process is
running process from the CPU and the selection is a process that is never deleted from the
of another process on the basis of a particular currently utilized. scheduler until it
strategy. It is an essential part of a finishes its job.
multiprogramming operating systems. Such Starvation may be Starvation can occur
operating systems allow more than one process caused, due to the when a process with
to be loaded into the executable memory at a insertion of priority large burst time
time and the loaded process shares the CPU process in the queue. occupies the system.
using time multiplexing. It is quite flexible It is rigid as even if a
Types of Process Scheduler because the critical critical process enters
Long term short term Medium term processes are allowed to the ready queue the
scheduler scheduler scheduler access CPU as they process running CPU is
arrive in to the ready not disturbed.
It is a job It is a CPU It is a process queue, no matter what
scheduler. scheduler. swapping process is executing
scheduler. currently.
Speed is Speed is fastest Speed is in Examples of preemptive Examples of non-
lesser than among other two. between both scheduling are Round preemptive scheduling
short term short and long Robin and Shortest are First Come First
scheduler. term Remaining Time First. Serve and Shortest Job
scheduler. First.
Operating System 89 YCT
Search on TG: @apna_pdf
Scheduling Algorithms Process Waiting Time
First-Come, First-Served (FCFS) Scheduling– P0 5−0 = 5
• In this scheduling algorithm, jobs are executed P1 8 −1 = 7
on a first come, first serve basis. P2 14 − 2 = 12
• It is both preemptive and non-preemptive P3 22 − 3 = 19
scheduling algorithm. Average Waiting Time = (5 + 7 + 12 +19 )/4
• Easy to understand and implement. = 10.75
• Its implementation is based on FIFO queue. Round-Robin Scheduling–
• Poor in performance as average wait time is • Round Robin is the preemptive process
scheduling algorithm.
high.
• Each process is provided a fix time to execute,
Process Arrival Time Execute Time Service Time it is called a time quantum.
P0 0 5 5 • Once a process is executed for a given time
P1 1 3 8 period, it is preempted and other process
P2 2 8 16 executes for a given time period.
P3 3 9 25 • Context switching is used to save states of
preempted processes.
Gantt Chart–
Example : Time Quantum = 3
P0 P1 P2 P3
Process Arrival Execute Service Waiting
0 5 8 16 25 Number time time time time
Waiting Time = Service Time – Arrival Time
Process Waiting Time
P0 0 4 12 12
P0 5 −0= 5
P1 1 5 17 16
P1 8 −1 = 7
P2 16 − 2 = 14 P2 2 3 9 7
P3 25 − 3 = 22 P3 3 2 11 8
Average Waiting Time = (5 + 7 + 14 + 22)/4 = 12 P4 5 6 20 15
Shortest-Job-First (SJF) Scheduling– Ready Queue
• This algorithm scheduling depends on the P0 ; P1 ; P2 ; P3 ; P4 ; P1; P5
length of next CPU burst of process, rather than Gantt chart
its total length. Process with the minimum burst
time at an instance executes first.
P0 P1 P2 P3 P0 P4 P1 P4
• It is very efficient in minimizing the waiting
0 3 6 9 11 12 15 17 20
time and is easy to implement in Batch system.
Average Waiting Time = (12 + 16 + 7 + 8+15)/5 = 11.6
• It cannot be implemented if the required CPU
Synchronization
time is not known in advance. Some processes perform read and some
Process Arrival Time Execute Time Service Time processes perform write on the file
P0 0 5 5 simultaneously. This lead to data inconsistency
as data is being read as well as modified by many
P1 1 3 8
processes at the same time. To prevent such data
P2 2 8 14 inconsistency process synchronization is
P3 3 6 22 required. All process that want to perform read
P0 P1 P2 P3 operation can do the reading simultaneously but
process that needs to perform write operation
0 5 8 14 22
should do it one at a time. The process that exist
Waiting Time = Service Time – Arrival Time at the same time are called concurrent processes.
Operating System 90 YCT
Search on TG: @apna_pdf
• Processes are categorized as one of the A solution to the critical-section problem must
following two types– satisfy the following three requirements:
1. Independent process– The execution of one 1. Mutual exclusion– If process Pi is executing
process does not affect the execution of other in its critical section, then no other processes
processes. can be executing in their critical sections.
2. Cooperative process– A process that can 2. Process– If no process is executing in its
affect or be affected by other processes critical section and some processes wish to
executing in the system. enter their critical sections, then only those
Process synchronization problem arises in the processes that are not executing in their
case of cooperative process also because remainder sections can participate in
resources are shared in cooperative process. deciding which will enter its critical section
Race Conditions– Process that are working next, and this selection cannot be postponed
together share some common storage (main indefinitely.
memory, file etc.) that each process can read and 3. Bounded waiting– There exists a bound, or
write. When two or more processes are reading limit, on the number of times that other
or writing some shared data and the final result processes are allowed to enter their critical
depends on who runs precisely when, are called sections after a process has made a request to
race conditions. Several processes access and enter its critical section and before that
process the manipulations over the same data request is granted.
concurrently then the outcome depends on the Mutex locks– The hardware solutions presented
particular order in which the access takes place. are after difficult for ordinary programmers to
A race condition is a situation that may occur access, particularly on multi-processor machines,
inside a critical section. and particularly because they are often platform,
The Critical-Section Problem– Consider a dependent. Therefore most systems after a
system consisting of n processes {P0, P1, ......, Pn– software API equivalent called mutex locks (the
1}. Each process has a segment of code, called a
term mutex is short for mutual exclusion).
critical section, in which the process may be We use the mutex lock to protect critical regions
changing common variables, updating a table, and thus prevent race conditions. That is, a
writing a file, and so on. The critical section process must acquire the lock before entering a
problem is to design a protocol that the processes critical section, it releases the lock and the
can use to cooperate. Each process must request release() function releases the lock.
permission to enter its critical section. do {
The section of code implementing this request is acquire lock
the entry section. The critical section may be critical section
followed by an exit section. The remaining code release lock
is the remainder section. The entry section and
remainder section
exit section are enclosed in boxes to highlight
} while (true);
these important segments of code. The general
structure of a typical process Pi is shown A mutex lock has a Boolean variable available
following– whose value indicates if the lock is available or
not. It the lock is available, a call to acquire()
do {
succeeds, and the lock is then considered
entry section
unavailable. A process that attempts to acquire
critical section an unavailable lock is blocked until the lock is
exit section released. Calls to either acquire() or release()
remainder section must be performed atomically. Thus, mutex
} while (true); locks are often implemented using one of the
hardware mechanisms described.
Operating System 91 YCT
Search on TG: @apna_pdf
Acquire: Release: Producer:
acquire() { release() { do{
while(!available) available = true; .......
; /*busy wait*/ } /*produce an item in next-produced*/
available = false;; .....
}
wait(empty);
Semaphores– A semaphore is simply an integer wait(mutex);
variable that is shared between threads. This ......
variable is used to solve the critical section /*add next-produced to the buffer*/
problem and to achieve process synchronization ......
in the multiprocessing environment. signal(mutex);
A semaphore S is an integer variable that, apart signal(full);
}while(true);
from initialization, is accessed only through two
standard atomic operations: wait() and signal(). Consumer:
do{
The wait() operation was originally termed P;
wait(full);
signal() was originally called V. All
wait(mutex);
modifications to the integer value of the ......
semaphore in the wait() and signal() operations /*remove an item buffer to next-consumed*/
must be executed indivisibly. ......
Wait: Signal: signal(mutex);
signal(empty);
wait(S){ signal(S) {
......
while (S < = 0) S++;
/*consume the item in next-consumed*/
; //busy wait } ......
S--; }while(true);
} We can interpret this code as the producers
The Bounded-Buffer Problem– This is a producing full buffers for the consumer or as the
generalization of the producer-consumer problem consumer producing empty buffers for the
wherein access is controlled to a shared group of producer.
buffers of a limited size. In this problem,, the
producer and consumer processes share the
Deadlocks
Deadlock is a situation where a set of processes
following data structures:
are blocked because each process is holding a
int n; resource and waiting for another resource
semaphore mutex = 1; acquired by some other process.
semaphore empty = n; Necessary Conditions of Deadlock-
semaphore full = 0; 1. Mutual exclusion- At least one resource must
We assume that the pool consists of n buffers, be held in a non-sharable mode, that is, only
each capable of holding one item. The mutex one process at a time can use the resource. If
another process requests that resource, the
semaphore provides mutual exclusion for
requesting process must be delayed until the
accesses to the buffer pool and is initialized to
resource has been released.
the value1. The empty and full semaphores count
2. Hold and Wait- A process must be holding at
the number of empty and full buffers. The least one resource and waiting to acquire
semaphore empty is initialized to the value n; the additional resources that are currently being
semaphore full is initialized to the value 0. held by other processes.
Operating System 92 YCT
Search on TG: @apna_pdf
3. No preemption- Resources cannot be As a result, the assignment edge is deleted.
preempted; that is, a resource can be released
only voluntarily by the process holding it, after
that process has completed its task.
4. Circular wait- A set {P0, P1, ... Pn} of waiting
processes must exist such that P0 is waiting for
a resource held by P1. P1 is waiting for a
resource held by P2, ... Pn-1 is waiting for a
resource held by Pn and Pn is waiting for a
resource held by P0.
Resource-Allocation Graph (RAG)– Deadlocks
can be described more precisely in terms of a
Banker's Algorithm– The resource-allocation-
directed graph called a system resource-allocation
graph algorithm is not application to a resource-
graph. This graph consists of a set of vertices V allocation system with multiple instances of each
and a set of edges E. The set of vertices V is resource type. The deadlock-avoidance algorithm
partitioned into two different types of nodes: P = that we describe next is applicable to such a system
{P1, P2, ....Pn}, the set consisting of all the active but is less efficient than the resource-allocation
processes in the system and R = { R1, R2 ......Rm graph scheme. This algorithm is commonly known
}, the set consisting of all resource types in the as the banker's algorithm.
system. We need the following data structures, where n is
the number of processes in the system and m is the
number of resource types:
• Available– A vector of length m indicates the
number of available resources of each type. If
available[j] equals k, then k instances of resource
type Rj are available.
• Max– An n × m matrix defines the maximum
demand of each process. If Max[i][j] equals k, then
process Pi may request at most k instances of
resource type Rj.
Request Edges– A set of directed edge from Pi to • Allocation- An n×m matrix defines the number of
Rj, indicating that process Pi has requested Rj(Pi resources of each type currently allocated to each
→Rj) and is currently waiting for that resource to process. If allocation [i][j] equals k, then process Pi is
become available. currently allocated k instances of resource type Rj.
• Need– An n×m matrix indicates the remaining
Assignment Edges– A set of directed edge from
resource need of each process. If need [i][j] equals
Rj to Pi indicating that resources Rj has been
k, then process Pi may need k more instances of
allocated to process Pi(Rj →Pi) and that Pi is
resource type Rj to complete its task.
currently holding resource Rj. Need[i][j] = Max [i][j] – Allocation [i][j]
When process Pi requests an instance of resource We can treat each row in the matrices Allocation
type Rj, a request edge is inserted in the resource- and Need as vectors and refer to them as Allocationi
allocation graph. When this request can be fulfilled, and Needi. The vector Allocationi specifics the
the request edge is instantaneously transformed to resources currently allocated to process Pi; the
an assignment edge. When the process no longer vector Needi specifies the additional resources that
needs access to the resource, it releases the resource. process Pi may still request to complete its task.
Operating System 93 YCT
Search on TG: @apna_pdf
Banker's algorithm consists of safety algorithm and inform the operator that a deadlock has occurred
resource request algorithm. and to let the operator deal with the deadlock
Safety Algorithm– The algorithm for finding out manually. Another possibility is to let the system
whether or not a system is in a safe state. This recover from the deadlock automatically. There are
algorithm can be described as follows: two options for breaking a deadlock. One is simply
1. Let work and finish be vectors of length m and n, to abort one or more processes to break the circular
respectively. Initialize work = Available and wait. The other is to preempt some resources from
Finish [i] = false for i = 0,1, ...., n – 1. one or more of the deadlocked processes.
2. Find an index i such that both (i) Process Termination– To eliminate deadlocks
a. Finish [i] = = false by aborting a process, we use one of two methods.
In both methods, the system reclaims all resources
b. Needi ≤ work
allocated to the terminated processes.
If no such i exists, go to step 4.
• Abort all deadlocked processes.
3. Work = Work + Allocation;
• Abort one process at a time until the deadlock
Finish [i] = true
cycle is eliminated.
Go to step 2.
(ii) Resource Preemption– To eliminate deadlock
4. If Finish [i] = = true for all i, then the system is in
using resources preemption, we successively
a safe state.
preempt some resources from processes and give
This algorithm may require an order of m×n2 these resources to other processes until the deadlock
operations to determine whether a state is safe. cycle is broken.
Resource-Request Algorithm– We describe the If preemption is required to deal with deadlocks,
algorithm for determining whether requests can be then three issues need to be addressed:
safely granted. 1. Selecting a victim
Let requesti be the request vector for process Pi. If 2. Rollback
Requesti [j] = = k, then process Pi wants k instances 3. Starvation
of resource type Rj. When a request for resources is
Memory-Management Strategies
made by process Pi,
Swapping– Swapping is a process of removing the
1. If Requesti ≤ Needi, go to step 2, otherwise,
currently running program from memory (called
raise an error condition, since the process has swap out) and bringing in another program in to the
exceeded its maximum claim. memory (called swap in). Swapping makes it
2. If Requesti ≤ Available, go to step 3. possible for the total physical address space of all
Otherwise, Pi must wait, since the resources are processes to exceed the real physical memory of the
not available. system, thus increasing the degree of
3. Have the system pretend to have allocated the multiprogramming in a system.
requested resources to process Pi by modifying A program can be swapped out under following
the state as follows: conditions–
Available = Available – Requesti ; (i) If its time quantum has expired.
Allocationi = Allocationi + Requesti ; (ii) If higher priority process has arrived.
Needi = Needi – Requesti ; (iii) If using preemptive SJF scheduling algorithm
If the resulting resource-allocation state is safe, the (iv) If a program has completed its execution.
transaction is completed, and process Pi is allocated Note–A process with pending I/O should never be
its resources. However, if the new state is unsafe, swapped out.
then Pi must wait for Requesti and the old resource- Swapping requires backing store which could be
allocated state is restored. fast disk. It should be large enough to accomodate
Recovery from Deadlock– When a detection copies of all memory images for all users. The
algorithm determines that a deadlock exists, several context-switch time in such a swapping system is
alternatives are available. One possibility is to fairly high.
Operating System 94 YCT
Search on TG: @apna_pdf
Memory Allocation– One of the simplest methods not necessarily all of the same sized are called
for allocating contiguous memory is to divide all segments. Segmentation gives the user's view of the
available memory into equal sized partitions, and to process which paging does not give. Here the user's
assign each process to their own partition. This view is mapped to physical memory.
restricts both the number of simultaneous processes
and the maximum size of each process and is no
longer used. An alternate approach is to keep a list
of unused (free) memory blocks (holes) and to find
a hole of a suitable size whenever a process needs to
be loaded into memory. There are many different
strategies for finding the 'best' allocation of memory
to processes, including the three most commonly
discussed:
1. First fit: Allocate the first hole that is big Important Points–
enough. Searching can start either at the • In the segmentation, Logical Address space
beginning of the set of holes or at the location will be divided in to various segments.
where the previous first-fit search ended. We • To achieve user's view of memory allocation,
can stop searching as soon as we find a free the segmentation will be implemented.
holes that is large enough. • The paging does not follow user's view of
2. Best fit– Allocate the smallest hole that is big memory allocation.
enough. We must search the entire list, unless • Segments of Logical Address space will vary in
the list is ordered by size. This strategy the size.
produces the smallest leftover hole. s = Number of bits required to represent segments
3. Worst fit– Allocate the largest hole. Again, we of logical address space.
must search the entire list, unless it is sorted by OR
segment number
size. This strategy produces the largest leftover
hole, which may be more useful than the d = Number of bits required to represent segment
size.
smaller leftover hole from a best-fit approach.
OR
Simulations have shown that both first fit and best
segment offset
fit are better than worst fit in terms of decreasing
time and storage utilization. Neither first fit nor best • Number of entries in the segment table is same as
fit is clearly better than the other in terms of storage number of segments in the logical address space.
utilization, but first fit is generally faster. • The variable size segments are brought from
logical address space to physical address space so it
Fragmentation– Fragmentation is an unwanted
is similarly behaving like variable partition scheme.
problem in the operating system in which the
Hence, the segmentation still suffers from 'External
processes are loaded and unloaded from memory
fragmentation'.
and free memory space is fragmented. Processes
Paging– The basic method for implementing paging
can't be assigned to memory blocks due to their
involves breaking physical memory into fixed sized
small size, and the memory blocks stay unused. It is
blocks called frames and breaking logical memory
also necessary to understand that as programs are
into blocks of the same size called pages. When a
loaded and deleted from memory, they generate free
process is to be executed, its pages are loaded into
space or a hole in the memory. These small blocks
any available memory frames from their source (file
cannot be allotted to new arriving processes, system or the backing store). The backing store is
resulting in inefficient memory use. divided into fixed-sized blocks that are the same
Segmentation– A process is divided in to segments. size as the memory frames or clusters of multiple
The chunks that a program is divided into which are frames.
Operating System 95 YCT
Search on TG: @apna_pdf
Step 3. Operating system will search for the
required page in the logical address space.
Step 4. The required page is brought from logical
address space (LAS) to physical address space
(PAS). But the problem in the PAS, all the frames
are occupied by some other pages, so we need to
replace the page, so for that reason we need page
replacement algorithm.
Step 5. So after replacement, the page table will be
To avoid, the overhead of bringing large size updated accordingly.
segment into memory, the segmented paging will be Step 6. The signal will be sent to the CPU to
implemented. continue the program execution and it will place the
In the segment paging, paging will be applied on the process back into the ready state.
segment. The CPU will access the required page in the main
Instead of bringing, the entire segments into the memory and continue the program execution.
memory, pages of segment will be brought into The page fault service time include the time to
memory. perform all the above six steps.
Number of entries in page table of segment = Page fault service time = s
Number of pages on segment.
main memory access time = m
Page size of segment is same as frame size of PAS page fault rate = p
(Physical address space).
then the formula for EMAT(Effective Memory
Virtual-Memory Management– Virtual memory
Access Time)
gives an illusion to the programmers that the
EMAT = p(s) + m
programs of larger size than actual physical memory
can be executed. EMAT = p*(s) + (1 – p)*m "s>>m"
Virtual memory is implemented by using Page Replacement Algorithms
Demand paging. (i) FIFO Page Replacement– In this algorithm, the
Demand Paging– The process of loading the page operating system keeps track of all pages in the
into memory on demand (Whenever page fault
memory in a queue, the oldest page is in the front of
occurs) is known as demand paging.
the queue, when a page needs to be replaced page in
the front of the queue is selected for removal.
Reference string: 7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2, 1,
2, 0, 1, 7, 0, 1
(Reference means page number referred by the
process in the logical address)
The number of frames allocated to the process will
be decided by instruction set architecture.
Assume, Number of Frame = 4

Virtual memory concept is implement in order to


increase the degree of multiprogramming.
Step 1. The CPU is trying to refer some page in the
memory but the page is currently not available in
the main memory (that is called page fault).
Step 2. The program execution will be stopped, so
the signal will sent to the operating system
regarding the page fault.
Operating System 96 YCT
Search on TG: @apna_pdf
Belady's Anomaly– By increasing number of Reference string:

frames to the process, the number of page faults

should decrease but instead they are increasing

case of FIFO, this problem is called as Belady's

anomaly.

(ii) Optimal Page Replacement– In the event of

page fault, the page is replaced which is not used Reference string:

for longest duration of time in future. Use of this

page replacement algorithm guarantees the lowest

possible page fault rate for a fixed number of

frames.

Reference string:

Thrashing– Thrashing is a condition or a situation


when the system is spending a major portion of its
time serving the page faults, but the actual
processing done is very negligible.

Note– If we confused about which one used (if they

are not given in future reference string), then follow

the FIFO order. If we further increase the degree of


multiprogramming, then the CPU utilization will
Reference string: drastically fall down and the system will spend
more time only in the page replacement and the
time taken to complete the execution of the process
will increased. This situation in the system is called
as Thrashing.
Cause of Thrashing–
1. High degree of multiprogramming
2. Lack of frames
Recovery of Thrashing–
1. Do not allow the system to go into thrashing and
(iii) LRU Page Replacement– In the event of page instruct long term scheduler, not to bring the
process in to the main memory after the point of 'λ'.
fault, replace the page which is least recently used.
2. If the system is already present in the thrashing
This approach is the Least Recently Used (LRU) then instruct the Midterm scheduler to suspend
some of the processes so that we can recover the
algorithm.
system from Thrashing.
Operating System 97 YCT
Search on TG: @apna_pdf
File System Markup xml, html, textual data,
A file is a named collection of related information tex documents
that is recorded on secondary storage. A file is the Word xml, rtf, various word-
smallest allotment of logical secondary storage; that processor docx processor formats
is, data cannot be written to secondary storage
Library lib, a, so, libraries of
unless they are within a file. Commonly, files
dill routines for for
represent programs and data. Data files may be
numeric, alphabetic, alphanumeric, or binary. Files programmers
may be free form, such as text files, or maybe Print or view gif, pdf, jpg ASCII or binary
formatted rigidly. file in a format for
File Attributes– A files attributes vary from one printing or viewing
operating system to another but typically consist of Archive rar, zip, tar related files
these: grouped into one
• Name file, sometimes
• Identifier compressed, for
• Type archiving or
• Location storage
• Size Multimedia mpeg, mov, binary file
• Protection mp3, mp4, containing audio or
• Time, date and user identification avi A/v information
All the attributes of the file is called as file context.
File context will be saved in the FCB (File Control Access Methods–
Block).
• Sequential Access (Record by Record)
File Operations– A file is an abstract data type. In
• Direct Access (Jump to particular Record)
the file is having various operations:
• Creating a file • Writing a file Directory Structure– The directory can be viewed
as a symbol table that translates file names into their
• Reading a file • Opening a file
directory entries. If we take such a view, we see that
• Truncating a file • Modify
the directory itself can be organized in many ways.
• Repositioning within a file • Deleting a file
The organization must allows us to insert entries, to
• Appeding a file • Save
delete entries, to search for a named entry and to list
• Rename • Redo all the entries in the directory.
• Print • Copy 1. Single Level Directory– The simplest directory
• Paste • Cut structure is the single level directory. All files are
• Send • Undo contained in the same directory, which is easy to
File Types– support and understand. The two files cannot have
File type Usual Function the same name.
Extension
Executable exe, com, ready-to-run
bin machine language
program
Object obj, O complied, machine 2. Two Level Directory– In the two level directory
language, not structure, each user has his own User File Directory
linked (UFD). The UFDs have similar structures, but each
Source code C, CC, java, source code in lists only the files of a single user. When a user job
perl, asm various language starts or a user logs in, the system's Master File
batch bat, sh commands to the Directory (MFD) is searched. The MFD is indexed
command by user name or a count number and each each
interpreter entry points to the UFD for that user.
Operating System 98 YCT
Search on TG: @apna_pdf
Disk Space Allocation Methods–
1. Contiguous Allocation-
Directory
File Starting Disk Block Size
Address (DBA)
abc.doc 2 4
xyz.doc 9 5

3. Tree structured Directories– The natural


generalization is to extend the directory structure to
a tree of arbitrary height. This generalization allows
users to create their own subdirectories and to
organize their files accordingly. A tree is the most
common directory structure. The tree has a root
directory and every file in the system has a unique
path name.
• In the contiguous allocation, whenever the file
is created then disk block will be allocated in
the contiguous manner.
• Every file will be associated with starting DBA
and size of file with respect to Disk Block.
• If we want to increase file 'xyz.doc' then block
14 (Next Block) is should be free, but it is not
true always, so that increasing the file size is
not possible always.
• Even Though, it is suffering from external
fragmentation.
4. Acyclic Graph Directories– An acyclic graph a
• Last block of file may not be full always, so,
graph with no cycles, allows directories to share that the internal fragmentation may exist in the
subdirectories and files. The same file or last disk block of the file.
subdirectory may be in two different directories. • It supports both sequential and random access
The acyclic graph is a natural generalization of the of the file.
Random Access : Random Access Possible by
tree-structured directory scheme.
'Random Access = Starting DBA + Offset'
2. Linked Allocation (Non-Contiguous
Allocation)– Linked allocation solves all problems
of contiguous with linked allocation, each file is a
linked list of disk blocks, the disk blocks may be
scattered anywhere on the disk. The directory
contains a pointer to the first and last blocks of the
file. Each block contains a pointer to the next block.
File Starting Ending (DBA)
(DBA)
abc.doc 2 1
xyz.doc 9 10
Directory

Operating System 99 YCT


Search on TG: @apna_pdf
addresses of the file, so it is pointing to another
block so it is behaving like indexed allocation.
• If the file is very-very small, it is waste of using
entire one disk block just to store the disk block
addresses.
• To avoid these problem, we go for unix-i node.
4. UNIX I-Node Implementation– An extension of
indexed allocation

• In the linked allocation, whenever the file is


created, the disk space will be allocated in a non-
contiguous manner.
• Increasing the file size is always possible if the
free disk block is available.
• There is no external fragmentation.
• In the last block, it may be full or may not be. The
internal fragmentation may exist in the last disk
block of the file.
• There is a overhead of maintaining the pointers in
every block. • UNIX follows I-Node way of allocation in order
• If the pointer of any disk lost, the file will be to allocate the disk space to the file.
truncate. • Every file is associated with its own I-Node.
• It supports only sequential access of the file. • All are disk block only, some contain disk block
• So to avoid overhead of maintaining the and some contain addresses of disk block.
pointer, we go for indexed allocation. • Single indirect means one level contain address
3. Indexed Allocation– and next level contains data block.
Directory • Double indirect means two level address and then
File Index node next level data block.
abc.do 4 • Whenever the file is created, then depending on
c the size of the file, it will be stored in only one
place either direct DBA or single indirect or
double indirect and so on.
• Depending on the size of the file, file will be
stored only in one particular place, may be in the
direct DBA's or may be in the single indirect or
double indirect and so on.
• Reference count = Reference count contains the
total number of link to DB'S.
DBsize
= Number of Disk Block Address 's
DBA
one disk block can contain
• In index allocation, every file is associated with a
its own index node. Disk Free-Space Management–
• The index node contains all the disk block 1. Bit Vector– The free-space list is implemented as
address of the file. a bit map or bit vector. Each block is represented by
• If the file is very-very large then one disk block 1 bit. If the block is free, the bit is 1; if the block is
may not be sufficient to store all the disk block allocated, the bit is 0.
Operating System 100 YCT
Search on TG: @apna_pdf
The main advantage of this approach is its relative The one-dimensional array of logical blocks is
simplicity and its efficiency in finding the first free mapped on to the sectors of the disk sequentially.
block or n consecutive free blocks on the disk. One Sector 0(zero) is the first of the first track on the
technique for finding the first free block on a system outermost cylinder. The mapping proceeds in order
that uses a bit-vector to allocate disk space is to through that tracks, then through the rest of the
sequentially check each word in the bit map to see tracks in that cylinder and then through the rest of
whether that value is not 0, since a 0-valued word the cylinders from outer most to inner most.
contains only 0 bits and represents a set of allocated
blocks. The first non-0 word is scanned for the first
1 bit, which is the location of the first free block.
The calculation of the block number is–
 number of bits 
  × ( number of 0 − value words ) + off set of first1bit.
 per word 
2. Linked List– In this approach, the free disk
blocks are linked together i.e. a free block contains
a pointer to the next free block. The block number
of the very first disk block is stored at a separate • Seek Time– Seek time is the time taken to locate
location on disk and is also Cached in memory. the disk arm to a specified track where the data is to
be read or write.
• 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.
• 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.
In above figure, the free space list head points to • Disk Access Time–
Block 4 which points to Block 5, the next free block Disk Access Time = Seek Time + Rotational
and so on. The last free block would contain a null Latency + Transfer Time.
pointer indicating the end of free list. A drawback DISK Scheduling Algorithms
of this method is the I/O required for free space list The goal of disk scheduling algorithms is to
traversal. minimize the average seek time of the disk.
3. Grouping– This approach stores the address of 1. FCFS Scheduling– A disk queue with requests
the free blocks in the first free block. The first free for I/O to blocks on cylinders ....
block stores the address of some, say n free blocks. 98, 183, 37, 122, 14, 124, 65, 67
Out of these n blocks, the first n-1 blocks are
actually free and the last block contains the address
of next free n blocks.
4. Counting– This approach stores the address of
the first free disk block and a number n of free
contiguous disk blocks that follow the first block.
Every entry in the list would contain–
(i) Address of first disk block
(ii) A number n
DISK Structure
Modern magnetic disk drives are addressed as large Total track movement made by read/write header
one-dimensional arrays of logical blocks, where the (seek time) = (98 – 53) + (183 – 98) + (183 – 37) +
logical block is the smallest unit of transfer. The (122 – 37) + (122 – 14) + (124 – 14) + (124 – 65) +
size of a logical block is usually 512 bytes, although (67 – 65)
some disks can be low-level formatted to have a = 45 + 85 + 146 + 85 + 108 + 110 + 59 + 2
different logical blocks size, such as 1024 bytes. = 640
Operating System 101 YCT
Search on TG: @apna_pdf
2. SSTF (Shortest Seek Time First) Scheduling– the other, servicing requests along the way. When
The SSTF algorithm selects the request with the the head reaches the other end, however, it
least (minimum) seek time from the current head immediately returns to the beginning of the disk
position. without servicing any requests on the return trip.
queue = 98, 183, 37, 122, 14, 124, 65, 67 The C-SCAN scheduling algorithm essentially
treats the cylinders as a circular list that wraps
around from the final cylinder to the first one.
queue = 98, 183, 37, 122, 14, 124, 65, 67

Seek time = (65 – 53) + (67 – 65) + (67 – 37) + (37


– 14) + (98 – 14) + (122 – 98) + (124 – 122) + (183
– 124)
= 12 + 2 + 30 + 23 + 84 + 24 + 2 + 59
= 236
3. SCAN Scheduling– In the scan algorithm, the Seek time = (65 – 53) + (67 – 65) + (98 – 67) +
disk arm starts at one end of the disk and moves (122 – 98) + (124 – 122) + (183 – 124) + (199 –
toward the other end, servicing requests as it 183) + (199 – 0) + (14 – 0) + (37 – 14)
reaches each cylinder, until it gets to the other end = 12 + 2 + 31 + 24 + 2 + 59 + 16 + 199 + 14 + 23
of the disk. At the other end, the direction of head = 382
movement is reversed and servicing continues. The 5. LOOK Scheduling– In this algorithm, it will go
head continuously scans back and forth across the till only the last request (not 199) and come back to
disk. The SCAN algorithm is sometimes called the satisfy the remaining request.
elevator algorithm.
queue = 98, 183, 37, 122, 14, 124, 65, 67
queue = 98, 183, 37, 122, 14, 124, 65, 67

Right– It will first satisfy all the right-side request


and go till the end and come back to satisfy the Seek time = (65 – 53) + (67 – 65) + (98 – 67) +
remaining left. (122 – 98) + (124 – 122) + (183 – 124) + (183 – 37)
Left– First satisfy all left side and go till the '0' and + (37 – 14)
satisfy the remaining. = 12 + 2 + 31 + 24 + 2 + 59 + 146 + 23
Seek time = (65 – 53) + (67 – 65) + (98 – 67) + = 299
(122 – 98) + (124 – 122) + (183 – 124) + (199 – 6. C-LOOK (Circular LOOK) Scheduling– In C-
183) + (199 – 37) + (37 – 14) LOOK, it will go in the right direction and go till
= 12 + 2 + 31 + 24 + 2 + 59 + 16 + 162 + 23 the last request and directly jump to first request
= 331 (14) left most and request and then satisfy the
4. C-SCAN (Circular SCAN) Scheduling– C- remaining request.
SCAN moves the head from one end of the disk to queue = 98, 183, 37, 122, 14, 124, 65, 67
Operating System 102 YCT
Search on TG: @apna_pdf
RAID-2 – This configuration uses striping across
disks, with some disks storing error checking and
correcting (ECC) information. RAID 2 also uses a
dedicated Hamming code parity, a linear form of
ECC. RAID 2 has no advantage over RAID3 and is
no longer used.

RAID-3 – This technique uses striping and


dedicates one drive to storing parity information.
Seek time = (65 – 53) + (67 – 65) + (98 – 67) + The embedded ECC information is used to detect
(122 – 98) + (124 – 122) + (183 – 124) + (183 – errors. Data recovery is accomplished by calculating
14) + (37 – 14) the exclusive information recorded on the other
= 12 + 2 + 31 + 24 + 2 + 59 + 169 + 23 drives. Because an I/O operation addresses all the
= 332 drives at the same time. RAID 3 cannot overlap I/O.
RAID Structure– RAID (Redundant Arrays of For this reason, RAID 3 is best for single user
Independent Disks) is a technique which makes systems with long record applications.
use of a combination of multiple disks instead of
using a single disk for increased performance,
data redundancy or both. RAID-4 – This level uses large stripes, which
means a user can read records from any signle
drive. Overlapped I/O can then be used for read
operations. Because all write operations are required
to update the parity drive, no I/O overlapping is
possible.

RAID-5 – This level is based on parity block level


striping. The parity information is striped across
RAID Levels– RAID combines several independent each drive, enabling the array to function, even if
and relatively small disks into single storage of a one drive were to fail. The array's architecture
large size. The disks included in the array are called enables read and write operations to span multiple
array members. The disks can combine into the drives. This results in performance better than that
array in different ways, which are known as RAID of a single drive, but not as high as a RAID-0 array.
levels. We describe the various levels here– RAID-5 requires at least three disks, but it is often
RAID-0 (Stripping)– This configuration has recommended to use at least five disks for
striping but no redundancy of data. It offers the best performance reasons.
performances but is does not provide fault
tolerance.

RAID-6– This technique is similar to RAID-5, but


it includes a second parity scheme distributed across
RAID-1 (Mirroring)– Also known as disk
the drives in the array. The use of additional parity
mirroring, this configuration consists of at least two
enables the array to continue functioning even if
drives that duplicate the storage of data. There is no
two disks fail simultaneously. However, this extra
striping. Read performance is improved, since either
protection comes at a cost. RAID 6 arrays often
disk can be read at the same time. Write have slower write performance than RAID 5 arrays.
performance is the same as for single disk storage.

Operating System 103 YCT

Powered by TCPDF (www.tcpdf.org)


Search on TG: @apna_pdf

09. COMPUTER NETWORK


Data Communication Data Flow
Data communication is the exchange of data Data flow is the communication between two
between device or human by local or remote devices. It can be simplex half duplex and full
using transmission medium. duplex.
Components– There are five mainly components
of a data communication system.

Simplex– It is an unidirectional communication


or one way start. Key boards traditional monitor
and radios are example of simplex devices.

1. Message Half-duplex– It is two or bidirectional


2. Sender communication. In half-duplex each station can
3. Receiver both transmit and receive but not at same time.
4. Transmission Medium Walkie-Takies is the example of half duplex
5. Set of rules (protocol) system.
Message It is the information or data to be
communicated. Message can be in
the form of text, number, picture,
audio, video and multimedia etc. Full duplex– It is two or bidirectional
Sender It is the device which capable of communication in full duplex both stations can
sending data over network. It can transmit and receive simultaneously. This
be a computer, telephone, laptop, sharing contain two physically separate
Mobile video camera and so on. transmission path to avoid collision telephone
Receiver It is the device (destination) where line is the example of full duplex.
finally message send by source
and received by receiver. It can be
computer workstation, telephone,
television etc. Networks
Transmission It is physical path by which data A computer network is a group of computers
medium travels from sender to receiver. It connected to each other that enables one
is act as bridge between sender computer to communicate with other computers
and receiver. and share their resources, applications and data.
Example– Twisted pair cable,
coaxial cable fiber optic cable and
radio waves.
Protocol It is a set of rules that govern data,
data communications. It represents
an agreement between the devices
without protocol you can connect
but not communicate.

Computer Network 104 YCT


Search on TG: @apna_pdf
Network Criteria
Performance It can be measured in many ways,
including transit time and
response time . Transit time is the
amount of time required for a
message to travel from one device (b) Multipoint– In this connection more than
to another. two specific devices share a single link.
Response time is the elapsed
between an inquiry and a
response.
The nature of a network depends
on a number of factors, including
the type transmission medium, the
number of user the capabilities of Two types of multipoint connection–
the connected hardware and the (i) Spatial sharing– In this sharing several
efficiency of the software. computer can share the link simultaneously.
Reliability Network reliability is measured (ii) Time sharing– In this, user must take turn.
by the frequency of failure. The Physical Topology
time is takes a link to recover In physical topology, a network is formed by
from a failure. physically connecting two or more devices with
Security Network security issues include two or more links.
protecting data from unauthorized Communication using OSI Model
access, protecting data loss and
implementing policies and
procedures for recovery from dot
losses.

Physical Structure
Types of connection– There are two possible
types of connection.
(a) Point-to-point connection– This connection
provides a dedicated link between two devices.
For example Television and remote control,
computer connected by telephone line.

OSI (Open Source Interconnection) Model


Layer Application Functions Protocols Central Devices
Application These application • Networks virtual SMTP, HTTP, FTP, –
Layer produce the data which terminal POP3, SNMP,
(Layer 7) has to be transferred • Mail services Telnet.
over the network. This • Directory services
layer also serves as a
window for the
application services to
access the network and
for displaying the
received information to
the user.
Example- browsers,
Skype, Messenger etc.

Computer Network 105 YCT


Search on TG: @apna_pdf
Presentation It is also called the • Translation ASCII to MPEG, XDR, SSL, –
Layer Translation Layer. the EBCDIC TLS, MIME
(Layer 6) data from the • Encryption/
application layer is Decryption
extracted here and
• Compression
manipulated as per the
required format to
transmit over the
network.

Session layer This layer is responsible • Session Net BIOS, SAP Gateway phone,
(Layer 5) for the establishment of establishment, PPTP, ADSP, Servers
connection maintenance maintenance and RTCP, PAP,RPCP
of sessions, termination
authentication and also • Synchronization
ensures security. • Dialog controller
Transport The data in the • Segmentation and TCP, Firewall, Gateway
Layer transport layer is reassembly UDP,
(Layer 4) referred to as • Services point SPX
segments. It is addressing
responsible for the end • Message
to end delivery of the acknowledgement
complete message. The
transport layer also
provides the
acknowledgement of
the successful data
transmission and re-
transmits the data if an
error is found.
Network Layer It works for the • Routing IPv4, IPv6, ICMP, Router
(Layer 3) transmission of data • Logical Addressing IPSEC, MPLS Brouters
from one host to the • Subnet traffic
other located in control.
different networks. It
also takes care of
packet routing. the
sender and receiver's
IP addresses are placed
in the header by the
network layer
Data Link It is responsible for the • Framing PPP, ARP Frame, Switch
Layer (Layer node-to-node delivery • Physical addressing Relay, ATM, Fiber Bridge
2) of the message. The • Error control Cable etc. Access point
main function of this
• Flow control
layer is to make sure
data transfer is error • Access control
free from one node to
another, over the
physical layer, it
collects the packets to
from frames, which are
then transmitted over
the network.
Computer Network 106 YCT
Search on TG: @apna_pdf
Physical Layer It is responsible for • Bit synchronization RJ-45 100 Base Tx, Hub, NIC, Cable,
(Layer 1) transmitting individual • Bit rate control ISDN. Modem, wireless
bits from one node to • Physical topologies Repeaters
the next. When
• Transmission mode
receiving data, this
layer will get the signal
received and convert it
into 0s and 1s and send
them to the data link
layer. Which will put
the frame back
together

Basis Bus Star Ring Tree Mesh Hybrid


Topology

Architecture A network A network In ring Tree topology In this The hybrid


topology in topology in topology each is the variation networking topology is the
which there which node is of star topology, combination of
is a single peripheral connected to topology. This each multiple
line (the bus) node are two other topology has a communicat topologies, used
to which all connected to devices, one hierarchical ing device for constructing a
nodes are central node each on either flow of data. is connected single large
connected (such as a side, the In tree with every topology.
and the node hub, switch nodes topology all other device
connect only or router) connected the computers in the
to this bus. with each are connected network. In
other thus like the order to
forms a ring branches of connect n
the link in a tree. nodes.
ring topology Mesh
is topology
unidirectional. require
n(n-1)/2
communicat
ion links

Computer Network 107 YCT


Search on TG: @apna_pdf
Advantages • Usually • Allows • Each node • Supported • Message • It is more
requires easy error has an equal by most delivery effective as it
less detection access to hardware is more uses multiple
cabling and other nodes and reliable. topologies
• The failure correction in the software • Network • It is contains the
of one • Star network • Date is congestio best and
computer topology is • Addition of receive a by n is efficient feature
does not easy to new node all the minimum of the
effect the install. does not nodes due to combined
other degrade the efficiently large topology form
computers performanc because of number which it is
in the e of the point-to- of links. constructed.
network network point link.
Disadvantage • The failure • The hub • It is • When the • It is very • It is relatively
s of the failure relatively root node expensive more complex
backbone leads to expensive to fails, the to than the other
cable the overall construct whole implemen topology
results in network the ring network t. • It is difficult to
the crash. topology. crashes. • It is very install and
breakdown • Requires • The failure • It is difficult difficult configure.
of entire more of one node to to
network amount of in the ring configure. configure
• It is cable for topology and
difficult to connecting affects the install.
reconstruct the nodes. other nodes
in case of in the ring.
faults
Delay/ Slow Good Data has to Slowly Manages Worst response
Response response response make a lot of because of high time.
time time because time, stops more traffic. amounts of
of one depends on traffic
computer lot of stops because
transmit at a multiple
time devices can
transmit
data
simultaneou
sly
Common Coaxial • Coaxial Twisted pair Overall length All king of Cabling depends
Cable cable, twisted cable requires more of each cable that on the types of
pair, fiber twisted cables than segment is can be used networks, twisted
pair fiber other limited by the with LAN pair, coaxial fiber.
• No more topologies of cabling and WAN.
than 100 used (Coaxial.
meters Twisted pair-
from the Fiber)
computer
to the
connection
device
Computer Network 108 YCT
Search on TG: @apna_pdf
Congestion One Compared Information A A few of Often used across
control computer at a bus topology goes in one transmission congestion long distances,
time sends it gives for direction from any direct from information on
information. much better around the station source to transfer can
Information performance ring and propagates destination happen in
goes along signals don't passes along throughout the except the different ways,
the cable and necessarily the ring until it medium and station with depending on the
the computer get reaches the can be less other topologies.
accesses the transmitted correct received by all connection
information to all the computer, no other stations.
off the cable work stations buffering at
repeater.
Reliability If the In hub fails If the cable In case of any A failure of Extremely rare
common then the fails or any node failure, one device reliability
cable fails, whole system computer other does not
then the will crash shuts down, hierarchical cause a break
whole system down. then the whole network are in the
will crash system will not affected network or
down. crash down. transmission
of data.
Complexity Easy to Average Complexity Move Installation the most
connect or complexity because of complex is complex complicated one
remove each device simple to data because of in mesh
nodes in a connects to to devices. tree is topology, as
network central combination a each node is
without device with star network connected
affecting any only one link topology and a to more
other node. only. bus topology. than one
node.
Security Any Security data travels The data pass The data The worst
computer depends on from one over more pass over security
that is central device to the than one node more than
connected to device next until they one node
bus topology security. reach their
network will destination.
be able to see
all the data
transmissions
on all the
other
computers

Computer Network 109 YCT


Search on TG: @apna_pdf

TCP/IP Model 4. Data link Layer- It is the closest to the network


hardware. It provides service to Internet layer.
TCP/IP stands for Transmission control
5. Application Layer- This layer is analogous to
Protocol/Internet Protocol and is suite
the transport layer at the OSI model. It is
communication Protocols used to interconnect
responsible for end to end communication and
network devices on the internet. TCP/IP is also
error free delivery of data.
used as a communication Protocol in a private
TCP/IP model Vs OSI Model
computer network. The TCP/IP model is a
concise version of the OSI model. OSI TCP/IP
OSI represent open TCP/ IP model represents
Logical connections between layers of
system Interconnection the Transmission Control
the TCP/IP Protocol. Protocol/ Internet
Protocol.
OSI is a generic TCP/IP model depends on
independent Protocol in standard protocols about
standard. It is acting as which the computer
an interaction gateway network has created. It is
the network and the a connection protocol that
final user. assigns the network of
hosts over the internet.
The OSI model It does not mention the
represents defines services, interfaces, and
administration, interface protocols.
and connections. It
describes clearly which
layer provides services.
The protocols of the .The TCP/IP model
OSI model are better protocols are not hidden,
unseen and can be and we can't fit a new
appropriate protocol protocol stack in it.
quickly.
1. Physical Layer- This layer is It provides both It provides connectionless
responsible for generating the data and connection and transmission in the
requesting connections. It acts on behalf of the connectionless oriented network layer and
sender and the Network access layer on the transmission in the supports connecting and
behalf of the receiver. network layer however connectionless oriented
2. Transport Layer- This layer monitors end to only connection transmission in the
oriented transmission in transport layer
end path selection of the packets. It also provides
the transport layer.
service to two application layer. Transmission
control Protocol (TCP) and User datagram The smallest size of the The smallest size of the
Protocol (UDP) are transport layer protocol at OSI header is 5 bytes. TCP/IP header is 20
bytes.
this level.
1. TCP 2. UDP Network Types
is responsible
3. Internet Layer- This layer Local Area Network– LAN is usually privately
for sending packets different networks. owned and connects a few hosts within a single
The main protocols residing at this layer building , office or campus.
are as follows. Each host in a LAN has a identifier, an address,
that uniquely defines the host in the LAN.
Packets sent by one host to another host contain
the addresses of both the source host and the
destination host.
Computer Network 110 YCT
Search on TG: @apna_pdf
Most LANs use a smart connecting switches
which is able to recognize the destination address
of the packet to all other hosts.

The Internet
Internet is two or more networks that can
transmit data with each other.
Back Backbones are large networks owned
bones by some communication companies
Verizon, AT & T, sprint etc.

Metropolitan Area Network


It is larger than LAN but smaller than WAN.
This is the type of computer network that
connects computers over a geographical
distance through a shared communication path
over a city, town or metropolitan area.
Government
College
building

MAN

Peering Peering points are complex switching


Office Residential
Area
Point system that connects backbones.
Network It is a smaller networks that use the
Wide Area Network
Provider services of the backbones for a free. It
WAN has a wide geographical extension, it
connected to backbones and sometime
means spreading in different geographical to other provider networks.
location. WAN inter connects connecting devices
such as switches, routers or modem. WAN is Customer The customer networks are networks at
normally built and operated by communications Network the edge of the internet that is use the
companies and leased by the organization using services provided by the internet.
it. Customer network pay a fee to the
Example of WAN– provider network to receive the
services.
Point-to-Point WAN– This network connects
two communicating device through a ISP Internet service providers is a
transmission media. combination of backbones and provider
networks.
The backbones are after referred to as
international ISPs.
Switch WAN– It is a combination of several Provider networks are often referred to
point-to-point WANs that are connected by as national or regional ISPs.
switches.
Computer Network 111 YCT
Search on TG: @apna_pdf
Accessing the Internet 1. Traditionally Cable Networks was called
Accessing Internet Community Antenna Television (CATV) in
1940s.
1. Using Telephone Networks
2. Hybrid Fiber-Coaxial Network (HFC) This
2. Using Cable Networks
network user a combination of fiber and
3. Using Wireless Networks
coaxial cable.
1. Using Telephone Networks–
i. Dial up service
ii. DSL service
i. Dial-up Service– In this connection the
services connect to the internet through a phone
line connection. Dial-up service established
between two or more communication devices in
which it uses Public Switched Telephone
Network (PSTN) for connect to the internet. Its
data transfer rate is up to 56 kbps.

ii. Digital Subscriber Line (DSL)– DSL


technology is the most promising for supporting
high-speed digital communication over the SONET
existing telephone. This technology is a set of
• Synchronous Optical Network is a
technologies, each differing in the first letter
communication protocol. It is used to transmit a
(ADSV, VDSL, HDSL and SDSL). The set is
large amount of data using optical fiber.
often referred to as xDSL, where x can be
replaced by A, V, H, S. ADSL, provides a wider • By SONET, multiple digital data streams
frequency range for downstream transfers, which transferred at the same time over the optical
offers several time faster downstream speeds. An fiber.
ADSL connection may offer 20 Mbps SONET Network Elements
downstream and 1.5 Mbps upstream. STS • Its converts electrical signal
Multiplexer to optical signal.
• STS performs multiplexing
of signals.
STS • It performs signal de-
De- multiplexing.
multiplexer • It converts optical signal to
electrical signal.
2. Cable Networks– Cable TV network ware Regenerator It is a repeater that takes an
originally created to provide access to TV optical signal and strengthens it.
programs, but later cable networks became Multiplexer This device allows to remove a
popular among people who just wanted a better signal or add signals coming
signal. In addition, cable networks enabled from different sources into
access to remote broadcast stations via given path.
microwave connections.
Now cable TV found a good market in internet
access provision.
Types of cable TV Networks are as follows–
1. Traditionally Cable Networks
2. Hybrid Fiber-Coaxial Network
Computer Network 112 YCT
Search on TG: @apna_pdf
SONET Layers– SONET includes four Microwaves– Microwaves are ratio waves that
functional layers provide a high-speed signal transmission.
Microwaves are a line of sight transmission.
Microwaves have a frequency range between
1GHz-300 GHz. Microwave unidirectional
antennas send out signal in one direction.
Millimeter wave– Millimeter wave is a band of
electromagnetic spectrum that can be used proud
range of product and services. It is high-speed
point to point wireless local area networks
Path • Path layer functionalities are provided (WLANs) and broadband access range 30 GHz
Layer by STS Mux/Demux. to 300 GHz.
• Path layer is responsible for the Lightwave Transmission
movements of signals from its optical
destination. Light wave transmission is used for wireless
lasers communication. It is a relatively low cost
Line • The line layer is in charge of signal
way to connect two building LAN. Laser light
Layer movement across a physical line.
also diffuses easily in poor atmospheric
• STS Mux/Demux and Add/Drop mux
condition likes rain, fog and so on.
provides its functions.
Telephone Local Loop– Local loop is the
Section • It layer responsible for the movement portion of the telephone system that connects
Layer of signal across a physical section.
home or office. Local loop wiring is used
• It layer functions are provided by each Unshielded Twisted Pair (UTP) cabling to the
network device. transmission method distance from the telco is co
Photonic • It layer relates to the OSI models to subscriber's customer premises 5 kilometers.
Layer physical layer.
• This includes physical specifications
for the optical fiber channel.
Wireless Transmission Radio
Wireless transmission is a format of unguided
media. Wireless communication involves no
physical link established between two or more
devices communicating wirelessly. A little part
of electromagnetic spectrum can be used for Trunks– Trunks are used to form networks and
wireless transmission. to interconnect LANs (Local Area Networks) to
Radio Transmission– Wireless communication form WAN (Wide Area Network) or VLAN
is the transmission of voice and data without (Virtual LAN). Trunk network is built up locally
cable or wire. Radio waves can have wavelength or through the internet. It is a point to point
from 1mm to 100,000 km and have frequency connection between two points on a different
range from 3Hz (Extremely low frequency) to networks.
300 GHz (extremely high frequency).
Multiplexing
Infrared– Infrared is used for short-range
communication like TV remotes, Mobile phones, Multiplexing is a set of technique used to
Personal computers etc. The frequency range of combine and send the multiple data over a single
infrared rays 300 GHz to 400 THz. medium. Multiplexing is a many to one combine
Radio waves– Radio waves can travel large a single stream. There are a three multiplexing
distances as well as penetrate any wall (uni- technique such as–
directional). The requirement of radio waves are Frequency Division Multiplexing (FDM), Wave
antennas, sending antennas when are transmit length Division Multiplexing (WDM), Time
message other is receiving range 3 KHz-1 GHz. Division Multiplexing (TDM).
Computer Network 113 YCT
Search on TG: @apna_pdf
FDM– FDM is an analog multiplexing technique Communications Satellite
that combines analog signals.
A communication satellite is a space station
WDM–WDM is an analog multiplexing receives microwave signal earth based station
technique to combine optical signals. WDM is amplifies a signal. Transmission from an earth
used the high data rate capability of a fiber optic based station to a satellite is an uplink.
cable. Transmission from a satellite to an earth-based
TDM– TDM is a digital process that allow a station is a down link. There are three
several connection to share high bandwidth of a communication satellite such a as Geo Stationary
link. Earth Orbit (CEO), Low-Earth-Orbit (CEO) and
Narrowband ISDN– Narrowband ISDN Medium-Earth-Orbit (MEO).
integrated services digital network is called the Geosynchronous Earth Orbit/Geo-stationary
N-ISDN. Narrowband integrated services digital Earth Orbit– Geosynchronous orbit is the
network an attempt to digitize the analog voice Geostationary orbit Geosynchronous orbit
information. N-ISDN is users 64 kbps circuit include O' to earth's equatorial plane (that is
switching. directly above the equator). Line-of-sight
Broadband ISDN– Broadband integrated propagation is sending and receiving antennas be
services digital network digital networking locked into each other location. A satellite moves
services and provides digital transmission faster or slower than the Earth's rotation is useful
telephone wires as well as over other media. The only for short periods.
broadband ISDN speed is around 2 MBPS to 1 LEO Satellites– Low-Earth-Orbit (LEO)
GBPS and the transmission is related to ATM. satellite polar orbits. The altitude is between 500
The broadband ISDN communication is usually and 2000 km with a rotation period of 90 to 120
made using the fiber optic cables. min. The satellite is a speed of 20,000 to 25000
ATM– A synchronous Transfer Mode (ATM) is km/h. Low-Earth-Orbit satellites orbits are
a switched wide area network based cell relay commonly used for communication military
protocol designed by ATM forum and adopted reconnaissance, spying and other imaging
by (ITU-T). International Telecommunication application.
Union-Telecommunication Standard Section
Switching
(ITU-T) efficient for call relay transmits all
information such as video or voice. In large networks, switching technology
determines the best path for data transmission,
High Speed LANs– The IEEE 802.3 to 802.6
from the sender to the receiver.
LAN is data transfer rates in the range of 10
Mbps to 16 Mbps served. The high speed LAN Switching techniques are used to connect
that is emerged broadly categorized into three switching techniques are used to connect systems
types on taken passing, successors of Ethernet to perform auto-one communications.
and switching technology. High speed LANs
with data transfer rate of 100 Mbps to more.
There are varieties of Fast Ethernet such as 100-
Base-Tx, 100-Base-Fx and 100-Base-Tu etc.
Cellular Radio– Cellular radio is a form of
broadcast radio used widely mobile
communication specifically wireless modems
and cell phones. A cell phone to access web,
send and receive e-mail. A cell phone is a
telephone devices that uses high frequency radio
waves to transmit voice and digital data Switching and TCP/IP Layers– There are four
messages. switching at TCP/IP layer.
Computer Network 114 YCT
Search on TG: @apna_pdf
Switching at Physical Layer– Physical layer 3. Teardown Phase– When one of the parties
can have only circuit switching. There are no needs to disconnect, a signal is sent to each
packets exchanged at the physical layer. Physical switch to release the resources.
layer allow signal to travel in one path or Packet-Switched Network
another. In a computer network, communication between
Switching at Data Link Layer– Data link layer two ends is done in blocks of data called packets,
is packet switching. Packets means frames or this allows us to make switches work for both
cells. Packet switching at the data link layer done storages and forwarding because a packet is an
using virtual circuit approach. independent entity that can be stared an later can
Switching at Network Layer– Network Layer is be sent in.
packet switching. Network layer can be used
virtual circuit approach or datagram approach.
Switching at Application Layer– Application
layer is a message switching. The
communication at application layer occurs by
exchanging messages. We can say that
communication using email is a kind of message There are two type of packet switched network.
switched communication. (i) Datagram networks
Circuit Switched Networks (ii) Virtual Circuit Networks
A circuit network is made of a set of switches Datagram networks– Datagram networks are
connected by physical links in which each link is referred to as connection less networks. There
divided in to n channels. ISDN is an example of are no setup or teardown phases. Each packet is
circuit switched network. treated the same by a switch regardless of its
source or destination.
i. Routing tables– The routing tables are
dynamic and updated periodically. The
destination addresses and the corresponding
forwarding output ports are recorded in the
tables.
ii. Destination address– The destination address
is the header of the packet in a data gram
network remains the same during the entire
journey of the packet.
• ATM (Asynchronous Transfer Mode) is
fundamental packet switching.
The actual communication in a circuit switch
network requires three phases are connection Virtual-Circuit Networks
setup, data transfer and connection teardown.
1. Setup Phase– Setup phase two parties (or
multiple parties in a conference call) can
communicate a dedicated circuit needs to be
established. The end systems are normally
connected through dedicated lines to the
switches.
2. Data Transfer Phase– After the
establishment of the dedicated circuit (channels)
the two parties can transfer data.
Computer Network 115 YCT
Search on TG: @apna_pdf
A virtual-circuit-switched network is across Broadcast address– Broadcasting one to all
between a circuit-switched network and a data communication. Example FF:FF:FF:FF:FF:FF
gram network. There are some characteristics of Redundancy– The control concept in detecting
a virtual circuit switched network such as or correcting error is redundancy. Redundant bits
i. There are setup and teardown phases in are added by the sender and removed by the
addition to the data transfer phase. receiver. It is allows the receiver to detect or
ii. Resource can be allocated in setup phase correct corrupted bits.
circuit switched network or on demand as in • An error-detecting code can detect only the type
a datagram network. of errors for which it is designed other of errors
iii. A virtual circuit network is normally may remain undetected.
implemented in data link layer. While circuit • A single-bit error is the same for us as a burst
switched network is implemented physical error called error correction. The number of
layer and datagram network in the network error and the size of message are important
layer. factors. We can divide coding schemes into two
Addressing– Virtual-circuit network two types broad categories block coding and convolution
addressing are involved such as global and local coding.
(virtual-circuit identifier) • Minimum hamming distance for error detection
Important factor of (ARP) Protocols is set of code words. The minimum hamming
• Address Resolution Protocol (APR) is used to distance is a smallest hamming distance
get MAC address of a node by providing IP between all possible pairs of code words.
addresses. • Minimum distance for linear block codes are
• ARP is used to find the MAC addresses that number of non-zero valid code word with the
corresponds to an IP address. smallest number.

• The ARP protocol is one of the auxiliary • Parity check code error detection is a linear
protocol defined in the network layer. It maps block code.
an IP address to a logical link address. ARP • Error detection technique is based on a binary
accepts IP address from the IP protocol maps division Cyclic Redundancy Check (CRC).
the address to the corresponding link layer • Cyclic Redundancy check is a subset of cyclic
address and pass to the data link layer. code (CRC) is used in network such as LAN,
• The data link layer is responsible to creation WAN. It is used to binary division error
and delivery of a frame to another node. It is detection technique.
responsible for packetizing (framing), flow • Checksum is an error detecting technique
control and error control, congestion control applied to a message of any length. Checksum
along the link. technique is used at the network and transport
• Link layer protocols three types of addresses layer rather than the data-link layer.
such as unicast, Multicast and broadcast. • Data link control (DLC) is connectionless or
Unicast– Address Unicasting one-to-one connection oriented. DLC is a net way and
communication. A frame unicast address transport layer protocol.
destination is destined only one entity in the • Data Link Control (DLC) is procedure for
link. Example A3:34:54:11:92:F1 It is communication between two adjacent nodes
separated by colons. such as node to node communication. Data link
Multicast address– Multicast address one-to- control function include control function
many communication. Example A2:34:45:11:92:F1 include framing and flow error control.
Computer Network 116 YCT
Search on TG: @apna_pdf
Connection less Protocol– Connectionless TDM– Time Division Multiplexing is requires
protocol frames are sent from one node to next the transmitter and receiver to be synchronized
without any relationship between the frames. periodically.
Frames are not numbered and there is no sense of Description
ordering. CSMA/CD CSMA/CD is reduce the possibility of
Connection Oriented Protocol– Connection- collision but it is not eliminate it.
oriented protocol is a logical connection Carrier Sense Multiple Access with
established between two nodes. Connection collision detection CSMA/CD
oriented protocol some point-to-point protocol. transmission and collision detection
Same wireless LAN, and some WAN. are continuous processes. We do not
Connection oriented protocol are rare in wired sent the entire frame and then look for
LAN. the collision. CSMA/CD as the media
access method Ethernet LAN as token
Protocol Description
passing, Token Ring, Token Bus.
PPP Point-to-point protocol provide the
CSMA/CA Carrier Sense Multiple Access with
services of physical layer. But to control
collision (CSMA/CA) is a wireless
and manage the transfer of data link
network. Collision are avoided through
layers. PPP does not provide any flow
the use of CSMA/CA three strategies
control. Error control is also limited to such as Inter frame space, contention
error detection. PPP uses a character window, acknowledgements.
oriented frame. It is a link layer protocol
such as link control protocol.
IEEEI 802 Standard for LANs (MAC)
HDLC High level Data Link Control (HDLC) is LLC-Logical Link Control MAC: Media Access
a bit oriented protocol for Control
communication over point-to-point and
Data-link layer Ethernet Token Ring Token
multipoint link. HDLC is a three types of
MAC MAC Bus
frames, information frame (I-frame),
MAC
supervisory frame (s-frames) and
Physical layer Ethernet Token Ring Token
unnumbered frames (u-frames).
Physical Physical Bus
Layer Layer Physical
Layer
Transmission media OSI or TCP/IP suite
Transmission media IEEE standard
• IEEE 802.16 standard for Wi-Max technology.
HUB
A hub is a device that operates only in the
physical layer. A repeater is a multiport device is
Media Access Control is a sub-layer in the data called hub. A hub or a repeater is a physical layer
link layer. device. Type of Hub- Active Hub, Passive Hub,
ALOHA– Aloha is random access method. It Intelligent Hub.
was designed for a radio (wireless) LAN, but it
can be used on any stared medium. The original
ALOHA protocol is called pure ALOHA. Pure
ALOHA is vulnerable time a station send frame.
Slotted ALOHA was invented to improve the
efficiency of pure ALOHA.
Computer Network 117 YCT
Search on TG: @apna_pdf
Routers 7 of OSI model. TLS is sometimes called SSL
A router is a three layer device operates in the (Secure Socket Layer).
physical layer. Data-link layer, network layer. A Fragmentation
router is an internetworking devices. A router
Fragmentation is a process divided packets into
change the link-layer addresses in a packet.
smaller pieces (fragments) so that resulting
pieces can travel across link smaller Maximum
Transaction Unit (MTU) that original packed
10 Gigabit
LAN size. The network layer fragmentation data when
the maximum size of a data gram exceeds the
Gigabit LAN
Gigabit LAN maximum size of data that can retained in a
Switch frame. There are three type of fragmentation.
Switch
External fragmentation, Internal fragmentation,
Data fragmentation.
...... ...... Firewalls
System System System System Firewalls provide protection against outside
cyber attackers by shielding your computer or
network from malicious or unnecessary network
Dynamic Host configuration Protocol
traffic. There is a two types of firewall.
(DHCP)– DHCP is an application layer program
i. Packet-Filter firewall– A packet-filter
using the client server helps TCP/IP at the
firewall is a router that uses a filtering table to
network layer. DHCP to assign permanent IP
decide packet must be discard (not forward). It is
address is the host and router.
based on network layer and transport layer.
Bridge ii. Proxy Firewall– A proxy firewall is a
A bridge operates data link layer. A bridge is a network security system that protect network
repeater add on functionality filtering by reading resource by filtering messages at the application
layer.
the MAC address source and destination. Bridge
is used inter connecting two LAN working same Routing → Routing Algorithms
protocols. i. Distance-vector Routing– DVR is used to
find the least cost (shortest distance) between
Gateway a source node (using the Bell man-ford
Gateways are protocol converters and operate at Equation).
any network layer. Gateways are generally more ii. Link state routing is select the best least-cost
complex than switch or routers. A gateway is route to transfer the data packets between the
also called protocol converter. sender/source and receiver/destination.
iii. Path-Vector-Routing is not actually used in
Tunneling
an internet and is mostly designed to route a
Tunneling is used in virtual private networks packet between ISP. Example BGP is a path
(VPNs). It can also setup efficient and source vector routing protocol.
connections between networks, enable the
Congestion Control
unsupported network protocol. A VPN is a Congestion control a number of packets send to
secure, encrypted connection over the public the network is greater than the capacity of the
shared network. VPN is a Transport Layer network. It can handle the number of packets a
Security (TLS) protocol operate layer 6 and layer network.
Computer Network 118 YCT
Search on TG: @apna_pdf
Cryptography Asymmetric key cryptography is a use to public
key and private key.
Cryptography is technique of securing
information and communication to achieve Electronic Email
message integrity and confidentiality and
Electronic mail allows users to exchange
exception. The cryptographic parameter client
messages. When the request arrives the server
and server a 48 byte master secret is created from
provides the service. Electronic mail is an on
the pre-master secret by applying two hash
way transaction.
function (SHA-1 and MDS).
Public key Email-Architecture
Public key cryptography is used for email traffic,
such as with the standard encryption method
S/MIME, for digital signatures as well as for
cryptographic protocol such as SSL/TLS, SSH
and HTTPS.
Secret key
Secret key cryptography is also called symmetric
cryptography because the same key is used to Protocol Description
both encryption and decryption the data. Secret SMTP Simple Mail Transfer Protocol is an
key crypto graphic include Advanced Encryption internet standard communication
Standard (AES). Triple Data Encryption protocol for electronic mail
Standard (3DES) and Rivest Cipher 4 (RC4). transmission message transfer agents
use SMTP to send and receive mail
Domain Name System
messages.
DNS is a host name for IP address translation
POP3 Post Office Protocol Version 3 (POP3)
service. It is application layer protocol for
provides access to an inbox stored in an
message exchange between clients and servers.
email server. It executes the down load
DNS is a distributed data base internet service
and delete operation for messages.
that translate domain name to IP address. TCP/IP
MIME Multipurpose Internet Mail Extensions
protocol use the IP address.
allows an e-mail message a non-ASCII
Electronic Email Security file such as a video image or a sound
Email security is the process of ensuring the and it provide mechanism transfer non
availability, integrity and authenticity of email text characters to text characters.
communication by protecting against the risk of IMAP4 Internet Message Mail Access Protocol,
email threats. version 4 is an application layer
Name Server protocol that operates for receiving
emails from mail server. Users have
Name server are work as a directory that
remote access to all the contexts.
translates domain names in to IP addresses.
Symmetric Key Cipher Domain Name System Resource Records
A symmetric key cipher uses the same key for Resource records are used to store data domain
both encryption and decryption. A key can be names and IP addresses. Each resource record
used for bidirectional communication. specifies information about particular object. The
Asymmetric key cryptography is based on server uses these records to answers queries for
applying mathematical function to the number. hosts in its zone.
Computer Network 119 YCT

Powered by TCPDF (www.tcpdf.org)


Search on TG: @apna_pdf

10. PROGRAMMING IN
C and C++
A token is the smallest element of a program that Arithmetic Operators
is meaningful in the compiler. Arithmetic operators are used to perform
mathematical operations.
Operators Meaning of Operators
+ Addition, Adds two values
– Subtraction, Subtracts one value
from another
* Multiplication, Multiplies two
values
/ Division, Divides one value by
Identifier refers to name given to entities such as another
variables, functions, structures, array etc. % Remainder after division
Identifiers must be unique. ++ Increment, increase the value of a
Keywords is reserved word. It can't use as a variable by 1
variable name and constant name. –– Decrement, Decreases the value of a
auto break case char variable by 1
const double else continue
Relational Operators
default do enum extern
float for goto if Relational Operators are used to checks the
int long register return relationship between two operands.

short signed sizeof static Operators Meaning of Operator

struct switch typedef union == Equal to


unsigned void volatile while != Not equal

Constant is a name given to the variable. It can't > Greater than


altered or changed during execution once < Less than
defined. >= Greater than or equal to
String is a sequence of characters terminated <= Less than or equal to
with a null character '\0' strings are defined as an
array of characters. Example– Logical Operators
Char str[] = "YCT"
Logical operators are used to determine the logic
Index 0 1 2 between variable or values and return either 0 or 1.
Str Y C T Operators Operators Meaning
Operators are used to perform the operations on && Logical and, Returns true if the both
variables and value. statements are true.
|| Logical or, Returns true if the one
of the statements is true.
! Logical Not, Reverse the result,
returns false if the result is true.

Programming in C & C++ 120 YCT


Search on TG: @apna_pdf
Bitwise Operators % Percent ` Apostrophe
Bitwise operators are used to perform bit level sign
operations. ^ Caret - Minus sign
Operators Meaning of Operators & Ampersand = Equal
& Bitwise AND * Asterisk < Opening angle
| Bitwise OR bracket
^ Bitwise XOR (Exclusive OR) ( Left > closing angle
parenthesis bracket
<< Left Shift
) right ? Question mark
>> Right Shift
parenthesis
~ Bitwise complement
– Underscore { Left brace
Assignment Operators + Plus sign } Right brace
Assignment operators are used to assign values ' Comma [ Left bracket
to variables.
. Period ] Right bracket
Operators Meaning of Operators
: Colon " Quotation mark
= Simple Assignment
; Semicolon
*= Multiplication Assignment
Data types in C– There are several different
/= Division Assignment ways to store data in C and they are all unique
%= Remainder Assignment from each other. The types of data that
+= Addition Assignment information can be stored as are called data type.
–= Subtraction Assignment
<< = Left Shift Assignment
>> = Right Shift Assignment
&= Bitwise AND Assignment
^= Bitwise exclusive OR Assignment
|= Bitwise inclusive OR Assignment
Other Operators
Operators Meaning of Operators
Sizeof() To return the actual sizeof any
given variable Control Structure: LOOPS– A loop is used to
repeat a block of code until the specified
& To return the address of any given
condition is met.
variable
* Pointer to a variable
?: Conditional expression or ternary
operator
–> Member selection operator
, Comma operators linked related
expression together.

Special Characters
Special symbols have some special meaning and
they can't be used for other purposes.
For Loop
Syntax:
Symbol Meaning Symbol Meaning
for(init statement; testexpression; updatestatement)
~ Tilde / Slash {
# Pound sign | vertical bar //body of loop
$ Dollar sign \ back slash }
Programming in C & C++ 121 YCT
Search on TG: @apna_pdf
How for loop works: Syntax–
for(init;condition;increment){
for(init;condition;increment){
//statement of inside loop
}
//statement of outer loop
}
Flow-Chart of Nested for Loop

/* Calculation of simple interest for 3 sets p, n


and r */
main(){
int p, n, count;
float r, si;
for (count = 1; count < =3; count
= count + 1)
{
printf("Enter values of p, n and r");
scanf("%d %d %f", &p, &n, &r);
si = p * n * r/100;
printf("simple interest = Rs. %f\n", si);
}
}

Flow-Chart of Program

Consider the program given below.


main(){
int r, c, sum;
for (r = 1; r<= 3; r++){
for(c = 1; c< = 2; c++){
sum = r + c;
printf("r = %d c=%dsum = %d\n", r, c,
sum);
}
}
}
Nested for Loop– A for loop inside another for While Loop– The while loop, loops through a block
loops is called nested for loop. of code as long as a specified condition is true.
Programming in C & C++ 122 YCT
Search on TG: @apna_pdf
Syntax– Selection Statements
While(condition){
1. If statement
//statement of
Syntax–
body
if(condition)
}
{
statement execute if
statement is true
}
Flow-Chart of if statement

Understand operation of the while loop by


chart–

2. If-else statement–
Syntax–
if(condition){
//execute block if condition true
}else{
//execute if condition false
}
Flow-Chart of if-else

Do/While Loop– This loop will execute the


code block once, before checking if the condition
is true, then it will repeat the loop as long as the
condition is true.
Syntax–
do { 3. Nested if–
//block to be executed Syntax–
} if(condition 1)
while (condition); {
//execute if condition 1 true
if(condition 2){
//execute if condition 2 true
} else{ execute if condition 2
false
}
}
else {
execute if condition 1 false
}
Programming in C & C++ 123 YCT
Search on TG: @apna_pdf
Flow-Chart of Nested if 1. Break Statement Syntax–
//specific condition
break;

Flow-Chart of break statement

4. If-else ladder–
2. Continue statement
Syntax–
if(test expression){ Syntax–

//statement Continue;
} else if { Flow-Chart of continue
//statement
}
else if{//statement
}
.
.
.
else{//statement
}
Flow-Chart of Ladder if -else

Array and Strings


Arrays– Array are used to store multiple values
in a single variable, instead of declaring separate
variables for each values.

Access the element of an Array–

Jump Statements
It is used to interrupt the flow of the program or
escape a particular section of the program.
Programming in C & C++ 124 YCT
Search on TG: @apna_pdf
Example– return 0;
int main(){ }
int myFirstIndex[] = {25, 40, 70, 150}; Output: 2
printf("%d", myFirstIndex[0]); 3
return 0; 4
} 5
output = 25 6
Array in Loop– 8
Example– Strings– Strings are used for storing
int main() text/characters.
{
int arr [] = {5, 10, 15, 17, 20};
int i = 0;
while (i < 5)
{
printf("%d", arr[i]);
'\0'
i++;
}
return 0;
C[0] C[1] C[2]
}
Output = 5 10 15 17 20 a b \0

Multidimensional Arrays– Example–


A multidimensional array is an array of arrays. int main(){
Syntax– char greetings[] = "Hello YCT";
data_type array_name[size1][size2].....[sizeN]; printf("%s", greetings);
return 0;
}
Output = Hello YCT
Memory Address
The memory address is the location of where the
variable is stored on the computers. Memory
Example– address is in hexadecimal form.
Column 0 Column1 Column 2 Pointers
Row 0 2 3 4 Pointers are used to store the address of variables
Row1 5 6 8 or memory location.
Syntax–
int main(){
datatype *var_name;
int matrix[2][3] = {{2,3,4},
Declare a pointer variable must be a * before its name.
{5,6,,8}};
int i,j; How to pointer works
for (i=0; i<2; i++){
for(j=0; j<3; j++){
printf("%d\n", matrix
[i][j]);
}
}

Programming in C & C++ 125 YCT


Search on TG: @apna_pdf
Example– Standard Library Functions– Library functions
main(){ are used to defined in header files.
int a; Some Header Files
pirntf("%d", &a); //print address of a conio.h It is type of console output/input header
return0; file.
} stdio.h It is a standard type of output/input header
Output = 0x7ffe59c7a1e4 file.
Note– Output can be assigned different address in
time.h The function that are time related
different runs.
math.h The function are related to math
Example–
operations.
int main(){
int* PC, C; errno.h The function are related to error handling
C = 32; functions.
printf(" Address of C:%d\n", & c); print() The function send formatted output on the
printf("value of C:%d\n\n", C); screen. This function defined in the stdio.n
PC = & C; header file.
printf("Address of pointer PC:%d\n"PC); Ctype.h Character type functions
printf("Content of pointer PC:%d\n\n", *PC); assert.h Program assertion functions
C = 11; User defined function– Working flow of user
printf("Address of pointer PC:%d\n", PC); defined function
printf("content of pointer PC:%d\n\n", * PC); #include<stdio.h>
*PC = 2; void functionName(){
printf("Address of C:%d\n", &C);
printf("value of C: %d\n\n", C);
return 0;
}
Output–
Address of C : 0x7ffd485f65ec
value of C: 32 function names are identifiers and should be
unique.
Address of pointer PC: 0x7ffd485f65ec
Content of pointer PC: 32 User Defined Function
Address of pointer PC: 0x7ffd485f65ec 1. No arguments and no return value
Content of pointer PC: 11 2. No arguments and a return value
Address of C: 0x7ffd485f65ec 3. Arguments and return value
Value of C: 2
4. Arguments and with return value
Functions
1. No Arguments and no return value–
Functions– A function is a block of code which
Syntax–
only runs when it is called.
void function_name(){
Syntax–
//no return value
void myFunct(){ //declaration
return;
//code to be executed(definition)
}
}
2. No arguments and a return value–
Syntax–
return_type function_name()
{
//execute program
return value;
}
Programming in C & C++ 126 YCT
Search on TG: @apna_pdf
3. Arguments and No return value– return n+ sum(n – 1);
Syntax– else
void function_name(type1 argument1, return n;
type2 argument2,.....typeN argumentN) }
{ Output– Enter a positive integer:6
//execute program
sum = 21
return;
} Structure
4. Arguments and with return value– A structure or struct is a collection of variables
Syntax– (different types) under a single name.
return_type function_name(type1 arguments1, Structure using the struct keyword and
type2 arguments2___typeN arguementN) declare each of its members inside curly braces.
{
Syntax–
//execute program
struct structureName {
return value;
datatype member1;
}
datatype member2;
Recursion
.......
A function that calls itself is known as a
};
recursive function and technique is known as a
Example–
recursion. This technique provides a way to
break complicated problems down into simple
problems which are easier to solve.
Working of Recursion

(.) Symbol Access the structure members.


Example–
struct myStructure{
int myNum;
char myLetter;
};
Sum of Natural Numbers–
#include <stdio.h> int main(){
int sum (int n); struct my StructureS1;
int main(){ S1.myNum = 13;
int number, result; S1.myLetter = 'B';
printf("Enter a positive integer"); printf("my number:%d\n",S1.myNum);
scanf("%d", & number); printf("my letter:%c\n",S1.myLetter);
result=sum(number); return 0;
printf ("sum = %d", result);
}
return 0;
Output–
}
my number: 13
int sum(int n){
if (n! = 0) my letter : B

Programming in C & C++ 127 YCT


Search on TG: @apna_pdf
Keyword typedef Output– Imaginary Part : 9
We use the typedef keyword to create an alias Real Part : 5.25
name for data types. Integer: 6
Example– Structure and Pointers– Pointer to structure
#include <stdio.h> members are accessed using arrow (→) operator.
#include <string.h> #include<stdio.h>
typedef struct person{ struct Point{
char name[50]; int a, b;
int dtdNo; };
float salary; int main(){
} person; struct Point p1 = {1, 2};
int main(){ struct Point *p2 = &p1;
person p1; printf("%d%d", p2 →a, p2→ b);
strcpy(p1.name, "Rahul"); return 0;
p1. dtdNo=1010; }
p1.salary = 9000; Output: 1, 2
printf("Name; %s\n", p1.name); Structure and functions– Structures can be
printf(" department No: %d\n",p1.dtdNo); passed as function arguments like all other data
printf("salary:%.2f", p1.salary); types. We can pass individual members of a
return0; structure, and entire structure.
} Example–
Output– #include <stdio.h>
Name: Rahul struct student {
Department No. 1010 char name[40];
Salary: 9000 int age;
Nested Structure– Nested struct within a struct. float salary;
# include <stdio.h> };
struct complex { void display(struct students);
int img; int main(){
float real; struct students S1;
}; printf("Enter name:");
struct number { scanf("%[^\n]%*c", S1.name);
struct complex comp; printf("Enter age: ");
int integer; scanf("%d", &S1.age);
} num1; printf("Enter salary: ");
int main(){ scanf("%f", &S1.salary);
num1.comp.img = 9; display(S1);
num1.comp.real = 5.25; return 0;
num1.integer = 6; }
printf("Imaginary Part; void display(struct students)
%d\n", num1.comp.img); {
printf("Real Part:%2f\n", printf("\n Displaying information\n");
num1.comp. real); printf("Name:%s", s.name);
printf("Integer:%d", num1.integer); printf("\n Age: %d", s.age);
return 0; printf("\n salary: %f",s.salary);
} }
Programming in C & C++ 128 YCT
Search on TG: @apna_pdf
Output– Enter name: Rahul Unions
Enter age: 29 Union is a user defined data type in C, which
Enter salary: 9000 stores a collection of different kinds of the data,
Displaying information just like a structure. The keyword union is used
Name : Rahul to declare the union in C.
Age : 29
Salary : 9000
An Array of structures as function
arguments– An array is a collection of similar
data types. A group of structures of the exact
definition is known as an array of structures.
Example–
#include <stdio.h>
struct details {
char name [10]; Syntax–
char sec [10] Union UnionName
float per; {
}; //member definitions
void print_struct (struct details str_arr[]); };
int main(){ Example–
struct details student[3]={ #include <stdio.h>
{"Rahul", "A", 90.5}, #include <string.h>
{"Pramod", "B", 85.5}, union course{
{"Vibhav", "C", 98.5}, char website [50];
}; char subject [50];
void print_struct(struct details int price;
str_arr[]) { };
int i; void main() {
for(i=0; i<3; i++){ union course c;
printf("Name:%s\n", strcpy(c.website,"yct.com");
str_arr[i].name); printf("website: %s\n", c.website);
printf("Section:%s\n", str_arr[i].sec); strcpy(c.subject, "The c programming
printf("percentage: % .2f\n",str_arr[i].per); of Language");
printf("\n"); printf("Book Author: %s\n", c.subject);
} c.price = 100;
} printf("Book Price: %d\n", c.price);
Output– }
Name: Rahul Output–
Section: A Website: yct.com
Percentage: 90.5 Book Author: the c programming language
Name: Pramod Book Price : 100
Section: B Pointers to Unions– We can have pointers to
Percentage: 85.5 unions and can access members using the arrow
Name: Vibhav operator (→).
Section: C # include <stdio.h>
Percentage: 98.5 union test {
Programming in C & C++ 129 YCT
Search on TG: @apna_pdf
int a; object take up space in memory and have as
char b; associated address like a record in Pascal or
}; structure or union in C.
int main(){ Encapsulation– Keeping the data and function
union test p1; into a single unit like a capsule.
p1.a = 50; Consider a real life example of encapsulation in a
union test*p2 = & p1; company, there are different sections like
accounts section, finance section, sales section
printf("%d %c", p2 → a, p2 → b)
etc. The finance section handles all the financial
return 0;
transaction and keeps records of all the data
}
related to finance.
Output–50
Abstraction– It is a process of hiding irrelevant
OOPs Concepts details from the user.
Object Oriented Programming System–

Example–
#include <iostream>
using namespace std.;
class implement abstraction {
Class– A class can be considered a container private:
containing data variables and functions. int a, b;
Human Being as a class– public;
void set (int x, int y){
a = x;
b = y;
}
void display(){
cout << "a=" <<a<<endl
cout << "b=" <<b<<endl
}
};
int main(){
implement abstraction obj;
Object– Objects are the instances of the class.
When a class is defined, no memory is allocated obj.set(10, 20);
but when it is instantiated memory is allocated. obj.display();
Class person{ return θ;
char name [30]; }
int id; Output– a = 10
public: b = 20
void getdetails(){} Inheritance– Inheriting features from a base
}; class into a derived class.
int main(){ The class which inherits/takes the features in
person p1;//p1 is a boject. known as the derived class and the class whose
} features if inherited is called the base class.
Programming in C & C++ 130 YCT
Search on TG: @apna_pdf
Example–

Example of Function Overloading–


#include <iostream>
using namespace std;
class Yct{
Example– public:
#include <iosterm> void fun(int x){
using namespace std; cout <<"value of X is"
class Yct{ <<x << endl;
public: }
Yct(){ void fun(double x) {
cout<<"Yct can give a writer" cout <<"value of x is"
<<endl; << x << endl;
} }
}; void fun(int x, int y){
class Yct computer{ cout<<" value of x and y is"
public: << x <<", " <<y << endl;
}
Yctcomputer(){
};
cout<<"department of
int main(){
computer"<<endl;
Yct obj1;
}
obj1.fun(5);
};
obj1.fun(5.52);
obj1.fun(55, 50);
class Man: public Yct, public
return 0;
Yctcomputer{};
}
int main(){
Output–
Man b1;
value of x is 5
return 0;
value of x is 5.52
}
value x is and y is 55, 50.
Output– Yct can give a writer
Department of computer
Polymorphism– Redefining the way something
works either by changing the method of
performing it or changing the parts using which
it is done.
Programming in C & C++ 131 YCT
Search on TG: @apna_pdf
In unary operator function no arguments should Default Constructor– A constructor with no
be passed. It works only with one class objects. arguments called default constructor.
In binary operator overloading function there Syntax–
should become argument to be passed. Class CLASS_NAME
The operator overloading function must precede { _____
with friend keyword and declare a function class public:
scope, friend operator function takes two CLASS_NAME()
parameter in a binary operator varies are { ____
parameter in a unary operator. }
Example Operator Overloading– // other member functions
#include <iostream> };
using namespace std; Para-meterized Constructor– It contains
class count{ parameters in the constructor definition and
private: declaration.
int value; Syntax–
public: class class_Name
count(): value(10){} {
void operator ++(){ public:
++value; Class_Name(datatype variable)
} { ____
void display(){ }
cout<<"count:"<<value };
Example–
<<endl;
#include <iostream>
}
using namespace std;
};
class Rectangle{
int main(){
private:
count count1;
double length;
++count1;
double breadth;
count1.display();
public:
return0;
Rectangle(double l,double b){
}
length = l;
Output– count:11
breadth = b;
Constructor and Destruction– A constructor is
}
a special member function with exact same name
double calculateArea() {
as the class name.
return length * breadth;
The constructor name is the same as the class
}
Name because, compiler uses this character to
};
differentiate constructors from the other member
int main(){
function of the class.
Rectangle obj1(10, 5);
A constructor must not declare a return type or
Rectangle obj2(13, 8)
void because it is automatically called and
cout<<"Area of Rectangle1:"
generally used for initializing values.
<<obj1.calculateArea();
cout<<"Area of Rectangle2:"
<<obj2.calculateArea();
return 0;
}
Programming in C & C++ 132 YCT
Search on TG: @apna_pdf
Copy Constructor– A copy constructor is a Example–
member function that initialize an object using # include<iostream>
another object of the same class. using namespace std;
Constructor Overloading– Overloading in int count = 0;
constructor are the constructors with the same class Test{
name and different parameters. public:
Example– Test(){
#include<iostream> count++;
using namespace std; cout<<"\n No. of object created:
class constructor{ \t"<<count;
public: }
float area; ~Test(){
constructor(){ cout<<"\n No object destroyed
:\t"<<count;
area = ();
--count;
}
}
constructor(int a, int b){
};
area = a*b;
main(){
}
Test t, t1
void display(){
return 0;
cout<<"Area:"<<area<<endl; Output–
} No. of object created: 1
}; No. of object created: 2
int main(){ No. of object destroyed: 2
constructor obj; No. of object destroyed: 1
constructor obj2(22, 40);
Templates
obj.display();
Templates are primarily implemented for crafting
obj2.display();
a family of classes or functions having similar
return; features.
}
Output– Area: 0
Area: 880
Destructors– Destructors are usually used to
deallocate memory and do other cleanup for a Functions templates– A functions template
class object and its class members when the defines a family of functions.
object is destroyed. Syntax–
A destructor is a member function with the same template<parameter_list>
name as its class prefixed by a ~(tilde). function_declaration
Class x{ export template <parameter_list>
public: function_declaration
//constructor for class x The general form of a function template is.
x(): Syntax–
//Destructor for class x template<class type> ret_type
~(); func_name(parameter list)
}; {
Destructor takes no arguments and has no return //body of function
type. Its address can't be taken. }
Programming in C & C++ 133 YCT
Search on TG: @apna_pdf
Example– template <class T>
# include<iostream.h> class vector {
#include<conio.h> T*V;
template<class swap>
public:
void swapp(swap & i, swap & j){
vector(){
swap t;
t = i; v = new T [size];
i = j; for(int i = 0; i<size; i++)
j = t; v[i]=0;
} }
int main(){ vector (T* a){
int e, f;
for(int i =0; i<size; i++)
char g, r;
float x, y; v[i] = a[i];
cout<<"\n please insert 2 integer values" }
cin>>e>>f; T operator*(vector & y){
swapp(e, f); T sum = 0;
cout<<"\n Integer values after swapping" for (int i=0; i <size; i++)
cout<<e<<"\t"<<f<<"\n\n";
sum + = this →v[i] *y.v[i];
cout"\n please insert2 character
return sum;
values:";cin>>g>>r;
swapp(g, r); }
cout<<"\n character values after };
swapping:"; int main(){
cout<<g<<"\t"<<r<<"\n\n"; int x[3] = {1, 2, 3};
cout<<"\n please insert 2 Float
int y[3] = {4, 5, 6};
values:"; cin>>x>>y;
vector <int> v1;
swapp(x, y);
cout <<"\n the resultant float values after vector <int> v2;
swapping:"; v1 = x;
cout <<x<<",\t" <<y<<"\n\n"; v2 = y1
} int R = v1*v2;
Output– cout<<"R="<<R<<"\n";
Please insert 2 Integer values: 10 15
return 0;
Integer values after swapping: 15 10
Please inert 2 character values: A B }
Character values after swapping : B A Output– R = 32
Please inert 2 Float values: 2.2 4.4 Function Template with multiple
The resultant float values after swapping:
Parameters
4.4 2.2
Class Template– A class template defines a Function template use more than one generic
family of classes. data type in the template statement, using a
Syntax– comma (,) separated list.
template class name<argument-list>; Syntax–
extern template class name<argument-list>; template<class T1, Class T2, _____>
Example– returntype functionname (arguments of types
#include <iostream> T1, T2, ____){
using namespace std; ≡ body of function
const size = 3; }
Programming in C & C++ 134 YCT
Search on TG: @apna_pdf
Overloading of template function Catch block syntax– You can declare a handler
to catch many types of exceptions. The objects
A template function may be overloaded either by
that a function can catch are declared in the
template functions or ordinary functions of its
parentheses following the catch keyword.
name.
Syntax–
Example–
#include <iostream>
#include <string>
using namespace std; Throw expressions– You use a throw
expression to indicate that your program has
template <class T>
encountered an exception.
void display (T x){
Syntax–
cout<<"Template display:"<<x<<"\n";
}
void display(int x){
the type of assignment_expression can't be an
cout <<"Explicit display:"<<x<<"\n";
incomplete type, abstract class type, or a pointer
}
to an incomplete type other than the following
int main(){
types.
display(1000);
void*
display(10.25); const void *
display('C'); volatile void *
return 0; const volatile void *
} The catch block that catches an exception must
Output– immediately follow the try block that throws the
Explicit display: 1000 exception. The general form of these two blocks
Template display: 10.25 are
Template display: C
Exception handling
Exception handling is a mechanism that
-------
separates code that detects and handles
-------
exceptional circumstances from the rest of your
try {
program. Exception basically built upon three
------
keyword, namely, try, throw and catch.
throw exception; //block of statements
Try– The keyword try is used to preface a block
------ which detects and
of statements which may generate exception.
------ throws an exception
You use a function try block to indicate that you
}
want to detect exception in the entire body of a
Catch (type arg) {
function.
----- //block of statements that
try block syntax–
----- //handles the exception
}
-----
Function try block syntax– -----
Example–
#include <iostream>
using namespace std;
void divide(int x, int y, int z){
Programming in C & C++ 135 YCT
Search on TG: @apna_pdf
cout<<"\n we are inside the function\n"; try{
if((x–y)!=0){ if(x= =1) throw x;
int R = z/(x–y); else
cout<<"Result+"<<R<<"\n"; if(x = = 0) throw x;
}else{ else
throw(x–y); if(x = = –1) throw 1.0;
} cout <<"End of try-block\n";
} }
int main(){ catch(char c){
try{ cout<<"Caught a character\n";
cout<<"we are inside the try }
block\"; catch(int m){
divide(10, 20, 30); cout<<"Caught an integer\n"'
divide(10, 10, 20); }
} catch (int i){ catch(double d){
cout<<" Caught the exception\n";
cout<<"Caught a double\n";
return 0;
}
}
cout<<"end of try_Catch system\n\n";
Output– We are inside the try block
}
We are inside the function
int main(){
Result = –3
cout<<"Testing Multiple Catches\n";
We are inside the function
cout <<"x= = 1\n";
caught the exception.
test(1);
Multiple Catch Statements cout<<" x = = 0\n";
It is possible that a program segment has more test(0);
than one condition to throw an exception. In such cout<<"x= = –1\n";
cases, we can associate more than one catch test (–1);
statement with a try (much like the conditions in
cout<<"x = = 2\n";
a switch statement).
test(2);
Syntax–
return 0;
try{ try block}
}
Catch(type1 arg){
Output–
//Catch block1
Testing Multiple Catches
}
x==1
Catch(type2 arg){
Caught an integer
//Catch block2
End of try_catch system
}
_____ x==0
____ Caught a character
Catch(typeN arg){ End of try catch system
//Catch blockN x = = –1
} Caught a double
Example– End of try_catch system
#include <iostream> x==2
using namesapce std; End of try black
void test(int x){ End of try catch system
Programming in C & C++ 136 YCT
Search on TG: @apna_pdf
Re-throwing an exception Instantiation
A handler may decide to re-throw the exception
The creation of a new instance of the class is
caught without processing it. In such situations,
called instantiation. Memory is allocated for that
we may simply invoke throw without any
object and the class construction runs.
arguments as show below throw;
There are three different ways of
Example–
# include <iostream> instantiation an object through constructors.
using namespace std;
void divide(double x, double y){
cout<<"inside function\n";
try{
if(y = = 0.0)
throw y; Steam– In C++ stream refers to the stream of
else characters that are transferred between the
cout<<"Division="<<x/y<<"\n"; program thread and I/O. Stream classes in C++
} are used to input and output operations on files
Catch(double){ and I/O devices.
cout<<"Caught double inside Stream Classes– The C++ I/O system contains a
function\n"; hierarchy of classes that are used to define
throw; various streams to deal with both the console and
} disk files.
cout<<"End of function\n\n";
}
int main(){
cout<<"Inside main\n";
try
{
divide(10.5, 2.0);
divide(20.0, 0.0);
} Stream classes for console I/O operations.
Catch (double){ As seen the above iOS is the base class for
cout<<"Caught double inside istream and ostream which are in turn base
main\n"; classes for iostream.
} Unformatted I/O Operations
cout<<"End of main\n"; Overloaded operators >> and << :- We have
return 0; used the objects cin and cout (pre defined in the
} iostream file) for the input and output of data of
Output– various types.
Inside main Cin>>variable1>> variable2>>....>variableN
Inside function
This is the general format for reading data from
Division = 5.25
the keyword.
Cout<<item1<<item2<<.......<<itemN
End of function
Inside function This is the general format for displaying data on
Caught double inside function the screen.
Caught double inside main get() and put() function– The classes istream
End of main and ostream define two member functions get()

Programming in C & C++ 137 YCT


Search on TG: @apna_pdf
and put() respectively to handle the single Example–
character input/output operations. #include <iostream>
using namespace std;
int main(){
int size = 20;
char city[20];
get(char*) version assigns the input character to
cout<<"Enter City Name:\n";
its argument.
cin>>city;
get(void) version returns the input character. cout<<"City name;" <<city<<"\n\n";
Example– cout<<Enter city name again;\n";
#include <iostram> cin.getline(city, size);
using namespace std; cout<<"City name now:"<<city<<"\n\n";
int main(){ cout<<"Enter another city name:\n";
int count = 0; cin.getline(city, size);
char c; cout<<"New city name:"<<city<<"\n\n";
cout<<"Input Text\n"; return 0;
cin.get(c); }
while(c! = '\n'){ Output–
cout.put(c); First run
count++; Enter city name:
cin.get(c); Delhi
} City name: Delhi
cout<<"\nNumber of character =
" <<count <<"\n"; Enter city name again:
return 0; City name now:
} Enter another city name:

Input text
Chennai
object oriented programming
New city name: Chennai
Output–
Second run
object oriented programming
Enter city name:
Number of characters = 27
New Delhi
When we type a line of input, the text is sent to
City name: New
the program as soon as we press the RETURN
key. The program, reads are characters at a time
Enter city name again:
using the statement cin.get(c); and displays it
City name now: Delhi
using the statement cout.pute(c);. The process is
terminated when the newline character is
Enter another city name:
encountered.
Greater Bombay
getline() and write() function– We can read and
New City Name: Greater Bombay.
display a line of text more efficiently using the
line oriented input/output function getline() and Formatted Console I/O Operations
write(). The getline() function reads a whole line Formatting the output these features include.
of text that ends with a newline character. This • iOS class functions and flags
function can be invoked by using the object cin. • Manipulators
cin.getline(line, size); • User defined output functions
Programming in C & C++ 138 YCT
Search on TG: @apna_pdf
Functions Task }
width() To specify the required field ostream & form (ostream & output){
size for displaying an output output.setf(ios:: showpos);
value output.setf(iso:: showpoint);
precision() To specify the number of digits output.fill('*');
to be displayed after the output.precision(2);
decimal point of a float value output.<<setiosflags(ios::fixed)
fill() To specify a character that is <<setw(10);
used to fill the unused portion return output;
of a field }
setf() To specify format flags that int main(){
can control the form of output cout<<currency << form << 7864.5;
display return 0;
Unsetf() To clear the flags specified }

Output– Rs**+ 7864.50


Manipulators
Console program file interaction flow–
Manipulators Equivalent ios function
setw() width()
setprecision() precision()
setfill() fill()
setiosflags() setf()
resetiosflags() unsetf()
The addition to these functions supported by the
C++ library.
Designing Our Own Manipulators– We can
design our own manipulators for certain special
purpose.
ostream & manipulator(ostream & output)
Classes for file stream operations
{
The I/O system of C++ contains a set of classes
____
that define the file handling methods.
____
Class Contents
____
return output; filebuf Its purpose is to set the file buffers
to read and write. Contains
}
openprot constant used in the
Example–
open() of file stream classes. Also
#include <iostream>
contain close() and open() as
#include <iomanip>
members.
using namespace std;
fstreambase Provides operations common to the
//user defined manipulators
file stream. Serves as a base for
ostream & currency (ostream & output){
fstream, ifstream and of stream
output <<"Rs";
class. Contains open() and close()
return output;
functions.

Programming in C & C++ 139 YCT


Search on TG: @apna_pdf
ifstream Provides input operations. cout<<"Enter item name:";
Contains open() with default input char name[30];
mode. Inherits the functions get(), cin>>name;
getline(), read() seekg() and tellg() outf>> name;
functions from istream. outf<<name<<"\n";
ofstream Provides output operations. cout<<Enter item cost:";
Constains open() with default float cost;
output mode. Inherits put(), cin>>cost;
seekp(), tellp() and wrtie(),
outf<<cost<<"\n";
function from ostream.
outf.close();
fstream Provides support for simultaneous
ifstream inf("item");
input and output operations.
inf>>name;
Contains open() with default input
inf>>cost;
made. Inherits all the functions
from istream and ostream classes cout<<"\n";
through iostream. cout<<"item name": <<name<<"\n";
cout<<"item cost:" <<cost<<"\n";
Opening and Closing a file inf.close();
The first method is useful when we use only one return 0;
file in the stream. The second method is used }
when we want to manage multiple files using one Output–
stream. Enter item name: CD-ROM
Enter item cost: 350
Item name : CD-ROM
Item cost : 350
Opening files using open()– The function
open() can be used to open multiple files that use
Opening files using constructor the same stream object.
We know that a constructor is used to initialize Example–
an object while it is being created. #include <iostream.h>
Create a file stream object to manage #include <fstream.h>
the stream using the appropriate class. That is to int main(){
say, the class ofstream is used to create the ofstream fout;
output stream and the class ifstream to create the fout.open("Country");
input stream. fout<<"United States of America\n";
Initialize the file object with the fout<<"United Kindom\n";
desired filename.
fout<<"south Korea\n";
ofstream outfile("results");//output only
fout.close();
ifstream infile("data");//input only fout.open("Capital");
Example– fout<<"Washinton\n";
#include <iostream.h> fout<<London\n";
#include <rstream.h> fout<<"Seoul\n";
int main(){ fout.close();
ofstream outf("item"); Const int N = 80;
Programming in C & C++ 140 YCT
Search on TG: @apna_pdf
Char line [N]; Then, the location of a desired object, say the
ifstream fin; mth object, may be obtained as follows.
fin.open("Country"); int location = m* object_length
cout<<"contents of country file\n"; The location gives the byte number of the first
while(fin){ byte of the mth object. We can set the file pointer
fin.getline(line, N); to reach this byte with the help of seekg() or
cout<<line; seekp().
} Error Handling During file operations– A file
fin.close(); which we are attempting to open for reading does
fin.open("capital"); not exist.
cout<<"\n contents of capital file\n"; • The file name used for a new file may already
while(fin){
exist.
fin.getline(line, N);
• We may attempt an invalid operation such as
cout<<line;
reading past the end of file.
}
• There may not be any space in the disk for
fin.close();
storing more data. We may use an invalid file
return 0;
name.
}
• we may attempt to perform an operation when
Output–
Contents of Country file the file is not opened for that purpose.

United States of America Error Handling functions


United Kingdom
Function Return value and meaning
South Korea
eof() Return true (non-zero value) if end of
file is encountered while reading
Contents of capital file
otherwise return false (zero)
Washington
London fail() Returns true when an input or output
Seoul operation has failed

Updating a file Random Access bad() Returns true if an invalid operations is

Updating is a routine task in the maintenance of attempted or any unrecoverable error

any data file. The updating would include one or has occurred. If it is false, it may be
more of the following tasks. possible to recover from any other
• Displaying the contents of a file error reported and continue operation.
• Modifying an existing item good() Return true if no error has occurred.
• Adding a new item This means, all the above functions
• Deleting an existing item. are false. For instance, if file.good() is
This can be easily implemented if the file true, all is well with the stream file
contains a collection of items/objects of lengths.
and we can proceed to perform I/O
In such cases, the size of each object. Can be
operation when it returns false, no
obtained using the statement.
further operations can be carried out.
int object_length=sizeof(object);
Programming in C & C++ 141 YCT

Powered by TCPDF (www.tcpdf.org)


Search on TG: @apna_pdf

11. WEB TECHNOLOGY


2000 W3C Recommendation XHTML 1.0
HTML
HTML is the standard markup language for 2008 WHATWG HTML5 first Public Draft
creating web pages. HTML stands for Hypertext 2012 WHATWG HTML5 Living standard
Markup Language and describes the structure of 2014 W3C Recommendation HTML5
a web page. HTML elements tell the browser 2016 W3C Recommendation HTML5.1
how to display the content.
2017 W3C Recommendation HTML5.1 2nd
<!DOCTYPE html> – Declaration defines that this
Edition
document is HTML5 document.
2017 W3C Recommendation HTML5.2
<html> – Element is the root element of an HTML
page. HTML tag and Element
<head> – Element contains meta information about the HTML element defined by a start tag some
HTML page. content and an end tag like.
<title> – Element specifies a title for the HTML page
(which is shown in the browser's title bar or in
the pages tab)
<body> – Element defines the documents body and is a
container for all the visible contents such as HTML Tag and Attributes
headings, paragraph, images, hyperlinks, tables, HTML attributes provide additional information
lists etc. about elements. Attributes are always specified
HTML Page Structure in the start tag and attributes usually come in
name/value pairs like, name = "value".
Example– The <a> tag defines a hyperlink. the
href attributes specifies the URL of the page the
link goes to.
<a href = "http://www.yct.com">
visit YCT</a >
Some Important Tags
Tag Description
<!......> Defines a comment
<!DOCTYPE> Defines the document type
<a> Defines a hyperlink
<abbr> Abbreviation or an acronym
<address> Defines contact information for
Version of HTML the author/owner of a document
Years Version <area> Area inside an image map
1991 First Versions of HTML <article> Defines an article
1995 HTML 2.0 <aside> Defines content aside from the
1997 W3C Recommendation 3.2 page content
1999 W3C Recommendation 4.01 <audio> Embedded sound content

Web Technology 142 YCT


Search on TG: @apna_pdf
<b> bold the text <frame> Defines a window in a frameset
<base> The base URL/target for all <frameset> Defines a set of frames
relative URLs in a document <h1> or <h6> Defines HTML headings.
<blockquote> A section that is quoted from <head> Contains metadata/Information
another source for the document.
<body> Documents of body <header> A header for a document or
<br> Single line break section.
<button> A clickable button <i> Defines a part of text in an
<canvas> Used to draw graphics, on the fly alternate voice or mood.
via scripting (usually javascript) <img> Defines an image.
<code> A piece of computer code <input> An input control.
<col> Specifies column properties for <label> Defines a label for an <input>
each column within a <colgroup> element.
element <legend> A caption for a <fieldset>
<colgroup> A group of one or more columns element.
in a table for formatting <li> A list item.
<data> Adds a machine readable <link> Defines the relationship between a
translation of a given content. document and an external
<datalist> A list of predefined options for resource.
input controls <map> Defines an image map.
<dd> Description/value of a term in a <mark> marked/highlighted text
description list <meta> metadata about an HTML
<details> Defines additional details that the document.
user can view or hide. <meter> Defines a scalar measurement
<dialog> A dialog box or window. within a known range.
<div> A section in a document <nav> Defines Navigation links.
<dl> Defines a description list <object> Defines a container for an
<dt> Defines a term/name in a external application.
description list <ol> Defines an ordered list.
<embed> A container for an external <optgroup> Defines a group of related options
application. in a drop-down list.
<fieldset> Groups related elements in a <option> An option in a dropdown list.
form. <output> The result of calculation.
<figcaption> Defines a caption for a <figure> <picture> Defines a container for multiple
element image resources.
<figure> specifies self contained <script> Defines a client-side script.
<font> Defines font, color and size for <section> A section in a document.
text <small> Defines smaller text.
<footer> A footer for a document or section <source> Defines multiple media resources
<form> HTML form for user input for media elements.

Web Technology 143 YCT


Search on TG: @apna_pdf
<span> A section in a document. Example–
<style> Defines style information for a <img src="imageName" alt="AltName">
document. HTML Favicon– A favicon is a small image
<sub> Subscripted text. displayed next to the page title in the browser
tab. To add a favicon to your website, either save
<summary> Defines a visible heading for a
your favicon image to the root directory of your
<details> element.
web server, or create a folder.
<sup> Defines superscripted text.
Add favicon
<svg> A container for SVG graphics.
<link rel=-"icon" type="image/icon"
<table> Defines a table. href="favicon path">
<tbody> Groups the body content in a List
table.
A list is a record of short pieces of related
<td> Defines a cell in a table. information or used to display the data or any
<textarea> A multiple input control. information on web pages in the ordered or
<time> a specific time unordered form.
<track> Defines text tracks for media
element (<video> and <audio>)
<var> Defines a variable.
<video> Defines embedded video content.
<wbr> A possible line-break.
Unordered List
Absolute URLs and Relative URLs An unordered list starts with the <ul> tag. Each
A full web address are using an absolute URL in list item starts with the <li> tag list items will be
the href attribute. marked with bullets by default.
Example– Unordered list marker– Use the CSS property
<a href="https://www.google.com/">Google</a> list_style_type, define the style of the list item
A local link (a link to a page within the same marker.
website) is specified with a relative URL disc– item marker to a bullet
(without the "https://www"),
circle– item marker to a circle
Example–
square– list item marker to a square
<a href="html_page.php">HTML File
none– the list items will not be marker
</a>
Example–
Link to an Email Address <ul style="list-style-type: square;">
Use mailto: inside the href attribute to create a <li> Rahul </li>
link that opens the user's email program (to let
<li> Raj </li>
them send a new email.)
</ul>
Example–
<a href="mailto:[email protected]"> Ordered list
Send Mail </a> An ordered list starts with the <ol> tag. Each list
HTML Image– The HTML <img> tag is used to item starts with the <li> tag. The list by default
embed an image in a web page. The <img> tag is marked will numbers.
empty, it contains attributes only and does not ordered list used to type attributes type
have a closing tag <img> tag has two attributes defines the list item marker.
src– Specifies the path to the image type = "1" ⇒ by default
alt– Specifies an alternate text for the image. type = "A" ⇒ Item numbered with upper case
Web Technology 144 YCT
Search on TG: @apna_pdf
type = "a" ⇒ Item numbered with lowercase
type = "I" ⇒ Item numbered with upper roman
numbers
type = "i" ⇒ Item numbered with lower roman
numbers Semantic Elements
Example– Semantic elements have meaningful names
<ol type = "1, A , a, I, or i"> which tells about type of content like header,
<li> Rahul </li> footer, table, .....etc.
<li> Raj </li> Semantic Elements– <article>, <aside>,
</ol> <details>, <figcaption>, <figure>, <footer>,
<header>, <main>, <mark>, <nav>, <section>,
List Tags–
<summary>, <time>.
<ul> ⇒ Defines unordered list
Non-semantic Elements
<ol> ⇒ Defines ordered list
Non-semantic categories as their names don't tell
<li> ⇒ A list item
anything about what kind of content is present
<dl> ⇒ Description list inside them <div> and <span> is non-semantic
<dd> ⇒ The term in a description list elements.
Head Element Form
The <head> HTML element contains machine HTML form on a web page allows a user to enter
readable information (metadata) about the data that is sent to a server for processing.
document. <form> element is a container for different
like <title>, <style>, <meta>, <link>, <script> types of input elements such as: text fields,
and <base> checkboxes, radio buttons, submit buttons etc.
<meta> element– The <meta> element is Form Attributes–
typically used to specify the character set, page Action- The action attributes define the action to
description, keywords, author of the document be performed when the form is submitted.
and viewport settings. Target- The target attribute specifies where to
Example– display the response that is received after
The character set used– submitting the form.
<meta charset = "UTF-8"> target value ⇒ _blank, _self, _parent, top,
framename.
Keywords for search engines–
Method– The method attributes specifies the
<meta name = "keywords" content = "HTML,
HTTP method to be used when submitting the
CSS, Javascript">
form data.
A description of your web page–
method = "get"
<meta name = "description" content =" Free
method = "post"
online PDF">
The author of page–
<meta name = "author" content ="YCT">
Refresh document every 30 seconds–
<meta http_equiv = "refresh" content="30"> Get method is mainly used at the client side to
Setting the viewport to make your website look send a request to a specified server to get contain
good on all devices. data or resources. It is send to limited data.
<meta name = "viewport" content = width = Post method sent to the server is stored in the
device-width, initial-scale =1.0"> request body of the HTTP request.
Web Technology 145 YCT
Search on TG: @apna_pdf
Multimedia Web Storage
Multimedia comes in many different formats. It Web storage can store data locally within the
can be almost anything you can hear or see, like, users browser.
images, music, sound, video, records, films,
animations and more.
Common Video Formats
Format File
LocalStorage– Stores data with no expiration
MPEG .mpg date and gets cleared only through JavaScript or
.mpeg clearing the browser cache/locally stored data.
AVI .avi SessionStorage– Stores data only for a session
meaning that the data is stored until the browser
WMV .WMV
(or tab) is closed. Storage limit is larger than a
QuickTime .mov cookie (at most 5 MB).
Realvideo .rm Web Worker– Web workers are multithreaded
.ram object which is used to execute JavaScript in the
background without affecting the performance of
Flash .swf
the application or webpage.
.flv
Server Sent Events (SSE)
ogg .ogg A server sent events is when a web page
WebM .webm automatically gets updates from a server via an
HTTP connection. This is a one way connection.
MPEG-4 or MP4 .mp4
The event source object is used to receive server
Note– Only MP4, WebM and Ogg Video are sent event notification.
supported by the HTML standard.
Events Description
Common Audio Formats– MP3 is the best
onopen When a connection to the server is
format for compressed recorded music. The term opened.
MP3 has become synonymous with digital onmessage When a message is received.
music. onerror When an error occurs.
Format File
DHTML
MIDI .mid
DHTML stands for Dynamic HTML, it is totally
.midi
different from HTML. DHTML is based on the
RealAudio .rm properties of the HTML, JavaScript, CSS and
.ram DOM which helps in making dynamic content.
DHTML is used to create interactive and
WMA .wma
animated web pages that are generated in real
AAC .aac time, also known as dynamic web pages so that
WAV .wav when such a page is accessed the code.
Ogg .ogg HTML– HTML stands for Hyper Text Markup
Language and it is a client side markup language.
MP3 .mp3
It is used to build the block of web pages.
Note– Only MP3, WAV and Ogg audio are JavaScript– It is client side scripting language
supported by the html standard. that enables you to create dynamically updating
Web Technology 146 YCT
Search on TG: @apna_pdf
content, control multimedia, animate images and The version = "1.0" is the version of the XML
pretty much everything else. currently used.
CSS– CSS is a language of style rules that we The encoding = "UTF-8" specifies the character
use to apply styling to our HTML content, for encoding used while writing an XML document.
example setting background colors and fonts and XML Valid and Well Formed– XML document
laying out our content in multiple columns. must be well formed. Document must conform to
DOM– DOM is known as a Document Object all XML syntax rules. Document conform to
Model which act as the weakest links in it. semantic rules, which are usually set in an XML
XML schema or a DTDC (document type definition).

XML stands for Extensible Markup Language. It Example–


was designed to store and transport data. It is <?xml version = "1.0" encoding = "UTF-8"?>
called extensible because it allows the author of <message>
the document to defines the markup elements by <warning>
their own. Hello Rahul
Advantages of XML– </warning>
• XML support Unicode, all most all the human </message>
readable written language can be XMLHttpRequest Object
communicated using XML.
The XMLHttpRequest object can be used to
• It can be used to render data structure i.e request data from a web server.
records and lists and trees.
• Update a web page without reloading the page.
• XML needs another software application called
• Request data from a server after the page has
parser. An XML document is very strict while
loaded.
maintaining a standard.
• Received data from a server after the page has
• XML is used both on and offline for storing and
loaded.
processing data.
• Send data to a server in the background.
• XML allows validation of the document using
XSD or schematron. These are types of the XMLHttpRequest Properties
schema for validating XML documents. readyState– Indicate the status of the
Difference Between XML and HTML connection.

XML was designed to carry data with focus on Status– It contains the http response code string
what data is. from server.
HTML was designed to display data with focus StatusText– It contains the http response string
on how data looks. from the server.responseText. It contains the
XML tags are not predefined like HTML tags response in text format from the server.
are. responseXML– It contains the response XML
In XML all elements must have a closing tag. from server.
XML tags are case sensitive. getAllResponseHeaders– It returns all the
XML Declaration– XML declaration is not a headers name as string.
tag. It is used for the transmission of the meta OverrideMimeType– It is used to set the mime
data of a document. type which is used to treat the response data type
Syntax– to be treated as text or XML type.
<?xml version = "1.0" encoding = "UTF-8"?> DTD– DTD stands for Document Type
This line represents the XML prolog or XML Definition. DTD defines the structure and the
declaration. The XML prolog is optional. It if legal elements and attributes of an XML
exists, it must come first in the document. document.

Web Technology 147 YCT


Search on TG: @apna_pdf
Schema– XML schema describes the structure of ECMAScript Added string,
an XML document. XML document with correct (2017) padding,
syntax is called "Well Formed". object.entries(),
object values()
JavaScript
added async
JavaScript is a programming language that
functions and shared
execute on the browser. It turns static HTML
memory, Allows
web pages into interactive web pages by
trailing commas for
dynamically updating content, validating form
function parameters.
data controlling multimedia animate images and
almost everything else on the web pages. ECMAScript Added rest/spread
Versions of JavaScript– In the years 1996, a (2018) properties,
standards organization called ECMA (European asynchronous
Computer Manufacture Association). iteraction, and
International carved out standard specifications promise.finally(),
called ECMA script (ES). ReqExp

ECMAScript Editions ECMAScript String.trimstar()


(2019) string.trimEnd()
Version Official Name Description
Array.flat(),
ES1 ECMAScript1 First edition object.fromEntries
(1997) optional catch
ES2 ECMAScript2 Editorial changes binding
(1998) ECMAScript The Nullish
ES3 ECMAScript3 Added regular (2020) Coalescring
(1999) expressions added operator(??)
try/Catch Added
Switch Added do-
Variable
Variables are containers for storing data (storing
while
data values.)
ES4 ECMAScript4 Never released
ES5 ECMAScript5 Added "strict mode",
(2009) JSOn support,
string.trim(),
Array.isArray() and
Added Array
iteration methods
Allows trailing
commas for object
literals.
ES6 ECMAScript Added let and const,
(2015) default parameter
values and Added
Array.find(),
Array.findIndex()
ECMAScript Added exponential Undefined

(2016) operator (**),


Array.includes()

Web Technology 148 YCT


Search on TG: @apna_pdf
BigInt– JavaScript BigInt variables are used to };
store big integer values that are too big to be document.getElementById("demo").
represented by a normal JavaScript number. innerHTML = person.fullName();
Undefined– A variable without a value has the </script>
value undefined. The type is also undefined. </body>
Null– The null value represents the intentional </html>
absence of any object value. It is treated as false Output–
for Boolean operations.
Rahul Kumar
Regular Expression– A regular expression is a
sequence of characters that forms a search
Arrow Function
pattern. Regular expressions are often used with Arrow function allow us to write shorter function
syntax.
the two string methods search() and replace().
The search() method uses an let myFunction = (a, b) ⇒ a*b;
expressions to search for a match and returns the Example–
position of the match. <html>
The replace() method returns a <body>
modified string where the pattern is replaced. <p id="demo"></p>
Regular Expression Modifiers– Modifiers can <script>
be used to perform case insensitive more global let hello = " ";
searches. hello = ( ) ⇒ {
Modifier Description return "Hello World";
i Perform case insensitive matching }
g Perform a global match(find all document.getElementById("demo").innerHTML
matches rather than stopping after = hello();
the first match) </script>
m Perform multiline matching. </body>
</html>
This Keyword
The this keyword refers to an object. Which Modules
object depends on how this is being invoked. Modules allow you to break up your code into
Note– This is not a variable. It is keyword you can't separate files modules are imported from
change the value of this. external files with the import statement. And also
Example– rely on type = "module" in the <script> tag.
<html> Example–
<body> <html>
<p id="demo"></p> <body>
<script> <p id = "demo"> </p>
const person = { <script type = "module">
firstName: "Rahul", import message from
lastName: "Kumar", "/message.js";
id: 1001, document.getElementById("demo").inner
fullName: function() { HTML = message();
return this.firstName +" " + </script>
this.lastName; </body>
} </html>
Web Technology 149 YCT
Search on TG: @apna_pdf
Servlet Architecture–

Syntax–
1. Export variable_name = value;
2. Variable_name = value;
Execution of Servlets–
export {variable_name}
1. The clients send the request to the web server.
Java 2. The web server receives the request.
Java was developed by James Gosling at 3. The web server passes the request to the
SunMicro system in the year 1995, later acquired corresponding servlet.
by oracle corporation. It is a simple 4. Servlet process the request and generates the
programming language. Java is an object response in the form of output.
oriented programming language with its runtime 5. The servlet sends the response back to the web
environment. It is combination of features of C server.
and C++ with some essential additional concepts. 6. The web server sends the response back to the
client and the client browser displays it on the
screen.
Applets
An Applet is a java program that can be
embedded into a web page. It runs inside the web
browser and works at client side. An Applet is
embedded in HTML page using the APPLET or
OBJECT tag and hosted on a web server. Applet
are used to make the website more dynamic and
entertaining.
Lifecycle of Applet

Servlets
Servlet is a server side java program module that
handles client requests and implements the
servlet interface. Servlets can respond to any
type of request and they are commonly used to
extend the application hosted by web servers.
Servlet is a web component that is deployed on
the server to create a dynamic page.
When an Applet begins, the following methods
Properties of servlets are as follows– Servlets are called in this sequence.
work on the server side. Servlets are capable of 1. init()
handling complex requests obtained from the 2. start()
web server. 3. paint()

Web Technology 150 YCT


Search on TG: @apna_pdf
When an Applet is terminated the following Python Programming
sequence of method calls takes place. Python is a general purpose, dynamic, high-level,
1. stop() and interpreted programming language.
It supports an Object Oriented programming
2. destroy()
approach to develop applications and
init()– The init() method is the first method to be It is used in web development, data science,
called. This is where you should initialize creating software prototypes, and so on.
variables. This method is called only once during Fortunately for beginners, Python has simple
easy-to-use syntax and this makes Python an
the run time of your Applet. excellent language to learn to program for
start()– The start() method is called after init(). It beginners.
is also called to restart an Applet after it has been History of Python
stopped. Python was created by Guido van Rossum, and
first released on February 20, 1991.
paint()– The paint() method is used to paint the The name of the Python programming language
Applet. It provides graphics class object that can comes from an old BBC television comedy sketch
be used for drawing oval, rectangle, arc etc. series called Monty Python’s Flying Circus.
stop()– The stop() method is called when a web Keywords in Python programming
In Python, keywords are case sensitive and they
browser leaves the HTML document containing
are reserved words. That means we cannot use
the applet, when it goes to another page. keywords as a variable or function.
destroy()– The destroy() method is called when Keywords are used to define the syntax and
structure of the Python language.
the environment determines that your Applet
Following are some keywords available in Python
needs to the removed completely from memory. programming language.
There are two standard ways to run an False await else import pass
Applet– None break except in raise
True class finally is return
1. Executing the Applet within a java compatible
and continue for lambda
web browser. as def from nonlocal while
2. Using an Applet viewer. assert del global not with
1. Using java enabled web browser– To async elif if or yield
try
execute an Applet in a web browser we have to
Note:- All the keywords except True, False and None are
write a short HTML text file that contains a tag in lowercase and they must be written as they are.
that loads the Applet. We can use APPLET or Python Identifiers
OBJECT tag for this purpose. An identifier is a name given to entities such as
class, functions, variables, etc.
<applet code = "HelloWorld" width = 200
It helps to differentiate one entity from another.
height = 60>
Rules for Defining Identifiers
</applet> 1. An identifier cannot start with a digit.
2. Using Applet Viewer– This is a easiest way For example-
to run Applet. To execute HelloWorld with an a1( valid declaration)
But 1a is not a valid declaration.
Applet viewer, you may also execute the HTML
2. Keywords cannot be used as identifiers.
file shown earlier. For example-
If the preceding HTML file is saved with assert = 1
HelloWorld html, then the following command 3. Special symbols such as !, @, #, $, % etc.
cannot be used as an identifier.
line will run HelloWorld.
For example-
appletviewer RunHelloworld.html b$ = 3
Web Technology 151 YCT
Search on TG: @apna_pdf
Variables in Python print("Value of N_new:",N_new)
Defining variables- print("datatype of N_new:",type(N_new))
In Python, variables are containers for storing data After running the above code we get output as :-
values. datatype of N_int: <class 'int'>
Variable is a name that is used to refer to memory datatype of N_float: <class 'float'>
location. Variables in python are also known as an
identifier and used to hold value. Value of N_new: 10.5
For example- datatype of N_new: <class 'float'>
a = 10
x = "welcome to yct" Explicit Type Conversion
print(a) In explicit type conversion, users convert the data
print(x) type of an object to required data type and for that
Output– we use the predefined functions such as int(),
10 float(), str(), etc to perform explicit type
welcome to yct conversion.
Data Type in Python Syntax–
Every value in Python has a data type. Since <required_datatype>(expression)
everything is an object in Python programming, For example– To add string and integer data types using
data types are actually classes and variables are explicit type conversion.
instances (object) of these classes. a = 50
Following diagram demonstrates the various types b = “100”
of data types in python programming language. result1 = a + b
b = int(b)
result2 = a + b
print(result2)
Output–
Traceback (most recent call last):
File “”, line 1, in
Type Conversion in Python– TypeError: unsupported operand type(s) for +:
The process of converting the value of one data ‘int’ and ‘str’
type such as (integer, string, float, etc.) to another
150
data type is known as type conversion. There are
In the above example, variable a is of the number
two types of type conversion.
data type and variable b is of the string data type.
Implicit Type Conversion When we try to add these two integers and store
In Implicit type conversion, Python automatically the value in a variable named result1, a TypeError
converts one data type to another data type. occurs as displayed in the output. So, in order to
For example– perform this operation, we have to use explicit
Converting integer to float- type casting. As we can see in the above code
N_int = 5 block, we have converted the variable b into int
N_float = 5.5 type and then added variables a and b. The sum is
N_new = N_int + N_float stored in the variable named result2, and when
print("datatype of N_int:",type(N_int)) printed it displays 150 as output, as we can see in
print("datatype of N_float:",type(N_float)) the output block.
Web Technology 152 YCT
Search on TG: @apna_pdf
Python Namespace For example–
A namespace is a collection of names and python fruits = ["mango", "banana", "orange"]
implements namespaces as dictionaries. for x in fruits:
A namespace allows us to have unique names for print(x)
each object If we don’t know, this is just a quick Output– mango
reminder to tell us that strings, lists, functions, etc. banana
everything in python is an object.
orange
In other words, we can say that the role of a
While Loop– With the help of while loop we can
namespace is like a surname.
execute a set of statements as long as a condition
Namespaces are of basically three types:-
is true.
1. Built-in Namespace– It includes functions and
Syntax–
exception names that are built-in in Python.
2. Global Namespace– It includes names from while test_expression:
the modules that are imported in the project. It is body of while
created when we include the module and it lasts For example–
until the script ends. i=1
3. Local Namespace– It is created when the while i < 5:
function is called and the scope ends when the value print(i)
is returned.
i += 1
if...else Statement in python Output–
If statement 1
Syntax–
2
if test exp:
3
statement(s)
4
if...else Statement
Syntax– Break Statement in Python
if test exp: With the help of break statement we can stop the
Body of if loop even if the while condition is true.
else: For example- Exit the loop when i is 4.
Body of else i=1
if...elif...else while i < 8:
Syntax– print(i)
if test exp: if (i == 4):
Body of if break
elif test exp: i += 1
Body of elif
Output–
else:
1
Body of else
2
Loop in Python Programming 3
For loop– A for loop is used for iterating over a
4
sequence (that is either a list, a tuple, a dictionary,
, or a string). Pass Statement in Python
Syntax– In Python programming, the pass statement is a
for val in sequence: null statement. It is generally used as placeholder.
loop body Syntax– pass
Web Technology 153 YCT
Search on TG: @apna_pdf
Errors and Exceptions in Python Example– tuple = ("Rahul", "Yct", "Raj")
Syntax Errors– when error caused by not print(tuple)
following the proper syntax of the language is Output– ("Rahul", "Yct", "Raj")
called syntax error or parsing error. Tuple Methods
Exceptions– when errors occurring at runtime Method Description
(after passing the syntax test) are called
count() Return the number of times a
exceptions or logical errors.
specified value occurs in a tuple
List
index() Searches the tuple for a specified
List are used to store multiple items in a single
value and returns the position of
variable. List are created using square brackets.
List items are ordered, changeable and allow where it was found
duplicate values. And list first item has index [0] Set– Sets are used to multiple items in a single
and second item has index [1]. variable and it is collection which is unordered,
Example– list = ["Rahul", "Raj", "Kumar"] unchangeable and unintexed sets are written with
print(list) curly brackets. Sets can't allow duplicate value.

Output– ['Rahul', 'Raj', 'Kumar'] Example–


theset = {"Rahul", "Kumar", "Raj" "Rahul")
List Methods
print(theset)
Method Description Output– ("Kumar", "Raj", " Rahul")
append() Adds an element at the end of the Set Methods
list
Method Description
clear() Removes all the element from the
add() Adds an element to the set
list
clear() Remove all the elements
copy() Returns a copy of the list
from the set
count() Returns the numbers of element
with the specified value copy() Returns a copy of the set

index() Returns the index of the first difference() Returns a set containing the
element with the specified value difference between two or
more sets
insert() Adds an element at the specified
differecne_update() Remove the items in this
position
set that are also included in
pop() Removes the element at the
another, specified set
specified
remove() Removes the item with the pop() Removes an element from
specified value the set
reverse() Reverses the order of the list remove() Remove the specified
sort() Sorts the list element
Tuple– Tuples are used to store multiple items in union() Return a set containing the
a single variable. A tuple is a collection which is union of sets
ordered and unchangeable and tuples are written
update() Update the set with the
with round brackets. Tuple items are indexed the
first item has index [0] and second index[1]. union of this set and others

Web Technology 154 YCT


Search on TG: @apna_pdf
Dictionary– Dictionaries are used to store data Array
value in key value pairs. It is written with curly
An array is a special variable which can hold
brackets. A dictionary is a collection which is
more than one value at a time. In order to create
ordered, changeable and is not allow duplicates.
Python arrays. You will first have to import the
Example–
array module.
thedict={"brand": "Ford",
Array Import
"Model":" Mustang",
Using import array at the top of the
"year": 1954
file. You would then go to create an
}
array using array.array().
print(thedict)
Instead of having to type array.array()
Output– {'brand': 'Ford', 'Mode': 'Mustang', 'year' "
1954} all the time, use import array as arr at
the top of the file or arr.array().
Dictionary Method
Use from array import* with*
Method Description
importing all the functionalities
clear() Removes all the elements
available.
from the dictionary
Example–
copy() Returns a copy of the
import array as arr
dictionary
numbers = arr.array('i', [10, 15, 20])
get() Returns the value of the
print(numbers)
specified key
Output–
items() Returns a list containing a
array('i',[10, 15, 20])
tuple for each key value
pair Methods of array
keys() Returns a list containing Method Description
the dictionary's keys append() Adds an element at the end of the list.
pop() Removes the element with clear() Removes all the elements from the list.
the specified key
copy() Returns a copy of the list.
popitem() Removes the last inserted
count() Returns the number of element with the
key value pairs
specified value.
update() Updates the dictionary
index() Returns the index of the first element
with the specified key-
with the specified value.
value pairs
insert() Adds an element at the specified
values Returns a list of all the
position.
values in the dictionary
pop() Removes the element of the specified
setdefault() Returns the value of the
position.
specified key. If the key
does not exist, insert the remove() Removes the first item with the

key with the specified specified position.


value reverse() Reverses the order of the list.

Web Technology 155 YCT


Search on TG: @apna_pdf
Module RegEx in Python
A module to be the same as a code library. A file A regular expression is a sequence of characters
containing a set of function you want to include that defines a search pattern. A pattern defined

in your application. A file with the file extension using RegEx can be used to match against a

.py. string.

Iterators in Python–
How to use Module and Variable– The module
An iterator is an object that implements the
we just created by using the import statement.
iterator protocol. In other words, an iterator is an
Module create variables of all types (arrays,
object that implements the following methods:
dictionaries, objects).
__iter__ - It returns the iterator object itself.
Example–
__next__ - It returns the next element.
file name mymodule.py Generators in Python–

company={ Python generators are a simple way of creating

"Name": "Yct", iterators.

A generator is a special type of function which


"Model": 1993,
does not return a single value, instead, it returns
"City": "Prayagraj"
an iterator object with a sequence of values.
}
In a generator function, a yield statement is used
So, import the module named my module and rather than a return statement.
access the company.
File Handling in python
import mymodule
Python has a number of functions for creating,
x= mymodule.company["model"]
reading, updating, and deleting files. The key
print(x) function for working with files in Python is the

Output– 1993 open() function. The open() function takes two

parameters; filename, and mode.


Exception Handling in Python
f = open(filename, mode)
When exceptions occur, the Python interpreter
There are four different modes for opening a file:-
stops the current process and passes it to the
"r" - Read - Opens a file for reading
calling process until it is handled. If not handled,
"a" - Append - Opens a file for appending
the program will crash. These exceptions can be
"w" - Write - Opens a file for writing
handled using the try statement. "x" - Create - Creates the specified file

Web Technology 156 YCT

Powered by TCPDF (www.tcpdf.org)


Search on TG: @apna_pdf

12. SOFTWARE ENGINEERING


delivery life cycle since this is the part where the
Software Development Life Cycle
(SDLC) team estimates the cost and defines the
SDLC is a process followed for a software requirements of the new software.
project, within a software organization. It Stage 2
consists of a detailed plan describing how to Analysis–Analyzing maximum information
develop, transit, replace, maintain and alter or from the client requirements for the software,
enhance particular software. the team has to discuss each details and
SDLC defines a methodology for improving the specification of the product with the customer
quality of software and the overall development and then analyze the requirements keeping the
process. design code of the software in mind.

Graphical representation of the various stages Stage 3


or steps of a typical SDLC: Designing– In this stage, Developers will first
outline the details for the overall application as
input and software architecture of the end user.
Designing helps the overall system architecture.
It serves as input for the next phase of the model
such as user interface, system interface, network,
and network requirements and database.
In designing phase, there are two kinds of
design documents:-

The SDLC is a structured process that enables


the production of high-quality, low-cost software
in the shortest production time. The goal of the
SDLC is to produce superior software that meets Stage 4
Building or Developing– In this stage, the
and exceeds all customer expectations and
actual development starts and the product is
demands, by the following of above
built. If the design is performed in a detailed and
stages/steps:-
organized manner, code generation can be
Stage 1
accomplished without much hassle. Hence,
Planning– Project planning is all about "What
programming code is generated as per DDS
do we want?" It is vital role in the software
during this stage.

Software Engineering 157 YCT


Search on TG: @apna_pdf
Stage 5

Coding or Implementation– Coding starts once


the developer gets the design document. The
software design is translated into source code. It
means translating the design to a computer-
legible language. File conversion, user training,
and new changes to the system are belong to this
stage/phase.

Stage 6

Testing– Testing is done by testing team to


verify that the functionality of entire application
works according to the customer requirements.
By finding some bugs/defects, the team fixes
them and sends back for a re-test. This process
continues until the software is bug-free, stable Waterfall Model– It is linear and straight-
forward and requires development teams to
and working according to the business needs of
finish one phase of the project completely before
that system. moving on the next.
Stage 7 Hence, the outcome of one phase acts as input
for the next phase. This model is not suitable for
Deployment or Installation– Product is
accommodating projects.
deployed in the production environment or first Example–
UAT (User Acceptance Testing) depending on Requirements
the customer expectation, then based on the Specification
Design
feedback given by the project manager, the final
Evaluation
software is released and checked for deployment Testing
issues if any. Iterative Model– This model focuses or stresses
on repetition and repeat testing. Developers
Stage 8
create a version rapidly for relatively less cost,
Maintenance– If any issue comes up in then test and improve it through successive
deployment phase and needs to be fixed or any versions.
Example–
enhancement, it is taken care by the developers
by using following three activities, because
maintenance phase of SDLC is most effected
during costly faults is introducing:

Software Engineering 158 YCT


Search on TG: @apna_pdf
Spiral Model– Spiral model starts with analysis. Example–
This model is flexible compared to other
methodologies. Projects pass through four main
phases again and again in a metaphorically spiral
motion. It is a risk-driven process model. It
resembles in its emphasis on repetition and
project risk factor is considered which is
Agile Model– It is a group of Iterative and
inefficient for smaller projects. Until the
software retires, it will continue. incremental model. In this model, any product is

Example– broken into small incremental builds as this

Spiral model has four phases:- model focuses more on flexibility rather than on
requirement while developing any product. New
features can be added easily in this model.
Agile does not rush the team to deploy the
product to customers but to perform testing at
the end of each sprint.

V-Model– This model is also known as


verification and validation model. In this model,
verification and validation goes hand-in-hand
i.e. development and testing goes parallel as it
Example–
includes tests at each stage of development. V-
model joins by coding phase.
Example–

Prototype Model– In this model, the prototype


is developed prior to the actual software. This
model has limited functional capabilities and
inefficient performance when compared to the
actual software. It gets the valuable feedback
from the customer. Feedbacks are implemented
and the prototype is again reviewed by the
customer for any change.
Software Engineering 159 YCT
Search on TG: @apna_pdf
Big Bang Model– This model is used for Money and efforts are put together as the input
smaller projects and experimental life cycle and output come as a developed software which
designed to inform other projects within same might be or might not be the same as the
company. requirements of customer, in this model.

Software Metrics: Software Project


Management
Software Metrics- It is standard measurement
for the estimation of quality, progress, health
This model is flexible because it doesn't follow and testing of software characteristics which are
any rigorous procedures or processes. It starts measurable or countable and quantifiable. It
with little planning and moves to the coding includes measuring software performance,
stage because it does not have requirements of planning work items, productivity and many
much scheduling and planning. other uses.

Classification of software Metrics

Software Engineering 160 YCT


Search on TG: @apna_pdf

In order to
p

M
C
by gathering

Software Engineering 161 YCT


Search on TG: @apna_pdf

Formula for Test metrics


If anyone wants to get the percentage of the test cases, the following formula can be useful;-
Sr. No. Percentage (%) of Formula
No. of test cases executed
1. Test cases executed × 100
Total no. of test cases

No. of detected defects


2. Test case effectiveness × 100
No. of running test cases

Total no. of test run


3. Passed test cases × 100
Total no. of test executed

Total no. of failed test cases


4. Failed test cases × 100
Total no. of test executed

Total no. of blocked tests


5. Blocked test cases × 100
Total no. of test executed

Total no. of flaues fixed


6. Fixed defects × 100
No.of defects reported

Actualrework efforts
7. Rework effort ratio × 100
Totalactualefforts

Defects accepted
8. Accepted defects × 100
Total defects

Deferred defects for future use


9. Defects deferred × 100
Total defects reported

Let's take an Example to Calculate Test Metrices


Data retrieved while developing
Sr. No. Testing Metrics
test cases
1. No. of requirements 5
2. No. of test cases 40
3. Total no. of test cases 200
4. Total no. of test cases executed 164
5. No. of passed test cases 100
6. No. of failed test cases 60
7. No. of blocked test cases 4
8. No. of unexecuted test cases 36
9. Total no. of defected test cases 20
10. Accepted defects 15
11. Defects deferred for future use 5
12 Fixed defects 12

Software Engineering 162 YCT


Search on TG: @apna_pdf
Solution for the above example is written below:-

Software Project Management- It is a proper way of


Software Project Management (SPM)
planning, leading, execution, supervision and control of
Project- A project is a collection of tasks as inputs and
software project. It is also a discipline and skill for
outputs needed to achieve a particular goal while a
organizing and managing software projects. It is
software project is the complete procedure of software
necessary to incorporate user requirements along with
development. budget and time constraints.

Software Engineering 163 YCT


Search on TG: @apna_pdf

Software Engineering 164 YCT


Search on TG: @apna_pdf
following them any organization can protect the integrity
of the software.
Needs/Requirements of Software Project
Management– For any software organization while
staying within the customers budget and completing the
product on time, delivering a high-quality product is an
essential part. time, cost and quality are the triple factors
of many factors including both internal and external
which may impact the other two.

The above list of focus areas that can tackle the broad
upsides of the software project management and by
Down sides of Software Project Management

If one wants to engage software project management


technique to put in place, these initiatives can be costly A project manager is a person who
and time consuming. One could need instruction since
makes both large and small
one's team will also be utilizing them. A project may
need help of professional or subject experts depend on projects and all types of decisions
situation.
and is responsible for planning,
It is multi-step difficult procedure tending to complicate
things excessively which may lead to provide confusion designing, monitoring, controlling,
among team. Project having a larger scope especially if it
executing and closure of a project.
doesn't have a dedicated team.
For the software project management, when we hire Role of a Project Manager
individuals, new hires join our company with or without 1. As a leader – What the team is expected is leaded
having company's culture then they can be kept at and guided by a project manager by providing them
workforce as small as possible. Resulting that the cost of direction to make them understandable.
communication tends to soar. 2. As a medium – A project manager may be a
medium between his clients and team if he
Sometimes. project managers provide little or no space
coordinates them and transfers all related
for creativity. To initiate rigid standard, the team leaders
information from clients to his team and reports to
either put much focus on management or put strict time
the senior management.
on staff, or encourage creativity. That is why an
3. As a team motivator – To encourage team member
organization can build and ship code quickly else it to work properly for the successful completion of
opens up new doors to achieve more objectives. the project.
Software Engineering 165 YCT
Search on TG: @apna_pdf
4. As a team organizer – To organize teams to deliver 4. Managing Project Risk – The following risks in a
on an outcome such as functions, structure and project consist of all activities like monitoring,
communications etc. analyzing, preparing and identification of the plan:-
5. As a mentor – A team must have an attachment The experienced team (staff) leaves the project and
guided by a mentor to his team at each step to the new team joins it.
provide a recommendation in the right direction. Changes in organization, requirements,
technologies, environment, business competition and
misinterpreting needs.
5. Managing Scheduling – It refers to roadmap with
specified order within time slot allotted to each
activity. It defines various tasks, milestones and
arrangement by keeping many factors in mind.
It is necessary to find out multiple tasks, break down
them into smaller, and manageable modules,
estimate time frame for each task, calculate the total
time from start to finish, etc.
6. Managing Project Communication – Effective
communication from planning to closure in the
1. Planning and Tracking Project – Planning and success of a project, it plays a vital role and bridges
tracking projects are multiple processes or tasks that gap between clients, team members, organizations as
are executed before the construction of the software well as other project creator or developer by
product starts, by managing project resource. following many steps like planning, sharing,
2. Managing Scope – Scope management avoids price feedback and closure.
and time overrun and clearly defines what would do 7. Managing Configuration – It controls the changes
and what would not. in software like need, design, functions and
3. Managing Estimation – It figures out the size (line development of the project. Configuration
of code), efforts, cost as well as time. management is needed because several people work
The line of code depends on the users or their needs. on software, help to build coordination between
By the help of efforts, a developer can quickly suppliers, run on multiple systems, change in need,
estimate how big team are needed to inform the budget, schedule, etc. by performing many tasks
software. including identification, base-line, change control,
The time can be easily determined when size and status accounting, audits and reviews.
efforts are estimated. Baseline defines completeness of a phase, change
Cost includes size, quality, hardware, control ensures all changes made to software system
communication, training, licenses, tools and skilled by using many steps like identification, validation,
manpower. analysis, control, execution and close request.

Software Engineering 166 YCT


Search on TG: @apna_pdf
Project Estimation Techniques
There are two broadly recognized techniques:-
Decomposition Technique Empirical Estimation Technique
It Assumes the software as a product of various It uses derived formula to make estimation based on LOC
compositions. It has two main model. or FPs

Line of code (LOC) Function Points (FPs) PUTNAM Model COCOMO


In the software product, In the software product, It maps time and efforts Software products are divided
LOC estimation is FPs estimation is needed with software size. into three categories of
completed on behalf of completed The PUTNAM model is software organic, semi-
number of line of codes. on behalf of number of made by Lawrence H. detached and embedded by
function points. Putnam, which is based on cocomo, which stands for
Norden's frequency COnstructive COst MOdel,
distribution (Rayleigh developed by Barry W.
curve) Boehm.

Difference between COCOMO-1 and COCOMO-2


COCOMO-1 COCOMO-2
It provides estimates of effort and schedule. It provides the estimates that represent one standard
deviation.
It is useful for waterfall model of SDLC (Software It is useful in non-sequential, rapid development.
Development Life Cycle).
It is based on linear reuse formula. It is based on non-linear reuse formula.

Effort exponent is determined by 3 development Effort exponent is determined by 5 scale factors.


models.
Size of software stated in terms of lines of code Size of software stated in terms of object points (OPs),
(LOC). Function Points (FPs) and Line of Code (LOC).

Software Engineering 167 YCT


Search on TG: @apna_pdf
COCOMO Model in Brief –
Cost estimation model developed by Boehm in 1981.
Regression model based on LOC (no of Lines of Code)
Predicts the effort (E) and schedule (D) of product based on size of software.
A cocomo model addresses the area of application composition model, early design state model and Post
architecture model.
Based on size
(i) Organic 1. Basic COCOMO Model
Example- Data processing, Inventory management system etc.
(ii) Semi-Detached 2. Intermediate model
Example- OS, DBMS, etc.
(iii) Embedded 3. Detailed or Complete Model
Example- ATM, Air Traffic Control, etc.
Intermediate model is an expansion of basic cocomo model while complete cocomo model is an expansion of
intermediate cocomo model.

(1)
Basic model KLOC model a1 a2 b1 b2
a2
E=a1(KLOC) P.M (2-50) Organic 2.4 1.05 2.5 0.38

D=b1 (E)b2 M (50-300) Semi-detached 3.0 1.12 2.5 0.35

KLOC (>300) Embedded 3.6 1.2 2.5 0.32


Productivity=
E

Where E=effort, D=development time.

(2)

Intermediate model Model 15 Cost Drivers


(Attribute)

E=a1(KLOC)a2 * EAF Product RELY, DATA, CPLX (Complexity)


(Effort Adjust Factor)

Project MODP, TOOL, SCED


D=b1Eb2

System TIME, STOR, VIRAT, TURN

Personnel ACAP, AEXP, PCAP, VEXP, LEXP

Software Engineering 168 YCT


Search on TG: @apna_pdf

Example– 1=> Solution- The most appropriate mode for 200 KLOC is

semi-detached mode.
Suppose a project was estimated to be 400 KLOC.
Hence, E=3.0(200)1.12=1133.12 PM
Calculate the effort and development time for each of the

three models i.e., organic, semi-detached and embedded. D=2.5(1133.12)0.35=29.3 PM

Solution- E
Average staff size (ss) = Persons.
D
(i) Organic mode,
1133.12
E=a1*(KLOC)a2 PM = 29.3

E=2.4 *(400)1.05=1295.31 PM = 38.67 Persons.

D=b1(E)b2.M KLOC
Productivity =
E
D=2.5*(1295.31)0.38=38.07 PM
200
=
(ii) Semi-detached mode, 1133.12
= 0.1765 KLOC / PM
E=3.0*(400)1.12=2462.79 PM
Productivity = 176 LOC/PM
D=2.5*(2462.79)0.35=38.45 PM
The following figure shows a plot of estimated effort
(iii) Embedded mode,
versus product size.
E=3.6*(400)1.20=4772.81 PM

D=2.5*(4772.8)0.32=38 Pm

Example– 2=>

A project size of 200 KLOC is be developed. The

team has average experience on similar type of project.

The Project schedule is not very tight. Calculate the

effort, development time, average staff size and

productivity of the project.

Software Engineering 169 YCT


Search on TG: @apna_pdf
PUTNAM Model in Brief 2 poor software dev. environment
Putnam Stated that Rayleigh-Norden curve that can be Ck = Constant 8 good
used to relate the number of delivered lines of code to the 11 excellent
effort and the time needed to develop the product.
The Putnam expression is
or K= K 3 / C3k td 4
L=CkK1/3td4/3
or K=C/td4
For the same product size, c=L3/Ck3 is a constant
K1
or = t 4 d 2 / t 4 d1
K2
or K ∝ 1/ t 4 d
or Cost ∝ 1/ t d
According to the Putnam, project effort is inversely
proportional to the fourth power of the development
Where K=total effort expended in PM
time. E = K/(TD**4)
L=Product size in KLOC This formula predicts zero effort for infinite development
td=time expended (development time) time.

Gantt Chart
It shows the project schedule with respect to time period which was devised by Henry Gantt in 1917. It is also
known as a horizontal bar chart which represents activities and time schedule for the project.

Software Engineering 170 YCT


Search on TG: @apna_pdf

Activities Planning Design Coding Testing Delivery

Start Week1 Week3 Week6 Week7 Week10

End Week3 Week5 Week8 Week9 Week10

Duration 3 3 3 3 1

PERT CHART Time Estimates (in weeks)


Pert stands for Project Evaluation and Review Most
Optimistic Pessimistic
Technique. Its main objective is the analysis through its Preceding likely
Activity time time
Activity time
three time values associated with each activity. These (to) (tp)
(tm)
are: Optimistic value, the pessimistic value and the most A None 2 4 12
likely value. B None 10 12 26
The optimistic time (to) => is the shortest possible time C A 8 9 10
in which activity can be finished. D A 10 15 20
E A 7 7.5 11
The pessimistic time (tp) => represents the longest time
F B, C 9 9 9
the activity could take if everything goes wrong.
G D 3 3.5 7
The most likely time (tm) => is the estimate of normal
H E, F, G 5 5 5
time the activity would take.
(i)
Determine the critical path.
Expected time (te) => It is the average time on activity (ii)
Draw the pert network
taken if it was to be repeated on large number of times, (iii)
Prepare the activity schedule
i.e. (iv)
What is the probability that the project will be
finished within the time limit if a 30 week
(to + 4.tm + tp) deadline is imposed?
te =
6
Solution– The shortest time and variance of each activity
is computed by the following formula for the given
network data-
2
to + 4tm + tp (tp − to)
te = and σ =
6 36

2 + 4 × 4 + 12 30
teof A = = =5
6 6
10 + 4 × 12 + 26 84
teof B = = = 14
6 6
Variance (σ)=> It is the variance of activity given by the 8 + 4 × 9 + 10 54
teof C = = =9
following formula:- 6 6
10 + 4 × 15 + 20 90
(tp − to)2
2 teof D = = = 15
σ = [(tp − to) / 6] =
2
6 6
36
7 + 4 × 7.5 + 11 48
Example– teof E = = =8
6 6
The following characteristics have eight activities 9 + 4×9 + 9 54
teof F = = =9
(A, B, C, D, E, F, G and H) of a small project:- 6 6
Software Engineering 171 YCT
Search on TG: @apna_pdf
3 + 4 × 3.5 + 7 24 The critical path of the project is 1-2-3-4-5-6,
teof G = = =4 critical activity being A ,D ,G and H.
6 6
The expected project is the sum of duration of each
5 + 4×5 + 5 30
teof H = = =5 critical activity =5+15+4+5=29 weeks.
6 6
25 25 4
Variance of project= + + +0 =6
9 9 9

Software design is a process or mechanism in which,


using a set of primitive components and subject to
(12 − 2) 2 100 25 constraints, any agent can create a specification of a
σ of A = = =
36 36 9 software artifact to fulfill goals and can transform user
(26 − 10) 2 256 64 requirements into some suitable form to help the
σ of B = = =
36 36 9 programmers in coding and implementation. Software
(10 − 8) 2 4 1 design usually involves problem solving and solution
σ of C = = = planning. It has above many design mainly the
36 36 9
following:-
(20 − 10) 2 100 25
σ of D = = =
36 36 9
2
(11 − 7) 16 4
σ of E = = =
36 36 9
(9 − 9)2 0
σ of F = = =0
36 36
(7 − 3)2 16 4
σ of G = = =
36 36 9
(5 − 5) 0
σ of H = = =0
36 36

Latest
Earliest Time
Activity σ Time
Start Finish Start Finish
A 25/9 0 5 0 5 Correctness- As per the need of the user, software
B 64/9 0 14 1 15 design should be correct.
Completeness- The design should be complete like
C 1/9 5 14 6 15 modules, external interfaces and data structures.
Flexibility- As per the need, it should be flexible to
D 25/9 5 20 5 20 modify or alter.
E 4/9 5 13 16 24 Efficiency- All resources should be used by the program
with efficient.
F 0 14 23 15 24 Consistency- The consistency should be maintain in the
design.
G 4/9 20 24 20 24 Maintainability- The design should be so simple in
order that it can be easily maintainable by other
H 0 24 29 24 29
designers.
Software Engineering 172 YCT
Search on TG: @apna_pdf
Software Design Levels / Metrics
There are many software design levels of which we
can divide into three main categories. These are;-

Architectural Design- This first level design is highest Objects- It inherits a class's attributes and operations
summarize edition of the system that determines the involved in solution design. For an instance, banks,
software or application as a method with more elements company, person and users are considered as objects.
interactive with each where the designers obtain the idea
Classes- These are generic descriptions of objects which
or thought of a suggested domain or province. It chooses
are class instances that define all the properties and
the overall structure and ignores the internal details.
methods. A Class encapsulates the data and procedural
High-Level Design- This second level design represents
abstractions described by attributes. A super class is
multiple components and cooperation with each. It is an
generally a set of classes from where both attributes and
identification of modular arrangement, different modules
operations can be inherited by a sub class.
and relationship among them. This design also defines
Messages- Massages consist of the integrity of the goal
the interface among each module. High Level Design is
object that is the name of requested operation and action
also known as preliminary design like a tree diagram
needed to. complete the function. All objects are
called the structure chart.
communicated by massage passing.
Detailed Design- This third level design determines the
Abstraction- Abstraction handles the complexity in
logical structure, data structure and algorithms of the
object oriented design. It is also the removal of the
different modules in comparison to previous module
unnecessary and amplification of the essentials.
designs and implementations. The accomplishment part
which will be finally seen by the system, dealt with this Encapsulation- Encapsulation is also known as
detailed design. information hiding concept or concealing. The data and
operations are tied to a single unit. It not only bundles or
Function Oriented Design groups a vital information of an object together but also
How the module should be interconnected and restricts access to the operation, method and data from
needed for the system based on SRS (Software the out access to the operation, method and data from the
Requirement Specification) are focused by the function outsider world.
oriented design. In this approach or method, the design is Inheritance- To be staked hierarchically, OOD permits
decomposed into a set of interacting units which have similar classes, where lower or sub classes can be
clearly defined by the following categories:- implemented, imported, reused variables and functions
from their immediate super classes. This OOD's
characteristics is called an inheritance because it makes
its easier to define and create a specific and generalized
classes respectively.
Polymorphism- Polymorphism provides a program the
Object Oriented Design ability to redefine techniques for derived classes. It
Object Oriented Design (OOD) is the process in permits a specific routine to uses different types of
which the system is viewed as a group of entities or variables at different times. Polymorphism is a feature /
objects. This process permits the creation of a software technique or mechanism where similar tasks or functions
solution based on object notion. Each object handles its performed depending.
state data among them, and responsible for its own data. upon how the service is invoked, then the respective
In other words, every object belongs to a class. portion of code gets executed.
Software Engineering 173 YCT
Search on TG: @apna_pdf
User Interface Design By using coding standards, our code will be easily
understandable, easy debugging, error-free according
The user interface is the frontend application view or
to needs.
the visual part of an application or operation system
The coding standards are the guidelines or rules how to
through which any user interacts with a computer or
write the code so that overall coding becomes
software in order to use software. How commands are
understandable.
given to computer or software and how data are
displayed on the screen are determined by interface The programmer should use-
design which is mainly of two types:- → Less global variable
→ Exception handling mechanism
Text Based User Interface or Command
→ Naming convention for global and local
Line Interface variable or constant.
It provides a command prompt, where the user types → Comments for better understanding.
the predefined commands in their syntaxed order. The → Maximum 1 to 20 line of code in a phase.
predefined commands are needed to be remembered by → Very clever or easy code.
the users. It is also known as Command User Interface → Different identifier for multiple purpose.
(CUI).
→ Name of variable and method not in short
Graphical User Interface form.
It provides the simple interactive interface to the Goals of Coding
users to interact with the system. Using GUI, users
interpret the software because GUI can be a group or
combination of both hardware and software. To reduce the cost To translate the design into a
of later phases. computer language format.

Making the program


more readable.
.
Testing-
Testing means software testing finding out the bugs
in the developed software or existing software. In other
words, find software errors and verify that application or
Coding and Testing
system is fit for use or not. Preventing bugs reducing
Coding- development costs and improving performance are the
Coding is the process or phase which is used to benefits of testing.
transform a system's design into a computer language There are two main types of testing.
format. This phase is concerned with the specification of
1. 2.
software translating design into the source code. Source
code writing is necessary done by the coders or Black Box Testing White Box Testing
programmers who are independent people. or or
Functional Testing Structured Testing
To develop a dynamic and reliable software, coding
is an essential part of software. Black Box Testing or Functional Testing-
By using coding, we can transform a system's design In this testing, the tester does not have the
into a programming language. knowledge of the coding. In this testing, we only check
Programmer should implement a well defined coding the functionality of the software that is input is passing
known as coding standard. correctly and related output is producing or not.
Software Engineering 174 YCT
Search on TG: @apna_pdf
White Box Testing or Structured Testing- 9. Beta Testing-
In this testing, the tester has the knowledge of In this testing, customer checks the functionality and
coking and internal structure of existing software features of the software and provide suggestions to
whether the internal structure is correct or not.
the developer team whether the software is
Types of Testing providing good results or not.
Besides above two types of testing there are many 10. Functional Testing-
different types of software tests, these are- It checks the functions by emulating business
1. Unit Testing- scenario based on functional needs. To verify these
This test is used to check the independent and functions, Black box testing is used in common way.
individual unit or module of software. A unit is the
11. Verification Testing-
smallest testable component of software.
It checks the product whether it is being built by the
2. Integration Testing-
coder in correct way or not.
This test integrates all the modules one by one and
checks the compatibility issues (Whether one 12. Validation Testing-
module is compatible with another or not). It checks the built product whether it is completing
3. System Testing- customer's requirements or not.
In this testing, a coder puts the software in different 13. Big Bang Testing-
environment and checks whether the software is In this testing methodology all components or
compatible with new environment or not.
modules of a system are combined together and
4. Stress Testing-
tested as a whole. This testing is of two types-
In this testing, the tester checks how the system
behaves with heavy load it means the capability of Top Down Integration- In this approach, firstly the
software how much loaded software can handle higher level modules are integrated then secondly,
before it fails. the lower level modules are integrated. This testing
5. Performance Testing- is also known as trickle-down approach.
It checks the speed and effectiveness of the software
to make sure that it generates the result within the Bottom Up Integration- In this approach, firstly the
specified time or real life load systems. Performance lower level modules are integrated then the higher
means how the software performs under different level modules are integrated. This testing is also
workloads. known as bubble-up approach.
6. Usability Testing-
It validates how well a customer can use a system or Software Quality and Reliability
web application to complete a task. In other words, Software Quality–"A quality product does exactly what
the coder checks the GUI part created by developer the users want it to do."
whether GUI part or design of software is user
The software products have the several quality factors-
friendly or not.
7. Unit Testing-
It is done by the customer to verify and check the
A quality can be measured a number of ways, two of
delivered product or whole system works as
them give excellent insights into the product's stability-
intended or customer acceptation.
8. Alpha Testing- 1. Between testing and actual delivery, the number of

In this testing, the developer feeds the input and errors and defects are discovered in the system.

measures the output because this testing is the last 2. The amount of time or the Mean Time to Defect
testing done by the developer side just before the (MTTD) are discovered prior to and after delivery to
delivery of the product. the customer between bugs or errors.
Software Engineering 175 YCT
Search on TG: @apna_pdf
Having fewer errors, bugs, defects, a higher MTTD is Reliability Testing or Software Testing
associated generally with better overall quality.
Reliability tests are designed to measure the ability
The software quality assurance is an umbrella of system to remain operation for long period of
activity for checking the quality of software time.
whether the software we are making is quality full
It is typically expressed in terms of Mean Time to
or not.
Failure (MTTF).
Software Reliability The average of all time intervals between successive
It is a probability of failure-free software operation failure is called the MTTF.
for a specified period of time within particular After a failure is observed, the developers analyze
environment. It is a dynamic system characteristics or and fix the defects or bugs that consumes
execution event. sometimes, it is called the Repair Time.
The failure of software depends on two factors-
Types of Reliability Testing
1. No. of faults being evaluated in software.
2. Operational profile of execution of the software.

Types of Time
1. Execution Time- The actual CPU time that the
software takes during its execution.
2. Calendar Time- Normal or regular time that we use
on a daily basis.
3. Clock Time- Actual time that is elapsed while the
software is executing. This time also includes the
time that the software spends while waiting in the
system.

Software Failure Mechanism


Software failure may due to bugs, ambiguities, Above three Reliability Testing are the main testing
oversights or misinterpretation. to test software functionalities but there are many more
The software failure are classified as- sub testing-

1. Transient Failure- It occurs only with particular ⇒ It involves subjecting the system
4. Stress
inputs. to high levels of usage to identify
Testing
performance that can cause the
2. Permanent Failure- It appears on all inputs. system to fail.
3. Recoverable Failure- It can be recovered by the
⇒ It involves running the system
system without operator's help. continuously for an extended
5. Endurance
4. Unrecoverable Failure- It can be recovered by the Testing period of time to identify issues
such as memory leaks.
system with operator's help only.
⇒ It involves subjecting to system
5. Non-corruption Failure- This failure doesn't corrupt to sudden, unexpected increases
6. Spike in load or usage to identify
system's data or state.
Testing performance, that can cause system
6. Corrupting Failure- This failure damages the
to fail.
system's data or state.

Software Engineering 176 YCT


Search on TG: @apna_pdf
There are three main categories of reliability testing- 2. Measurement
It is a technique by which measurement of reliability
1. Modeling testing is performed by using following methods-

Predictive Modeling- It is a statistical technique Mean Time Between Failure (MTBF)- It measures

using machine learning and data mining. It is used to the reliability testing in terms of mean time between

predict and forecast future outcomes. It reduces time, failure.

effort and costs in forecasting. Mean Time to Failure (MTTF)- It is the time
between two consecutive failures.
Estimation Modeling- It is a technique which is used
Mean Time to Repair (MTTR)- It is known as the
to find out the cost estimates to develop and test
software algorithm, equations, etc. time taken to fix the failure.

Measure of Reliability Testing


Sr. No. Metric Analysis Methods
Total time
1. Mean Time to Failure (MTTF)
Number of units tested

Mean Time to Repair Total timefor maintenance


2.
(MTTR) Totalrepairs
Mean Time to Failure (MTTF)
Mean Time Between
3. +
Failure (MTBF)
Mean Time to Repair (MTTR )

1
4. Occurrence Rate of Failure
Mean Time to Failure(MTTF)

Number of Failures
5. Probability of Failure
Totalcasesconsidered

Mean Timeof Failure(MTTF)


6. Availability
Mean TimeBetween Failure(MTBF)

Example- Find out the calculation of Mean Time to It helps the system upgrade process to be straight-
Failure (MTTF), where the total time and the number of forwarded.
unit tested are needed.
Greater productivity is given by system efficiency and
Solution-If the values are as below, the Mean Time to
higher performance.
Failure (MTTF) is calculated as:-
Totaltime Clean Room Approach
MTTF =
Number of units tested This approach was first proposed by Mills, Dyer and
100 Linger during the 1980s.
= = 2.5
40 In software engineering, clean room is an approach
Advantage of Software Reliability to produce quality software. It follows a set of principles
It is used for data preservation. and practices for gathering needs, designing, testing,
It helps to avoid software failure coding, managing, etc which improves the quality of the

Software Engineering 177 YCT


Search on TG: @apna_pdf
product and increases productivity by consisting the correctness specification that starts with the
following four key processes- highest level testing or box structure and moves
1. Management- It consists of project mission, forwards to the design detail and then moves
resources, risk, schedule, training, analysis, forwards to the design detail and then to the
configuration, etc. code. By applying a set of ''Correctness
2. Specification- It consists of function, analysis, Questions", its first level occurs or takes place.
needs, usage, incremental planning by If these do not signify or demonstrate, the
considering the first process of each increment. specification correctness, more formal and
3. Development- it consists of correctness, mathematical methods are used.
reengineering, verification, incremental design, 6. Code Generation, Inspection and
etc. by considering the second process of each Verification- The box structure specification is
increment. represented in a particular language which is
4. Certification- It consists of test planning, translated into the appropriate programming
modeling, statistical training, certification language by using technical reviews for the
process, etc. by considering the final process of semantic conformance of box structure and
each increment. code. At last, correctness verification is
There are some tasks which occur in clean room conducted for the source code.
approach- 7. Statistical Test Planning- The clean room
1. Increment Planning- activity is organized, analyzed, conducted,
planned, designed the projected usage of
• It adopts the incremental strategy, which is
software in parallel specification, verification
developed.
and code generation.
• It creates each increment's functionality,
8. Statistical Use Testing- Designing a finite
project size, and clean room schedule.
number of test cases is always necessary
• According to the plan, each increment is
because exhaustive testing of software is
integrated and certified in proper time which
impossible. Use statistical technique to execute
is needed to be care taken.
a set of tests derived from a statistical sample of
2. Requirement Gathering- A more detailed
possible execution by all users from a targeted
description of the customer level need is done
population.
and developed by using the traditional
9. Certification- The increments are certified and
techniques like analysis, design, coding, testing,
ready for integration, once the verification,
and debugging.
inspection, all errors and usage testing have
3. Box Structure Specification- To describe the
been correctly completed.
functional specification, box structure is used.
Box Structure in Clean Room Process
The behavior, data and procedure in each
increment are separated and isolated by the box Model
structure. In clean room engineering, box structure is a
4. Formal Design- By using black box structure modeling approach. A box is like a container that
approach, the clean room design is a natural and contains the details of system or aspects. By using the
seamless extension of specification that is called following three types of boxes that are independent to
as clear boxes and state boxes that is also deliver the required information in each box
known as component level design. specification-
5. Correctness Specification- The clean room 1. Black Box- It identifies the system's behaviour to
team conducts the exact series of rigorous respond specific events.
Software Engineering 178 YCT
Search on TG: @apna_pdf
2. State Box- It identifies the operation or sate data that
are similar to the objects by representing the history
of the black box.
3. Clear Box-It identifies the transition function used by
state box. The procedural design for the state box is
included by the clear box.

Benefits of Clean Room Approach


Clean Room approach delivers high quality
products, reduces developing cost and overall project
time, saves resources, and increases productivity.
Booch Method
Software Reengineering
Booch method is widely used on object-oriented
It is an activity that improves one's understanding of analysis and design process. This method was authored
software or prepares or improves the software itself for by Grady Booch when he was working for Rational
increased maintainability, reusability, evalvability. Software. This method consists of the following five
activities in its macro process:-
Analysis, Design, Conceptualization, Evolution,
Maintenance .
Macro process- This process consists of the above five
activities, in which the conceptualization takes into
account the perspective of the customer, while the
Software reengineering is a process of software analysis develops a model by defining classes, attributes,
development or examination and alteration of a system to inheritance, method, etc. The design develops an
reconstitute in a new form. It also changes a "bad" design architecture. Evolution relates the implementation, and
into a "good" design. This process encompasses a the maintenance maintains the delivery of the product by
combination of sub processes like inventory analysis, adding new requirements and eliminating bugs.
reverse engineering, restructuring, re-documentation,
forward engineering code and data restructuring, etc. The Unified Modeling Language (UML) supersedes
the notation aspect of the Booch method from
By variety of reasons, re-engineering can be done–
which UML features the graphical elements form
⇒ It adds new features. the Object-Modeling Technique (OMT).

⇒ It substitutes high casts.


⇒ It improves maintainability. Micro Process- This process is a description of day to
day activities. Each macro process has its own micro
⇒ It adds new regulations and compliance.
process which consists of the following phases that are
⇒ It boosts up productivity.
identified by Micro Process:-
⇒ It improves opportunity.
Classes, objects, object semantics, related to
⇒ It reduces risks.
programming, object relationship, object interface,
⇒ It saves and optimizes time. abstraction and implementation.
Software Engineering 179 YCT
Search on TG: @apna_pdf
Example- Lets illustrate a Booch diagram related to a Jacobson Method
BankAccount (Super class) having two attributes Jacobson method is used to plan, design and implement
SavingAccount and CheckingAccount that inherit the
object-oriented software which covers the entire life
super class:-
cycle and stress traceability between different phases

both backward and forward. It is also known as Object-

Oriented Software Engineering (OOSE). This method is

broken down into five models or parts:-

Requirements, Analysis, Design, Implementation, and

Testing model. Jacobson method is also called Object-

Advantage of Booch method- Oriented Business Engineering (OOBE). The visual,

This method consists of many diagrams as class, textual and structural methods were formulated by Ivar
object, state transition, module, process and interaction. Jacobson in 1986.

Disadvantage of Booch method- Use cases-


This method doesn't use all symbols and diagrams
It needs the scenario for understanding system.
while it defines a lot of symbols for almost every design
decision. No clear flow of events with non-formal text is

Rumbaugh Method needed.

It is an approach very friendly and easy With a clear flow of events to follow, text is easy to
methodology used to develop manageable object- read.
oriented because it is the closet to the traditional
Formal style using pseudo code.
approach. Rumbaugh method is also known as OMT
(Object Modeling Technique) used in the real world for It governs interaction between the various actors.
designing and modeling of software. OMT includes the How and when the use case begins and ends.
four stages (analysis, designing system, designing object
How and when of data storage and usage ends.
and implementation).
Additionally, OMT is always broken down into How the constraints of the problem domain are
three different parts or models (object, dynamic, handled.
functional). These three models are similar to traditional
Example- Lets illustrate a Jacobson method ordering
system.
Example- Lets illustrate a Rumbaugh diagram related to kiosk system, which relies on the customer for order
a Bank-Account having the transaction between
same as the receipt relies on the kiosk for order:-
customer and Bank Account:-

Software Engineering 180 YCT

Powered by TCPDF (www.tcpdf.org)


Search on TG: @apna_pdf

13. CLOUD COMPUTING


Introduction – Store, backup and recover data.
Cloud computing is on-demand access via the internet Stream audio and videos.
which contains a significant pool of resources including Deliver software on demand from one place to
servers, storage, database, analytics, software, another.
networking and intelligence over the cloud (internet). Analyze, test and built applications.

Cloud based storage makes your data possible


to save them to a remote database rather than
keeping/storing them on a hard drive or local
storage device.

If any user uses an online service to send emails, Cloud computing provides more options for
documents, watch movies, listen to music, send people and business as cost savings, increase
pictures, play games then these all are made possible productivity, speed and efficiency, performance
behind the scene by cloud computing. It generally used and security that are benefits for users.
to store, backup and recover data. By using the Example of cloud computing - Google Drive,
following you can - One Drive, Box or Dropbox, etc.
Features of Cloud
There are many cloud features–

Automation Performance Cost Governance


& Monitoring Management & Security
Archestration compliance
Risk, Audits
Migration/Images Applications, Instance and Encryption mobile
service and
configuration computations billing or endpoint
resource
management storage, networks management security
governance

Types of Cloud Computing Public Cloud - This service is sold on-demand by the
minute or hour through long-term commitments because
Private Cloud - A private cloud is the service and a third-party CSP (Cloud Service Provider) provides the
infrastructure that are maintained on a private network, service over the internet. In this cloud, all hardware,
because it refers resources that can be physically located software, servers, storage and other infrastructure are
on the company's or organization's on-site data center. owned and managed by the CSP.
Rarely, even some organizations pay third-party service Hybrid Cloud - A hybrid cloud is the combination of
to be built and hosted by private cloud. public cloud and private cloud services. It is used to

Cloud Computing 181 YCT


Search on TG: @apna_pdf
store/share applications and data to both physical Disadvantage of Cloud Computing
storage and cloud storage. It provides company's
There are naturally risks with all the efficiencies,
business greater flexibility and deployment. speed, innovations that come with cloud
computing.
Advantage of Cloud Computing
When security comes to a sensitive medical
Cloud based software promises to reduce IT records, it has always been a great concern.
complexity and costs. Encryption protects the vital information.
It offers companies from all fields to use software All the files, documents and data disappear when
the encryption key is lost.
from any device via a native app or a browser.
The company's servers may fall victim to natural
It provides a number of benefits that is why users disasters, internal errors (bugs), and even power
can carry their files to other devices remotely or outages maintained by cloud computing.
seamless manner. Types of Cloud Services (IaaS, PaaS, SaaS)
By using Dropbox and Google Drive, users can
check, send emails on any computer and can store
files.
It makes possible for users to backup, share, store
their files, music and photos. There are four broad categories that are fallen
It can provide security to users' files, documents, into by most cloud computing services; they
consist of the following-
in the event of a hard drive crash.

On Premises or
IaaS PaaS SaaS
On-site

Application Application Application Application


Data Data Data Data
Runtime Runtime Runtime Runtime
Middleware Middleware Middleware Middleware
O/S O/S O/S O/S
Virtualization Virtualization Virtualization Virtualization
Servers Servers Servers Servers
Storage Storage Storage Storage
Networking Networking Networking Networking
You manage Other manages
1. IaaS (Infrastructure as a Service)- Apart from the above resources, the IaaS also
It is a computing infrastructure managed over offers-
internet. IaaS is also called HaaS (Hardware as a Virtual machine disk storage
Service). It helps users to avoid the cost and Load balancers
complexity of purchasing and managing physical Virtual local area networks (VLANs)
servers. Users have an allocated storage capacity IP addresses
and can start, stop, access and configure the Software bundles
Virtual Machine (VM) and storage as required.
Example- Google Compute Engine (GCE),
Microsoft Azure, Linode, DigitalOcean, Amazon
Cloud Computing 182 YCT
Search on TG: @apna_pdf
Web Services (AWS), Racksapace, Cisco Meta Below are the several SaaS applications-
cloud. Help desk applications
Characteristics of IaaS- Billing and invoicing system
■ Resources are available as a service. Human Resource (HR) solutions

■Services are highly scalable, dynamic, flexible. Customer Relationship Management (CRM)
applications
■ GUI and API based access.
Characteristics of SaaS-
■ Automated administrative tasks.
■ Updation are applied automatically so users
2. PaaS (Platform as a Service)- are not responsible for hardware and software
It is a created platform for the programmers updates.
to develop, test, run and manage the applications,
■ Managed from a central location.
so that users can access these tools over the
internet using APIs, web portals or gateway
■ Hosted on a remote server.
software. PaaS offers runtime environment for ■ Accessible over the internet.
applications to be developed. It has a feature of ■ The services are purchased on the pay-as-per-
point-and-click tool that enables non-developers use basis.
to create web applications. Virtualization-
Example- Windows Azure, Heroku, Force.com, It is a creation or technique of a virtual (rather
Google App Engine, Apache Stratos, AWS than actual) version of something such as a
Elastic Beanstalk, Magento Commerce Cloud server, a desktop, a storage device (RAM), an
and OpenShift, etc. operating system or network resources which
Characteristics of PaaS- allow to share a single physical instance.
■ Integrates with web services and databases. Creating a virtual machine over existing
■ Accessible to various users via the same operating system and hardware is known as

development application. Hardware virtualization. The machine on which


the virtual machine is going to create is called a
■ Supports multiple languages and frameworks.
Host Machine.
■ Provides an ability to Auto-scale.
■ Builds on virtualization technology, so that
resources can easily be scaled up or down as
per the company's needs.
3. SaaS (Software as a Service)-
It is a web service by which users can access the
applications with the help of internet connection
and web browser on their phone, tablet or PC. It
is also called 'on-demand software' in which the
applications are hosted by a cloud service Types of Virtualization-
provider. 1. Hardware virtualization
Example-ZenDesk, Slack, Google Apps, 2. Operation system virtualization
BigCommerce, SalesForce, Dropbox, Cisco 3. Server virtualization
WebEx, and GoToMeeting, etc. 4. Storage virtualization

Cloud Computing 183 YCT


Search on TG: @apna_pdf
Cloud Services Requirements

Cloud and Dynamic Infrastructure

Cloud Service Management delivered to the users. These deployment models


are-
The cloud service management system offers
1. Public clouds- In this model, a business rents
standardization, support desk, operational control,
monitoring, and consistent service delivery needed for the capability and pays for what is used on-
private, public, and hybrid cloud platforms by using the demand.
following –
Advantages- Minimal investment, No setup
1. Simplify user interaction with IT
cost, Infrastructure management is not required,
Service catalog enables standards and speeds up
No maintenance, Dynamic scalability required.
the delivery.
2. Enable policies to lower the cost Disadvantages- Less secure, Low customization.
Automated provison & decommission speed up 2. Private clouds- In this model, a business
delivery and assets respectively. essentially turns its IT environment into a cloud
3. Enhance system administrator Efficiency
and uses it to deliver services to their users.
Migration from various management isolates full-
Advantages- Better control, Data Security and
fledged service.
Privacy, Support Legacy System, Customization.
Cloud Deployment Models
Disadvantages- Less scalable, more costly.
Using cloud deployment models, business
processes, application, data and any type of IT 3. Hybrid Clouds- Hybrid clouds combine
resource can be provided as a service and elements of public and private clouds. By using

Cloud Computing 184 YCT


Search on TG: @apna_pdf
this model, you may host the app in a safe standardized Service-Oriented Architecture
environment. (SOA) assets, that can be broadly deployed into
Advantages- Flexibility and control, cost, new and existing accounts and is a lower-cost
security. model.
Disadvantages- Difficult to manage, slow data 7. Dynamic Private Clouds- It allows client
transmission. workloads to dynamically migrate to and from the
4. Community or Commodity Clouds- compute cloud as required.
Community clouds are managed by groups of 8. Multi Clouds- It combines the resources of
people, communities and agencies especially public and private clouds as the name implies. It
government to have the common interests is similar to the hybrid cloud deployment model.
working on the same mission. Instead of merging public and private clouds, this
Advantages- Cost effective, security, shared cloud uses many public clouds to improve the
resources, collaboration and data sharing. reliability of the services.

Disadvantages- Limited scalability, Rigid in Advantages- Reduced Latency, High availability


customization. of service.

5. Shared Private Clouds- This is a shared Disadvantages- Complex, security, issue.


compute capacity with variable usage-based
pricing to business units that are based on service Cloud Infrastructure
offerings, accounts, datacenters. To take over or It is the need of the hour to reduce the risks and
buy infrastructure made available through cost associated with business, it is becoming at
account consolidations, it needs on internal profit. the same time vital to increase the agility and
6. Dedicated Private Clouds- It has IT service quality of the IT infrastructure by consisting of
catalog with dynamic provisioning. It depends on the following:-

Cloud Computing 185 YCT


Search on TG: @apna_pdf

Types of Hypervisor A grid computing network consists of three types


1. Type 1 Hypervisor- It is also called bare-metal or of machine names- Control node, Provider, and
native. It is a layer of software installed directly on User and layers names- Lower layer, Middle
top of a physical server. It is mainly found in layer and Upper layer.
enterprise environment. A grid computing works like the following

Pros Cons Example figure.

VM (Virtual Control node is also known as server.


Limited VMware,
Machine) Provider is also known as grid node.
functionality vSphere with
Mobility

Complicated ESX/ESXi,
Security
Management Oracle VM,
Microsoft
Resource over
Price Hyper-V, Lynx
allocation
Secure
2. Type 2 Hypervisor- It is also called hosted
hypervisor which is installed and run inside the
physical host machine's operating system. It is
found in environments with a small number of
For the efficient execution, grid computing breaks down
servers.
each task into small fragments and each fragment is
Pros Cons Example processed parallel. For example.
Less flexible A = (4 × 7) + (3 × 8) + (2 × 9)
Easy to manage
resource Oracle VM Step 1: A = 28 + (3 × 8) + (2 × 9)
management VirtualBox, Step 2: A = 28 + 24 + (2 × 9)
Step 3: A = 28 + 24 + 18
Convenient for VMware
Performance Step 4: A = 70
testing Workstation
Advantages of Grid Computing-
Allows access Pro/ VMware
All machines with various operating systems can
to additional Fusion
Security use a single grid computing network.
productivity Across different physical locations, the tasks can
tools be done or processed parallel while users don't
have to pay money for them.
GRID COMPUTING Servers are not needed because it is not
To accomplish a joint task, a grid is made up of a centralized.
Disadvantages of Grid Computing
number of resources and layers or distributed
For some applications, licensing may make it
architecture of various computers connected by
restrictive.
networks. On a network, all machines collaborate Many groups are reluctant with sharing
under a common protocol because all tasks are resources.
difficult for a single machine to handle. The grid software is still in the involution stage.

Cloud Computing 186 YCT


Search on TG: @apna_pdf

Key Components of Grid Computing

Types of Grid Computing


Computational Collaborative Manuscript Modular Data Grid

Grid computing is important for several Scalability


reasons as efficiency, cost, and flexibility in the Availability
financial services, gaming, engineering and Disadvantages of cluster Computing-
entertainments.
High cost due to its high hardware and its
Cluster Computing design.
A cluster is a type of parallel or distributed Problem in finding bugs or faults.
processing system, which consists of a collection More space is needed to manage and monitor
of interconnected stand–alone computer working the infrastructure may increase.
together as a single, integrated computing, A
Types of Cluster Computing
cluster generally refers to two or more computers
(nodes) connected together. 1. High availability (HA) Clusters- It is used
Cluster computing is important to resolve the to face failure issues. It is also called
demand and process services in a faster way. It failover cluster. In this cluster, services and
ensures the computational power to be always applications may be made available to
available. It gives a single strategy as it is different nodes if a node declines.
inexpensive, unconventional to the large server. 2. Load-balancing Clusters- It allocates all

Applications of Cluster Computing the incoming traffic or request resources


among several nodes that run the equal
■ Weather forecasting machines and programs having similar
■ Flight simulation content. In this cluster, services or requests
■ Earthquake simulation are distributed amongst all the nodes if a

■ Image rendering node declines.


3. High Performance (HP) Cluster- It is
■ Petroleum exploration
designed to take benefit of the parallel
■ Various e-commerce applications processing of all nodes. It utilizes super
Advantages of Cluster Computing- computers to resolve computational
Cost effectiveness problems.
Processing speed 4. High Availability + Load Balancing- The
Improved flexibility combined performance of high-availability
High performance and load balancing clusters provides an ideal
Easy to manage solution. This cluster is generally used for
Expandability FTP server, web, news and e-mail.
Cloud Computing 187 YCT
Search on TG: @apna_pdf
Classification of Cluster It is a group of workstations or computers
connected via speed interconnections.
1. Open Cluster- This type of cluster causes
These workstations work together as a
enhanced security concerns and needed by
single, integrated computing resources,
every node accessed through the web or
that are designed with arrays. A node
internet.
having input and output functions,
2. Close Cluster- It is good for
memory, an operating system, works either
computational tasks and needs fewer IP
with a single or a multiprocessor.
addresses. This type of cluster provides
Two or more nodes are generally
increased protection to the nodes that are
connected to a single line.
hidden behind the gateway node.
Every node might be connected
Cluster Computing Architecture individually through a LAN network.

Types of Clustering

1. Hierarchical Clustering- Hierarchical clustering


has a bottom up approach if it uses a tree-like
structure in agglomerative clustering.

Hierarchical clustering has also a top-down approach


It begins with each element as a separate if it uses top-down tree like structure. It begins with the
successively more massive clusters:- whole set and proceed to divide it into success cluster.

Cloud Computing 188 YCT


Search on TG: @apna_pdf

DBSCAN- In image processing, machine learning,


data-mining and other fields are widely used by
DBSCAN. DBSCAN is a data clustering algorithm
based on density. It is widely used with the
increasing size of clusters. It is also used for
2. Partitioning Clustering- This clustering is divided
applying new data partitioning and merging
into two sub-types, first one is K-means clustering
method, by using KD tree Get neighbours query.
and second one is Fuzzy C-means.
OPTICS- It is similar to DBSCAN. It is useful for
The objects are divided into many clusters identifying clusters of different densities. It is also a
mentioned by the number 'K' in K-means data clustering algorithm based on density. OPTICS
clustering. It is divided into two clusters C1 and C2 extracts the clustering structure. This algorithm
but both have the similar characteristics. builds a density representation by creating core
distance and reach-ability distance.
STING- It is a statistical information grid-based
approach which follows a hierarchical approach to
divide the spatial area into rectangular cells similar
While in Fuzzy C-means clustering, objects to a quadtree. This approach separates the high
have the similar characteristics but a single object level cells into multiple smaller cells which can be
cannot belong to two different clusters because it is simply computed and stored.
very similar to K-means. CLIQUE- It is a grid based density based
technique or algorithm. In grid based algorithm, the
CLIQUE divides the space of distance into a grid
structure, while in density based algorithm, a
cluster is a maximal set of connected dense units in
a subspace. With respect to the value of records,
Example- this algorithm is very scalable.
(i) A cricket game having runs scored by the player Advantages of CLIQUE- DBSCAN, K-Means and
and wickets taken by the players. Farthest First are outperforms in accuracy and
(ii) Academic performance execution time by CLIQUE algorithm. It is one of
(iii) Diagnostic systems the simplest methods which is able to find clusters
(iv) Wireless sensor networks and any number of clusters.
(v) Search engines Disadvantage of CLIQUE- The estimation will
How does K-Means Clustering work? take place and correct clusters will not be able to
K-Means clustering works like following find if the size of the cell is unsuitable for a set of
flowchart:- high values.
Cloud Computing 189 YCT
Search on TG: @apna_pdf
Beowulf Cluster The hadoop consists of the following mainly four
components:
It is a multi-computer architecture consisting of
multiple client nodes and a single server connected 1. MapReduce- It is like a data-structure or an

through internet. The word "Beowulf" is originated algorithm. MapReduce performs the

from an old English poem having the same name. A distributed processing in parallel in a hadoop

group of identical and commodity grade computers cluster to work so fast. It has only two phases

is called Beowulf cluster. This cluster differs from namely Map and Reduce that are utilized. Any
others in its behaviour of working on many big data are inputted, they go through Map and
operating systems- Reduce phases until they got executed in
Kerrighed output form. Map function breaks the data
MOSIX blocks (big data input) into tuples which works

DragonFly BSD as input to Reduce function. Then the Reduce

Rocks Cluster Distribution function combines the tuples into set of tuples

PelicanHPC and performs summation and sorting type jobs.

Cluster knoppix Finally they are sent to the output terminal in

A Beowulf cluster have the following the output format.

characteristics-
A private network with dedicated processors, and
easy replication for multiple vendors.
It is a free and open source software scalable
with Input-Output and no custom components.
It is an Apache open source framework. It is
written in java that allows distributed execution
using programming models. The hadoop's Map function does many tasks as
environment provides distributed storage and RecordReader, Combiner, Partitionar, etc and
computation across computer clusters. By the help Reduce function also does many tasks as
of two major layers, it is designed to scale up from shuffle and sort, Reduce and Produce output
a single server to thousands of servers. Its two format.
layers are –
2. HDFS- HDFS stands for Hadoop Distributed
(i) Computation/processing layer (MapReduce)
File System. It works on commodity hardware
(ii) Storage layer (HDFS)
and utilizes storage permission. It is used to
The main purpose of hadoop is, it utilizes a large
cluster of commodity hardware to keep and store store data in large chunk of blocks to the

big size data by working on MapReduce following two nodes-

programming algorithm. For example- Yahoo, (a) NameNode (Master)- It is used to guide
Facebook, eBay, Netflix are using hadoop in their the Datanode (slaves) because it works as a
organization to deal with big data. master in Hadoop cluster.
Cloud Computing 190 YCT
Search on TG: @apna_pdf
(b) DataNode (Slaves)- It is used to utilize or Oozie
store the data in Hadoop cluster because it
It is a Java web application used to schedule
works as a Datanode.
hadoop jobs. Multiple jobs are combined
3. YARN- It is a framework on which sequentially into one logical unit of tasks by
MapReduce works. YARN works two oozie. For Hadoop, oozie is a workflow scheduler
operations- Job Scheduling and Resource that permits users to create Directed Acyclic
Management. Job scheduler divides a big task Graphs of workflow.
into small jobs and Resource management Oozie consists of two parts:-
manages all the resources that are made (a) Workflow engine- It is responsible to run
available for running Hadoop cluster. YARN and store workflows of Hadoop jobs as
performs its tasks by using many features- MapReduce, Hive and Pig. If workflow
as Multi- Tenacy, Scalability, Compatibility engine specify a sequence of actions to
and cluster Utility. execute, then workflow job has to wait.
4. Hadoop Common- It is also known as (b) Coordinator engine- Based on predefined
common utility used by HDFS, MapReduce schedules and data availability, coordinator
and YARN. Hadoop common utilities are Java engine runs workflow jobs.
files or Java library or Java script needed for
other components. It solves the hardware
failure if it occurs in hadoop framework.

Advantages of Hodoop
Hadoop has an ability to store large amount of
data.
Hadoop has high flexibility and high
computational power.
Hadoop's tasks are independent i.e. open source.
Oozie can manage the lifecycle of the jobs and
It has linear scaling. timely execution of thousands of workflows.
Disadvantage of Hadoop Anyone can easily start, stop, suspend
Hadoop is not more effective for small data. (terminate) and re-run the jobs as oozie is very

Hadoop has hard cluster management and much flexible and it has command line interface

stability issues. as well as client API.

Hadoop concerns the security. Mahout


Hadoop has complexity, latency, limited support The name mahout came from Apache Hadoop
for real time processing and limited support for which uses an elephant's logo. A Mahout is one
structured data. who drives an elephant. It is an open source
Hadoop has data security, limited support for Ad- project also. Many popular machine learning
hoc queries, for graph and machine learning. techniques such as classification,

Cloud Computing 191 YCT


Search on TG: @apna_pdf
recommendation and clustering are implemented Low Touch
by Mahout. Developers are enabled to use
optimized algorithm by highly scalable machine It is also an on-boarding model or method that is

learning liabrary that is called Mahout. largely self serve in nature. Low touch model is

opposite of a high touch model. It simply doesn't

have man power or the resources to provide a

high tough experience to each customer so it is

attractive to new, and small companies.

Benefits of low touch- Low touch model takes


High Touch
very little time out of customer access team's that
It is hands-on for customers who require a lot of
is one of the biggest benefits.
interaction and less reliance on digital
Characteristics of low touch-
engagement with any company. It is used to boil
Little to no human interruption during on-
down to how frequently the customer can be
boarding.
contacted.

In other words, to support the customers through To deliver value on automation tools, heavy

the pre- and post-sale phases, a high touch emphasis is occur.

model, a human first method is used. It is often Executing task and accomplishing goals can

used when a customer needs direct guidance to quickly be started by customers.

navigate a complex process. It includes in- High, Low, No-Touch Partner Program
person-meeting, webinars, video chat, demos and
Segmentation
phone calls, etc.

Benefits of high touch- The main benefits of a


high touch method are that customers feel like
they are receiving special attention and
customers can tap into as much support as they
require.

Characteristics of high touch When high-value reoccurs, it is said High touch

Little to no human interruption during on- customer service. On the other hand, when

boarding. company uses automation to digitally engage

To deliver value on automation tools, heavy with customers, it is called low touch customer

emphasis is occur. service while neither high-value reoccurs nor

Executing task and accomplishing goals can company uses automation to digitally engage, it

quickly be started by customers. is called no-touch customer service.

Cloud Computing 192 YCT

Powered by TCPDF (www.tcpdf.org)

You might also like