0% found this document useful (0 votes)
2 views

C PROG

The document provides a comprehensive overview of fundamental concepts in C programming, including primitive data types, control structures, arrays, strings, pointers, and data structures. It explains various programming constructs such as loops, functions, and data handling techniques, along with examples and code snippets. Additionally, it covers advanced topics like unions, structures, abstract data types, and linked lists, highlighting their properties and applications.

Uploaded by

angelg
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

C PROG

The document provides a comprehensive overview of fundamental concepts in C programming, including primitive data types, control structures, arrays, strings, pointers, and data structures. It explains various programming constructs such as loops, functions, and data handling techniques, along with examples and code snippets. Additionally, it covers advanced topics like unions, structures, abstract data types, and linked lists, highlighting their properties and applications.

Uploaded by

angelg
Copyright
© © All Rights Reserved
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 19

Object

Object 10
28
27
26
25
24
23
22
21
20
19
18
17
16
15
14
13
12
11
9
8
7
6
4
3
2
1

.1 What is primitive data type?


Ans. : Primitive data types in C are the fundamental data types such as int, float, char and void.
The int data type is for representing the whole number values
Q.2 What is the difference between for and while statement ?
Ans. :

Q.3 Explain the use of void data type.


Ans. : • The void data type indicates that the function is returning nothing.
• If the function is not returning anything from the function then its data type is specified as void.

Q.4 What is the use of arrays ?


Ans. : Array is used to store the elements of same data type. For storing the strings - the arrays is used.
Object 5

Q.5 Explain the concept of string in C.


Ans. : String is a collection of characters. For example
char a="hello";
char a=['h', 'e', '1', '1', 'o'];

Q.6 Differentiate between while and do-while loops.


Ans.

Q.7 What do you mean by nested loops ?


Ans.
Nested loops mean loops within the loops. For example for nested, the loop is given below
for (i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("It's My Life!!!");
}
}

Q.8 How will you initialize array in C ?


Ans. There are two ways by which an array can be initialized -
i) Initializing an array at declaration.
ii) Initializing an array with the help of loop.
Initializing an array means storing some value in it at some specific location.
i) Initializing an array at declaration -
At declaration of an array it can be initialized..
For example:
int a[5] = {10, 20, 30, 40};
float marks [8] = {33.2, 57.8, 76.5, 81.3};
ii) Initializing array with the help of loop -
Using for loop or while loop an array can be initialized.
For example -
30
For (i=0; i<5; i++)
{
scanf("%d", &a[i]);
}

Q.9 What is the purpose of do-while statement ?


Ans. :
The purpose of do-while is to bring looping in programming statements. The way to write the do... while
statement is -
do
{

statements;

while (some condition);
For example
count = 1
do
{
printf("\n I am on first line of do-while");
count++;
} while (count < = 5);

Q.10 What are the basic operations performed on an array ?


Ans.: Array is simply a collection of elements which are of same data type. Mainly we can perform following
operations on an array-
i) Storing the elements in an array
ii) Retrieving or printing elements from an array.
Following 'C' program performs these operations-
#include <stdio.h>
#include <conio.h>
main( )
{
int a[10], index;
clrscr( );
printf ("In Store The Elements In An Array a");
for (index = 0; index < = 9; index++)
scanf("%d", &a[index]);//storing elements in array
printf ("\n Retrieving the array elements");
for (index=0; index <=9; index++)
printf("%d", a[index]); //retrieving elements from array
}

Q.11 List the primary data types in C.


Ans. : Primary data types in C are as given below

Q.12 What are string operations defined in C?


Ans. : Various string operations defined in C are
1) strlen(): For Finding out length of string
2) strcpy(): For copying the one string to another
3) strcat(): For concatenating two strings
4) strcmp(): For comparing two strings
5) strrev(): For reversing two strings
Q. 13 What is a static variable? Give an example.
Ans. : Static variables are those variable that retain their values even after they come out of the scope.
For example
#include<stdio.h>
int fun( )
{
static int count = 0;
count++;
return count;
}
int main( )
{
printf("\n%d",fun());
printf("\n%d",fun());
printf("\n%d",fun());
printf("\n%d",fun());
return 0;
}
Output
1
2
3
4
Q.14 Write a C program to get a paragraph of text as input.
AU: Dec.-19
Ans. :
#include<stdio.h>
int main( ) {
char para[100];
printf("Enter Paragraph: ");
scanf("%[^\t]s", para);//accept all the characters except tab
printf("Accepted Paragraph: %s", para);
return 0;
}
Q.15 How an n dimensional array is represented ?
AU: May-19
Ans. : A multidimensional array is declared using the following syntax : type array_name[d1][d2] [d3]
[d4]....................[dn];
where each d is a dimension, and dn is the size of final dimension.
The conceptual syntax for 3D array is this:
data_type array_name[table][row][column];
Q.16 Differentiate between row major and column major representation of arrays.
AU: Dec.-19
Ans. : In row-major order, consecutive elements of the rows of the array are contiguous in memory; in column-
major order, consecutive elements of the columns are contiguous.
The difference between row-major and column-major order is simply that the order of the dimensions is
reversed.
Q.1 What is union ?
Ans. : Union is a user defined data structure which is just similar to structure. It is used to store members of
different data types.
Q.2 What is the difference between structure and union ? AU: Dec.-18
Ans. :

Q.3 While handling the structure keyword struct is used.


Ans. :
1) Both the structure and union are user defined data types.
2) The structure and union are meant for storing the various member variables of different data types.
3) The dot operators are used to access the members of the union and structures.
Q.4 How do you access the address, where the elements of a matrix, whose index is given is stored ?
Ans : Following program shows how to access the address of particular array
#include<stdio.h>
#include<conio.h>
void main()
{
int a[]={1,2,3,4,5},i;
int *ptr;
ptr=a;
for(i=0;i<5;i++)
{
printf("\nAddress of a[%d]=%u",i,ptr);
ptr++;
}
}
expected output will be
Address of a[0]=65516
Address of a[1]=65518
Address of a[2]=65520
Address of a[3]=65522
Address of a[4]=65524
Q.5 Declare a variable 'code' of type union item consisting of an integer m,float x and char c. Explain what
would be the output of the following statements:
code.c='A';
code.m=385;
code.x=14.7;
printf("%c%d",code.c,code.m);
Ans.:
The output of above code is some garbage value
3 13107
These are basically garbage values because the union assigns memory of the member occupying highest
memory space. In above example float requires highest memory space(i.e. 4 bytes). And at a time union keeps only
one member active. We have lastly accessed
code.x=14.7;
Hence the variable x will be currently active and remaining members will hold the garbage values. Hence
code.c and code.m are printing garbage values.
Q.6 What do you mean by tag of a structure ?
Ans. :
The structure tag is a name used along with the structure declaration. This tag is useful in declaration of
structure variables.
For example
typedef struct student
{
int roll;
char name [20];
}st;
Here st is used as a tag for the structure student.
We can declare then
st s1, s2, s3;
The variables s1, s2, s3 are of structure type.
Q.7 What is the use of. operator in structures ?
Ans. :
The operator is used to access the members of the structure.
For example
s1.name or s1.roll
Q.8 Define structure within a structure. What is its scope?
Ans. : The structure within a structure is called nested structure. When we have to handle a collection of data
which is related to another kind of collection of data then it is comfortable to use nested structures.
For example
struct bdata {
int day;
int mnth;
int year;
} dt;
struct student {
int roll.no;
Char name [10];
struct bdate dt;
} std;
One can access the birthdate of a student by following statements -
printf("\n Enter Student's birth date (mm.dd.yy)");
scanf("%d %d %d", &std.dt.month, &std.dt.day,&std.dt.year);
The scope of the nested structure is within the outer structure, and it can be accessed with the tag of outer and
inner structure.
Q.9 Define preprocessor directives and list out a few examples. AU; Dec.-18, May-19
Ans. :
• Preprocessor directive is a kind of program which is used to preprocess the C program before compiling.
• Commands used in preprocessor are called preprocessor directives and they begin with symbol #.
• Examples of Preprocessor Directives :
• Macro: Using #define the constant value can be defined.
• Header file inclusion: Using #include the required header file can be included in the C program.
• Conditional compilation: Using #ifdef,#endif#if,#else the conditions can be included in the program before
compilation.

Q.10 Define pointer and initialize it. AU: May-19


Ans. : Pointer is a variable that represents the memory location of some other variable. It can be initialized as
int a = 10;
int *ptr=&a;
Q.11 What does #include < header_name> do? How is it possible to tell the preprocessor where to look for
header files? AU: Dec.-19
Ans. : The #include is a preprocessor directive which requests the header file. It is possible to tell the
preprocessor to look for the desired header file by specifying its name and path of the file. For standard header files
of C program the system directories are searched.
Q. 1 Explain the term data structure.
Ans. : The data structure can be defined as the collection of elements and all the possible operations which are
required for those set of elements. Formally data structure can be defined as a data structure is a set of domains D, a
set of functions F, and a set of axioms A. This triple (D, F, A) denotes the data structure d.
Q. 2 What do you mean by non linear data structure? Give examples.
Ans. : The non linear data structure is the kind of data structure in which the data may be arranged in
hierarchical fashion. For example - Trees and graphs.
Q. 3 What do you mean by linear data structure ? Give example.
Ans. : The linear data structure is a kind of data structure in which the data is linearly arranged. For example -
Stacks, queues, linked list.
Q. 4 Enlist the various operations that can be performed on data structure.
Ans. : Various operations that can be performed on the data structure are -
1. Create
2. Insertion of element
3. Deletion of element
4. Searching for the desired element
5. Sorting the elements in the data structure.
6. Reversing the list of elements.
Q. 5 What is abstract data type? What are all not concerned in an ADT ? AU: Dec.-19
Ans. : The abstract data type is a triple of D i.e. set of axioms, F-set of functions and A- Axioms in which only
what is to be done is mentioned but how is to be done is not mentioned. Thus ADT is not concerned with
implementation details.
Q. 6. List out the areas in which data structures are applied extensively.
Ans. : Following are the areas in which the data structures are applied extensively.
1. Operating system - The data structures like priority queues are used for scheduling the jobs in the operating
system.
2. Compiler design - The tree data structure is used in parsing the source program. inil vlduob Stack data
structure is used in handling the recursive calls.
3. Database management system The file data structure is used in database management systems. Sorting and
searching techniques can be applied on these data in the file.
4. Numerical analysis package - The array is used to perform the numerical analysis ble on the given set of
data.
5. Graphics - The array and linked list are useful in graphics applications.
6. Artificial intelligence - The graph and trees are used for the applications like building expression trees, game
playing.
7. Networking - The graph is used for finding the shortest path length between any two computers that are
connected in a LAN.
8. Simulation - The queue is used for simulation and modeling.
Q. 7 What is a linked list ? 10 AU: Dec.-19
Ans. : A linked list is a set of nodes where each node has two fields 'data' and 'link'. The data field is used to
store actual piece of information and link field is used to store address of next node.
Q. 8 Write down the steps to modify a node in linked lists.
Ans. :
1. Enter the position of the node which is to be modified.
2. Enter the new value for the node to be modified.
3. Search the corresponding node in the linked list.
4. Replace the original value of that node by a new value.
5. Display the message as "The node is modified".
Q. 9 State the properties of LIST abstract data type with suitable example.
Ans. Various properties of LIST abstract data type are –
1. It is linear data structure in which the elements are arranged adjacent to each other. elinteb neilstrsms.
2. It allows to store single variable polynomial.
3. If the LIST is implemented using dynamic memory then it is called linked list.
Example of LIST are - Stacks, Queues, Linked List.
Q. 10 State the advantages of circular lists over doubly linked list.
Ans. In circular list the next pointer of last node points to head node, whereas in doubly linked list each node
has two pointers: One previous pointer and another is next pointer. The main advantage of circular list over doubly
linked list is that with the help of single pointer field we can access head node quickly. Hence some amount of
memory get saved because in circular list only one pointer field is reserved.
Q. 11 What are the advantages of doubly linked list over singly linked list?
Ans. : The doubly linked list has two pointer fields. One field is previous link field and another is next link
field.
Because of these two pointer fields we can access any node efficiently whereas in singly linked list only one
pointer field is there which stores forward pointer, which makes accessing of any node difficult one.
Q. 12 What is the advantage of linked list over arrays ? AU: May-19
Ans. : The linked list makes use of the dynamic memory allocation. Hence the user can allocate or de allocate
the memory as per his requirements. On the other hand, the array makes use of the static memory location. Hence
there are chances of wastage of the memory or shortage of memory for allocation.
Q. 13 What is circular linked list ? AU: Dec.-14, May-16
Ans. The circular linked list is a kind of linked list in which the last node is connected to the first node or head
node of the linked list.
Refer section 3.6.
Q. 14 What is the basic purpose of header of the linked list?
Ans. : The header node is the very first node of the linked list. Sometimes a dummy value such as -999 is stored
in the data field of header node. Refer Fig. 3.10.1.

This node is useful for getting the starting address of the linked list. As there is only a forward link present in
the linked list, for accessing the entire linked list it is necessary to obtain the starting address of the linked list.
Q. 15 What is advantage of an ADT ? AU: May-14, Dec.-18
Ans. : The advantages of ADT are
1. Change: The implementation of the ADT can be changed without making changes bruin the client program
that uses the ADT.
2. Understandability: ADT specifies what is to be done and does not specify the implementation details.
Hence code becomes easy to understand due to ADT.
3. Reusability: The ADT can be reused by some program in future.
4. Flexibility: Different implementations are possible for the same ADT.
Q. 16 Should arrays of linked lists be used for the following type of applications. Justify your Answer.
a) Many search operations in sorted list.
b) Many search operations in unsorted list. AU: May-14
Ans. :
a) If the list is sorted then using linked list the desired element can be searched, simply by moving forward
using 'next' pointer.
b) If a list is not sorted then using arrays the desired element can be searched. The arrays facilitates the access to
random element.
Q. 17 What are abstract data type? AU: Dec.-14
OR Define ADT AU: May-15
Ans. : Refer Q. 5.
Q. 18 What is static linked list? State any two applications of it. AU: May-15
Ans. The linked list structure which can be represented using arrays is called static linked list.
1. It is easy to implement, hence for creation of small databases, it is useful.
2. The searching of any record is efficient, hence the applications in which the record need to be searched
quickly, the static linked lists are used.
Q. 19 Write syntax of calloc() and relloc() and mention its applications in the linked list AU: May-15
Ans. : calloc() is for allocating the required amount of memory. The syntax is void *calloc(size_t nitems, size_t
size)
This function returns the pointer to the allocated memory. The calloc function is just similar to malloc but it
initializes the allocated memory to zero and malloc does not.
The realloc() function modifies allocated memory size by malloc() and calloc() functions to new size. The
syntax is
void *realloc (void *ptr, size_t size)
If insufficient memory exists then to expand the memory block, realloc() is used.
Q. 20 What are the disadvantages of linked list over arrays. AU: Dec.-18
Ans. 1) In linked list, we can access elements in sequence. So it is very difficult and time consuming to access
element randomly.
2) Some amount of memory gets wasted in storing the next node's address in each nodes.
Q. 1Give an example that shows how a stack is used by a computer system.
Ans. : In computer system the memory model consists of stack memory stores types of variables that have a
fixed lifetime based on how C programs run. It is a section of RAM that grows and shrinks as the program runs.
When you call a function, its parameters and any variables you have defined in that function (which are not static)
are stored on the stack.
Q. 2 What do you understand by polish notation? Explain.
Ans. : This is also called as prefix notation. In this type of notation the operator followed by two operands. For
example if (a+b)*c is a given expression then its polish notation will be *+ abc.
Q. 3 What is a top pointer of a stack?
Ans. : The top denotes the only one end of the stack from which the element can be inserted or deleted. When
we push the element onto the stack, the top is incremented. When we pop the element from the stack the top is
decremented.
Q. 4 Write the postfix notation for following expression. (A+B)*C-(D-E)^F
Ans.: Following steps can be followed for computing the postfix expression -
Step 1: (AB+)*C-(D-E)^F
Step 2: (AB+C*)-(D-E)^F
Step 3: (AB+C*)-(DE-)^F
Step 4: (AB+C*)-(DE-F^)
Step 5: AB+C*DE-F^-
Q. 5 Write any two applications of stack. AU: Dec.-14, 18, 19
Ans. : The stack can be used for
1. Conversion of expression from one form to another. Various forms of expression are infix, prefix and postfix.
2. Evaluation of postfix expression.
3. Evaluation of recursive functions.
4. Reversing the string.
5. For checking the well formedness of parenthesis.
Q. 6 List the characteristics of stacks.
Ans. :
1. Insertion and deletion can be made by one end only. Hence the element inserted last will be first one to come
out. Hence sometimes it is called LIFO.
2. Stacks are useful for evaluating an expression.
3. Stacks can store the functions calls.
Q. 7 Write the role of stack in function call.
Ans. : The stack is an useful data structure for handling the recursive function calls. When a recursive call is
encountered, the status of call is pushed onto the stack. And at the return of the call the stack is popped off. Thus
execution of recursive statements is done with the help of stack.
Q. 8 What is Last-In-First-Out strategy? Which data structure follows this strategy?
Ans. : In the Last In First Out strategy we insert the element in the data structure lastly and while removing the
elements from this data structure, the element which is inserted lastly will get removed first.
The stack data structure makes use of Last In First Out(LIFO) data structure.
Q. 9 Write the steps to reverse the contents of the list with the help of stack data structure.
Ans. :
Step 1: Read each element from the list and push it onto the stack.
Step 2: Pop the element from the stack and store the popped element in a separate
Step 3: Read the array completely from left to write. This will be the reversed list of the elements.
Q. 10 Which data structure is used in handling the recursive function?
Ans. : The stack is used to handle the recursive function call.
Q. 11 Given the prefix for an expression write its postfix. AU: May-15
-*-+abc/ef-g/hi
Ans. :
-*-+abc/ef-g/hi
- * - T1 cef-g/hi T1 = ab+
-T2/ef-g/hi T2 = T1c-
- T2 T3 g/hi T3=ef /
- T4g-/hi T4 = T2T3*
- T4 g T5 T5 = hi/
-T4 T6 T6=g T5-
T7 T7= T4 T6
By backward substitution,
T7
T4 T6-
T2 T3 T6 -
T1 c T3 * T6 -
ab + c - T3 * T6 -
ab + c –ef/*t6-
ab + c -ef/* g T5--
ab + c - ef /* ghi/ -- is postfix expression
Q. 12 Give the infix for an expression, write its prefix a* b/c+d?
Ans. : The prefix expression is /* ab + cd.
Q. 13 Convert the following infix expression to postfix expression using stack.
AU: May - 19
Ans. :

The required postfix expression is abc*def++g/+.


Q. 14 State the rules to be followed during infix to postfix conversion. AU: Dec.-19
Ans. : Refer section 4.6.
Q. 15 What do the terms LIFO and FIFO means? Explain.
Ans. : The LIFO stands for Last In First Out. This property belongs to stack. That means the element inserted
lastly will be the element to be popped off first from the stack.
The FIFO stands for First In First Out. This property belongs to queue. That means the element inserted first in
the queue will be the first to get deleted.
Q. 16 What are the front and rear pointers of queue.
Ans. : The front end of the queue from which the element gets deleted is called front and the end from which
the element is inserted in the queue is called rear. is called rear.roA For example: Refer Fig. 4..10.1.
Q. 17 Write any four applications of queues. AU: May-14
Ans. :
1. In operating system for scheduling jobs, priority queues are used.
2. In Local Area Network (LAN) multiple computers share few printers. Then these printers accumulate jobs in
a queue. Thus printers can process multiple print commands with the help of queues.
3. For categorizing data, queues are used.
4. In simulation and modeling queues are used.
5. In computer networks, while broadcasting message, the message packets are accumulated in queue. And then
these packets are forwarded.
Q. 18 What is a dequeue? AU: May-14,16 Dec.-14
Ans. : The dequeue is a data structure in which the element can be inserted from both the ends i.e. front and
rear. Similarly, the element can be deleted from both the front and rear end.
Q. 19 How do you test for an empty queue?
Ans. : Following is a C code which is used to test an empty queue -
if((Q.front==-1) | | (Q.front>Q.rear))
printf("\n The Queue is Empty!!");
else
printf("\n The Queue is not Empty!!");
Q. 20 What is the use of queue in operating system ?
Ans. :
The queue is used for scheduling the jobs in operating system.
Q. 21 What is stack and queue ?
AU: Dec.-15
Ans. :
Stack is linear data structure in which insertion and deletion of element is from one end called top.
Queue is a linear data structure in which insertion of element is from one end called rear and deletion of
element is from other end called front.
Q. 22 What are priority queues? What are the ways to implement priority queue?
AU: Dec.-18
Ans. :
• Definition: The priority queue is a data structure having a collection of elements which are associated with
specific ordering.
• Ways to implement priority queue:
There are two ways to implement priority queue.
1. Ascending priority queue - It is a collection of items in which the items can be inserted arbitarily but only
smallest element can be removed.
2. Descending priority queue - It is a collection of items in which insertion of items can be in any order but
only largest element can be removed.
Q.1 What is the difference between linear and non-linear data structures?
Ans. :
Q.2 Define: Binary tree.
Ans. :
A binary tree is a finite set of nodes which is either empty or consists of root and two disjoint binary trees called
the left subtree and right subtree. Refer Fig.
Q.3 Give various implementation of tree.
Ans. : The tree can be implemented by two ways
1. Sequential implementation: The tree is implemented using arrays in this type of implementation.
2. Linked implementation : The tree is implemented or represented using linked list.
Q.4 Which tree representation is mostly preferred by the developers linked? Justify.
Ans. :
There are two ways of representing the binary tree - sequential representation and linked representation. The
linked representation is normally preferred by developers because in the linked representation the binary tree is
represented using linked list. Hence the tree with any number of nodes can be created. Secondly there is no wastage
or shortage of the memory in this representation.
Q.5 List the applications of trees.
Ans. :
1. In computer networking such as Local Area Network (LAN), Wide Area Networking (WAN),
internetworking.
2. In telephone cabling graph theory is effectively used.
3. In job scheduling algorithms the graphs are used.
Q.6 In tree construction which is the suitable efficient data structure ?
Ans. :
The linked list is the efficient data structure for constructing the trees. Because using linked list there is no
wastage of memory or shortage of memory. The nodes can be allocated or de-allocated as per the requirements.
Q.7 What is meant by equivalent binary tree?
Ans. :
The two binary trees are said to be equivalent if the sequence of their traversal is same.
Q.8 Define complete binary tree.
Ans. :
A complete binary tree is a tree in which every node except the root node should have exactly two children not
necessarily on the same level. Refer Fig. 5.7.1

Q.9 What is level of a tree?


AU: Dec.-19
Ans. :
The root node is always considered at level zero. The adjacent nodes to root are supposed to be at level 1 and so
on.
Q.10 What are internal and external nodes in a tree ?
Ans. :
Leaf node means a node having no child node. As leaf nodes are not having further links, we call leaf nodes
external nodes and non-leaf nodes are called internal nodes.
Q.11 What is sibling node in a tree?
Ans. : The nodes with common parent are called siblings or brothers.
Q.12 What is forest ?
Ans. Forest is a collection of disjoint trees. From a given tree if we remove its root then we get a forest. Refer
Fig. 5.7.2.
Q.13 What is full binary tree?
Ans. : A full binary tree is a tree in which every node has zero or two children. Refer Fig. 5.7.3.

Q.14 List out the traversal techniques used in tree.


Ans. :
1. Preorder 2. Postorder 3. Inorder traversal
Q.15 Which traversal results in elements in sorted order?
Ans. : The inorder traversal results in elements in sorted order.
Q. 16 How is binary tree represented using an array ? Give an example.
AU: Dec.-05
Ans. : In an array root node will be at position 1. Its left child will be at position 2 and right child will be at
position 3. Hence the nodes of tree are placed in array using following formula -
Parent (n) = floor ((n-1)/2)
left (n) = (2n+1)
right (n) = (2n + 2)
Consider tree as given below.

It will be placed in an array as given below.

Q.17 Construct an expression tree for the expression A+ (BC) * D* (E + F).


AU: May-06
Ans. :

Q.18 Define binary search tree.


AU: May-07, ECE, May-08, Dec.-09, 19
Ans.: Binary search tree is a binary tree in which each node is systematically arranged i.e. the left child has less
value than its parent node and right child has greater value than its parent node. The searching of any node in such a
tree becomes efficient in this type of tree.
For example -

Q.19 List the operations defined on binary trees data type with a suitable example.
Ans. :
Various operations that can be performed on binary trees are - 1. Insertion 2. Deletion 3. Traversal
The insertion operation is performed to insert a node at any desired position.
For example -

We can delete any desired node from the binary tree except root node.
For example -

Traversal means a walkover a binary tree. It can be preorder, postorder and inorder traversal.
Q.20 Write an algorithm to declare nodes of a tree structure.
Ans. Algorithm :
1. Declare a C structure for the node of a binary tree
typedef struct node
{
int data;
struct node *left;
struct node *right;
}bin;
2. Create a node by allocating memory by using the dynamic memory allocation.
New (bin*)malloc(sizeof(bin));
3. Initialize the Left and Right child pointers to NULL.
New->left=NULL;
New->right=NULL;
Thus a single node gets created. This is the first node of the tree, hence it is called as the root node.
root=New;
4. Attach the next subsequent nodes to either as a left child or a right child to the corresponding parent nodes
depending on the user's choice.
Q.21 Why it is said that the searching a node in a binary search tree is efficient than that of a simple binary
tree?
Ans. : In the binary search tree the nodes are arranged in such a way that the left node is having less data value
than root node value. And the right nodes are having larger value than that of root. Because of this while searching
any node the value of target node will be compared with the parent node and accordingly either left sub branch or
right sub branch will be searched. This procedure will be repeated if required. So one has to compare only particular
branches. Thus searching becomes efficient.
Q.22 If a binary tree with n nodes is represented sequentially, then for any node with index i (a) 1 ≤ i ≤n,
then left child (i) is at 2i, if 2i ≤n. (b) If 2i>n, then I has no left child. Name the type of binary tree which satisfies
both (a) and (b).
AU: May-11
Ans. : The complete binary tree.
Q.23 What is meant by equivalent binary tree?
AU : May-11
Ans. : The two binary trees are said to be equivalent if the sequence of there traversal is same for example -

The sequence is 8, 8, 9, 10, 11, 12, 13.


Q.24 List the applications of trees. AU: Dec.-11
Ans.
Binary tree is used in various applications such as -
1. Binary search tree
2. Game tree
3. Expression tree
4. Threaded Binary tree.
Q.25 Define binary tree and give binary tree node structure.
AU: Dec.-12
Ans. : A binary tree is a finite set of nodes which is either empty or consists of root or two disjoint binary trees
called the left subtree and right subtree.
Each node in the binary tree contains three fields left child pointer, data field and right child pointer.
Left child Data Right child
struct BST
{
BST *leftchild;
int data;
BST *rightchild;
};
Q. 26 How many trees are possible with 3 nodes ?
Ans. :
For 3 nodes there are 23 - 3 trees possible. That means 5 such trees can be drawn. For example - If there are 3
nodes with the value 10, 20, 30 then
Q. 27 Show the result of inorder traversal of the binary search tree given in Fig. 5.7.4.

Ans. : Inorder Traversal: 1, 2, 3, 4, 5, 6, 7, 9


Q.28 For the tree in Fig. 5.7.5. AU: Dec.-18
a) List the siblings for node E.
b) Compute the height.

Ans. : i) Siblings are those


nodes that share common parents. Hence sibling of E is D.
ii) The maximum level of tree is called height. The maximum level is AB-E-J-M. Thus height of tree of tree is
4.
Q. 29 The depth of complete binary tree is 8 and compute the number of nodes in leaf.
AU: May-19
Ans : The relationship between depth of a tree and maximum number of nodes in leaf is,
2d -1 = n
28 -1 = n
n = 255
Q. 30 How to resolve null links in a binary tree?
AU: May-19
Ans. : The left null link can point to predecessor node and the right null link can point to successor node. This
way the null links can be utilized so that tranversing of the tree becomes efficient.
Q.1 What is hashing?
AU: May-16
Ans. :
Hashing is a technique of storing the elements directly at the specific location in the hash table. The hashing
makes use of hash function to place the record at its position. Using the same hash function the data can be retrieved
directly from the hash table.
Q.2 List out the various techniques of hashing.
Ans. :
Various techniques of hashing are -
1. Division method 2. Mid square method 3. Multiplicative hash function
4. Digit folding 5. Digit analysis.
Q.3 What is uniform hash function ?
Ans. : An uniform hash function is one that equally distributes data items over the whole hash table data
structure.
Q.4 What is rehashing ?
AU: Dec.-15
Ans. :
Rehashing is a technique in which the table is resized. That means the size of the table is doubled by creating a
new table. The total size of the table is usually a prime number. Following are the situations in which the rehashing is
required -
1. When table is completely full.
2. With quadratic probing the table is filled half.
3. When insertions fail due to overflow.
Q.5 What is collision in hashing ?
Ans. : The situation in which the hash function returns the same hash key for more than one record is called
collision.
Q.6 What is overflow in hashing?
Ans. : The situation in which there is no room for a new pair in the hash table is called overflow.
Q.7 What are the characteristics of good hashing function?
Ans. : Refer section 6.3
Q.8 What is the major problem in linear probing ?
Ans. : One major problem in linear probing is primary clustering. Primary clustering is the process in which a
block of data is formed in the hash table when collision is resolved.
Q.9 What are the advantages of rehashing ?
Ans. : Following are the advantages -
1. This technique provides the programmer a flexibility to enlarge the table size if required.
2. Only the space gets doubled with simple hash function which avoids occurrence of collisions.
Q.10 What is the advantage of chained hash table over open addressing scheme ?
Ans. : The deletion of particular record from the hash function becomes easier.
Q.11 State some major drawback of chaining.
Ans. : Requirement of additional data structure is the major drawback of chaining.
Q.12 Specify the hashing technique in which the table size can be changed.
Ans. : The rehashing is a hashing technique in which the table size can be changed.
Q.13 What will be the position of the number 3111 in a hash table, when the mid square method is applied ?
(The table size is 1000)
Ans. : The position will be 783 because (3111)2 = 9678321.
Q.14 Which hash function maintains the record in order of hash field values ?
Ans. : The folding method maintains the record in order of hash field values.
Q.15 Enlist the conditions in which the rehashing is required.
Ans. : The rehashing is required in following conditions -
1. Table is completely full.
2. Insertion fails due to overflowing.
3. When there is a need to transfer the contents from old hash table to new hash table.

Q.16 What do you understand by collision resolution by chaining ?


Ans. : When collision happens we create a new memory location outside the existing table and use a chain to
link to the new memory location.
Q.17 Use of pointer is in ----- hashing technique.
Ans. : chaining.
Q.18 What are the advantages and disadvantages of separate chaining and linear probing?
Ans. : 1) Separate chaining:
Advantages:
i) It is simple to implement.
ii) Hash table never fills and we can add elements in the linked list fashion.
iii) The meaning of hash function can be preserved.
Disadvantages:
i) It requires extra space to maintain links.
ii) If the chain becomes too long then it takes more time to search an element.
iii) There may be wastage of space as some parts of hash table are never used.
2) Linear probing:
Advantage:
1) It is faster due to locality of references.
Disadvantage:
1) It forms primary clustering. Hence only some part of hash table remain occupied bim and other part remains
vaccant.
Q.1 What is the importance of sorting and searching techniques ?
Ans.: Sorting is useful for arranging the data in desired order. After sorting the required element can be located
easily.
Searching technique is essential for locating the position of the required element from the heap of data.
Q.2 Give any two applications of sorting.
Ans. :
1. The sorting is useful in database applications for arranging the data in desired order.
2. In the dictionary like applications the data is arranged in sorted order.
3. For searching the element from the list of elements, the sorting is required.
Q.3 What do you understand by the term sorting?
Ans. : Sorting is a mechanism of arranging the data in particular order.
Q. 4 What is the need for sorting?
Ans. : The sorting is useful for –
1. Searching the desired data efficiently. 2. Responding to the queries.
Q. 5 What is the meaning of sort key?
Ans. : Sort key is a field in the record based on which the sorting is conducted.
Q.6 Name the slowest and fastest sorting technique.
Ans. : Bubble sort is a slowest sorting technique and quick sort is the fastest sorting technique.
Q.7 Differentiate between internal and external sorting.
AU: Dec.-14, 19
Ans. : Internal sorting: This is a type of sorting technique in which data resides on main memory of computer.
External sorting: This is a sorting technique in which there is huge amount of data and it resides on secondary
storage devices while sorting.
Q.8 Explain the meaning of the term passes in context with sorting.
Ans. : While sorting the elements in some specific order, there is lot of arrangement of elements. The phases in
which the elements are moving to acquire their proper position is called passes.
Q.9 What is ascending and descending order?
Ans.
Ascending order is the sorting order in which the elements are arranged from low value to high value. In other
words it is called increasing order. For example: 10, 20, 30, 40.
Descending order is the sorting order in which the elements are arranged from high value to low value. In other
words it is called decreasing order. For example: 40, 30, 20, 10.
Q.10 What is the basic principle behind the quick sort ?
Ans. :
Sorting and Searching Techniques The division of the list into two sublists(which is called partition) and then
sorting each sublist independently. This is the basic principle used in quick sort. Based on the value of pivot element,
the list is subdivided.
Q.11 Enlist four internal sorting techniques.
Ans. : Following are some internal sorting techniques –
1. Insertion sort
2. Selection sort
3. Shell sort
4. Bubble sort
Q.12 What do you mean by heap?
Ans. : Ans. Heap is a complete binary tree or almost complete binary tree in which every parent node be either
greater or lesser than the parent node.
Q.13 What are the two stages in which heap sort is conducted ?
Ans. : Following are the two stages in which the heap sort is conducted - W Heap construction: The heap
structure is build for given list of elements
Deletion of maximum key: In this phase the root key is deleted for n 1 times.
Q.14 The way a card game player arranges his cards as he picks them one by one, is an example of ----------
Ans. : insertion sort
Q.15 A sort which iteratively passes through a list to exchange the first element with any element less than it
and then repeats with a new first element is called……..
Ans. : selection sort
Q.16 Explain why binary search can not be performed using linked list ?
Ans. : In binary search algorithm, the mid element needs to be searched. If binary search is implemented using
arrays then by simply saying a[mid] we can access the middle element of an array in constant time. But for finding
the mid element of a linked list we have to execute separate algorithm and it can not be done in constant time. Thus
implementing binary search using linked list is very inefficient way. Hence it is not preferred to implement a binary
search using linked list.
Q.17 What do you understand by the term searching?
Ans. Searching means locating the position of the desired record or key element from the given database.
Q.18 What are the advantages of binary search over the linear search?
Ans. : Binary search is an efficient searching method than the linear search. Using this method, the list is
subdivided each time and only sublist is scanned for locating the key value.
Q.19 List the sorting algorithms which uses logarithmic time complexity
Ans. : The sorting algorithms which use the logarithmic time complexity are - Quick sort and merge sort.
Q.20 Compare linear search and binary search.
Ans. :
AU: Dec.-15, May-19

You might also like