Q1).
What are the types classes for classful IP addressing are there in
the internet ?
Ans). IP Address Class A, B and C Network and Host Capacities
In the preceding topics I introduced the concepts of IP address classes and showed
how the classes related to ranges of IP addresses. Of the five classes, D and E are
dedicated to special purposes, so I will leave those alone for now. Classes A, B and C are
the ones actually assigned for normal (unicast) addressing purposes on IP internetworks,
and therefore the primary focus of our continued attention.
As we've seen, they differ in the number of bits (and octets) used for the network ID
compared to the host ID. The number of different networks possible in each class is a
function of the number of bits assigned to the network ID, and likewise, the number of
hosts possible in each network depends on the number of bits provided for the host ID.
We must also take into account the fact that one, two or three of the bits in the IP address
is used to indicate the class itself, so it is effectively "excluded" from use in determining
the number of networks (though again, it is still part of the network ID).
Based on this information, we can calculate the number of networks in each class, and for
each class, the number of host IDs per network. Table 45 shows the calculations.
Table 45: IP Address Class Network and Host Capacities
IP
Address
Class
Total
Bits
Of First
Network
For Octet of ID
Network
IP
ID / Host Address
Used
Usable
Bits Of
To Network
Identify
ID Bits
Number
Host
IDs
of Possible Per
Network
Network
IDs
ID
ID
Class A
Class B
Class C
8 / 24
16 / 16
24 / 8
Class
0xxx xxxx 1
10xx xxxx 2
110x xxxx 3
8-1 = 7
16-2 = 14
24-3 = 21
2 -2 = 126
224-2
16,277,214
214 =
216-2
16,384
65,534
221 =
2,097,152
28-2 = 254
Let's walk through one line of this table so we can see how it works. I'll stick with class B
since it's "in the middle". The basic division is into 16 bits for network ID and 16 bits for
host ID. However, the first two bits of all class B addresses must be "10, so that leaves
only 14 bits to uniquely identify the network ID. This gives us a total of 214 or 16,384
class B network IDs. For each of these, we have 216 host IDs, less two, for a total of
65,534.
Why less two? For each network ID, two host IDs cannot be used: the host ID with all
zeroes and the ID with all ones. These are addresses with "special meanings" as described
in the topic that follows. You will also notice that 2 has been subtracted from the number
of network IDs for class A. This is because two of the class A network IDs (0 and 127)
are reserved. There are actually several other address ranges that are set aside in all three
of the classes that I haven't shown here. They are listed in the topic on reserved, private
and loopback addresses. (The exclusion of 0 and 127 from class A is probably the bestknown address range reservation which is why I am explicit with that one in the table
above.)
Q2). Briefly explain about classless IP addressing scheme and what are
the its advantages and the disadvantages ?
Ans). IP Classless Addressing: Classless Inter-Domain Routing (CIDR) / "Supernetting"
As the early Internet began to grow dramatically, three main problems arose with the
original classfull addressing scheme. These difficulties were addressed partially
through subnet addressing, which provides more flexibility for the administrators of
individual networks on an internet. Subnetting, however, doesn't really tackle the
problems in general terms. Some of these issues remain due to the use of classes even
with subnets.
While development began on IP version 6 and its roomy 128-bit addressing system in the
mid-1990s, it was recognized that it would take many years before widespread
deployment of IPv6 would be possible. In order to extend the life of IP version 4 until the
newer IP version 6 could be completed, it was necessary to take a new approach to
addressing IPv4 devices. This new system calls for eliminating the notion of address
classes entirely, creating a new classless addressing scheme sometimes called Classless
Inter-Domain Routing (CIDR).
In this section I describe modern classless IP addressing. I begin with an overview of the
concepts behind classless addressing and the idea behind supernetting, including why it
was created and what its advantages and disadvantages are. I then define CIDR and
describe how the system works in more detail, including the notation used for address
blocks. I list each of the CIDR address block sizes and show how they relate to the older
class A, B and C networks. I conclude with an example of CIDR addressing, which is
similar to the practical subnetting section prior to this one, but focused on CIDR and a bit
more condensed.
IP Classless Addressing and "Supernetting" Overview, Motivation, Advantages and
Disadvantages
The Many Benefits of Classless Addressing and Routing
CIDR provides numerous advantages over the classful addressing scheme, whether or
not subnetting is used:
o
Efficient Address Space Allocation: Instead of allocating addresses in fixed-size
blocks of low granularity, under CIDR addresses are allocated in sizes of any
binary multiple. So, a company that needs 5,000 addresses can be assigned a
block of 8,190 instead of 65,534, as shown in Figure 81. Or, to think of it another
way, the equivalent of a single Class B network can be shared amongst 8
companies that each need 8,190 or fewer IP addresses.
Elimination of Class Imbalances: There are no more class A, B and C networks,
so there is no problem with some portions of the address space being widely used
while others are neglected.
Efficient Routing Entries: CIDR's multiple-level hierarchical structure allows a
small number of routing entries to represent a large number of networks. Network
descriptions can be aggregated and represented by a single entry. Since CIDR is
hierarchical, the detail of lower-level, smaller networks can be hidden from
routers that move traffic between large groups of networks. This is discussed
more completely in the section on IP routing issues.
No Separate Subnetting Method: CIDR implements the concepts of subnetting
within the internet itself. An organization can use the same method used on the
Internet to subdivide its internal network into subnets of arbitrary complexity
without needing a separate subnetting mechanism.
Figure 81: Classless Addressing (CIDR) Solves The Granularity Problem
Figure 64 illustrated the primary problem with classful addressing: the great distance
between the size of Class B and Class C networks. CIDR solves this issue by allowing
any number of bits to be used for the network ID. In the case of an organization with
5,000 hosts, a /19 network with 8,190 hosts can be assigned. This reduces the address
space waste for such an organization by about 95%.
The Main Disadvantage of CIDR: Complexity
Since the main benefit of classful addressing was its simplicity, it's no surprise that the
main drawback of CIDR is its greater complexity. One issue is that it is no longer
possible to determine by looking at the first octet to determine how many bits of an IP
address represent the network ID and how many the host ID. A bit more care needs to be
used in setting up routers as well, to make sure that routing is accomplished correctly.
Q3). What is the efficiency of the class B IP addressing network have
5000 hosts ?
Ans).
The given network is class B network
Given number of hosts are 5000
We know that the total capacity of hosts that the class B having is 2^16
i.e 2^16 = 65536
so for efficiency we have the formula is
n = (number of hosts that the network have total capacity)
so
n = (5000/65536)
= 0.07629
% efficiency n = 0.07629 * 100 = 7.629
Q4). Briefly explain about the tree and the binary tree ?
Ans).
What is a Tree?
It is actually hard to define what we mean be a tree, but the idea can be seen in the
following picture of an example tree showing course prerequisites. A course with a line
to a second course below it is a prerequisite for the second course. The left to right
ordering means nothing. We would still have the same tree if 330 were to the right of
310,
for
example.
At this point it is helpful to introduce some terminology. The root node (or simply root)
is the node at the top of the tree diagram. In our case it is the one containing 110. Note
that in computer science trees have their root at the top and branch out as you go down!
This is simply the customary way of drawing trees.
The parent of a node is the one directly connected to it from above. In our example, 111
is the parent of 350, 230 is the parent of 310, 110 has no parent, etc. A child is a node
connected directly below the starting node. Thus 350 is a child of 111, 310 is a child of
230, etc. It is simply the reverse of the parent relationship. Nodes with the same parent
are called siblings. So, 221, 230, and 350 are siblings in our example.
An ancestor of a given node is either the parent, the parent of the parent, the parent of
that, etc. In our example 110 is an ancestor of all of the other nodes in the tree. The
counterpart of ancestor is descendant. For example, 310 is a descendant of 111, but 310
is not a descendant of 221.
The leaves of a tree (sometimes also called external nodes) are those nodes with no
children. In our example, 221, 350, 330, and 310 are leaves. Note that leaves do not have
to be at the lowest level in the tree. The other nodes of the tree are called non-leaves (or
sometimes internal nodes).
Note that each node of a tree can be considered to be the root of a subtree consisting of
that node and all its descendants. For example, the subtree rooted at 230 is as follows:
A branch is a sequence of nodes such that the first is the parent of the second, the second
is the parent of the third, etc. For example, in the above tree, the sequence 111, 230, 310
is a branch. The length of a branch is the number of line segments traversed (which is one
less than the number of nodes). The above branch has length 2.
The height of a tree is the maximum length of a branch from the root to a leaf. The above
tree has height 3, since the longest possible branch from root to leaf is either 110, 111,
230, 310 or 110, 111, 230, 330, both of which have length 3.
A more formal definition of a tree can be written as follows: A (general) tree consists of
a set of nodes that is either empty or has a root node to which are attached zero or more
subtrees. Of course, a subtree itself must be a tree. Thus this is a recursive definition.
Note, too, that there is no left to right ordering of the subtrees.
What is a Binary Tree?
A binary tree is similar to a tree, but not quite the same. For a binary tree, each node can
have zero, one, or two children. In addition, each child node is clearly identified as either
the left child or the right child. Thus there is a definite left-right ordering of the child
nodes. Even when a node has only one child, that child must be identified as either the
left child or the right child. As an example, here is the binary expression tree for the
expression 4 * 5 - 3. Note that a child drawn to the left of its parent is meant to be the left
child and that a child drawn to the right of its parent is meant to be the right child.
Reversing the left to right order of any siblings gives a different binary tree. For example,
reversing the subtrees rooted at * and at 3 gives the following different binary tree. It
happens to be the binary expression tree for 3 - 4 * 5.
Q5). Briefly describe the longest prefix match with example binary search
Tree and its uses ?
Ans).
Longest prefix match (also called Maximum prefix length match) refers to
an algorithm used by routers in Internet Protocol (IP) networking to select an entry from
a routing table .[1]
Because each entry in a routing table may specify a network, one destination address may
match more than one routing table entry. The most specific of the matching table entries
the one with the highest subnet mask is called the longest prefix match. It is called
this because it is also the entry where the largest number of leading address bits of the
destination address match those in the table entry.
For example, consider this IPv4 routing table (CIDR notation is used):
192.168.20.16/28
192.168.0.0/16
When the address 192.168.20.19 needs to be looked up, both entries in the routing table
"match". That is, both entries contain the looked up address. In this case, the longest
prefix of the candidate routes is 192.168.20.16/28, since its subnet mask (/28) is higher
than the other entry's mask (/16), making the route more specific.
Routing tables often contain a default route, which has the shortest possible prefix match,
to fall back on in case matches with all other entries fail.
What is a Binary Search Tree?
A binary search tree is a binary tree in which the data in the nodes is ordered in a
particular way. To be precise, starting at any given node, the data in any nodes of its left
subtree must all be less than the item in the given node, and the data in any nodes of its
right subtree must be greater than or equal to the data in the given node. Of course, all of
this implies that the data items can be ordered by some sort of less than relationship. For
numbers this can obviously be done. For strings, alphabetical ordering is often used. For
records of data, a comparison based on a particular field (the key field) is often used.
The following is a binary search tree where each node contains a person's name. Only
first names are used in order to keep the example simple. Note that the names are ordered
alphabetically so that DAVE comes before DAWN, DAVID comes before DAWN but
after DAVE, etc.
How does one create a binary search tree in the first place? One way to do so is by
starting with an empty binary search tree and adding the data items one by one. The first
item becomes the root. The next item is placed in either a left child or right child node,
depending on the ordering. The third item is compared to the root, we go left or right
depending on the result of the comparison, etc. until we find the spot for it. In each case
we follow a path from the root to the spot where we insert the new item, comparing the
new item to each item in the nodes encountered along the way, going left or right at each
node so as to maintain the ordering prescribed above.
Traversals of Binary Trees
There are several well-known ways to traverse, to travel throughout, a binary tree. We
will look at three of them. The first is aninorder traversal. This consists of three overall
steps: traverse the left subtree (recursively), visit the root node, and traverse the right
subtree (recursively). When we "visit" a node we typically do some processing on it, such
as printing out the contents of the node. For example, an inorder traversal of the above
binary search tree gives us the names in this order:
BETH
CINDI
DAVE
DAVID
DAWN
GINA
MIKE
PAT
SUE
Note that we got the data back in ascending order. This will always happen when doing
an inorder traversal of a binary search tree. In fact, a sort can be done this way. One first
inserts the data into a binary search tree and then does an inorder traversal to obtain the
data in ascending order. Some people call this a tree sort.
Ads by OffersWizardNow, how exactly did we get the above list of data? Essentially,
we did so by following the recursive definition for an inorder traversal. First we traverse
the left subtree of the root, DAWN. That left subtree is the one rooted at DAVE. How do
we traverse it? By using the same three-step process. We first traverse its left subtree, the
one rooted at BETH. Of course, we then have to go through the three steps on the subtree
rooted at BETH. We begin by traversing its left subtree, but it is empty, so we visit the
root, BETH. That is the first data item printed. Then we traverse the right subtree, the one
rooted at CINDI. We use the three-step process on it, but since its subtrees are empty, we
simply print the root, CINDI, which is the second item printed. We then back up to where
we left off with the subtree rooted at DAVE. We have now traversed its left subtree, so
we go on to print the root, DAVE, and then traverse the right subtree. Since the right
subtree itself has empty subtrees, we end up just printing its root, DAVID. We continue
in a similar fashion for the rest of this binary search tree.
The other two traversals that we will study are the preorder traversal and thepostorder
traversal. They are very similar to the inorder traversal in that they consist of the same
three steps, but reordered slightly. The preorder traversal puts the step of visiting the root
first. The postorder traversal puts the step of visiting the root last. Everything else stays
the same. Here is an outline of the steps for all three of our traversals.
Preorder traversal
1. Visit the root
2. Traverse the left subtree
3. Traverse the right subtree
Inorder traversal
1. Traverse the left subtree
2. Visit the root
3. Traverse the right subtree
Postorder traversal
1. Traverse the left subtree
2. Traverse the right subtree
3. Visit the root
As an example, let's do a postorder traversal of the binary expression tree for 4 * 5 3 that
we
looked
at
earlier.
The
tree
is
shown
again
for
convenience:
First we traverse the left subtree of the whole binary tree. This is the subtree rooted at *.
To do so, we apply our three steps. We traverse its left subtree, which results in
printing 4. Then we traverse the right subtree, which results in printing 5. Then we visit
the root, printing *. Next, we back up to where we left off with the whole binary tree. We
have now traversed the left subtree, so we traverse the right subtree, printing 3. Then we
visit the root, printing -. Overall we end up printing 4 5 * 3 -, the postfix formof the
expression. A postfix expression is deciphered by looking at it left to right and using the
fact that each operator (such as *) applies to the two previous values. Note that the
traversal always works like this: a postorder traversal of a binary expression tree yields
the postfix form of the expression. You may be familiar with postfix expressions in that
some calculators use them. In ordinary mathematics we are used to using infix
expressions, where operators such as + and * come between the two values to which they
apply.
For practice try a preorder traversal of the same binary expression tree for 4 * 5 - 3. The
result should be - * 4 5 3. This is the prefix form of the expression, that is, the form in
which each binary operator precedes the two quantities to which it applies. A preorder
traversal of a binary expression tree always gives the prefix form of the expression.
The natural conjecture, then, would be that the inorder traversal of a binary expression
tree would produce the infix form of the expression, but that is not quite true. With the
above expression it is true. However, try the infix expression (12 - 3) * 2. Here
parentheses are used to indicate that the subtraction should be done before the
multiplication. The binary expression tree looks like this:
As you can verify, an inorder traversal of this binary expression tree produces 12 - 3 * 2,
which is the infix form of a slightly different expression, one in which the multiplication
is done before the subtraction. The problem is that we did not get the parentheses back. It
is possible to modify the code for an inorder traversal so that it always parenthesizes
things, but a plain inorder traversal does not give any parentheses.
Uses of a Binary Search Tree
A binary search tree can be a very useful data structure. We have already seen that it can
be used to create a sort routine. Such a sort routine is normally pretty fast. In fact, it
is Theta(n * lg(n)) on the average. However, it does have a bad worst case, namely when
the data is already in ascending or descending order. (Try it. Start with a list of data items
in order and insert them one by one into a binary search tree. What does this tree look
like? Why would this make it slow to access the data later when we do the inorder
traversal?)
Another use of a binary search tree is in storing data items for fast lookup later. In the
average case it is pretty fast to insert a new item into a binary tree, because in the average
case the data is fairly random and the binary tree is reasonably "bushy". (In such a tree it
is known that the height of the binary tree is Theta(lg(n)), so that insertion is
a Theta(lg(n)) operation.) Similarly, doing a lookup of an item already in the binary tree
follows the same pattern as used when it was inserted. Thus lookup is Theta(lg(n)) on
average.
For example, to look up GINA in the binary tree above, one compares GINA to DAWN,
the root. Since GINA is larger, move to the right child, MIKE. Now compare GINA to
MIKE. Since GINA is smaller, move to the left child GINA. Now compare GINA to the
item in the node, also GINA, and we see that we have a match. All lookups are like this.
One starts at the root and follows a path from the root to the matching item (or to a leaf if
no match is ever found).