SlideShare a Scribd company logo
UNIT - I
LINEAR DATA STRUCTURES – LIST
Abstract Data Types (ADTs) – List ADT – array-based implementation –
linked list implementation ––singly linked lists- circularly linked lists-
doubly-linked lists – applications of lists –Polynomial Manipulation – All
operations (Insertion, Deletion, Merge, Traversal).
Elavarasi.K
AP/CSE
S.A Engineering College
06-06-2018 CS8351 - DATA STRUCTURES 1
Introduction to DS
• Data structures are generally based on the ability of a computer to
fetch and store data at any place in its memory, specified by a pointer
• Thus, the array and record data structures are based on computing the
addresses of data items with arithmetic operations
• What is Program?
• A Set of Instructions
Data Structures + Algorithms
Data Structure = A Container stores Data
Algorithm = Logic + Control
CS8351 - DATA STRUCTURES
06-06-2018 2
• Data Structure
• Data: are simply a value are set of values of different type which is called data
types like string, integer, char etc.
• Structure: Way of organizing information, so that it is easier to use
In simple words we can define data structures as
• Its a way organizing data in such a way so that data can be easier to use.
• Data Structure ..
• A data structure is a particular way of organizing data in a computer so that it
can be used efficiently.
• A scheme for organizing related pieces of information.
06-06-2018 CS8351 - DATA STRUCTURES 3
Classification of Data Structure
06-06-2018 CS8351 - DATA STRUCTURES 4
• Primitive Data Structure:
• A Primitive Data Structure used to represent the standard data types of any one of the computer
languages (integer, Character, float etc.).
• Non - Primitive Data Structure :
• A Primitive Data Structure can be constructed with the help of any one of the primitive data
structure.
• It can be structure and it is having a specific functionality.
• It can be designed by user.
• It can be classified as Linear and Non-Linear Data Structure.
06-06-2018 CS8351 - DATA STRUCTURES 5
Linear Data Structures:
A linear data structure traverses the data elements sequentially, in which only one data element
can directly be reached.
Ex: Arrays, Linked Lists ,Stacks, Queues
Non-Linear Data Structures:
Every data item is attached to several other data items in a way that is specific for reflecting
relationships. The data items are not arranged in a sequential structure.
Ex: Trees, Graphs ,Heaps
Operations on Data Structures
• The basic operations that are performed on data structures are as follows:
• Traversal: Traversal of a data structure means processing all the data elements
present in it exactly once.
• Insertion: Insertion means addition of a new data element in a data structure.
• Deletion: Deletion means removal of a data element from a data structure if it is
found.
• Searching: Searching involves searching for the specified data element in a data
structure.
• Sorting: Arranging data elements of a data structure in a specified order is called
sorting.
• Merging: Combining elements of two similar data structures to form a new data
structure of the same type, is called merging.
06-06-2018 CS8351 - DATA STRUCTURES 6
Abstract Data Types (ADTs)
• An Abstract Data type refers to set of data values and associated operations
that are specified accurately, independent of any particular implementation.
(Or)
• ADT is a user defined data type which encapsulates a range of data values
and their functions.
(Or)
• An Abstract Data Type is a mathematical model of a data structure. It
describes a container which holds a finite number of objects where the
objects may be associated through a given binary relationship.
Ex: List, Stack ,Queue
06-06-2018 CS8351 - DATA STRUCTURES 7
The LIST ADT
• A list or sequence is an abstract data type that represents a countable number of
ordered values, where the same value may occur more than once.
A sequence of zero or more elements
A1, A2, A3, … AN
N: length of the list
A1: first element
AN: last element
Ai: position i
If N=0, then empty list
Linearly ordered
Ai precedes Ai+1
Ai follows Ai-1
06-06-2018 CS8351 - DATA STRUCTURES 8
Lists are a basic example of containers, as they contain other values. If the same
value occurs multiple times, each occurrence is considered a distinct item.
Operations
• A list contains elements of same type arranged in sequential order and
following operations can be performed on the list.
get() – Return an element from the list at any given position.
insert() – Insert an element at any position of the list.
remove() – Remove the first occurrence of any element from a non-empty
list.
removeAt() – Remove the element at a specified location from a non-
empty list.
replace() – Replace an element at any position by another element.
size() – Return the number of elements in the list.
isEmpty() – Return true if the list is empty, otherwise return false.
isFull() – Return true if the list is full, otherwise return false.
06-06-2018 CS8351 - DATA STRUCTURES 9
Implementation of LIST ADT
• Each operation associated with the ADT is implemented by one or more
subroutines
• Two standard implementations for the list ADT
• Array-based
• Linked list
• An array is a random access data structure, where each element can be accessed
directly and in constant time.
• A typical illustration of random access is a book - each page of the book can be open
independently of others.
• A linked list is a sequential access data structure, where each element can be
accessed only in particular order.
• A typical illustration of sequential access is a roll of paper or tape - all prior material must be
unrolled in order to get to data you want.
06-06-2018 CS8351 - DATA STRUCTURES 10
An Array-based Implementation (LIST)
• An Array is a data structure which can store a fixed-size sequential collection
of elements of the same type.
(An array is used to store a collection of data, but it is often more useful to think of an array as a
collection of variables of the same type.)
• Instead of declaring individual variables, such as number0, number1, ..., and
number99, you declare one array variable such as numbers and use
numbers[0], numbers[1], and ..., numbers[99] to represent individual variables.
• A specific element in an array is accessed by an index.
• All arrays consist of contiguous memory locations. The lowest address
corresponds to the first element and the highest address to the last element.
06-06-2018 CS8351 - DATA STRUCTURES 11
06-06-2018 CS8351 - DATA STRUCTURES 12
Operations:
Is Empty(LIST)
If (Current Size==0) "LIST is Empty"
else "LIST is not Empty"
Is Full(LIST)
If (Current Size=Max Size) "LIST is FULL"
else "LIST is not FULL“
Insert Element to End of the LIST
1. Check that weather the List is full or not
1. If List is full return error message ”List is full. Can’t Insert”.
2. If List is not full.
1. Get the position to insert the new element by Position=Current Size+1
2. Insert the element to the Position
3. Increase the Current Size by 1 i.e. Current Size=Current Size+1
06-06-2018 CS8351 - DATA STRUCTURES 13
Delete Element from End of the LIST
1. Check that weather the List is empty or not
1. If List is empty return error message ”List is Empty. Can't Delete”.
2. If List is not Empty.
1. Get the position of the element to delete by Position=Current Size
2. Delete the element from the Position
3. Decrease the Current Size by 1 i.e. Current Size=Current Size-1
Insert Element to front of the LIST
1. Check that weather the List is full or not
1. If List is full return error message ”List is full. Can't Insert”.
2. If List is not full.
1. Free the 1st Position of the list by moving all the Element to one position forward i.e New
Position=Current Position + 1.
2. Insert the element to the 1st Position
3. Increase the Current Size by 1 i.e. Current Size=Current Size+1
06-06-2018 CS8351 - DATA STRUCTURES 14
Delete Element from front of the LIST
1. Check that weather the List is empty or not
1. If List is empty return error message ”List is Empty. Can't Delete”.
2. If List is not Empty.
1. Move all the elements except one in the 1st position to one position backward i.e New Position=
Current Position -1
2. After the 1st step, element in the 1st position will be automatically deleted.
3. Decrease the Current Size by 1 i.e. Current Size=Current Size-1
Insert Element to nth Position of the LIST
1. Check that weather the List is full or not
1. If List is full return error message ”List is full. Can't Insert”.
2. If List is not full.
1. If List is Empty, Insert element at Position 1.
2. If (nth Position > Current Size)
1. Return message “nth Position Not available in List”
3. else
1. Free the nth Position of the list by moving all Elements to one position
forward except n-1,n-2,... 1 Position i.e move only from n to current
size position Elements. i.e New Position=Current Position + 1.
2. Insert the element to the nth Position
3. Increase the Current Size by 1 i.e. Current Size=Current Size+1
06-06-2018 CS8351 - DATA STRUCTURES 15
Delete Element from nth Position of the LIST
1. Check that weather the List is Empty or not
1. If List is Empty return error message ”List is Empty.”
2. If List is not Empty.
1. If (nth Position > Current Size)
1. Return message “nth Position Not available in List”
2. If (nth Position == Current Size)
1. Delete the element from nth Position
2. Decrease the Current Size by 1 i.e. Current Size=Current Size-1
3. If (nth Position < Current Size)
1. Move all the Elements to one position backward except n,n-1,n-2,... 1 Position i.e move only
from n+1 to current size position Elements. i.e New Position=Current Position - 1.
2. After the previous step, nth element will be deleted automatically.
3. Decrease the Current Size by 1 i.e. Current Size=Current Size-1
06-06-2018 CS8351 - DATA STRUCTURES 16
Search Element in the LIST
1. Check that weather the list is empty or not.
1. If List is empty, return error message “List is Empty”.
2. If List is not Empty
1. Find the Position where the last element available in the List by Last Position = Current Size
2. For( Position 1 to Last Position)
1. If(Element @ Position== Search Element)//If Element matches the search element
2. return the Position by message “Search Element available in Position”
3. Else return message “Search Element not available in the List”
Print the Elements in the LIST
1. Check that weather the list is empty or not.
1. If List is empty, return error message “List is Empty”.
2. If List is not Empty
1. Find the Position where the last element available in the List by Last Position = Current Size
2. For( Position 1 to Last Position)
3. Print the Position and Element available at the position of List.
06-06-2018 CS8351 - DATA STRUCTURES 17
Array Implementation of LIST ADT
LIST ADT
06-06-2018 CS8351 - DATA STRUCTURES 18
Linked List Implementation - LIST
• Like arrays, Linked List is a linear data structure.
• Unlike arrays, linked list elements are not stored at contiguous
location; the elements are linked using pointers.
06-06-2018 CS8351 - DATA STRUCTURES 19
Why Linked List?
Arrays can be used to store linear data of similar types, but arrays have
following limitations.
1) The size of the arrays is fixed: So we must know the upper
limit on the number of elements in advance. Also, generally, the
allocated memory is equal to the upper limit irrespective of the usage.
2) Inserting a new element in an array of elements is expensive,
because room has to be created for the new elements and to create room
existing elements have to shifted.
06-06-2018 CS8351 - DATA STRUCTURES 20
For example, in a system if we maintain a sorted list of IDs in an array id[].
id[] = [1000, 1010, 1050, 2000, 2040].
And if we want to insert a new ID 1005, then to maintain the sorted order, we
have to move all the elements after 1000 (excluding 1000).
Deletion is also expensive with arrays until unless some special techniques
are used. For example, to delete 1010 in id[], everything after 1010 has to be
moved.
• Advantages over arrays
1) Dynamic size
2) Ease of insertion/deletion
• Drawbacks:
1) Random access is not allowed. We have to access elements sequentially
starting from the first node. So we cannot do binary search with linked lists.
2) Extra memory space for a pointer is required with each element of the
list.
06-06-2018 CS8351 - DATA STRUCTURES 21
Representation in C:
A linked list is represented by a pointer to the first node of the linked
list. The first node is called head. If the linked list is empty, then value
of head is NULL.
Each node in a list consists of at least two parts:
1) data
2) pointer to the next node
In C, we can represent a node using structures. Below is an example of a
linked list node with an integer data.
06-06-2018 CS8351 - DATA STRUCTURES 22
06-06-2018 CS8351 - DATA STRUCTURES 23
data next
ListStart
node
null
pointer
Singly Linked List
06-06-2018 CS8351 - DATA STRUCTURES 24
CODING
Doubly Linked List
06-06-2018 CS8351 - DATA STRUCTURES 25
CODING
Singly Circular Linked List
06-06-2018 CS8351 - DATA STRUCTURES 26
CODING
Doubly Circular Linked List
06-06-2018 CS8351 - DATA STRUCTURES 27
CODING
Comparison of array-based lists and linked lists
Array-based lists Linked lists
Pro
no wasted space for an
individual element
only need space for the objects
actually on the list
Con
size must be predetermined;
wasted space for lists with
empty slots
overhead for links (an extra
pointer added to every node)
Space complexity Ω(n) (or greater) Θ(n)
06-06-2018 CS8351 - DATA STRUCTURES 28
Applications of List
• Lists can be used to store a list of elements. However, unlike in
traditional arrays, lists can expand and shrink, and are stored
dynamically in memory.
• In computing, lists are easier to implement than sets.
• Lists also form the basis for other abstract data types including the
queue, the stack, and their variations.
06-06-2018 CS8351 - DATA STRUCTURES 29
Polynomial Manipulation
• A polynomial is a mathematical expression consisting of a sum of terms,
each term including a variable or variables raised to a power and multiplied
by a coefficient. The simplest polynomials have one variable.
• Representation of a Polynomial: A polynomial is an expression that
contains more than two terms. A term is made up of coefficient and
exponent. An example of polynomial is
• P(x) = 4x3+6x2+7x+9
06-06-2018 CS8351 - DATA STRUCTURES 30
A polynomial thus may be represented using arrays or linked lists.
• Array representation assumes that the exponents of the given expression are
arranged from 0 to the highest value (degree), which is represented by the
subscript of the array beginning with 0.
• The coefficients of the respective exponent are placed at an appropriate
index in the array.
• The array representation for the above polynomial expression is given
below:
06-06-2018 CS8351 - DATA STRUCTURES 31
• A polynomial may also be represented using a linked list. A structure may
be defined such that it contains two parts- one is the coefficient and second
is the corresponding exponent. The structure definition may be given as
shown below:
struct polynomial
{
int coefficient;
int exponent;
struct polynomial *next;
};
• Thus the above polynomial may be represented using linked list as shown
below:
06-06-2018 CS8351 - DATA STRUCTURES 32
Here are the most common operations on a polynomial:
• Add & Subtract
• Multiply
• Differentiate
• Integrate
• etc…
There are different ways of implementing the polynomial ADT:
• Array (not recommended)
• Linked List (preferred and recommended)
Array Implementation:
• p1(x) = 8x3 + 3x2 + 2x + 6
• p2(x) = 23x4 + 18x - 3
• This is why arrays aren’t good to represent polynomials:
• p3(x) = 16x21 - 3x5 + 2x + 6
06-06-2018 CS8351 - DATA STRUCTURES 33
• Advantages of using an Array:
• only good for non-sparse polynomials.
• ease of storage and retrieval.
• Disadvantages of using an Array:
• have to allocate array size ahead of time.
• huge array size required for sparse polynomials. Waste of space and runtime.
06-06-2018 CS8351 - DATA STRUCTURES 34
Linked list Implementation:
• p1(x) = 23x9 + 18x7 + 41x6 + 163x4 + 3
• p2(x) = 4x6 + 10x4 + 12x + 8
Representation
struct polynode {
int coef;
int exp;
struct polynode * next;
};
typedef struct polynode *polyptr;
06-06-2018 CS8351 - DATA STRUCTURES 35
coef exp next
• Advantages of using a Linked list:
• save space (don’t have to worry about sparse polynomials) and easy to
maintain
• don’t need to allocate list size and can declare nodes (terms) only as needed
• Disadvantages of using a Linked list :
• can’t go backwards through the list
• can’t jump to the beginning of the list from the end.
06-06-2018 CS8351 - DATA STRUCTURES 36
Addition of two Polynomials:
• For adding two polynomials using arrays is straightforward method,
since both the arrays may be added up element wise beginning from 0
to n-1, resulting in addition of two polynomials.
• Addition of two polynomials using linked list requires comparing the
exponents, and wherever the exponents are found to be same, the
coefficients are added up.
• For terms with different exponents, the complete term is simply added
to the result thereby making it a part of addition result.
06-06-2018 CS8351 - DATA STRUCTURES 37
Adding polynomials using a Linked list representation: (storing the result in p3)
To do this, we have to break the process down to cases:
Case 1: exponent of p1 > exponent of p2
• Copy node of p1 to end of p3.
• [go to next node]
Case 2: exponent of p1 < exponent of p2
• Copy node of p2 to end of p3.
• [go to next node]
Case 3: exponent of p1 = exponent of p2
• Create a new node in p3 with the same exponent and with the sum of the coefficients
of p1 and p2.
CODING
06-06-2018 CS8351 - DATA STRUCTURES 38
06-06-2018 CS8351 - DATA STRUCTURES 39
Multiplication of two Polynomials:
Multiplication of two polynomials however requires manipulation of each node such
that the exponents are added up and the coefficients are multiplied.
After each term of first polynomial is operated upon with each term of the second
polynomial, then the result has to be added up by comparing the exponents and
adding the coefficients for similar exponents and including terms as such with
dissimilar exponents in the result.
All Operations (Insertion, Deletion, Merge, Traversal)
• Insertion
• Deletion
• Merge two sorted linked lists
• Traversal
• Assume, that we have a list with some nodes. Traversal is the very basic
operation, which presents as a part in almost every operation on a singly-linked
list.
• For instance, algorithm may traverse a singly-linked list to find a value, find a
position for insertion, etc. For a singly-linked list, only forward direction
traversal is possible.
Traversal algorithm
• Beginning from the head,
• check, if the end of a list hasn't been reached yet;
• do some actions with the current node, which is specific for particular algorithm;
• current node becomes previous and next node becomes current. Go to the step 1.
06-06-2018 CS8351 - DATA STRUCTURES 40
Example
• As for example, let us see an
example of summing up values in
a singly-linked list.
06-06-2018 CS8351 - DATA STRUCTURES 41

More Related Content

Similar to unit-ids17-180709051413-1.pdf

AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docxAD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AmuthachenthiruK
 
Data Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptxData Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptx
UsriDevi1
 
Data structure &amp; algorithms introduction
Data structure &amp; algorithms introductionData structure &amp; algorithms introduction
Data structure &amp; algorithms introduction
Sugandh Wafai
 
unit 1_Linked list.pptx
unit 1_Linked list.pptxunit 1_Linked list.pptx
unit 1_Linked list.pptx
ssuser7922b8
 
DSA - Copy.pptx
DSA - Copy.pptxDSA - Copy.pptx
DSA - Copy.pptx
BishalChowdhury10
 
General Data structures
General Data structuresGeneral Data structures
General Data structures
Youssef Elsalhawy
 
Data Structure
Data StructureData Structure
Data Structure
HarshGupta663
 
Data Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptxData Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptx
mexiuro901
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
Rajitha Reddy Alugati
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
Swapnil Mishra
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
 
Data Structures 3
Data Structures 3Data Structures 3
Data Structures 3
Dr.Umadevi V
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
Nguync91368
 
Intro ds
Intro dsIntro ds
Intro ds
John Fathima
 
project on data structures and algorithm
project on data structures and algorithmproject on data structures and algorithm
project on data structures and algorithm
AnujKumar566766
 
chapter three ppt.pptx
chapter three ppt.pptxchapter three ppt.pptx
chapter three ppt.pptx
selemonGamo
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبيانات
Rafal Edward
 
introduction_dst.pptx
introduction_dst.pptxintroduction_dst.pptx
introduction_dst.pptx
HammadTariq51
 
Unit 1.ppt
Unit 1.pptUnit 1.ppt
Unit 1.ppt
Minakshee Patil
 
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCEARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
Venugopalavarma Raja
 

Similar to unit-ids17-180709051413-1.pdf (20)

AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docxAD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
 
Data Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptxData Structures & Algorithms Unit 1.pptx
Data Structures & Algorithms Unit 1.pptx
 
Data structure &amp; algorithms introduction
Data structure &amp; algorithms introductionData structure &amp; algorithms introduction
Data structure &amp; algorithms introduction
 
unit 1_Linked list.pptx
unit 1_Linked list.pptxunit 1_Linked list.pptx
unit 1_Linked list.pptx
 
DSA - Copy.pptx
DSA - Copy.pptxDSA - Copy.pptx
DSA - Copy.pptx
 
General Data structures
General Data structuresGeneral Data structures
General Data structures
 
Data Structure
Data StructureData Structure
Data Structure
 
Data Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptxData Structures and algoithms Unit - 1.pptx
Data Structures and algoithms Unit - 1.pptx
 
TSAT Presentation1.pptx
TSAT Presentation1.pptxTSAT Presentation1.pptx
TSAT Presentation1.pptx
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
Data Structures 3
Data Structures 3Data Structures 3
Data Structures 3
 
1 list datastructures
1 list datastructures1 list datastructures
1 list datastructures
 
Intro ds
Intro dsIntro ds
Intro ds
 
project on data structures and algorithm
project on data structures and algorithmproject on data structures and algorithm
project on data structures and algorithm
 
chapter three ppt.pptx
chapter three ppt.pptxchapter three ppt.pptx
chapter three ppt.pptx
 
هياكلبيانات
هياكلبياناتهياكلبيانات
هياكلبيانات
 
introduction_dst.pptx
introduction_dst.pptxintroduction_dst.pptx
introduction_dst.pptx
 
Unit 1.ppt
Unit 1.pptUnit 1.ppt
Unit 1.ppt
 
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCEARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
ARRAYS IN C++ CBSE AND STATE +2 COMPUTER SCIENCE
 

Recently uploaded

digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
drwaing
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
University of Maribor
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
PauloRodrigues104553
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
Madhumitha Jayaram
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
nooriasukmaningtyas
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
anoopmanoharan2
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
jpsjournal1
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
camseq
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
PuktoonEngr
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
awadeshbabu
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
Ratnakar Mikkili
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
Dr Ramhari Poudyal
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
gerogepatton
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
heavyhaig
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
Divyam548318
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
wisnuprabawa3
 

Recently uploaded (20)

digital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdfdigital fundamental by Thomas L.floydl.pdf
digital fundamental by Thomas L.floydl.pdf
 
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
Presentation of IEEE Slovenia CIS (Computational Intelligence Society) Chapte...
 
Series of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.pptSeries of visio cisco devices Cisco_Icons.ppt
Series of visio cisco devices Cisco_Icons.ppt
 
Wearable antenna for antenna applications
Wearable antenna for antenna applicationsWearable antenna for antenna applications
Wearable antenna for antenna applications
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Low power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniquesLow power architecture of logic gates using adiabatic techniques
Low power architecture of logic gates using adiabatic techniques
 
PPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testingPPT on GRP pipes manufacturing and testing
PPT on GRP pipes manufacturing and testing
 
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECTCHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
CHINA’S GEO-ECONOMIC OUTREACH IN CENTRAL ASIAN COUNTRIES AND FUTURE PROSPECT
 
Modelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdfModelagem de um CSTR com reação endotermica.pdf
Modelagem de um CSTR com reação endotermica.pdf
 
2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt2. Operations Strategy in a Global Environment.ppt
2. Operations Strategy in a Global Environment.ppt
 
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
[JPP-1] - (JEE 3.0) - Kinematics 1D - 14th May..pdf
 
Exception Handling notes in java exception
Exception Handling notes in java exceptionException Handling notes in java exception
Exception Handling notes in java exception
 
Literature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptxLiterature Review Basics and Understanding Reference Management.pptx
Literature Review Basics and Understanding Reference Management.pptx
 
International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...International Conference on NLP, Artificial Intelligence, Machine Learning an...
International Conference on NLP, Artificial Intelligence, Machine Learning an...
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
Technical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prismsTechnical Drawings introduction to drawing of prisms
Technical Drawings introduction to drawing of prisms
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
bank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdfbank management system in java and mysql report1.pdf
bank management system in java and mysql report1.pdf
 
New techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdfNew techniques for characterising damage in rock slopes.pdf
New techniques for characterising damage in rock slopes.pdf
 

unit-ids17-180709051413-1.pdf

  • 1. UNIT - I LINEAR DATA STRUCTURES – LIST Abstract Data Types (ADTs) – List ADT – array-based implementation – linked list implementation ––singly linked lists- circularly linked lists- doubly-linked lists – applications of lists –Polynomial Manipulation – All operations (Insertion, Deletion, Merge, Traversal). Elavarasi.K AP/CSE S.A Engineering College 06-06-2018 CS8351 - DATA STRUCTURES 1
  • 2. Introduction to DS • Data structures are generally based on the ability of a computer to fetch and store data at any place in its memory, specified by a pointer • Thus, the array and record data structures are based on computing the addresses of data items with arithmetic operations • What is Program? • A Set of Instructions Data Structures + Algorithms Data Structure = A Container stores Data Algorithm = Logic + Control CS8351 - DATA STRUCTURES 06-06-2018 2
  • 3. • Data Structure • Data: are simply a value are set of values of different type which is called data types like string, integer, char etc. • Structure: Way of organizing information, so that it is easier to use In simple words we can define data structures as • Its a way organizing data in such a way so that data can be easier to use. • Data Structure .. • A data structure is a particular way of organizing data in a computer so that it can be used efficiently. • A scheme for organizing related pieces of information. 06-06-2018 CS8351 - DATA STRUCTURES 3
  • 4. Classification of Data Structure 06-06-2018 CS8351 - DATA STRUCTURES 4
  • 5. • Primitive Data Structure: • A Primitive Data Structure used to represent the standard data types of any one of the computer languages (integer, Character, float etc.). • Non - Primitive Data Structure : • A Primitive Data Structure can be constructed with the help of any one of the primitive data structure. • It can be structure and it is having a specific functionality. • It can be designed by user. • It can be classified as Linear and Non-Linear Data Structure. 06-06-2018 CS8351 - DATA STRUCTURES 5 Linear Data Structures: A linear data structure traverses the data elements sequentially, in which only one data element can directly be reached. Ex: Arrays, Linked Lists ,Stacks, Queues Non-Linear Data Structures: Every data item is attached to several other data items in a way that is specific for reflecting relationships. The data items are not arranged in a sequential structure. Ex: Trees, Graphs ,Heaps
  • 6. Operations on Data Structures • The basic operations that are performed on data structures are as follows: • Traversal: Traversal of a data structure means processing all the data elements present in it exactly once. • Insertion: Insertion means addition of a new data element in a data structure. • Deletion: Deletion means removal of a data element from a data structure if it is found. • Searching: Searching involves searching for the specified data element in a data structure. • Sorting: Arranging data elements of a data structure in a specified order is called sorting. • Merging: Combining elements of two similar data structures to form a new data structure of the same type, is called merging. 06-06-2018 CS8351 - DATA STRUCTURES 6
  • 7. Abstract Data Types (ADTs) • An Abstract Data type refers to set of data values and associated operations that are specified accurately, independent of any particular implementation. (Or) • ADT is a user defined data type which encapsulates a range of data values and their functions. (Or) • An Abstract Data Type is a mathematical model of a data structure. It describes a container which holds a finite number of objects where the objects may be associated through a given binary relationship. Ex: List, Stack ,Queue 06-06-2018 CS8351 - DATA STRUCTURES 7
  • 8. The LIST ADT • A list or sequence is an abstract data type that represents a countable number of ordered values, where the same value may occur more than once. A sequence of zero or more elements A1, A2, A3, … AN N: length of the list A1: first element AN: last element Ai: position i If N=0, then empty list Linearly ordered Ai precedes Ai+1 Ai follows Ai-1 06-06-2018 CS8351 - DATA STRUCTURES 8 Lists are a basic example of containers, as they contain other values. If the same value occurs multiple times, each occurrence is considered a distinct item.
  • 9. Operations • A list contains elements of same type arranged in sequential order and following operations can be performed on the list. get() – Return an element from the list at any given position. insert() – Insert an element at any position of the list. remove() – Remove the first occurrence of any element from a non-empty list. removeAt() – Remove the element at a specified location from a non- empty list. replace() – Replace an element at any position by another element. size() – Return the number of elements in the list. isEmpty() – Return true if the list is empty, otherwise return false. isFull() – Return true if the list is full, otherwise return false. 06-06-2018 CS8351 - DATA STRUCTURES 9
  • 10. Implementation of LIST ADT • Each operation associated with the ADT is implemented by one or more subroutines • Two standard implementations for the list ADT • Array-based • Linked list • An array is a random access data structure, where each element can be accessed directly and in constant time. • A typical illustration of random access is a book - each page of the book can be open independently of others. • A linked list is a sequential access data structure, where each element can be accessed only in particular order. • A typical illustration of sequential access is a roll of paper or tape - all prior material must be unrolled in order to get to data you want. 06-06-2018 CS8351 - DATA STRUCTURES 10
  • 11. An Array-based Implementation (LIST) • An Array is a data structure which can store a fixed-size sequential collection of elements of the same type. (An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type.) • Instead of declaring individual variables, such as number0, number1, ..., and number99, you declare one array variable such as numbers and use numbers[0], numbers[1], and ..., numbers[99] to represent individual variables. • A specific element in an array is accessed by an index. • All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element. 06-06-2018 CS8351 - DATA STRUCTURES 11
  • 12. 06-06-2018 CS8351 - DATA STRUCTURES 12
  • 13. Operations: Is Empty(LIST) If (Current Size==0) "LIST is Empty" else "LIST is not Empty" Is Full(LIST) If (Current Size=Max Size) "LIST is FULL" else "LIST is not FULL“ Insert Element to End of the LIST 1. Check that weather the List is full or not 1. If List is full return error message ”List is full. Can’t Insert”. 2. If List is not full. 1. Get the position to insert the new element by Position=Current Size+1 2. Insert the element to the Position 3. Increase the Current Size by 1 i.e. Current Size=Current Size+1 06-06-2018 CS8351 - DATA STRUCTURES 13
  • 14. Delete Element from End of the LIST 1. Check that weather the List is empty or not 1. If List is empty return error message ”List is Empty. Can't Delete”. 2. If List is not Empty. 1. Get the position of the element to delete by Position=Current Size 2. Delete the element from the Position 3. Decrease the Current Size by 1 i.e. Current Size=Current Size-1 Insert Element to front of the LIST 1. Check that weather the List is full or not 1. If List is full return error message ”List is full. Can't Insert”. 2. If List is not full. 1. Free the 1st Position of the list by moving all the Element to one position forward i.e New Position=Current Position + 1. 2. Insert the element to the 1st Position 3. Increase the Current Size by 1 i.e. Current Size=Current Size+1 06-06-2018 CS8351 - DATA STRUCTURES 14
  • 15. Delete Element from front of the LIST 1. Check that weather the List is empty or not 1. If List is empty return error message ”List is Empty. Can't Delete”. 2. If List is not Empty. 1. Move all the elements except one in the 1st position to one position backward i.e New Position= Current Position -1 2. After the 1st step, element in the 1st position will be automatically deleted. 3. Decrease the Current Size by 1 i.e. Current Size=Current Size-1 Insert Element to nth Position of the LIST 1. Check that weather the List is full or not 1. If List is full return error message ”List is full. Can't Insert”. 2. If List is not full. 1. If List is Empty, Insert element at Position 1. 2. If (nth Position > Current Size) 1. Return message “nth Position Not available in List” 3. else 1. Free the nth Position of the list by moving all Elements to one position forward except n-1,n-2,... 1 Position i.e move only from n to current size position Elements. i.e New Position=Current Position + 1. 2. Insert the element to the nth Position 3. Increase the Current Size by 1 i.e. Current Size=Current Size+1 06-06-2018 CS8351 - DATA STRUCTURES 15
  • 16. Delete Element from nth Position of the LIST 1. Check that weather the List is Empty or not 1. If List is Empty return error message ”List is Empty.” 2. If List is not Empty. 1. If (nth Position > Current Size) 1. Return message “nth Position Not available in List” 2. If (nth Position == Current Size) 1. Delete the element from nth Position 2. Decrease the Current Size by 1 i.e. Current Size=Current Size-1 3. If (nth Position < Current Size) 1. Move all the Elements to one position backward except n,n-1,n-2,... 1 Position i.e move only from n+1 to current size position Elements. i.e New Position=Current Position - 1. 2. After the previous step, nth element will be deleted automatically. 3. Decrease the Current Size by 1 i.e. Current Size=Current Size-1 06-06-2018 CS8351 - DATA STRUCTURES 16
  • 17. Search Element in the LIST 1. Check that weather the list is empty or not. 1. If List is empty, return error message “List is Empty”. 2. If List is not Empty 1. Find the Position where the last element available in the List by Last Position = Current Size 2. For( Position 1 to Last Position) 1. If(Element @ Position== Search Element)//If Element matches the search element 2. return the Position by message “Search Element available in Position” 3. Else return message “Search Element not available in the List” Print the Elements in the LIST 1. Check that weather the list is empty or not. 1. If List is empty, return error message “List is Empty”. 2. If List is not Empty 1. Find the Position where the last element available in the List by Last Position = Current Size 2. For( Position 1 to Last Position) 3. Print the Position and Element available at the position of List. 06-06-2018 CS8351 - DATA STRUCTURES 17
  • 18. Array Implementation of LIST ADT LIST ADT 06-06-2018 CS8351 - DATA STRUCTURES 18
  • 19. Linked List Implementation - LIST • Like arrays, Linked List is a linear data structure. • Unlike arrays, linked list elements are not stored at contiguous location; the elements are linked using pointers. 06-06-2018 CS8351 - DATA STRUCTURES 19
  • 20. Why Linked List? Arrays can be used to store linear data of similar types, but arrays have following limitations. 1) The size of the arrays is fixed: So we must know the upper limit on the number of elements in advance. Also, generally, the allocated memory is equal to the upper limit irrespective of the usage. 2) Inserting a new element in an array of elements is expensive, because room has to be created for the new elements and to create room existing elements have to shifted. 06-06-2018 CS8351 - DATA STRUCTURES 20
  • 21. For example, in a system if we maintain a sorted list of IDs in an array id[]. id[] = [1000, 1010, 1050, 2000, 2040]. And if we want to insert a new ID 1005, then to maintain the sorted order, we have to move all the elements after 1000 (excluding 1000). Deletion is also expensive with arrays until unless some special techniques are used. For example, to delete 1010 in id[], everything after 1010 has to be moved. • Advantages over arrays 1) Dynamic size 2) Ease of insertion/deletion • Drawbacks: 1) Random access is not allowed. We have to access elements sequentially starting from the first node. So we cannot do binary search with linked lists. 2) Extra memory space for a pointer is required with each element of the list. 06-06-2018 CS8351 - DATA STRUCTURES 21
  • 22. Representation in C: A linked list is represented by a pointer to the first node of the linked list. The first node is called head. If the linked list is empty, then value of head is NULL. Each node in a list consists of at least two parts: 1) data 2) pointer to the next node In C, we can represent a node using structures. Below is an example of a linked list node with an integer data. 06-06-2018 CS8351 - DATA STRUCTURES 22
  • 23. 06-06-2018 CS8351 - DATA STRUCTURES 23 data next ListStart node null pointer
  • 24. Singly Linked List 06-06-2018 CS8351 - DATA STRUCTURES 24 CODING
  • 25. Doubly Linked List 06-06-2018 CS8351 - DATA STRUCTURES 25 CODING
  • 26. Singly Circular Linked List 06-06-2018 CS8351 - DATA STRUCTURES 26 CODING
  • 27. Doubly Circular Linked List 06-06-2018 CS8351 - DATA STRUCTURES 27 CODING
  • 28. Comparison of array-based lists and linked lists Array-based lists Linked lists Pro no wasted space for an individual element only need space for the objects actually on the list Con size must be predetermined; wasted space for lists with empty slots overhead for links (an extra pointer added to every node) Space complexity Ω(n) (or greater) Θ(n) 06-06-2018 CS8351 - DATA STRUCTURES 28
  • 29. Applications of List • Lists can be used to store a list of elements. However, unlike in traditional arrays, lists can expand and shrink, and are stored dynamically in memory. • In computing, lists are easier to implement than sets. • Lists also form the basis for other abstract data types including the queue, the stack, and their variations. 06-06-2018 CS8351 - DATA STRUCTURES 29
  • 30. Polynomial Manipulation • A polynomial is a mathematical expression consisting of a sum of terms, each term including a variable or variables raised to a power and multiplied by a coefficient. The simplest polynomials have one variable. • Representation of a Polynomial: A polynomial is an expression that contains more than two terms. A term is made up of coefficient and exponent. An example of polynomial is • P(x) = 4x3+6x2+7x+9 06-06-2018 CS8351 - DATA STRUCTURES 30
  • 31. A polynomial thus may be represented using arrays or linked lists. • Array representation assumes that the exponents of the given expression are arranged from 0 to the highest value (degree), which is represented by the subscript of the array beginning with 0. • The coefficients of the respective exponent are placed at an appropriate index in the array. • The array representation for the above polynomial expression is given below: 06-06-2018 CS8351 - DATA STRUCTURES 31
  • 32. • A polynomial may also be represented using a linked list. A structure may be defined such that it contains two parts- one is the coefficient and second is the corresponding exponent. The structure definition may be given as shown below: struct polynomial { int coefficient; int exponent; struct polynomial *next; }; • Thus the above polynomial may be represented using linked list as shown below: 06-06-2018 CS8351 - DATA STRUCTURES 32
  • 33. Here are the most common operations on a polynomial: • Add & Subtract • Multiply • Differentiate • Integrate • etc… There are different ways of implementing the polynomial ADT: • Array (not recommended) • Linked List (preferred and recommended) Array Implementation: • p1(x) = 8x3 + 3x2 + 2x + 6 • p2(x) = 23x4 + 18x - 3 • This is why arrays aren’t good to represent polynomials: • p3(x) = 16x21 - 3x5 + 2x + 6 06-06-2018 CS8351 - DATA STRUCTURES 33
  • 34. • Advantages of using an Array: • only good for non-sparse polynomials. • ease of storage and retrieval. • Disadvantages of using an Array: • have to allocate array size ahead of time. • huge array size required for sparse polynomials. Waste of space and runtime. 06-06-2018 CS8351 - DATA STRUCTURES 34
  • 35. Linked list Implementation: • p1(x) = 23x9 + 18x7 + 41x6 + 163x4 + 3 • p2(x) = 4x6 + 10x4 + 12x + 8 Representation struct polynode { int coef; int exp; struct polynode * next; }; typedef struct polynode *polyptr; 06-06-2018 CS8351 - DATA STRUCTURES 35 coef exp next
  • 36. • Advantages of using a Linked list: • save space (don’t have to worry about sparse polynomials) and easy to maintain • don’t need to allocate list size and can declare nodes (terms) only as needed • Disadvantages of using a Linked list : • can’t go backwards through the list • can’t jump to the beginning of the list from the end. 06-06-2018 CS8351 - DATA STRUCTURES 36
  • 37. Addition of two Polynomials: • For adding two polynomials using arrays is straightforward method, since both the arrays may be added up element wise beginning from 0 to n-1, resulting in addition of two polynomials. • Addition of two polynomials using linked list requires comparing the exponents, and wherever the exponents are found to be same, the coefficients are added up. • For terms with different exponents, the complete term is simply added to the result thereby making it a part of addition result. 06-06-2018 CS8351 - DATA STRUCTURES 37
  • 38. Adding polynomials using a Linked list representation: (storing the result in p3) To do this, we have to break the process down to cases: Case 1: exponent of p1 > exponent of p2 • Copy node of p1 to end of p3. • [go to next node] Case 2: exponent of p1 < exponent of p2 • Copy node of p2 to end of p3. • [go to next node] Case 3: exponent of p1 = exponent of p2 • Create a new node in p3 with the same exponent and with the sum of the coefficients of p1 and p2. CODING 06-06-2018 CS8351 - DATA STRUCTURES 38
  • 39. 06-06-2018 CS8351 - DATA STRUCTURES 39 Multiplication of two Polynomials: Multiplication of two polynomials however requires manipulation of each node such that the exponents are added up and the coefficients are multiplied. After each term of first polynomial is operated upon with each term of the second polynomial, then the result has to be added up by comparing the exponents and adding the coefficients for similar exponents and including terms as such with dissimilar exponents in the result.
  • 40. All Operations (Insertion, Deletion, Merge, Traversal) • Insertion • Deletion • Merge two sorted linked lists • Traversal • Assume, that we have a list with some nodes. Traversal is the very basic operation, which presents as a part in almost every operation on a singly-linked list. • For instance, algorithm may traverse a singly-linked list to find a value, find a position for insertion, etc. For a singly-linked list, only forward direction traversal is possible. Traversal algorithm • Beginning from the head, • check, if the end of a list hasn't been reached yet; • do some actions with the current node, which is specific for particular algorithm; • current node becomes previous and next node becomes current. Go to the step 1. 06-06-2018 CS8351 - DATA STRUCTURES 40
  • 41. Example • As for example, let us see an example of summing up values in a singly-linked list. 06-06-2018 CS8351 - DATA STRUCTURES 41