0% found this document useful (0 votes)
15 views12 pages

Data Structures With C

This document discusses data structures in C including pointers, stacks, queues, linked lists, trees and binary trees. It provides definitions and examples of these common data structures.

Uploaded by

vishnunaidu29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views12 pages

Data Structures With C

This document discusses data structures in C including pointers, stacks, queues, linked lists, trees and binary trees. It provides definitions and examples of these common data structures.

Uploaded by

vishnunaidu29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

DATA STRUCTURES WITH C

1.0 ANSWER THE FOLLOWING

1.1 What is pointer?


Ans: A pointer is a variable whose value is the address of
another variable, i.e., direct address of the memory
location.
1.2 What is stack? What are the operations can be
performed on stack?
Ans: Stack is a linear data structure, where elements can
be inserted at one end and the elements are deleted
from the same end of the stack.
The operations can be performed on stack are:
a. PUSH
b. POP

1.3 What is meant by queue?


Ans: Queue is a linear data structure, where elements can
be inserted at one end and the elements are deleted from
another end. The insertion happened at one end called
rear and deletion happens at another end called front.

1.4 Explain Linked List?


Ans: A linked list is a data structure consisting of a group
of nodes which together represent a sequence.
1.5 Define Siblings?
Ans: The nodes with same parent are called as siblings.

1.6 What is Merge sort?


Ans: Merge sort is a sorting technique which is used to
sort two sorted arrays. It is
important that it will work only if the two input arrays are
already sorted.

1.7 What is Linear Search?


Ans: Linear search is a very simple search algorithm. In
this type of search, a sequential search is made over all
items one by one.

1.8 What is structure? Give its syntax.


Ans: To define a structure, you must use the struct
statement. The struct statement defines a new data
type, with more than one member. The format of
the struct statement is as follows:
struct[structure tag]
{
member definition;
member definition;
...
member definition;
}[one or more structure variables];

1.9 List out any four applications of stack


Ans: a. Recursion.
b. Conversion.
c. Undo/Redo.
d. String reverse.

1.10 Write the condition for stack full and stack empty?
Ans: Stack full
Top==max -1.
Stack empty
Top==-1.

2.0 ANSWER THE FOLLOWING

2.1 Write the difference between variable, array and


structure in C
Ans: Array: Arrays can only hold elements of the same data
type.
Structure: Structures can hold elements of different data
types.
Variable: A variable is a value that can change,
depending on conditions or on information passed to the
program.

2.2 Convert the infix expression into corresponding


prefix and postfix notation
A+(B-C*D)/E-(F^G)
Ans:

2.3 What are the types of linked list and explain anyone?
Ans: a. Singly Linked Lists
b. Doubly Linked Lists
c. Circular Singly Linked Lists
d. Circular Doubly Linked Lists

Singly Linked Lists:


2.4 List down the various sorting techniques
Ans: 1. Bubble Sort
2. Selection Sort
3. Merge Sort
4. Quick Sort
5. Radix Sort
6. Insertion Sort
7. Heap Sort

2.5 Explain calloc() with its syntax and example


Ans: The name calloc stands for "contiguous allocation".
The only difference between malloc() and calloc() is that,
malloc() allocates
single block of memory whereas calloc() allocates
multiple blocks of memory each
of same size and sets all bytes to zero.
Syntax of calloc()
ptr = (cast-type*)calloc(n, element-size);

For example:
ptr = (float*) calloc(25, sizeof(float));

2.6 Draw the neat diagram od different types of data


structures?
Ans:

2.7 Explain In order, preorder, and post order?


Ans: 1 Inorder
Inorder traversal in a binary tree can be performed
recursively by following
order.
1. Traverse the left sub tree in preorder recursively (Left)
2. Visit the root node ( Root )
3. Traverse the right sub tree in preorder recursively (right)
void inorder( Node root)
{
if(root ==NULL)
return ;
inorder(root->llink);
printf(“\n%d “, root->data);
inorder(root->rlink)
}
Inorder Traversal = Left->Root->Right

2 Preorder
Preorder traversal in a binary tree can be performed
recursively by
following order.
1. Visit the root node ( Root )
2. Traverse the left sub tree in preorder recursively (Left )
3 Traverse the right sub tree in preorder recursively (right )
void preorder( Node root)
{
if(root ==NULL)
return ;
printf(“\n%d “, root->data);
preorder(root->llink);
preorder(root->rlink);
}
Preorder Traversal = Root->Left->Right

3 Postorder
Preorder traversal in a binary tree can be performed
recursively by
following order.
1. Traverse the left sub tree in postorder recursively (Left)
2. Traverse the right sub tree in postorder recursively
(right)
3. Visit the root node (Root)
void postorder( Node root)
{
if(root ==NULL)
return ;
postorder(root->llink);
postorder(root->rlink);
printf(“\n%d “, root->data);
}
Postorder Traversal = Left->Right->Root.

2.8 What is call by reference? Explain with an example


Ans: Call by reference:
This method copies the address of an
argument into the formal parameter. Inside the
function, the address is used to access the actual
argument used in the call. This means that
changes made to the parameter affect the
argument.
For example: refer 3rd experiment of DSC.

3.0 ANSWER THE FOLLOWING:

3.1 Explain double pointer and void pointer with


its syntax and example
Ans: Double pointer:
We already know that a pointer points to a
location in memory and thus used to store address
of variables. So, when we define a pointer to
pointer. The first pointer is used to store the
address of second pointer. That is why they are
also known as double pointers. Declaring Pointer
to Pointer is similar to declaring pointer in C. The
difference is we have to place an additional ‘*’
before the name of pointer.

int **ptr; // declaring double pointers

Below diagram explains the concept of Double


Pointers:
For example:
int main()
{
int var = 789;
int *ptr2; // pointer for var
int **ptr1; // double pointer for ptr2
ptr2 = &var; // storing address of var in ptr2
ptr1 = &ptr2; // Storing address of ptr2 in ptr1
// Displaying value of var using both single and
double pointers
printf("Value of var = %d\n", var );
printf("Value of var using single pointer = %d\n",
*ptr2 );
printf("Value of var using double pointer = %d\n",
**ptr1);
return 0;
}
Output:
Value of var = 789
Value of var using single pointer = 789
Value of var using double pointer = 789

Void Pointer:
A void pointer is a pointer that has no associated
data type with it. A void pointer can hold address
of any type and can be typcasted to any type.
int a = 10;
char b = 'x';

void*p = &a; // void pointer holds address of int 'a'


p = &b; // void pointer holds address of char 'b'

3.2 Briefly explain different types of queues


Ans: 1. Simple Queue:
A queue is defined as a special type of data
structure where elements are inserted from one end
and elements are deleted from another end. The
end from where elements are inserted is called as
rear end and the end from where elements are
deleted is called as front end. Ordinary queue
follows FIFO ( Last In First Out). The element first
inserted will be deleted or come out of queue first.
Array implementation of Ordinary Queue.

2. Circular Queue
In Circular queue elements will be inserted and
deleted in a circular fashion. Circular queue follows
FIFO (First in First Out). Pictorial representation of
Circular queue.

3. Priority Queue
Priority queue is a special type of data structure
in which items can be inserted or deleted based on
the given priority. Always an element with highest
priority is
processed before processing the lowest priority
elements. If the elements in the queue come with
same or equal priority, then the element which is
inserted first will be
processed first.

a. Ascending Priority Queue.


In ascending priority queue elements can be
inserted in any order, while deleting an element
from queue the highest priority items will be deleted
first ie the
smallest element in the queue will be removed first.
Ascending order priority queue treat the smallest
number has highest priority.
b. Descending Priority Queue.
In descending priority queue also elements can
be inserted in any order, while deleting an element
from queue the highest priority items ie the largest
element in
the queue will be delete. Descending order priority
queue treat the largest number in the queue with
highest priority.
4. Double Ended Queue (Deque)
A deque is a special data structure in which
insertions and deletions can be performed at both
the ends ie rear and front ends. Operations that can
be performed on deque are
1. Insertion on Rear
2. Insertion on Front
3. Deletion from Front
4. Deletion from rear

Two variants of Double ended queue

a. Input Restricted Deque


An Input Restricted Deque is a variation of
Double Ended Queue (Deque), which supports
following operations
1.Delete front
2.Delete rear
3.Insert front
4.Display
Unlike Deque it won’t support insertion rear
operation on Input restricted deque.
b. Output Restricted Deque
An Output Restricted Deque is a another
variation of Double Ended Queue (Deque), which
supports following operations
1.Delete front
2.Insert rear
3.Insert front
4.Display
Unlike Deque it won’t support deletion rear
operation on Output restricted deque.

3.3 Define 1) Left Subtree 2) Parent 3)


Descendants 4) Root Node (refer assignment 9
question)
Ans: 1) Left Subtree:
The left subtree of a node consists of all
the nodes that are descendants of the node and are
positioned to the left of that node.

2) Parent:
A parent is a node that has any number of
child nodes. In simple terms, a parent node is the
one that has branches (child nodes) extending from
it.
3) Descendants:
Descendants in a tree refer to all the
nodes that can be reached from specific node.

4) Root node:
The initial node in the tree or first node in
the tree is known as root node.

3.4 What is searching? Explain different searching


techniques
Ans:

REMAINING DO YOUR SELF FOR YOUR OWN


KNOWLEDGE

You might also like