Sei sulla pagina 1di 26

Practical uses of different data structures

Hash Table - used for fast data lookup - symbol table for compilers, database indexing,
caches,Unique data representation.
Trie - dictionary, such as one found on a mobile telephone for autocompletion and spellchecking.
Suffix tree - fast full text searches used in most word processors.
Stack - undo\redo operation in word processors, Expression evaluation and syntax parsing,
many virtual machines like JVM are stack oriented.
Queues - Transport and operations research where various entities are stored and held to be
processed later ie the queue performs the function of a buffer.
Priority queues - process scheduling in the kernel
Trees - Parsers, Filesystem
Radix tree - IP routing table
BSP tree - 3D computer graphics
Graphs - Connections/relations in social networking sites, Routing ,networks of
communication, data organization etc.
Heap - Dynamic memory allocation in lisp
Application of Stack :
1.
2.
3.
4.
5.

Parsing
Recursive Function
Calling Function
Expression Evaluation
Expression Conversion
o Infix to Postfix
o Infix to Prefix
o Postfix to Infix
o Prefix to Infix
6. Towers of Hanoi

What are the Real Life Applications of Data Structures.


You have the following data structures available to you: single and two dimensional arrays,
linked-list, doubly linked-list, queue, stack, binary tree, binary search tree, heap, a balanced
search tree (such as 2-3, 2-3-4, etc), hash table, and directed and undirected graphs. For each
of the following scenarios given below
a) To store a set of programs which are to be given access to a hard disk according to their
priority.
b) For representing a city region telephone network.
c) To store a set of fixed key words which are referenced very frequently.
d) To represent an image in the form of a bitmap.
e) To implement back functionality in the internet browser.
f) To store dynamically growing data which is accessed very frequently, based upon a key
value.
g) To implement printer spooler so that jobs can be printed in the order of their arrival.
h) To record the sequence of all the pages browsed in one session.
i) To implement the undo function in a text editor.
j) To store information about the directories and files in a system.

PART-A
1.What is called as a Data Structure?
A Data Structure defines a way of representing or organizing all data that contains
both the data items and their relationship with each other.
2.Differentiate between data type and data structures.
Data Type: Data Type of a variable is a set of values the variable may assume.
Eg. int, char & real
Data Structures: Data structure mean the way of organizing data values with the help of
existing data types.
Eg. Array, stack queue, & tree.
3.What are Primary Data Structures?
Integers
Floating-point numbers.
Character Constants

4.What are the types of Secondary Data Structures?


Static Data structures
Dynamic Data structures.
5.What are the static data structures?
Arrays
Structures
6.What are the types of dynamic data structures?
Linear Data Structures
Non-Linear Data Structures.
7.Give examples of Linear and Non-Linear Data Structures.

Linear Data Structures


i)
Linked Lists(Singly & Doubly Linked Lists)
ii)
Circular Linked Lists(Circular-singly&Circular-doubly
Linked Lists).
Non-Linear Data Structures
i)
Trees
ii)
Graphs.

8.What do you mean by Abstract Data Types?


Classes encapsulate all the essential properties of the objects that are to be
created. Since the classes use the concept of data abstraction, they are known as Abstract
Data Types (ADT).
9.List the operation of set ADT?
Union and Find are the two operations on set ADT
10. Define Stack.
Stack is a list, in which insertion and deletion of elements are made at one end called
top. Push and Pop are two important operations performed on stacks.
Push: The incoming element is placed on top of the stack.
Pop: Removes the topmost element from the stack.
11. Define Queue.
Queue is a list in which insertion takes place at one end, called the rear and the
deletion at the other end, called the front.
In queue, the item inserted first is removed first. Therefore it is called a First In First
Out (FIFO) structure.
12. Define Circular Queue.
In array based implementation of queue, inefficiency arises only when the value of the
rear pointer exceeds maximum size during insertion. This can be rectified if we logically
consider the queue to be circular.

In circular queue, once the rear pointer reaches the maximum size, the next location I the
first one (index 0), provided the first location is vacant. The specific location is calculated by
mod (%) operator.
13. Give some applications of stack.
Evaluation of Expressions.
Expression conversion.
Balancing of symbols.
Function Calls.
14. Define Dequeue.
A dequeue is an ordered list in which additions and deletions may be carried out at either
end.

15. Distinguish between stack and queue.


STACK
Insertion and deletion are made at one end.
The element inserted last would be
removed first. So LIFO structure.
Full stack condition:
If(top==Maxsize)
Physically and Logically full stack

QUEUE
Insertion at one end rear and deletion at
other end front.
The element inserted first would be
removed first. So FIFO structure.
Full stack condition:
If(rear = = Maxsize)
Logically full. Physically may or may not
be full.

16.State the difference between cursor and pointers.


Pointer: Pointer is a variable, which stores the address of another variable.
Using pointers, memory can be allocated dynamically.
Cursor: Cursor is a temporary memory space. Memory allocated is static.
17.What is an ordered list
An ordered list is a linear list which is been ordered by some key.
Eg. An alphabetized list of students in a class, a list of exam scores in decreasing order.
18.State the difference between array and linked list.
Array

Linked List

Contiguous memory location

Memory location need not be necessarily


contiguous

Operations such as insertion and deletion Insertion and deletions are easier and needs

are ineffective since the memory locations only one pointer assignment.
need to be moved up and down
respectively.
Inefficient use of memory space.

A small amount of memory is been wasted


for storing a pointer, which is been
associated with each node.

19.Give the applications of linked list.


Applications of linked list are:
Bin Sort, radix sort, convex Hull, Offline Equivalence classes, Polynomial Manipulation.

20.What are the advantages and disadvantages of linked list?


Advantages:
a. Memory location for a linked list is dynamic, that is memory allocation is done during
run time. So memory will not be wasted.
b. Data movements during insertion and deletion will be eliminated. So time will not be
wasted.
c. Memory allocation for each node of a linked list need not be continuous.
Disadvantages:
d. Nodes of a linked list cannot be accessed directly. To access a particular node accessing
should start only from the beginning.
e. To store a single data, along with data, memory must be allocated for a pointer also,
which wastes memory.
21.Convert the infix (a+b)*(c+d)/f into postfix & prefix expression
Postfix
:ab+cd+*f/
Prefix
:/*+ab+cdf
22.Write the steps required to evaluate the postfix expression.
Repeatedly read characters from postfix expression
If the character read is an operand, push the value associated with it into the stack
If it is an operator, pop the top two values from stack, apply the operator to them
and push the result back onto the stack.
23.Define Singly Linked List.
A singly linked list is a list structure in which each node contains a single pointer field
that points to the next node in the list, along with a data field.

24.Define Doubly Linked List.


A doubly linked list is a list structure in which each node contains two pointer fields
along with a data field namely,
BLINK Points to the previous node in the list
FLINK Points to the successive node in the list

PART-B
1.Write a program to print out the elements of a singly linked list.
2.Given two sorted lists,L1 and L2,write a procedure to compute L1 L2 using only the
basic list operation.
3.Write a program to evaluate a postfix expression.
4.Write a program to convert postfix expression in to infix.
5.Write a routine to implement queues using linked list
6.Write a routine to implement queues using Array.
7.Explain the procedure to insert a new node in the
(a) Beginning
(b) End of the list
8.Write an algorithm for the following in doubly linked list.
(i) inserting a node to the left.
(ii) Deleting a node.
9.Explain the cursor implementation of linked list.
10.Explain the following algorithm of a circular linked list.
(a) inset the node at the beginning
(b) delete a node from beginning
11. Write a routine to implement stack using
(a) array
(b) linked list
12. Write a routine to implement polynomial ADT.

UNIT-II
PART-A

Tree Structures

1. Define Tree.
A Tree is a collection of one or more nodes with a distinct node called the root , while
remaining nodes are partitioned as T1 ,T2, ..,Tk , K 0 each of which are sub trees, the edges
of T1,T2,,Tk are connected the root.

2. Give some applications of Trees.

Implementing the file system of several operating systems.


Evaluation of arithmetic expression.
Set representation.
Gaming/Decision making problems.

3. Define node, degree, siblings, depth/height, level.


Node: A node is an item of information with branches to other items.
Degree: The number of subtrees of a node is called is degree.
Siblings: The children of the same parent is said to be siblings.
Level: The level of a node is defined recursively by assuming the level of the root to be
one and if a node is at level l, then its children at level l+1.
Depth/Height: The depth/height of a tree is defined to be the level of a node which is
maximum.
4.Define a path in a tree.
A path in a tree is a sequence of distinct nodes in which successive nodes are
connected by edges in the tree.
5.Define terminal nodes in a tree.
A node which has no children is called a terminal node.It is also referred as a leaf
node.these nodes have a degree as zero.
6. Define nonterminal nodes in a tree
All intermediate nodes that traverse the given tree from its root node to the terminal
nodes are referred as terminal nodes.

7.Define a Binary Tree.


A Binary Tree is a tree,which has nodes either empty or not more than two child
nodes,each of which may be a leaf node.
8.Define a full binary tree.
A full binary tree,is a tree in which all the leaves are on the same level and every nonleaf node has exactly two children.
9.Define a complete binary tree.
A complete binary tree is a tree in which every non-leaf node has exactly two children
not necessarily to be on the same level.
10.Define a right-skewed binary tree.
A right-skewed binary tree is a tree,which has only right child nodes.
11.State the properties of a Binary Tree.
Maximum No. of nodes on level n of a binary tree is 2^(n-1),where n>=1.
Maximum No. of nodes in a Binary tree of height is 2^(n-1),where n>=1.
For any non-empty tree,nl=nd+1 where nl is the number of leaf nodes and nd is the
no. of nodes of degree 2.
12.What are the different ways of representing a Binary Tree?
Linear Representation using Arrays.
Linked Representation using Pointers.
13.State the merits of linear representation of binary trees.
Store methods is easy and can be easily implemented in arrays.
When the location of the parent/child node is known,other one can be determined
easily.
It requires static memory allocation so it is easily implemented in all programming
languages.
14.State the DISADVANTAGES of linear representation of binary trees.
Insertions and deletions are tougher.
Processing consumes excess of time.
Slow data movements up and down the array.
15. Define Traversal.
Traversal is an operation which can be performed on a binary tree is visiting all the
nodes exactly once.
Inorder: traversing the LST, visiting the root and finally traversing the RST.
Preorder: visiting root, traversing LST and finally traversing RST.
Post- order: traversing LST, then RST and finally visiting root.
16.What are the tasks performed while traversing a binary tree?

Visiting a node
Traverse the left structure
Traverse the right structure.

17.What are the tasks performed during preorder traversal?


Process the root node
Traverse the left subtree
Traverse the right subtree.
Ex : +AB
18.What are the tasks performed during inorder traversal?
Traverse the left subtree
Process the root node
Traverse the right subtree.
Ex : A+B
19.What are the tasks performed during postorder traversal?
Traverse the left subtree
Traverse the right subtree.
Process the root node.
Ex : AB+
20. Give the pre & postfix form of the expression (a + ((b*(c-e))/f).

21.Define a Binary Search Tree.


A Binary Search Tree is a special binary tree,which is either empty or if it is
empty it should satisfy the conditions given below:

Every node has a value and no two nodes should have the same value(Values should
be distinct).

The value in any left subtree is less than the value of its parent node.

The value in any right subtree is greater than the value of its parent node.

22.What do u mean by General trees?


General Tree is a tree with nodes having any number of children.

23. Define Forest.


A forest is a collection on N(N>0) disjoint tree or group of trees are called forest. If
the root is removed from the tree that tree becomes a forest.
PART-B
1.what are the types of representation of binary tree?
2.what is traversal? Give an algorithm for traversal in the binary tree.
3.Draw a Binary search tree for the following input list 60,25,75,15,50,66,33,44.Trace the
algorithm to delete the nodes 25,75,44 from the tree.
4.Explain and write routine to the various tree traversal methods.
5.Show the result of inserting 3,1,4,6,9,2,5,7 in to an initially empty binary search tree.
6.Show that for the perfect binary tree of height h containing 2h+1-1nodes.
7.Write a routine to implement the basic binary search tree operations.
8.Show the result of inserting 2,1,4,5,9,3,6,7 in to an initially empty binary tree.
9.Explain in detail about Threaded binary trees.
10. Write a procedure to Delete an element from a binary search tree and show the result
of deleting the root.
11.Construct an expression tree for the input ab+cde+**

UNIT-III

Balanced Trees

PART-A
1.Define balanced search tree.
Balanced search tree have the structure of binary tree and obey binary search tree
properties with that it always maintains the height as O(log n) by means of a special kind of
rotations. Eg. AVL, Splay, B-tree.
2. Define AVL tree.
An empty tree is height balanced. If T is a non-empty binary tree with TL and TR as
Its left and right subtrees, then T is height balanced if
1. TL and TR are height balanced.
2. | hL - hR | 1.
Where hl and hr are the height of TL and TR respectively.
3.What are the drawbacks of AVL trees?
The drawbacks of AVL trees are
Frequent rotations
The need to maintain balances for the trees nodes
Overall complexity, especially of the deletion operation.
4. What is a heap?
A heap is a partially ordered data structure, and can be defined as a binary tree

assigned to its nodes, one key per node, provided the following two conditions
are met
The trees shape requirement-The binary tree is essentially complete, that is all
the leaves are full except possibly the last level, where only some rightmost
leaves will be missing.
The parental dominance requirement-The key at each node is greater that or
equal to the keys of its children
5.What is the main use of heap?
Heaps are especially suitable for implementing priority queues. Priority queue is a set
of items with orderable characteristic called an items priority, with the following
operations
Finding an item with the highest priority
Deleting an item with highest priority
Adding a new item to the set
6.Give three properties of heaps?
The properties of heap are
There exists exactly one essentially complete binary tree with n nodes. Its
height is equal to log2n
The root of the heap is always the largest element
A node of a heap considered with all its descendants is also a heap
7.Give the main property of a heap that is implemented as an array.
A heap can be implemented as an array by recording its elements in the top-down, left-toright fashion. It is convenient to store the heaps elements in positions 1 through n of such
an array. In such a representation
The parental node keys will be in the first n/2 positions of the array, while the
leaf keys will occupy the last n/2 positions
The children of a key in the arrays parental position i (1 i n/2) will be in
positions 2i and 2i+1and correspondingly, the parent of the key in position i
(2 i n) will be in position i/2.
8.What are the two alternatives that are used to construct a heap?
The two alternatives to construct a heap are
Bottom-up heap construction
Top-down heap construction
9.Give the pseudocode for Bottom-up heap construction.
ALGORITHM HeapBottomUp(H[1..n])
//Constructs a heap from the elements of the given array
//Input An array H[1..n] of orderable elements
//Output A heap H[1..n]
for I n/2 downto 1 do

k I ; v H[k]
heap false
while not heap and 2*k n do
j 2*k
if j < n
if H[j] < H[j+1] j j+1
if v H[j]
heap true
else H[k] H[j]; k j
H[k] v
10.What is the algorithm to delete the roots key from the heap?
ALGORITHM
Exchange the roots key with the last key K of the heap
Decrease the heaps size by one
Heapify the smaller tree by sifting K down the tree exactly in the same way
as bottom-up heap construction. Verify the parental dominance for K: if it
holds stop the process, if not swap K with the larger of its children and repeat
this operation until the parental dominance holds for K in its new position.
11.Who discovered heapsort and how does it work?
Heapsort was discovered by J.W.J. Williams. This is a two stage process that
works as follows
Stage 1 Heap construction: construct a heap for a given array.
Stage 2 Maximum deletions: Apply the root deletion operation n-1 times to the
remaining heap
12.What is a min-heap?
A min-heap is a mirror image of the heap structure. It is a complete binary tree in
which every element is less than or equal to its children. So the root of the min-heap contains
the smallest element.
13. Define splay tree.
A splay tree is a binary search tree in which restructuring is done using a scheme called
splay. A splay is heuristic method which moves a given vertex v to the roof of the splay tree
using a sequence of rotations.
14. Define B-tree?
A B-tree of order m in an m-way search tree that is either empty or is of height 1 and
1. The root node has at least 2 children
2. All nodes other than the root node and failure nodes have at least m/2 children.
3. All failure nodes are at same level.
15. Define Priority Queue?

Priority queue is a specialized data structure in which the elements are organized
according to the priorities of some key value.
16. Define Binary Heap?
A Binary Heap is a complete binary tree in which the key value of any node must be
lesser than its children is called min heap. If the key value of any node is greater than its
children is called max heap.Binary heap is also called as partially ordered tree.
17. Explain array implementation of Binary Heap.
For any element in the array position i, the left child is at the position 2i, the right
child is at the position 2i+1 and parent is at the position i/2.
18. Define Max-heap.
Maxheap: A heap in which the parent has a larger key that the childs key values then
it is called Maxheap.
19. Explain AVL rotation.
Manipulation of tree pointers is centered at the pivot node to bring the tree back into
height balance. The visual effect of this pointer manipulation so to rotate the sub tree whose
root is the pivot node. This operation is referred as AVL rotation.
20.What are the different type of Rotation in AVL Tree?
Two types of rotation are
1.single rotation
2.double rotation.
PART-B
1.Show the result of inserting 10,12,1,14,6,5,8,15,3,9,7,4,11,13, and ,2, one at a time, in
to an initially empty binary heap.
2.Write a procedure to perform percolate up and percolate down in a binary heap.
3.Write and test a program that performs the operation Insert,DeleteMin,Build
Heap, Findmin, DecreaseKey, Delete ,and IncreaseKey in a binary Heap
4.Show the result of inserting 2,4,1,5,9,3,6,7 in to an initially empty AVL Tree.
5.Write a procedure to implement AVL single and double rotations.
6.Write a routine to perform insertion and deletion in B-Tree
7.Show the result of accessing the keys 3,9,1,5 in order in the splay tree in the following
figure

8.Show the result of deleting the element with key 6 in the resulting splay tree for the
previous exercise.
9.construct the heap for the following array structure.
5
19
8
37
75
55
14
22
43
4
10.Discuss the concept of AVL Tree in Detail with example.

UNIT-IV

Hashing and Set

PART-A
1.General idea of hashing and what is the use of hashing function?
A hash table similar to an array of some fixes size-containing keys.
The keys specified here might be either integer or strings, the size of the table is
taken as table size or the keys are mapped on to some number on the hash table
from a range of 0 to table size
2. Explain Hashing .
Hashing is a technique used to identify the location of an identifier x in the memory
by some arithmetic functions like f(x), which gives address of x in the table.
3.Explain Hash Function.
Hash Function takes an identifier and computes the address of that identifier in the
hash table.
4.Mention Different types of popular hash function.
1.Division method
2.Square method
3.Folding method
5.Define Collision.
When two different keys compute in the same location or address in the hash table
through any one of the hashing function then it is termed as collision.

6. Mention Different types of collision resolving techniques.


The collision resolving techniques are:
1.Separate chaining.
2.Open Addressing
Linear Probing
Quadratic Probing
Double Hashing.
7. Define Separate Chaining
Separate Chaining is a technique used to avoid collision, where a linked list is used to
store the keys which fall into the same address in the hash table.
8.Define Open Addressing.
Open addressing is an alternative to resolving collisions with linked lists.In an open
addressing hashing system,if a collision occurs,alternative cells are tried until an empty cell is
found.
9.Define Linear probing.
In Linear Probing,F is a linear function of i,typically F(i)=i.This amount to trying
cells sequentially in search of an empty cell.
10.Define Quadratic Probing
Quadratic Probing is a collsion resolution method that eliminates the primary
clustering problem of linear probingThe popular choice is F(i)=i2.
11.Define Double Hashing.
For Double Hashing ,One popular choice is F(i)=i . hash2(X).This formula says that
we apply a second hash function to X and probe at a distance hash2(X), hash2(X)and so on.
12.What are the use of hash table?
1.Compilers can use hash table to keep track of declared variable in source code.
2.A hash table is useful for any graph theory problem where nodes haver real
names instead of numbers
3.A third use of hash table is in program that play games.
4.On line spell checkers
13.Define Equivalence relation?
A relation R is defined on a set S if for every pair of element (a, b), a, bS, aRb is
either true or false if aRb is true, then we say that a is related to b.
An Equivalence relation is a relation R that satisfies these properties,
(1)
Reflexive aRa, for all a S
(2)
Symmetric aRa if and only if bRa
(3)
Transitive aRb and bRc implies that aRc.
Eg:- Electrical connectivity
14. List the operation of set ADT?
Union and Find are the two operations on set ADT

15.What is electrical connectivity?


Where all connection are metal wires, in an equivalence relation. The relation is
clearly reflexive ,as any component is connected to itself. If a is electrically connected to b,
then b must be electrically connected to a, so this relation is symmetric. Finally if a is
connected to b and b is connected to c then a is connected to c. Thus electrical connectivity is
an equivalence relation.
16.What is equivalence class?
The equivalence class of an element a S is the subset of S that contain all the
element that are related to a.
17.When the Disjoint set Union / Find algorithm is dynamic?
During the course of the algorithm,the set can change via the Union operation.The
algorithm must also operate on-line:when a find is preformed ,it must give an answer before
continuing.
18.Define smart union algorithms.
Always to make the smaller tree a sub tree of the larger ,breaking ties by any
method
Union by size
Union by height
19.What is path compression?
This is the only way to speed the algorithm up ,without reworking the data structure
entirely. Path compression is performed during a Find operation.
20.Write the code disjoint set Find with path compression method.
Set Type
Find(Element Type X,DisjSet S)
{
if(S[X]<=0)
return X;
else
return S[X]=Find(S[X],S);
}
PART-B
1.Explain Different types of Hash Function with example.
2.Given input { 4371,1323,6173,4199,4344,9679,1989} and a hash function h(X) = X
(mod 10).Show the resulting
1.Separate chaining table
2.Open addressing hash table using linear probing
3.Open addressing hash table using Quadratic probing
4.Open addressing hash table with second hash function h2(X)=7-(X mod 7)
3.Explain about collision resolution techniques.
4.Show the result of the following sequence of instructions :Union(1,2),
Union(3,4),Union(3,5),Union(1,7),Union(3,6),Union(8,9),Union(1,8),Union(3,10),
Union(3,11),Union(3,12),Union(3,13),Union(14,15),Union(16,17),Union(14,16),
Union(1,3),Union(1,14) where the Unions are: a. Performed arbitrarily

b. Performed by height
c. Performed by size
5.For each of the trees in the previous exercise, perform a Find with path compression on
the deepest node. Why dose path compression make De union hard?
6.Explain in detail about applications of set with example.
7.Show that if Union are performed by height, then the depth of any tree is O(log N).

UNIT-V

Graphs

PART-A
1. Define Graph.
A Graph G, consists of a set of vertices V, and a set of edges E.V is a finite non-empty set
consisting of vertices of vertices of the graph. The set of edges E consists of a pair of vertices
from the vertex set.

2.What is undirected graph.


If an edge between any two nodes in a graph is not directionally oriented, a graph is
called as undirected graph. It is also called as unqualified graph.
a

3.What is directed graph.


If an edge between any two nodes in a graph is directionally oriented, a graph is
called as directed graph.It is also called as digraph.
a

4.Define a cycle in a graph.


A cycle is a path containing atleast thee vertices such that the starting and the ending
vertices are the same.
5.Define a weakly connected graph.
A directed graph is said to be a weakly connected graph if any vertex doesnt have a
directed path to any other vertices.
6.Define a weighted graph.

A graph is said to be weighted graph if every edge in the graph is assigned some
weight or value.The weight of an edge is a positive value that may be representing the
distance between the vertices or the weights of the edges along the path.
2
a

b
5

11
c

7. Define parallel edges


In some directed as well as undirected graph certain pair of nodes are joined by more
than one edge, such edges are called parallel edges.
a

b
a

c
d
a
a
8.List some representation of Graphs?
Physically a graph can be represented as,
-adjacency matrix
-Incident matrix
-Adjacency list
-Adjacency multilist
-Circular adjacency list
8.Define Adjacency Matrix.
Adjacency Matrix is a representation used to represent a graph with zeros and ones.A
graph containing n vertices can be represented using n rows and n columns.
9.What is meant by Traversing a Graph?
It means visiting all the nodes in the graph
10. Define undirected graph / directed graph.
If G=(V, E) is a graph. The edge between v1 and v2 is represented as (v1, v2). If the edges
of the form (v1, v2) and (v2, v1) are treated as the same edge, then G is said to be an undirected
graph.
In case of a directed graph, the edge <v1, v2> and <v2, v1> are different.
11. Define out degree of a graph.
In a directed graph, for any node v, the number of outgoing edges from v are called
out degree of a node v. Ex : out degree of c =2
a

c
12. Define In degree of a graph.
In a directed graph, for any node v, the number of incoming edges to v are called
In degree of a node v. Ex : In degree of c =1
a

13. Define total degree of a graph.


The sum of the In degree and out degree of a node is called the total degree of the
node. Ex : total degree of a node c = 1 +2 =3
a

c
14. Define a path in a graph.
A path in a graph is defined as a sequence of distinct vertices each adjacent to the
next,except possibly the first vertex and last vertex is different.
The path in a graph is the route taken to reach the terminal node from a starting node.
a

c
a
The path from a to e are
P1 = ((a,b),(b,e))

b
a

d
a

e
a

P2 = ((a,c),(c,d),(d,e))
15. What is a complete Graph.
A complete graph is a graph in which there is an edge between every pair of vertices.
a

b
a

c
a

d
a

16. Give the adjacency list representation for the following

A
A

B
0
0
0
1

1
C0
a 0
1

B
a
D

C
1
0
0
1

1
D1
1
0

17. List out the graph traversals of graph search?


The two methods of traversal is,
-Depth First Search (DFS)
-Breadth First Search (BFS)
18. Define minimum cost spanning tree?
A spanning tree of a connected graph G, is a tree consisting of edges and all the vertices
of G.
In minimum spanning tree T, for a given graph G, the total weights of the edges of the
spanning tree must be minimum compared to all other spanning trees generated from G.
-Prims and Kruskal is the algorithm for finding Minimum Cost Spanning Tree.
19. Define Shortest path problem?
For a given graph G=(V, E), with weights assigned to the edges of G, we have to find the
shortest path (path length is defined as sum of the weights of the edges) from any given
source vertex to all the remaining vertices of G.
20.Define topological sort?
A topological sort is an ordering of vertices in a directed acyclic graph, such that if there
is a path from vi to vj appears after vi in the ordering.
21.What is the use of Kruskals algorithm and who discovered it?

Kruskals algorithm is one of the greedy techniques to solve the minimum spanning
tree problem. It was discovered by Joseph Kruskal when he was a second-year graduate
student.
22.What is the use of Dijksras algorithm?
Dijkstras algorithm is used to solve the single-source shortest-paths problem: for a
given vertex called the source in a weighted connected graph, find the shortest path to all its
other vertices. The single-source shortest-paths problem asks for a family of paths, each
leading from the source to a different vertex in the graph, though some paths may have edges
in common.
23. Prove that the maximum number of edges that a graph with n Vertices is
n*(n-1)/2.
Choose a vertex and draw edges from this vertex to the remaining n-1 vertices. Then,
from these n-1 vertices, choose a vertex and draw edges to the rest of the n-2 Vertices.
Continue this process till it ends with a single Vertex.
Hence, the total number of edges added in graph is
(n-1)+(n-2)+(n-3)++1 =n*(n-1)/2.
24. Define connected and strongly connected graph.
Two Vertices u and v are said to be connected if there exists a path from u to v in the graph.
A directed graph is said to be connected if every pair of vertices in the graph is connected.
A directed graph is said to be strongly connected if for every pair of distinct vertices vi and
vj, there exists two disjoint paths, one from vi to vj and the other from vj to vi.
1. Define Abstract Data Type (ADT).
Abstract data type is a collection of value definitions and the operations on
those values.
Value definitions
Operator definitions
2. Define a sequence.
A sequence is an ordered set of elements.
S=<s0,s1,s2.sn-1>
3. Write short notes on structures in C.
A basic data structure in C is called as the structure. A Structure is a group of
items in which each item is identified by its own identifier.
Example:
struct nametype
{
char first[10];
int roll;
}sname, ename;

4. What is the difference between a structure and union in C.


a. Same memory is used for all the members of union. At any time only one
member can be accessed.
b. Individual memory is used for structure members.
5. Define a Stack.
A stack is an ordered collection of items into which new items may be inserted and
from which items may be deleted at one end called the top of the stack.
It is also called as Last In First Out (LIFO).
6. What are the primitive operations that are performed on a Stack?
The primitive operations are
Push- inserting an element at the top of the stack
Push(s,i);
Pop removing an element at the top of the stack
i=pop(s);
7. How do you implement the Stack definition in C. Use array implementation?
#define STACKSIZE
struct stack
{
int top;
int items[STACKSIZE];
};
8. Write the steps for implementing the pop operation.
If the stack is empty, print a warning message and halt execution
Remove the top element from the stack.
Return this element to the calling program
9. What is recursive definition?
An object in terms of simpler case of itself is called recursive definition.
Examples:
To find the factorial of a given number
To print the Fibonacci series.
10. Define a queue.
A queue is a ordered collection of items from which itesm may be deleted at
one end (called the front of the queue) and into which items may be inserted at
the other end (called the rear of the queue).
It is also called as First in First out (FIFO).
11. How the queue is represented in C?
#define MAXQUEUE 100
struct queue

{
int items[MAXQUEUE];
int front, rear;
}q;
12. Define priority queue. What are the types of Priority queue?
The priority queue is a data structure in which the intrinsic ordering of the
elements does determine the results. There are two types
ascending priority queue
is a collection of items into which items can be inserted arbitrarily and
from which only the smallest item can be removed.
descending priority queue
13. What is the purpose of header node?
Sometimes it is desirable to keep an extra node at the front of the list. Such a
node does not represent an item in the list and is called the header node or a
list header.
14. How to create and delete a dynamic variable in C?
malloc() is a function helpful for creating a dynamic variable.
free() is a function helpful for deleting a dynamic variable.
15. How to create a node of a singly linked list using dynamic variables?
struct node
{
int info;
struct node *next;
};
typedef struct node *NODEPTR;
16. How to create a node of a Doubly linked list using dynamic variables?
struct node
{
int info;
struct node *next, *previous;
};
typedef struct node *NODEPTR;
17. Define a binary tree.
A binary tree is a finite set of elements that is either empty or is partitioned
into three disjoint subsets. One subset is the left and one subset of the right
and the third subset is the root of the tree.
18. What is a strictly binary tree?

If every non leaf node in a binary tree has nonempty left and right subtrees,
the tree is named as the strictly binary tree.
19. Define traversal in tree and what is the different type of traversals in tree?
To pass through the tree, enumerating each of its nodes once.
Three types of traversals
preorder traversal
i. visit the root
ii. Traverse the left subtree in preorder.
iii. Traverse the right subtree in preorder
inorder traversal
i. Traverse the left subtree in preorder.
ii. visit the root
iii. Traverse the right subtree in preorder
postorder traversal
i. Traverse the left subtree in preorder.
ii. Traverse the right subtree in preorder
iii. visit the root
20. How the binary tree node is represented dynamically?
struct nodetype
{
int info;
struct nodetype *left;
struct nodetype *right;
};
21. What are called leaf nodes?
The nodes which dont have any sons are called as leaf nodes.
22. What are called internal and external nodes?
The leaf nodes are called as external nodes and the non leaf nodes are called as
internal nodes.
23. Define O notation.
To capture the concept of one function becoming proportional to another as it
grows, a notation is which is called as O notation.
24. Define a graph.
A graph consists of a set of nodes (or vertices) and set of arcs (or edges).
25. Define weighted graph.
A number is associated with each arc of a graph is called a weighted graph.
The number associated with the arc is called the weight.
26. Define minimum spanning tree.

Given a connected weighted graph G, it is often desired to create a spanning


tree T for G such that the sum of the weights of the tree edges in T is as small
as possible. Such a tree is called minimum spanning tree.
27. Define Depth First Traversal.
Visits the successors of a visited node before visiting any of its brothers.
In DFT, each visited node is placed in the stack
28. Define Breadth First Traversal.
Visits all successors of a visited node before visiting any successors of any of
those successors.
In BFT, each visited node is placed on the queue.
29. What are called Dynamic data structures?
Structures which grow or shrink as the data they hold changes.
Example: Lists
30. Define Binary Search.
A technique for searching an ordered list in which we first check the middle
item and - based on that comparison - "discard" half the data. The same
procedure is then applied to the remaining half until a match is found or there
are no more items left.
31. What are the advantages of linked lists?
Overflow can never occur unless the memory is actually full.
Insertions and deletions are easier than for contiguous (array) lists.
With large records, moving pointers is easier and faster than moving
the items themselves.
32. What are the disadvantages of linked lists?
The pointers require extra space.
Linked lists do not allow random access.
Time must be spent traversing and changing the pointers.
Programming is typically trickier with pointers.
33. Define Binary Search Trees.
A binary search tree is a binary tree where each node contains a key such that:
All keys in the left subtree lesser than the key in the root.
All keys in the right subtree greater the key in the root.
The left and right subtrees of the root are again binary search trees.
34. What is the difference Data types vs. Data Structures?
A data type is a well-defined collection of data with a well-defined set
of operations on it.

A data structure is an actual implementation of a particular abstract


data type.

Potrebbero piacerti anche