Data Structure

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 5

#Who to measure performance of an algorithm?

===Performance analysis of an algorithm is the process of


calculating space required by that algorithm and time required by that algorithm. Performance analysis of
an algorithm is performed by using the following measures. 1. Space required to complete the task of that
algorithm (Space Complexity). It includes program space and data space. 2. Time required to complete
the task of that algorithm (Time Complexity).
#What is polynomial? How is it differ from structure? ===A polynomial is a mathematical expression
involving a sum of powers in one or more variables multiplied by coefficients. A polynomial in one variable
with constant coefficients is given by,
#What is balance factor? How is it calculated? === The balance factor of a binary tree is the difference in
heights of its two subtrees (hR - hL). The balance factor (bf) of a height balanced binary tree may take on
one of the values -1, 0, +1.
#What are Abstract Data types? ===This definition is also called as Abstract Data Type (ADT).
Implementation details of an ADT are hidden, that's why it is called abstract. To represent the
mathematical model underlying an ADT, we use data structure, which is collection of variables, data types
connected in different ways
#What is Ancestor of Node? === An ancestor of a node is any other node on the path from the node to the
root. • A descendant is the inverse relationship of ancestor: A node p is a descendant of a node q if and
only if q is an ancestor of p. • We can talk about a path from one node to another.
#State the types of graph.=== Undirected graph= In an undirected graph, the pair of vertices representing
any edge is unordered i.e. the pairs (v1, v2) and (v2, v1) represent the same edge. In other words the edges
have no direction in undirected graph. directed graph =In a directed graph each edge is
represented by a directed pair (v1, v2), v1 is the tail and v2 is head of the edge i.e. the pairs (v1, v2) and
(v2, v1) are different edges. In other words the edges have direction in directed graph. Directed graph is
also called as Digraph.
#What is pointer to pointer? === A pointer to a pointer is a form of multiple indirection, or a chain of
pointers. Normally, a pointer contains the address of a variable. When we define a pointer to a pointer, the
first pointer contains the address of the second pointer, which points to the location that contains the
actual value
#What is spanning tree? ===A spanning tree is a subset of Graph G, which has all the vertices covered with
minimum possible number of edges. Hence, a spanning tree does not have cycles and it cannot be
disconnected.. By this definition, we can draw a conclusion that every connected and undirected Graph G
has at least one spanning tree.
#Explain Insertion sort technique with an example. === Insertion sort works similarly as we sort cards in
our hand in a card game. We assume that the first card is already sorted then, we select an unsorted
card. If the unsorted card is greater than the card in hand, it is placed on the right otherwise, to the left.
#What is circular queue? How it is differ from static queue? === A circular queue is the extended version of
a regular queue where the last element is connected to the first element. Thus forming a circle-like
structure. The circular queue solves the major limitation of the normal queue. In a normal queue, after a
bit of insertion and deletion, there will be non-usable empty space.
#What is stake? ===A stack is an ordered collection of homogeneous data elements where the insertion
and deletion operations take place at only one end; called as top of the stack.
#List operations performed on stack. ===The following operations are performed on the stack: 1.
Creating a stack 2. Checking stack empty or not 3. Checking stack full or not 4. Insert (push) an
element in the stack 5. Delete (pop) an element from the stack 6. Access the top element 7.
Status: to identify the present position of stack. Let us discuss the above operations on the stack.
# What are the various applications of stack. === 1)A Stack can be used for evaluating expressions
consisting of operands and operators. 2) Stacks can be used for Backtracking, i.e., to check parenthesis
matching in an expression. 3)It can also be used to convert one form of expression to another form. 4)It
can be used for systematic Memory Management.
#Explain various types of Dynamic Memory Allocation functions. ===1))malloc() =1)The malloc() function
reserves a block of memory in the "heap" of the specified number of bytes. And, it returns a pointer to the
new block. 2)malloc() returns NULL if it cannot fulfill the request. 3)The malloc() function reserves a block
of memory of specified size and return a pointer of type void. This means that we can assign it to any type
of pointer.
*2)Calloc() =1) calloc() is another memory allocation function that is normally used for requesting memory
space at runtime for storing derived data types such as arrays and structures. 2)While malloc()
allocates a single block of storage space, calloc allocates multiple blocks of storage; each of the same size,
then sets all bytes to zero. 3)The general form of calloc() is, ptr= (cast_type*) calloc(n, elem-size);

#Write a c program for evaluation of polynomial. === #include <iostream>


using namespace std;
// returns value of poly[0]x(n-1) + poly[1]x(n-2) + .. + poly[n-1]
int horner(int poly[], int n, int x)
{
int result = poly[0]; // Initialize result
// Evaluate value of polynomial using Horner's method
for (int i=1; i<n; i++)
result = result*x + poly[i];
return result;
}
// Driver program to test above function.
int main()
{
// Let us evaluate value of 2x3 - 6x2 + 2x - 1 for x = 3
int poly[] = {2, -6, 2, -1};
int x = 3;
int n = sizeof(poly)/sizeof(poly[0]);
cout << "Value of polynomial is " << horner(poly, n, x);
return 0;
}

#Define Directed graph. === In a directed graph each edge is represented by a directed pair (v1, v2), v1 is
the tail and v2 is head of the edge i.e. the pairs (v1, v2) and (v2, v1) are different edges. In other words the
edges have direction in directed graph. Directed graph is also called as Digraph.
#Define Strict binary tree. === If every non-leaf node in a binary tree has nonempty left and right subtrees,
the tree is termed a strictly binary tree. Or, to put it another way, all of the nodes in a strictly binary tree
are of degree zero or two, never degree one. A strictly binary tree with N leaves always contains 2N - 1
nodes.ee
#Define Cyclic graph. === A cyclic graph is a graph containing at least one graph cycle. A graph that is not
cyclic is said to be acyclic. A cyclic graph possessing exactly one (undirected, simple) cycle is called a
unicyclic graph. Cyclic graphs are not trees.
#Convert the following expression into postfix. 1)A/B $ CD * E – A * C=== ans = AB/ $CD * E –A * C
(2)(A + B * C-D)/ E $ F . ===ans=A+ B * CD- /E $F
#Define an Algorithm. Explain different characteristics of an algorithm. === An algorithm is a step-by-step
procedure that defines a set of instructions that must be carried out in a specific order to produce the
desired result. Algorithms are generally developed independently of underlying languages, which means
that an algorithm can be implemented in more than one programming language.

#List out different types of data structure. Ans=Linear data structures= In linear data structures, the
elements are arranged in sequence one after the other. Since elements are arranged in particular order,
they are easy to implement. Linear=Array, linked list, stack, queue. Non-Linear data structures= Unlike
linear data structures, elements in non-linear data structures are not in any sequence. Instead they are
arranged in a hierarchical manner where one element will be connected to one or more elements. Non-
linear=trees, graph
#What is Self Referential structure? Ans= A self referential data structure is essentially a structure
definition which includes at least one member that is a pointer to the structure of its own kind. Such self
referential structures are very useful in applications that involve linked data structures, such as lists and
trees.
#Explain selection sort technique. Ans= Selection sort works by taking the smallest element in an unsorted
array and bringing it to the front. You'll go through each item (from left to right) until you find the smallest
one. The first item in the array is now sorted, while the rest of the array is unsorted.
#What is sorting? State tha techniques of sorting. Ans= Sorting is the processing of arranging the data in
ascending and descending order. There are several types of sorting in data structures namely – bubble
sort, insertion sort, selection sort, bucket sort, heap sort, quick sort, radix sort etc.
#Explain linear searching technique in detail. Ans= A linear search is the simplest approach employed to
search for an element in a data set. It examines each element until it finds a match, starting at the
beginning of the data set, until the end. The search is finished and terminated once the target element is
located.
#Describe different types of linked list. Ans= In a singly linked circular linked list, each node has a pointer
that points to the next node in the list. The last node in the list points back to the first node. In a doubly
linked circular linked list, each node has pointers that point to both the next node and the previous node
#Priority queue== Priority Queue is an abstract data type that is similar to a queue, and every element has
some priority value associated with it.
#What is mean by degree of node? Ans= The degree of a node is the number of connections that it has to
other nodes in the network. In a social network if you have 100 friends then the node that represents you
has a degree of 100. Path length is simply the distance between two nodes, measured as the number of
edges between them.
#Define Balance Factor= DEFINITION: The balance factor of a binary tree is the difference in heights of its
two subtrees (hR - hL). The balance factor (bf) of a height balanced binary tree may take on one of the
values -1, 0, +1.
#Define Leaf Node= Leaf − The node which does not have any child node is called the leaf node. Subtree −
Subtree represents the descendants of a node. Visiting − Visiting refers to checking the value of a node
when control is on the node.
#What are tha various application of graph? Ans= Some of the most popular applications are: Helps to
define the flow of computation of software programs. Used in Google maps for building transportation
systems. In google maps, the intersection of two or more roads represents the node while the road
connecting two nodes represents an edge.
#write difference between stack and queue. Ans= stack = 1. It follows the LIFO (Last In First Out) order to
store the elements, which means the element that is inserted last will come out first. 2 2. It has only one
end, known as the top, at which both insertion and deletion take place. 3.The insertion operation is known
as push and the deletion operation is known as pop. Queue= 1. It follows the FIFO (First In First Out)
order to store the elements, which means the element that is inserted first will come out first. 2. It has two
ends, known as the rear and front, which are used for insertion and deletion. The rear end is used to insert
the elements, whereas the front end is used to delete the elements from the queue. 3. The insertion
operation is known as enqueue and the deletion operation is known as dequeue. ‘
#What are tha applications of queue? Ans= Applied as waiting lists for a single shared resource like CPU,
Disk, and Printer. Applied as buffers on MP3 players and portable CD players. Applied on Operating system
to handle the interruption. Applied to add song at the end or to play from the front.
#What is queue? Explain its types in detail. Ans= A Queue is a linear structure that follows a particular
order in which the operations are performed. The order is First In First Out (FIFO). A good example of a
queue is any queue of consumers for a resource where the consumer that came first is served first.
#What is space and time complexity? ===
#What are the advantages of linked list? ===
#What is adjacency of matrix? ===
#What is complete binary tree? ===
#What is priority queue? ===
#What is the need for the header? ===
#What is height-balanced tree? ===
#What is linked list? Explain its types in detail. ===
#Explain different types of asymptotic notation in detail. ===
#Differentiate array and structure. ===
#Write a function to create & display circular singly linked list. ===
#Write a function for in order traversal of the tree. ===
#Write a function to delete first node from singly linked list. ===
#Write a function to search the element from array using binary search. ===
#Define Child node. ===
#Define path. ===
#Construct an AVL tree for given data: WED, TUE, MON, SAT, THUR, FRI. ===
#For given data, constract a binary search tree:15, 30, 20, 5, 10, 2, 7. ===
#Sort the following data by using quick sort:10, 5, 75, 62, 49, 58. ===
#Write a C-program to traverse the linked list. ===
#What is Dequeue? ===

You might also like