Sie sind auf Seite 1von 12

Summer 2014 ASSIGNMENT

PROGRAM MCA(REVISED FALL 2012)


SEMESTER SECOND
SUBJECT CODE & NAME-MCA2020- ADVANCED DATA STRUCTURE
CREDIT 4, BK ID B1476, MAX. MARKS 60
Q. No. 1Define data structure? Explain different types of data structures [2+8] 10
Answer: A data structure is a particular way of storing and organizing data in a computer so
that it can be used efficiently.
Different kinds of data structures are suited to different kinds of applications, and some are
highly specialized to specific tasks. For example, B-trees are particularly well-suited for
implementation of databases, while compiler implementations usually use hash tables to look
up identifiers.
Data structures provide a means to manage large amounts of data efficiently, such as large
databases and internet indexing services. Usually, efficient data structures are a key to designing
efficient algorithms. Some formal design methods and programming languages emphasize data
structures, rather than algorithms, as the key organizing factor in software design. Storing and
retrieving can be carried out on data stored in both main memory and in secondary memory.
Data structures can be divided in to two types:
Linear data structure
Non Linear data structure
Linear data structure
When the data is stored in the memory in linear or sequential form is called linear data
structure. Examples of linear data structures include Array, Stack, Queue, Linked list.
Non Linear data structure
When the data is stored in the memory in dispersed or non sequential order is called non linear
data structure. Example of non linear data structures includes trees, graphs, files etc.
Arrays
Linear array (one dimensional array) is the simplest type of data structures. Linear array means
a list of a finite number n of similar data type referenced respectively by a set of n consecutive
numbers 1, 2, 3 n. For example, if the name of the array is A then the elements of array A are
denoted either by subscript notation, or by the parenthesis notation, or by the bracket notation.
a1, a2, a3 an
or

A (1), A (2), A (3) A (N)


or
A [1], A [2], A [3] A [N]
Where the number N in A [N] is called a subscript and A [N] is called a subscripted variable.
Linked Lists
Linked list is a way to store data in memory. A linked list consists of a serious of nodes, which
are not necessarily adjacent in memory. Each node contains the data field which has the element
and the next field which has the link to the node containing its successor. The figure 1.2 shows a
node with data and link fields.

Figure 1.2: Node of a linked list


Generally in linked list the elements are connected by the link field which contains the address
of the next node. The link field of last node is marked by null pointer which indicates the end of
the list and a START variable which contains the address of the first node in the list. The figure
1.3 shows the linked list.

Figure 1.3: Linked list


Stack
It is a linear list in which insertions and deletions are restricted at one end, called the top. The
following figure 1.4 shows a stack with 5 elements and the top pointer where both insertion and
deletion are performed.

Figure 1.4: Stack


Stack contains two operation push and pop. Push is used to insert an element into stack and pop
is used to remove an element from stack. The following figure 1.5 shows the two operations how
it is performed in stack. It is also called as last- in first- out (LIFO), because the element pushed
last need to be popped out first.
Queue

It is a linear list in which insertion and deletion will take place in different end. As shown in
figure 1.6 the end where we insert an element is called the rear end and deletion at front end.
The element entered first need to be removed first, so it is also called as first- in first- out
(FIFO).

Figure 1.5: Queue


Trees
Tree is a nonlinear data structure which contains the hierarchical relationship between various
elements is called a tree. One node is distinguished as a root, every other node is connected by a
directed edge from exactly one other node, with the direction of parent -> children as referred in
the figure 1.7.

Figure 1.6: Tree Structure


Graph
Data sometimes contain a relationship between pairs of elements which is necessarily
hierarchical in nature. The data structure referred in figure 1.8 reflects this type of relationship
is called a graph.

Figure 1.8: Graph Structure

2 Write short notes on:

a) Doubly linked list


b) Circular linked list [5+5] 10
Answer:
a) Doubly linked list
In some situation we need to traverse both forward and backward of a linked list. The linked list
with this property needs two link field one to point the next node is called next link field and
another to point the previous node is called previous link field. The linked list containing this
type of nodes is called doubly linked list or two- way list. Here first nodes previous link field and
the last nodes next link field are marked as null. The figure 3.15 shows the node structure.

Figure: Node Structure


The figure 3.16 shows the structure of doubly linked list.

Figure: Doubly Linked List


The operations of doubly linked list are same as one- way list they are traversing, searching,
insertion and deletion.
b) Circularly linked list
Circular linked list is the one where the null pointer in the last node is replaced with the address
of the first node so that it forms a circle. The advantage of this circular linked list is easy
accessibility of node i.e. every node is accessible from a given node. The circular linked list can
be implemented both in one- way list and two- way lists.
The following figure shows a singly circular list where the link of the last node is points to the
first node.

Figure: A Singly Circular Linked List


The following figure shows a doubly circular list where the last nodes next link points to the first
node and first nodes previous link points to the last node and makes a circle.

Figure: A Doubly Circular Linked List

3 List the Advantages and Disadvantages of Linear and linked representation of


tree. [5+5] = 10
Answer:
Advantages of linear representation of binary tree
1) Node can be accessed directly with the help of the index through which we can improve the
efficiency of execution time of an algorithm.
2) Data are stored without pointer reference of successor or predecessor
3) This representation is very much useful where the language does not support the dynamic
memory allocation.

Disadvantages of Linear representation of binary tree


1) Memory is wasted here because it will be allocated for all the nodes absence of node will leads
to empty entries in array.
2) Since the array size is limited enhancement of tree structure is restricted.
3) Inefficiency in processing time during insertion or deletion of nodes because considerable
movement of up and down is taking place in array structure.
Advantages of linked representation of binary tree
1) Utilization of memory is efficient.
2) Enhancement of tree is possible in this representation.
3) Insertion and deletion of nodes can be easily handled with the pointers without data
movement.

Disadvantages of linked representation of tree


1) It is difficult to implement with the language which does not support the dynamic allocation
of memory.
2) Since pointer is involved for data reference it occupies more memory.

4 List and explain any Five types of graph. [5*2]= 10


Answer:
Types of Graphs
Depending upon the vertices and edges and the weight associated to it, graphs can be classified
as:
1) Undirected graph: In Undirected Graph, the directions of edges are not assigned. Edges in
the Undirected graph only connect to each other. In an undirected graph, edge (v1,v2) is
equivalent to edge (v2,v1) since they are unassigned.
2) Directed graph: A directed graph G is defined as a graph where each edge e in G is
assigned a direction. In directed graph each edge e is identified with an ordered pair (v1,v2) of
nodes in G rather than an unordered pair (v1,v2). Or we can also say that in directed graph
(v1,v2) and (v2,v1) are two edges where the former edge leaves v1 and ends at v2, and the
opposite for the latter.
In directed graph since each edge has a capacity and each edge receives a flow, it can be seen as
a flow network. The Ford-Fulkerson algorithm is used to find out the maximum flow from a
source to a sink in a graph.
3) Weighted graphs: The graph is called Weighted Graph, if information like cost or weight is
associated to the traversal of an edge. Directed and undirected graphs may both be weighted.
The operations on a weighted graph are the same with addition of a weight parameter during
edge creation. Weighted Graph operation is the extension of Undirected or Directed graph
operation.
4) Multigraph: A multigraph is a graph which has more than one edge between the same two
vertices. For example, if one were modeling airline flights, there might be multiple flights
between two cities, occurring at different times of the day.
When we want to distinguish between different nodes and edges then we can associate labels
with each nodes and edges. If a label is associated with each nodes and edges in a graph then
such a graph is said to be labeled.

5) Sparse graph: Graphs are said to be sparse if the number of edges is far less than |V |2 i.e.
|E| << |V |2.

6) Acyclic graph: It is defined as a graph with no path and starts and ends at the same vertex.
An acyclic undirected graphic is like a tree.

Directed Acyclic graph (DAG) is a directed graph with no path that starts and ends at the same
vertex. It is also known as oriented acyclic graph.
7) Graph with isolated vertices: If a vertex is not adjacent to any other vertices in a graph,
then such type of vertex is known as Isolated Vertex.
8) Null graph: A graph containing only isolated vertices is called Null Graph.
9) Strongly connected graph: A directed graph G is said to be strongly connected if for each
pair (v1, v2) of nodes in G there is a path from v1 to v2 and there is also a path from v2 to v1.
Whereas G is said to be unilaterally connected graph if for any pair (u, v) of nodes in G, there is a
path from u to v or a path v to u.
10) Unilaterally connected graph: A graph is said to be Unilaterally connected graph if for
any pair (v1,v2) of nodes in G, there is a path from v1 to v2 or a path from v2 to v1. .

5 Explain
1. Fixed block storage allocation.
2. Variable block storage allocation [5+5] = 10
Answer:
Fixed block storage allocation
First block storage allocation is the simplest case of dynamic storage allocation. This is the
straight forward method in which, all the blocks are of identical in size. The user can decide the
size of the block. The operating system keeps a pointer called AVAIL. This pointer points to
memory as shown in figure 10.1.

AVAIL

FIXED
NODE

SIZE

Figure 10.1: Free storage with fixed block memory


A user program communicates with the memory manager by means of two functions
GETNODE(NODE) and RETURNNODE (ptr). GETNODE() procedure is used to avail an free
node from the AVAIL list whereas the RETURNNODE() is used to return the block of memory,
whenever a memory block is no longer required.
Procedure GETNODE(NODE)
If (AVAIL=NULL) then
Print The memory is insufficient
Else
Ptr=AVAIL
AVAIL=AVAIL.LINK
Return(ptr)
Exit
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 as shown in the figure 10.2.

Figure 10.2: Getting a block from AVAIL list

Procedure RETURNNODE(ptr)
Ptr1=AVAIL
While(ptr1.LINK is not NULL)
Ptr1=ptr1.LINK
Ptr1.LINK=ptr
Ptr.LINK=NULL

Procedure RETURNNODE() used to return back the used memory to the AVAIL list, it will be
added at the end of the list as shown in the figure 10.3.

Figure 10.3: Returning a block to AVAIL list


So far as the implementation of fixed block allocation is concerned, this is the simplest strategy.
But main drawback of this strategy is the wastage of space. For example, suppose each memory
block is of size 1k (1024 bytes); now for a request of a memory block, say, of size 1.1k we have to
avail 2 blocks (that is 2k memory space), thus wasting 0.9k memory space. Making the size of
the block too small reduces the wastage of space; however, it also reduces the overall
performance of the scheme.
Variable block storage allocation
To overcome the disadvantages of fixed block storage, blocks of variable sizes are used, which is
represented in the figure 10.4. Here also linked lists play a vital for the management of memory
blocks. The procedures used for allocation and deallocation of memory blocks from the variable
block storage are as follows.

Figure 10.4: Availing a node from a pool with variable sized blocks.
Procedure GETNODE(NODE)
If (AVAIL=NULL) then
Print Memory is insufficient
Exit.
Endif
Ptr=AVAIL
While (ptr.LINK is not NULL) and
(ptr.SIZE<SIZEOF(NODE)) do
ptr1=ptr

ptr=ptr.LINK
Endwhile
if (ptr.LINK is NULL) and
(ptr.SIZE<SIZEOF(NODE)) then
Print Memory request is too large: unable to serve
Else
Ptr1.LINK=ptr.LINK
Return (ptr)
Endif
Exit

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(ptr)
Ptr1=AVAIL
While (ptr1.SIZE < ptr. SIZE) and (ptr1.LINK NULL) do
Ptr2=ptr1
Ptr1=ptr.LINK
Endwhile
If (ptr.SIZE <ptr1.SIZE) then
Ptr2.LINK =ptr
Ptr.LINK=ptr1
Else
Ptr1.LINK=ptr
Ptr.LINK=NULL
Endif
Exit

Procedure RETURNNODE() will return the used block of memory to the memory pool. While
returning unless like fixed block, it searches for the size the existing pool where it can be
inserted. Because we assume that the free pool memory blocks are arranged in ascending order.
So while returning, procedure will find the place according 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? Explain any two external storage
devices [4+3+3]=10
Answer:
An external storage device may be defined as device other than the main memory on which
information or data can be stored and from which the information retrieved for processing.
External storage devices are having larger capacities and fewer expenses to store compared to
main memory.
Primary uses of external storage devices are:
Backup or overlay of program during execution.
Storage of programs, subprograms and data.
Storage of information in files.

External storage devices:


Magnetic tape
Magnetic tape is an information storage medium consisting of a magnetisable coating on a thin
plastic strip. Nearly all recording tape is of this type, whether used for video with a video
cassette recorder, audio storage (reel-to-reel tape, compact audio cassette, digital audio tape
(DAT), digital linear tape (DLT) and other formats including 8-track cartridges) or general
purpose digital data storage using a computer (specialized tape formats, as well as the abovementioned compact audio cassette, used with home computers of the 1980s, and DAT, used for
backup in workstation installations of the 1990s).
Modern magnetic tape is most commonly packaged in cartridges and cassettes. The device that
performs actual writing or reading of data is a tape drive. When storing large amounts of data,
tape can be substantially less expensive than disk or other data storage options. Tape storage has
always been used with large computer systems. Modern usage is primarily as a high capacity
medium for backups and archives.

Magnetic drums
A magnetic drum, is a direct-access or random-access storage device, also referred to as drum.
is a metal cylinder coated with magnetic iron-oxide material on which data and programs can be
stored. Magnetic drums were once used as a primary storage device but have since been
implemented as auxiliary storage devices.
The tracks on a magnetic drum are assigned to channels located around the circumference of the
drum, forming adjacent circular bands that wind around the drum. A single drum can have up to
200 tracks. As the drum rotates at a speed of up to 3,000 rpm, the device's read/write heads

deposit magnetized spots on the drum during the write operation and sense these spots during a
read operation. This action is similar to that of a magnetic tape or disk drive.
Unlike some disk packs, the magnetic drum cannot be physically removed. The drum is
permanently mounted in the device. Magnetic drums are able to retrieve data at a quicker rate
than tape or disk devices but are not able to store as much data as either of them.
A magnetic drum differs from a magnetic disk in that the tracks in which the data is stored are
assigned to channels located around the circumference of the drum as shown in figure 12.2. That
is, the channels form circular bands around the drum. The coded representation of data in figure
12.2 is similar to that used on 9-track magnetic tape, 8-bit code. The basic functions of the
read/write heads are to place magnetized spots (those little binary 0's and 1's) on the drum
during a writing operation and to sense these spots during a reading operation. The read/write
heads of a drum perform in a manner similar to the read/write heads of a magnetic tape unit or
disk drive unit.
The tracks on each channel are grouped into sectors. It is almost like the format used on disk
packs when referring to tracks (or cylinders) and sectors. As the drum rotates, the reading or
writing occurs when the specified sector of a given channel passes under the read/write head for
that channel. Some drums are mounted in a horizontal position, while others are mounted in a
vertical position. Another major difference in the design is the number of read/write heads.
Some drums use only one read/write head, which services all channels on the drum. In this case,
the head moves back and forth (or up and down) over the surface of the drum as required. Other
drums, using multiple read/write heads, have one principal advantage over drums with the
single-head type. Since one read/write head is assigned to each channel, no read/write head
movement is required. That is, the time required for head positioning is zero. The only
significant time required when reading or writing is the rotational delay that occurs in
reaching a desired record location.

Figure 12.2: Magnetic drum

Das könnte Ihnen auch gefallen