CDS - QB - Unit3 4 5
CDS - QB - Unit3 4 5
CDS - QB - Unit3 4 5
S.
Question
No.
1 What is a data structure?
● A data structure is a method for organizing and storingdata which would allow
efficient
data retrieval and usage.
● A data structure is a way of organizing data that considersnot only the items stored,
but
also their relationships to each other.
2 Why do we need data structures?
● Data structures allow us to achieve an important goal:component reuse.
● Once data structure has been implemented, it can be usedagain and again in
various applications.
3 List some common data structures.
● Stacks
● Queues
● Lists
● Trees
● Graphs
● Tables
struct polynomial
{
int coefficient;int exponent;struct polynomial *next;
};
2 Define a data structure? What are the different types of data Structures?
4 What is Single Linked List? Explain the operations of singly linked lists
7 Write algorithm for the following insertion operations of Single linked list
S. Question
No.
1 Define Stack.
A stack is an ordered list in which all insertions anddeletions are made at
one end, called the top. It is an abstract data type and based on the principle of
LIFO (Last In First Out).
struct stack
{
int element;
struct stack *next;
}*top;
8 Write the routine to pop a element from a stack.
int pop()
{ if(top==NULL)
{ printf(“\n Stack is empty.\n”);getch();exit(1);}else
{int temp;
temp=top→element; top=top→next; return temp; }}
9 Define queue.
It is a linear data structure that maintains a list ofelements such that
insertion happens at rear end and deletion happens at front end.
FIFO – First In First Out principle
STACK QUEUE
Insertion and deletion are made Insertion at one end rear and
at one end. deletion at other end front.
If(top==Maxsize) condition:If(rear =
Postfix :ab+cd+*f/
Prefix :/*+ab+cdf
23 Write postfix from of the expression –A+B-C+D?
A-B+C-D+
24 How do you test for an empty queue?
To test for an empty queue, we have to check whether READ=HEAD where REAR is a
pointer pointing to the last node in a queue and HEAD is a pointer that pointer to the
dummy header. In the case of array implementation of queue, thecondition to be checked
for an empty queue is READ<FRONT.
S.
Question
No.
1 Define non-linear data structure
Data structure which is capable of expressing more complex relationship than
that of physical adjacency is callednon-linear data structure.
2 Define tree?
A tree is a data structure, which represents hierarchicalrelationship between
individual data items.
3 Define leaf?
In a directed tree any node which has out degree o iscalled a terminal node or
a leaf.
4 Explain the representations of priority queue.
Using Heap structure, Using Linked List
6 Convert the infix expression (A-B/C)*(D/E-F) into a postfix.
Postfix: ABC/-DE/F-*
What are the steps to convert a general tree into binary tree?
* use the root of the general tree as the root of the binary tree
* determine the first child of the root. This is the leftmost nodein the general tree at
the next level
* insert this node. The child reference of the parent node refersto this node
* continue finding the first child of each parent node and insert itbelow the parent
node with the child reference of the parent to this node.
* when no more first children exist in the path just used, moveback to the
parent of the last node entered and repeat the above process. In other words,
determine the first sibling of the last node entered.
* complete the tree for all nodes. In order to locate where thenode fits you must search
for the first child at that level and then follow the sibling references toa nil where the next
sibling can be inserted. The children of any sibling node can be insertedby locating the
parent and then inserting the first child. Then the above process is repeated.
What is meant by directed tree?
8 Directed tree is an acyclic diagraph which has one node called its rootwith in degree o
while all other nodes have in degree I.
9 What is a ordered tree?
In a directed tree if the ordering of the nodes at each level isprescribed then such a
tree is called ordered tree.
10 What are the applications of binary tree?
1. Binary tree is used in data processing.
2. File index schemes
3. Hierarchical database management system
11 What is meant by traversing?
Traversing a tree means processing it in such a way, that eachnode is visited only
once.
12 What are the different types of traversing?
The different types of traversing are
a. Pre-order traversal-yields prefix form of expression.
b. In-order traversal-yields infix form of expression.
c. Post-order traversal-yields postfix form of expression.
13 What are the two methods of binary tree implementation?
10 What is a loop?
An edge of a graph which connects to itself is called a loopor sling.
1 Define sorting
Sorting arranges the numerical and alphabetical data present in a list in a specific
order or sequence. There are a number of sorting techniques available. The algorithms can
be chosen based on the following factors
● Size of the data structure
● Algorithm efficiency
Programmer’s knowledge of the technique
19 What is sorting?
Sorting is the process of arranging the given items in a logical order. Sorting is an
example where the analysis can be preciselyperformed.
20 What is mergesort?
The mergesort algorithm is a classic divide conquer strategy. Theproblem is divided into
two arrays and merged into single array
25 What does internal sorting mean?
Internal sorting is a process of sorting the data in themain memory
32 Define searching
Searching refers to determining whether an element is present in a given list of
elements or not. If the element is present, the search is considered as successful, otherwise
it is considered as an unsuccessful search. The choice of a searching technique is based on
the followingfactors Order of elements in the list i.e., random or sorted Size of the list
5 Write a C program to sort the elements using bubble sort, insertionsort and radix sort.