Data Structure & Algorithm Assignment
Data Structure & Algorithm Assignment
Q.No.1 Describe the difference between singly linked list and circular linked list with suitable diagrams. Also
describe the difference between one-way list (uni-directional) and two-way
list (bi-directional) with suitable diagrams.
Answer:
Difference between singly linked list and circular linked list are -
In circular linked list
1)Two pointers are maintained in a node of circular list, one will keep the address of first previous node and first
next node in sequence.
2)In circular list, we can move backward as well as forward direction as each node keeps the address of previous
and next node in sequence.
3)During deletion, we have to keep only one node address i.e the node to be deleted. This node will give the
address of previous node automatically.
1)Only one pointer is maintained in a node of singly list which contains the address of next node in sequence
another will keep the address of.
2)In singly, we can not move in backward direction because each in node has next node pointer which facilitates
us to move in forward direction.
3)During deletion of a node in between the singly list, we will have to keep two nodes address one the address of
the node to be deleted and the node just previous of it.
A node in a singly linked list contains a data item and a node pointer to the next node. In a singly linked list we
can traverse only in one direction. A node in a doubly circular linked list contains a data item and two node
pointers, one to the previous node and one to the next node.
Difference between one way list and two way list are as follows
1-way or singly linked list is the simple one in which there is one head node and other nodes are
connected in forward manner. i.e, you cannot traverse backwards as there is no back pointer.
2-way or doubly linked list is more advanced one in which each node contains one more link which
points to the previous element/node. You can traverse forward as well as backwards in this Data
structure.
Both the lists are used to store dynamic data. Major difference is : singly linked list is "unidirectional
traverse of data" where as doubly linked is "bi-directional traverse of data". Singly linked lists contain
nodes which have a data field as well as a 'next' field, which points to the next node in line of nodes.
Two-way lists • A two-way list is a linear collection of data elements, called nodes, where each node
N is divided into three parts: – Information field – Forward Link which points to the next node –
Backward Link which points to the previous node • The starting address or the address of first node
is stored in START /
Furthermore, what is one way linked list? 1-way or singly linked list is the simple one in which there
is one head node and other nodes are connected in forward manner. i.e, you cannot traverse
backwards as there is no back pointer.
If we need better performance while searching and memory is not a limitation in this case doubly
linked list is more preferred. As singly linked list store pointer of only one node so consumes lesser
memory. On other hand Doubly linked list uses more memory per node(two pointers).
Q.No.2
a)What are LIFO and FIFO data structures? Explain both LIFO and FIFO taking help of some
real life examples along with their uses in computer programmes.
Answer :
Two common data structures in computer science are LIFO (last-in-first-out) and FIFO (first-in-
first-out).
Last-In-First-Out
In a LIFO data structure, the newest element added to the queue will be processed first.
Sometimes this will be called a stack and is usually pictured as below. The new element is always
added at the end of the stack. There are two basic operations that a LIFO needs to allow:
LIFO is an abbreviation for Last in, first out is same as first in, last out (FILO). It is a method
for handling data structures where the last element is processed first and the first element is
processed last.
BINARY TREE is a non linear data structure where each node can have atmost two child nodes BINARY
SEARCH TREE is a node based binary tree which further has right and left subtree that too are binary search tree.
BINARY TREE is unordered hence slower in process of insertion, deletion, and searching. Insertion,
deletion, searching of an element is faster in BINARY SEARCH TREE than BINARY TREE due to the ordered
characteristics
IN BINARY TREE there is no ordering in terms of how the nodes are arranged IN BINARY SEARCH TREE the
left subtree has elements less than the nodes element and the right subtree has elements greater than the nodes
element.
The BST of following set is -