Professional Documents
Culture Documents
Programs can be designed more easily because a small team deals with only a
small part of the entire code.
assert(!empty(q));
{
void *temp = q -> head -> element;
q -> head = cdr_and_free(q -> head);
if(empty(q))
q -> tail = NULL;
return temp;
}
3.
4. It is very easy to move from a child to its parents and vice versa.
Disadvantages:
1. Lot of memory area wasted.
2. Insertion and deletion of nodes needs lot of data movement.
3. Execution time high.
4. This is not suited for trees other than full and complete tree
List the advantages of linear representation and linked representation of binary tree.
In this representation, each node of a binary tree is defined as shown below
LEFT
DATA
RIGHT
DATA field contains information. LEFT field holds the address of left child node and
RIGHT field holds the address of right child node. If there are no children, the address
fields hold null value. The first node address is called pointer of the tree. Using this
address only we can access the tree.
Consider the tree given below.
The linked list representation of the above tree is
Advantages and disadvantages of linked representation
Advantages
1. A particular node can be placed at any location in the memory.
2. Insertions and deletions can be made directly without data movements.
3. It is best for any type of trees.
4. It is flexible because the system takes care of allocating and freeing of nodes.
Disadvantages
1. It is difficult to understand.
2. Additional memory is needed for storing pointers
3. Accessing a particular node is not easy.
4. Define binary tree traversal and explain any one traversal with example.
A. Binary tree traversal:- Binary tree traversal is defined as a process of visiting all
the nodes in the binary tree once. The visit always starts from the root node.
1. To read (print) or write data in the node. It is denoted by letter v.
2. To move to the left of that node. It is denoted by letter L.
3. To move to the right of that node. It is denoted by letter R.
a. In order traversal
b. Pre order traversal
c. Post order traversal
In order traversal (LVR)
This traversal is denoted by the letters LVR. The steps to be followed are
a. Start from the root node and move left until there is no left child. Then visit
the last node (print the data).
b. Move right and move left until there is no left child. Then visit the last node
c. If it is not possible to move right go back one node visit the node (print the
data) and do step
This traversal is called in order traversal.
Example: consider the binary tree
Steps
Start from the root node A and move left till last node that is up to node B and
print the data B
Move one step back and print the data A
Then move right to node C and move left till last node that is upto print the
data D
Move one step back and print the data C
Then move right to node E since no path to move. Print the data E
Therefore the result of the in order traversal is B A D C E.
Binary tree creation:
The following steps are used to create the binary tree.
Define a self-referential structure to define the node.
Allocate memory space for an empty node using the defined self-referential
structure.
Create the binary tree node using step i) and ii).
Step (i)- defining self-referential structure to define a node.
A node can be defined as a self-referential structure as shown below.
Struct node
{
datatype data;
Struct node *link;
struct node *rlink;
};
Where
directed graphs we usually use arrows for the arcs between vertices. An arrow
from u to v is drawn only if (u,v) is in the Edge set. The directed graph below
Whenever the GETNODE() is executed it checks for the availability of free node in the
AVAIL list and get a memory block from the AVAIL list.
Procedure returnnode() used to return back the used memory to the avail list, it will
be added as end of the list.
Variable block Storage Allocation:To over come the disadvantages of fixed block storage, block of variable sizes are a
used, which is represented in figure 1.1. Here also linked lists play a vital role for the
management of memory blocks. The procedures used for allocation and deallocation
of memory blocks from the variable block storage are as follows.
This procedure assumes the blocks of memory are stored in ascending order of their
sizes. The node structure maintains a field to store the size of the block, namely SIZE.
SIZEOF () is a method that will return the size of the node. The above procedure
initially check for the NULL status of AVAIL list and proceeds with the search for the
exact size of block which is requested and return the same, if the pool does not have
the requested size it will return the bigger size of block.
Procedure RETURNNODE() will return the used block of memory to the memory pool.
While returning useless like fixed block, it researches for the size of the existing pool
where it can be inserted. Because we assume that the free pool memory blocks are
arranged in ascending the size of the returning block and the same will be inserted
into the memory pool.
6. What is the use of external storage devices?
External storage Any type of storage device that is connected to and controlled
by a computer but is not integrated within it. Generally the devices are peripheral
units such as disk drives or tape transports. An external storage device may be
shared by more than one computer.
This takes the form of a stand-alone device that is separate from the computer.
External drives are connected to the computer with a cable plugged into a suitable
interface such as an USB port. Data then passes back and forth across the interface.
Once an external drive is attached to the system, it appears as an extra drive letter
in the folder tree, for example, E drive or K drive. The user can transfer files in the
usual way by using the drag and drop method.
The main advantage of external drives is that they are portable and so data is easily
moved from one location to another. External drives also allow safe backup of
internally stored data.
The main disadvantage compared to an internal drive is data transfer is slower and
they also take up space around the computer. Constant plugging in and out can also
physically wear out the port over time.
External storage takes many forms, for example:
portable hard disks
magnetic tape
DVD or CDs
PAN Drive
Disadvantages :
Not as reliable as other storage options like external hard disk and SSD. One
damaged disk in a backup set can make the whole backup unusuable.
Storage space is typically less than that of traditional magnetic hard drives.