Computer Science Formula Book Copy Backup
Computer Science Formula Book Copy Backup
About Me
I am shashank singh. A computer science and engineering grad from IET (Govt.)
Lucknow
P.S. This book should be used as a quick reference guide only for formulas. For concepts
please go through some standard text books. Also depending on your feedback, I am
planning to write a new edition of this book with more formulas and numerical problems
in it. Also please provide your valuable feedback as I am planning to publish another
quick peek reference book on important facts of computer science subjects so that
you can revise your subjects quickly.
P a g e |2
COMPUTER NETWORKS
Delay Calculations:
Propagation delay =
Transmission delay =
Channel Utilization:
1. For Ethernet, channel utilization, u
, where a =
1.1. for 1- persistent CSMA/CD LAN 10-1000Mbps speed, simplified channel efficiency is,
, where A =
4. For unrestricted simplex protocol: If a frame has d data bits and h overhead bits and channel
bandwidth = b bits/sec then,
u=
, where a =
frame is in error.
5.2. Also Maximum channel utilization =
P a g e |3
={
7.2. Selective reject,
7.2.1.Channel utilization
,u ={
Throughput Calculations:
Throughput = Channel Utilization
Channel Bandwidth
is not in decibels).
Baud rate: A baud is the number of changes per second in the signal.
bit-rate
P a g e |4
Now, if the channel is divided into N sub channels each with capacity
each of the N channels is
T(fdm) =
then,
, where
Vulnerability period in pure ALLOHA: For successful frame transmission, no other frame should
be on the channel for vulnerability period equal to twice the time to transmit one frame. That is,
P a g e |5
PPP
In Point to Point Protocol (PPP), number of channels grows as square of the number of
computers. That is, (
STATE
Non-Adaptive (or Static)
Non-Adaptive (or Static)
Delay time, T =
Congestions deals with wires and routers while flow deals with hosts.
Traffic Shaping:
Leaky Bucket Algorithm (If the bucket overflows, then packets are discarded).
Congestion control through Load Shedding may lead to deadlock and unfairness.
P a g e |6
The size of data portion of the datagram is = [Total length] [size of header]
Datagram format:
Total length
Header length
Flag length
Type of service
Identification bits
Fragment offset
Time to Live
Protocol version
Header Checksum
Source Address
Destination Address
In Layer 2 of OSI model (Data link layer), destination field appears before source field where as in
layer 3 (Network layer), the ordering is opposite.
IP class addressing:
Class Name
Class A
Class B
Class C
Class D
Class E
16 bits
4 bits
3 bits
8 bits
16 bits
13 bits
8 bits
8 bits
16 bits
32 bits
32 bits
Starts with
0
10
110
1110
11110
Range
0-127
128-191
192-223
224-239
240-255
Internet addresses refer to network connections rather than hosts. (For example, Gateways have two
or more network connections and each interface has its own IP address). Thus, Physical (or Ethernet)
address is constant (fixed) but Network (or IP address) may change.
Transport Layer:
To cope with the widely varying delays, TCP maintains a dynamic estimate of the current RTT (Round
Trip Time) calculated this way:
P a g e |7
SERVER
Socket
Socket
Bind
Connect
Listen()
Send()
Accept()
Receive()
Receive()
Close()
Send()
Marshalling, Shunt
Client, Skelton
Socket, connect.
While trying to access a webpage www.facebook.com, a user gets the http error message could
not resolve host name. What could be the cause of this problem?
A wants to send a group message to a number of people. How can it be ensured that the message
actually came from A and not from someone else?
A encrypts via its own private key; and the group decrypts via As public key.
The number of bits used for IPV6 addressing is 128 bits whereas for Ethernet address 48 bits are
used.
If n is the number of bits used to represent the frame sequence number then:
Name of sliding window
protocol
Go-back-N
P a g e |8
Selective Repeat
The maximum burst rate at which network can handle the traffic is given by,
, where C = Capacity of bucket(in bits); M = Network rate(e.g., token ring with 10 Mbps
network LAN); R = arrival rate(e.g., rate of entering into the bucket).
Router
Network Layer
Physical Layer
A group of (
node. Router I communicate with router J by sending a message to the root of the tree. The root then
sends the message back down to J, then
P a g e |9
Interrupts
External
Interrupts
Maskable
Interrupts
Internal
Interrupts
Software
Interrupts
Non-Maskable
Interrupts
Maskable interrupts are enabled and disabled by executing instructions such as EI or DI. If the
computers interrupts is disabled, the computer ignores the maskable interrupt.
The Non-Maskable interrupt has higher priority than the maskable interrupt.
If both maskable and non-maskable interrupts are activated at the same time, the processor will
service the non-maskable interrupt first.
PIPELINE
(
Latch delay.
, where,
P a g e | 10
Hazards of Pipeline:
Branch Instruction: For each branch instruction additional (n-1) pipeline clocks are required;
where n is the number of segments in the pipeline.
Data dependency
Resource Conflicts.
, where S=
The unit block of data for transferring between disk and memory is called a page. (Typically 4kB)
Virtual memory uses write back method because frequent access to disk is very slow.
An interrupt in which device supplies the interrupt requests as well as its address is called Vectored
Interrupt.
When INTER is encountered, the processor branches to the memory location which is
In 8085 microprocessor,
DAD H: Add HL pair with HL pair and store the result in HL pair.
ALE is a pin of an 8085 microprocessor that is used to the latch the 8 bits of address lines AD7-AD0
into an external latch.
P a g e | 11
Chip notation:
How many bits will be required to store a decimal number containing (a) 3 digit (b) 4 digit (c) 96 digits
)
)
)
Key formula is
Let N be the required number of bits and n be the number of decimal digits given, then
)
)
P a g e | 12
P a g e | 13
THEORY OF COMPUTATION
If an NFA contains N no. of States then the corresponding DFA will contain maximum of
states.
Ardens theorem:
If P & Q are two regular expressions over an alphabet S such that P does not contain
following equation:
then the
P a g e | 14
Recursive languages are closed under complementation but recursively enumerable languages
are NOT closed under complementation.
The minimum number of states in DFA accepting strings containing number of 0s divisible by P and
1s divisible by Q =
X, for each
Thus if | |
Number of equivalence relations = 1,2,5,15,52,203 for 1,2,3,4,5,6, elements. (i.e., the BELL
number).
P a g e | 15
DATA STRUCTURE AND ALGORITHMS
C operators in order of precedence (highest to lowest). Their associativity indicates in what order
operators of equal precedence in an expression are applied.
Operator
()
Parentheses(function call)
[]
->
++ --
++ --
+-
!~
(type)
Associativity
Left-to-Right
Right-to-Left
Dereference
&
sizeof
*/%
Left-to-Right
Addition / Subtraction
Left-to-Right
Left-to-right
< <=
Left to right
> >=
+<< >>
== !==
Left to right
&
Bitwise AND
Left to right
Bitwise exclusive OR
Left to right
Bitwise inclusive OR
Left to right
Logical AND
Left to right
||
Logical OR
Left to right
?:
Ternary conditional
Right to left
Assignment
Right of left
&&
+= -=
Addition/subtraction assignment
*= /=
%= &=
^= |=
<<= >>=
,
Description
Left to right
P a g e | 16
Worst case time complexity = O(kN); N number of numbers each with k digits.
)
)
For a look up in a B+ tree, we traverse from root node to leaf node. If there are K search keys and
number of pointers per node (or degree) is P, then for a look up,
Column-major order:
[
[
o(gn)
Relationship
Definition
P a g e | 17
Complexity ordering:
(
Bubble sort:
Total number of sqaping required for arranging n elements in the sorted order by using bubble
sort =
If the file is already sorted then the time taken by bubble sort is order of O(n), as it will require
Quick sort:
Insertion Sort:
Best case:
Time complexity = O(
Selection Sort:
P a g e | 18
SHELL sort:
Time complexity = O(
Binary Search:
Maximum number of comparisons is approximately
Interpolation search:
Hashing:
Double hashing:
Merge Sort:
Here
In an open addressing scheme, the expected number of probes in an unsuccessful search is at most
assuming uniform hashing.
Balance tree:
AVL tree
P a g e | 19
Kruskals Algorithm:
The total time taken by this algorithm to find the minimum spanning tree is O
Prims Algorithm:
B-Tree.
For a complete n-ary tree having either 0 or 1 sons. If k is the number of internal nodes of a complete
n-ary tree, then the number of leaves in it is given by =
Heap Sort:
A tighter bound is
times.
( )
Suppose we use a hash function h to hash n distinct keys into a array T of length m. Assuming simple
( )
uniform hashing:
of disks.
Dijkstras algorithm:
Let T(l) and T(r) denote the left and right subtrees of a binary tree T. If T has n nodes, then the
Total Path Length, P(T) = P( l )+P( r ) + n-1 ; where P(l) is the path length of left subtree and P(r)
is the path length of right subtree.
P a g e | 20
Insert
Search
Direct addressing
O(1)
O(1)
Ordered addressing
O(N)
O(log N)
Ordered List
O(N)
O(N)
Unordered array
O(1)
O(N)
Unordered List
O(1)
O(N)
In complete k-ary tree, every internal node has exactly k children. The number of leaves in such a
4
)
( )
( )
processes.
An n-dimensional hypercube (
) are
Number of edges =
P a g e | 21
Best case =
Worst case =
MASTER METHOD
It is applicable to only limited classes of recurrences which are in the form of,
( )
for n>=n0}
Compare fn with
Case 1: If fn =
for some
Tn =
Case 2: If fn =
) for some
Tn =
Case 3: If fn =
) for some
and
Tn =
For example, Find the time complexity of the following recurrence relation:
( )
; so fn =nlogn =
Hence by case 2 of master theorem,
Tn =
( )
Let n =
So T(
) = T(
Let T(
) = S(m)
) + C1
P a g e | 22
DATABASE MANAGEMENT SYSTEM
Cross Product:
Then, in
,(
Access time: The time it takes from when a read or write request is issued to when data transfer
begins. It consists of:
SEEK TIME: The time it takes to reposition the arm over the correct track.
ROTATIONAL LATENCY: The time it takes to reposition the arm over the correct track.
Lock modes:
Read lock shared lock (s); write lock Exclusive lock (X)
R
OK
WAIT
WAIT
WAIT
P a g e | 23
OPERATING SYSTEM
If there are n processes in ready queue and time quantum is q, then each process gets
of the
Each process must wait no longer than (n-1)q time units until next time quantum.
If waiting time or fraction of each process is P and n is the number of processes, then
CPU utilization =
And probability that N processes will all wait at the same time =
Unix Inode:
Suppose there are 12 direct blocks and 1 indirect block and 1 double indirect block and 1 triple
indirect block then the maximum size of process supported by inode is
[
size).
P a g e | 24
DIGITAL ELECTRONICS
Rs complement:
Total delay = (2N + 1)tp ; where tp= propagation delay of each gate.
If the n-bit decoded information has unused or dont care combinations, the decoded output will have
less than
(R-1)s complement of N =
Operator Precedence:
0 and 0 for N = 0;
N: a +ve number in base r with an integer part of n digits and a fraction part of m digits, then
for N
R-1 complement:
Rs complement of N =
outputs.
Sequential Circuits:
Integer representation:
1s complement representation:
2s complement representation:
Duty cycle: A duty cycle is the percentage of one-period in which a signal is active.
So duty cycle,
P a g e | 25
SOFTWARE ENGINEERING
Efforts in person-months,
where a,b,c,d are coefficients that have fixed values for different classes of projects.
Organic
2.4
1.05
2.5
0.38
Semi-detached
3.0
1.12
2.5
0.35
Embedded
3.6
1.20
2.5
0.32
Cyclomatic complexity V(G) for a flow graph G with V vertices and E edges is defined as,
V(G) = E V + 2
Node X dominates node Y iff all the paths from initial node to node Y passes through node X.
Boundary value analysis and equivalence class partitioning both are test case design techniques in
black box testing.
P a g e | 26