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

ds imp

The document provides an overview of various data structures, including data structures, searching methods, linked lists, stacks, binary trees, and queues. It explains fundamental concepts, operations, advantages, and disadvantages associated with each structure. Additionally, it covers specific types of linked lists and queues, detailing their applications and characteristics.
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)
4 views

ds imp

The document provides an overview of various data structures, including data structures, searching methods, linked lists, stacks, binary trees, and queues. It explains fundamental concepts, operations, advantages, and disadvantages associated with each structure. Additionally, it covers specific types of linked lists and queues, detailing their applications and characteristics.
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/ 11

1) What is data Structure ?

Data Structure is a way of collecting and organising data in such a way that we
can perform operations on these data in an effective way.

2) What is searching? Mention its types


Searching is the process of finding a given value position in a list of values.
Types of Searching
1. Sequential (Linear) Search
2. Binary Search

3) Define Linked list. List operations of single linked list


A linked list is a sequence of data structures, which are connected together via
links
Operations 1. Traversing 2. Insertion 3. Deletion 4 seafrching 5 sorting

4) What is stacks? State applications of stacks


A stack is a linear data structure in which all the insertion and deletion of data
takes place from same or one end called TOP OF STACK,
1) Evaluating Expressions.
2) Converting between expressions.
3) Back tracking.
4) Parsing context-free languages.
5) Recursion removal.
6) Tree and graph traversa

5) What is Binary tree


A binary tree is a tree data structure where each node has up to two child
nodes, creating the branches of the tree. The two children are usually called the
left and right nodes.

6) Explain Advantages and dis advantages of linked list

 Dynamic data structure: A linked list is a dynamic arrangement so it can


grow and shrink at runtime by allocating and deallocating memory. ...
 No memory wastage: In the Linked list, efficient memory utilization can be
achieved since the size of the linked list increase or decrease at run time
so there is no ...
 Implementation: Linear data structures like stack and queues are often
easily implemented using a linked list.
 Insertion and Deletion Operations: Insertion and deletion operations are
quite easier in the linked list.

Disadvantages of using linked list


 Searching a particular element in a list is difficult and time consuming.
 We have to start at the head node and traverse the linked list to find an
element.
 A linked list will use more storage space than an array to store the same
number of elements. Because you need to store address of next node in
the list along with data elements.

CONVERT INFIX TO POSTFIX EXPRESSION A^B*C/(D*E-F)


Explain operations of single linked list
Traverse a Linked List
Displaying the contents of a linked list is very simple. We keep moving the temp
node to the next one and display its contents. When temp is NULL, we know that
we have reached the end of the linked list so we get out of the while loop.
Search an Element on a Linked List
You can search an element on a linked list using a loop using the following steps.
Make head as the current node.
 Run a loop until the current node is NULL because the last element points
to NULL.
 In each iteration, check if the key of the nod

Sort Elements of a Linked List


We will use a simple sorting algorithm, Bubble Sort, to sort the elements of a
linked list in ascending order below.
1. Make the head as the current node and create another node index for later
use.
2. If head is null, return.
3. Else, run a loop till the last node (i.e. NULL).
4. In each iteration, follow the following step 5-6.
5. Store the next node of current in index.
6. Check if the data of the current node is greater than the next node. If it is
greater, swap current and index.
EXPLAIN BINARY TREE
A binary tree is a special type of tree in which every node or vertex has either no
child node or one child node or two child nodes. A binary tree is an important
class of a tree data structure in which a node can have at most two children. Child
node in a binary tree on the left is termed as 'left child node' and node in the right
is termed as the 'right child node.'
 Binary trees are of following types
 1. A full binary tree which is also called as proper binary tree or 2 tree is a
tree in which all the node other than the leaves has exact two children.
 A complete binary tree is a binary tree in which at every level, except
possibly the last, has to be filled and all nodes are as far left as possible.
 A binary tree can be converted into an extended binary tree by adding new
nodes to its leaf nodes and to the nodes that have only one child. These
new nodes are added in such a way that all the nodes in the resultant tree
have either zero or two children. It is also called 2 - tree.
 The threaded Binary tree is the tree which is represented using pointers
the empty subtrees are set to NULL, i.e. 'left' pointer of the node whose left
child is empty subtree is normally set to NULL.

WHAT IS COMPLETE BINARY TREE


A complete binary tree is just like a full binary tree, but with two major
differences
 Every level must be completely filled
 All the leaf elements must lean towards the
left.
 The last leaf element might not have a right
sibling i.e. a complete binary tree doesn't
have to be a full binary tree

EXPLAIN COMPLETE BINARY TREE


A complete binary tree is a binary tree in which all the levels are completely filled
except possibly the lowest one, which is filled from the left.
A complete binary tree is just like a full binary tree, but with two major
differences
1. All the leaf elements must lean towards the left.
2. The last leaf element might not have a right
sibling i.e. a complete binary tree doesn't have
to be a full binary tree.

How a Complete Binary Tree is Created?


 Select the first element of the list to be the root node. (no. of elements on
level-I: 1)
 Put the second element as a left child of the root node and the third
element as the right child. (no. of elements on level-II: 2)
 Put the next two elements as children of the left node of the second level.
Again,
 put the next two elements as children of the right node of the second level
(no. of
 elements on level-III: 4) elements).
 Keep repeating until you reach the last elemen

Explain Basic Operations on Stack


There are three basic operations on a stack.
1. PUSH – Inserting an element into a stack.
2. POP – Deleting an element from a stack.
3. PEEK – Returns the topmost element of the stack.
PUSH Operation on a Stack
Inserting a new element in the TOP of the stack is called the PUSH operation. We
must check if the stack is full before insertion. After PUSH operation the TOP will
point to the newly inserted item. In the following figure, item 7 will be added into
the stack on the top of item 6 and after insertion, the TOP pointer will point to
item 7.
Stack Overflow Condition
In computer programs, the size of the stack is predefined. If we try to insert a new
element into a full stack, then the stack overflow condition will occur.

POP Operation on a Stack


The POP operation deletes an element from the top of the stack. We must check
if the stack is empty before deletion. The value of TOP will be decremented by
one after the POP operation. In the figure, item 6 will be removed from the stack
and now the TOP will be pointing to item 5.
Stack Underflow Condition
Stack underflow condition occurs when we try to remove an item from an empty
stack.
Stack underflow condition occurs when we try to remove an item from an empty
stack.
EXPLAIN IMPLEMENTATION OF STACK
Stacks can be maintained in a program by
using a linear array of elements and pointer
variables TOP and MAX. The TOP pointer
contains the location of the top element of
the stack and MAX gives the maximum
number of elements in the stack.
The stack is empty if TOP=-1 or TOP=NULL. The following figure shows an array
representation of the stack.
TOP=3 indicates that the stack has four elements(0 to 3). Since MAX-1=9, there is
space for 6 more elements in the stack.
********** progrm ***********

EXPLAIN BINARY TREE TRAVERSAL

Displaying (or) visiting order of nodes in a binary tree is called as Binary Tree
Traversal.
There are three types of binary tree traversals.
1. In - Order Traversal
2. Pre - Order Traversal
3. Post - Order Traversal
1. In - Order Traversal
( leftChild - root - rightChild )
in In-Order traversal, the
root node is visited between
the left child and right child. In this traversal, the left child node is visited
first, then the root node is visited and later we go for visiting the right child
node. This is performed recursively for all nodes in the tree.
In the above example of a binary tree, first we try to visit left child of root
node 'A', but A's left child 'B' is a root node for left subtree. so we try to
visit its (B's) left child 'D' and again D is a root for subtree with nodes D, I
and J. So we try to visit its left child 'I' and it is the leftmost child. So first we
visit 'I' then go for its root node 'D' and later we visit D's right child 'J'. With
this we have completed the left part of node B. Then visit 'B' and next B's
right child 'F' is visited. With this we have completed left part of node A.
Then visit root node 'A'. With this we have completed left and root parts of
node A. Then we go for the right part of the node A. In right of A again
there is a subtree with root C. So go for left child of C and again it is a
subtree with root G. But G does not have left part so we visit 'G' and then
visit G's right child K. With this we have completed the left part of node C.
Then visit root node 'C' and next visit C's right child 'H' which is the
rightmost child in the tree. So we stop the process.
In-Order Traversal for above example of binary tree is I - D - J - B - F - A - G
-K-C–H

2. Pre - Order Traversal ( root-leftChild-rightChild )In Pre-Order traversal, the


root node is visited before the left child and right child nodes. In this
traversal, the root node is visited first, then its left child and later its right
child.
In the above example of binary tree, first we visit root node 'A' then visit its
left child 'B' which is a root for D and F. So we visit B's left child 'D' and
again D is a root for I and J. So we visit D's left child 'I' which is the leftmost
child. So next we go for visiting D's right child 'J'. With this we have
completed root, left and right parts of node D and root, left parts of node
B. Next visit B's right child 'F'. With this we have completed root and left
parts of node A. So we go for A's right child 'C' which is a root node for G
and H. After visiting C, we go for its left child 'G' which is a root for node K.
So next we visit left of G, but it does not have left child so we go for G's
right child 'K'. With this, we have completed node C's root and left parts.
Next visit C's right child 'H' which is the rightmost child in the tree. So we
stop the process.

Pre-Order Traversal for above example binary tree is A - B - D - I - J - F - C -


G-K–H

3. Post - Order Traversal ( leftChild - rightChild - root )


In Post-Order traversal, the root node is visited after left child and right
child. In this traversal, left child node is visited first, then its right child and
then its root node. This is recursively performed until the right most node is
visited.
Here we have visited in the order of I - J - D - F - B - K - G - H - C - A using
Post-Order Traversal.
Post-Order Traversal for above example binary tree is I - J - D - F - B - K - G
-H-C–A
What is Linked List ? Explain types of Linked List
A linked list is a linear data structure, in which the elements are not stored at
contiguous memory locations. The elements in a linked list are linked using
pointers. In simple words, a linked list consists of nodes where each node
contains a data field and a reference(link) to the next node in the list.
Types of Linked List
1. Singly Linked List
2. Circular Linked List:
3. Doubly Linked List:
4. Doubly Circular linked list

Singly Linked List: It is the simplest type of linked list in which every node
contains some data and a pointer to the next node of the same data type. The
node contains a pointer to the next node means that the node stores the address
of the next node in the sequence. A single linked list allows traversal of data only
in one way. HEADER is an empty node (having data content NULL) and only used
to store a pointer to the first node Thus, if
one knows the address of the HEADER
node from the link field of this node, the
next node can be traced, and so on. This
means that starting from the first node
one can reach to the last node whose link
field does not contain any address but
has a null value.

Circular Linked List: A circular linked list is that


in which the last node contains the pointer to
the first node of the list. While traversing a
circular liked list, we can begin at any node and
traverse the list in any direction forward and
backward until we reach the same node we
started. Thus, a circular linked list has no beginning and no end. Below is the
image for the same:
Doubly Linked List: A doubly linked list or a two-way linked list is a more complex
type of linked list which contains a pointer to the next as well as the previous
node in sequence, Therefore, it contains three parts are data, a pointer to the
next node, and a pointer to the previous node. This would enable us to traverse
the list in the backward direction as well.

Doubly Circular linked list: A Doubly Circular linked list or a circular two-way
linked list is a more complex type of linked-list that contains a pointer to the next
as well as the previous node in the sequence. The difference between the doubly
linked and circular doubly list is the same as that between a singly linked list and a
circular linked list. The circular doubly linked list does not contain null in the
previous field of the first node

Types of Queues
1. Simple Queue or ordinary queue
2. Circular Queue
3. Dequeue
4. Priority Queue

Simple Queue
A simple queue are the general queue that we use on perform insertion and
deletion on FIFO basis i.e. the new element is inserted at the rear of the queue
and an element is deleted from the front of the queue
Applications of Simple Queue
1.CPU scheduling
2. Disk Scheduling
3. Synchronization between two process
Circular Queue
Circular queue is a type of queue in which all nodes are treated as circular such
that the first node follows the last node. It is also called ring buffer. In this type of
queue operations are performed on first in first out basis i.e the element that has
inserted first will be one that will be deleted first.
Applications of Circular Queue
1.CPU scheduling
2.Memory management
3.Traffic Management

Double Ended Queue


Double ended queue are also known as deque. In this type of queue insertion and
deletion of an element can take place at both the ends. Further deque is divided
into two types:-
1.Input Restricted Deque :- In this, input
is blocked at a single end but allows
deletion at both the ends.
2.Output Restricted Deque :- In this,
output is blocked at a single end but allows insertion at both the ends.
Applications of Double Ended Queue
1.To execute undo and redo operation.
2.For implementing stacks.
3.Storing the history of web browsers.

Priority Queue
Priority Queue is a special type of queue in which elements are treated according
to their priority. Insertion of an element take place at the rear of the queue but
the deletion or removal of an element
take place according to the priority of the
element. Element with the highest priority is removed first and element wit h the
lowest priority is removed last.

Applications of Priority Queue


1.Dijkstra’s shortest path algorithm
2.Data compression in huffman codes.
3.Load balancing and interrupt handling in operating system.
4.Sorting heap.

You might also like