100% found this document useful (1 vote)
1K views4 pages

Data Structure & Algorithm Assignment

The document describes the differences between singly linked lists and circular linked lists, one-way and two-way linked lists, LIFO and FIFO data structures, and binary trees and binary search trees. For singly vs circular linked lists, it notes the number of pointers per node and ability to traverse in different directions. For one-way vs two-way lists, it explains that one-way lists only allow forward traversal while two-way lists allow both forward and backward traversal via additional pointers. It gives examples of real-world applications of LIFO and FIFO queues, describing LIFO as a stack where the last element added is first removed and FIFO as a queue where the first element added

Uploaded by

Nazmus M Sakib
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
100% found this document useful (1 vote)
1K views4 pages

Data Structure & Algorithm Assignment

The document describes the differences between singly linked lists and circular linked lists, one-way and two-way linked lists, LIFO and FIFO data structures, and binary trees and binary search trees. For singly vs circular linked lists, it notes the number of pointers per node and ability to traverse in different directions. For one-way vs two-way lists, it explains that one-way lists only allow forward traversal while two-way lists allow both forward and backward traversal via additional pointers. It gives examples of real-world applications of LIFO and FIFO queues, describing LIFO as a stack where the last element added is first removed and FIFO as a queue where the first element added

Uploaded by

Nazmus M Sakib
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

UT-191-250-0017

BCA HC-3026 (Data Structure & Algorithm)

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.

In Singly linked list

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:

push – append an element to the end of the container


pop – remove the most recent element from the container
FIFO is an abbreviation for first in, first out. It is a method for handling data structures where the
first element is processed first and the newest element is processed last.

Real life example:

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.

Real life example:


b) What is a Tree? How does a normal tree differ with the Binary Search Tree (BST)? Arrange the following set of
numbers to create a BST.
7, 17, 0, 270, 34, 50, 77, 99, 4, 55, 120
Answer:
A tree whose elements have at most 2 children is called a binary tree. Since each element in a binary tree can have
only 2 children, we typically name them the left and right child.
Binary Search Tree is a node-based binary tree data structure which has the following properties:
-The left subtree of a node contains only nodes with keys lesser than the node’s key.
-The right subtree of a node contains only nodes with keys greater than the node’s key.
-The left and right subtree each must also be a binary search tree.
-There must be no duplicate nodes.

Difference between Binary Tree and Binary Search Tree:

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 -

You might also like