SlideShare a Scribd company logo
1 of 17
Click to add Title
Comparison between vector
List & Sequence
e-Infochips Institute of Training Research and Academics Limited
Prepared By:
Savani Nirali
Sanghani Monika
Sequence: Collection of elements organized in a specified order. Allows random
access by rank or position.
Stack: Sequence that can be accessed in LIFO fashion.
Queue: Sequence that can be accessed in FIFO fashion.
Vector: Sequence with random access by rank. The term rank to refer to the index of
an element in a vector.
List: Sequence with random access by position. The abstract node objects positions
to refer to the elements of list ADT.
Introduction
• The rank of an element e in a sequence S is the number of elements that are
before e in S.
• A linear sequence that supports access to its elements by their ranks is called a
vector.
• The vector ADT extends the notion of array by storing a sequence of arbitrary
objects.
• An element can be accessed, inserted or removed by specifying its rank (number
of elements preceding it)
• An exception is thrown if an incorrect rank is specified (e.g., a negative rank)
Vector ADT
• Main vector ADT operations:
elemAtRank(int r): returns the element at rank r without removing it
replaceAtRank(int r, Object o): replace the element at rank r with o
insertAtRank(int r, Object o): insert a new element o to have rank r
removeAtRank(int r): removes the element at rank r
• Additional operations: size() and isEmpty().
A Simple Array-Based Implementation of Vector:
• Use an array V of size N
• A variable n keeps track of the size of the vector (number of elements stored).
• Operation elemAtRank(r) is implemented in O(1) time by returning V[r].
Insertion:
• In operation insertAtRank(r,o), we need to make room for the new element by
shifting forward the n − r elements V[r], . . ., V[n − 1].
• In the worst case (r = 0), this takes O(n) time.
Deletion:
• In operation removeAtRank(r), we need to fill the hole left by the removed
element by shifting backward the n − r − 1 elements V[r + 1], . . ., V[n − 1]
• In the worst case (r = 0), this takes O(n) time
Performance:
•In the array based implementation of a vector ADT
The space used by the data structure is O(n)
size, isEmpty, elemAtRank and replaceAtRank run in O(1) time
insertAtRank and removeAtRank run in O(n) time
•If we use the array in a circular fashion, insertAtRank(0) and removeAtRank(0) run
in O(1) time
•In an insertAtRank operation, when the array is full, instead of throwing an
exception, we can replace the array with a larger one
Node-Based Operations and Positions:
Position:
• We view a list ADT as a container of elements that stores each element at a position
and positions are arranged in a linear order
• The position ADT models the notion of place within a data structure where a single
object is store.
• A special nullposition refers to no object
• Positions provide a unified view of many ways of storing data, such as
a cell of an array
a node of a linked list
List ADT
• Member functions:
•Object& element(): returns the element stored at this position
•boolisNull(): returns true if this is a null position
• A position is always defined relatively, that is in term of its neighbors. p will
always be "after" some position q and "before" some position s (unless p is the
first or last position).
The List Abstract Data Type
• It establishes a before/after relation between positions
• Generic methods:
size(), isEmpty()
• Query methods:
isFirst(p), isLast(p)
• Accessor methods:
first(), last()
before(p), after(p)
• Update methods:
replaceElement(p, o), swapElements(p, q)
insertBefore(p, o) insertAfter(p, o)
insertFirst(o), insertLast(o)
remove(p)
Doubly Linked List Implementation:
•A doubly linked list provides a natural implementation of the list ADT
•Nodes implement positions and store:
element
link to the previous node
link to the next node
•Special trailer and header nodes
Insertion:
• We visualize operation insertAfter(p, X) which returns position q.
Deletion:
• We visualize remove(p), where p = last()
The Sequence Abstract Data Type
• The sequence ADT is the union of the vector and list ADTs
• Elements accessed by
Rank, or Position
• Generic methods:
size(), isEmpty()
• Vector-based methods:
elemAtRank(r), replaceAtRank(r, o),
insertAtRank(r, o), removeAtRank(r)
• List-based methods:
first(), last(),
before(p), after(p),
replaceElement(p, o), swapElements(p, q),
insertBefore(p, o), insertAfter(p, o),
insertFirst(o), insertLast(o),
remove(p)
Sequence ADT
Implementing a Sequence with an Array
• We use a circular array storing positions
• A position object stores:
Element
Rank
• Indices f and l keep track of first and last positions
Operation Array List
size, isEmpty 1 1
atRank, rankOf, elemAtRank 1 n
first, last, before, after 1 1
replaceElement, swapElements 1 1
replaceAtRank 1 n
insertAtRank, removeAtRank n n
insertFirst, insertLast 1 1
insertAfter, insertBefore n 1
remove n 1
Sequence Implementation:
Thank you

More Related Content

What's hot (20)

Queue
QueueQueue
Queue
 
Standard template library
Standard template libraryStandard template library
Standard template library
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Data Structures and Files
Data Structures and FilesData Structures and Files
Data Structures and Files
 
How to choose best containers in STL (C++)
How to choose best containers in STL (C++)How to choose best containers in STL (C++)
How to choose best containers in STL (C++)
 
Team 6
Team 6Team 6
Team 6
 
Standard template library
Standard template libraryStandard template library
Standard template library
 
2CPP16 - STL
2CPP16 - STL2CPP16 - STL
2CPP16 - STL
 
Talk on Standard Template Library
Talk on Standard Template LibraryTalk on Standard Template Library
Talk on Standard Template Library
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Lec3
Lec3Lec3
Lec3
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
L11 array list
L11 array listL11 array list
L11 array list
 
Detalied information of queue
Detalied information of queueDetalied information of queue
Detalied information of queue
 
Queue
QueueQueue
Queue
 
Lec2
Lec2Lec2
Lec2
 
Insertion & Selection Sort - using Priority Queues
Insertion & Selection Sort - using Priority QueuesInsertion & Selection Sort - using Priority Queues
Insertion & Selection Sort - using Priority Queues
 
Quick sorting
Quick sortingQuick sorting
Quick sorting
 
02 Stack
02 Stack02 Stack
02 Stack
 
Data Structures 01
Data Structures 01Data Structures 01
Data Structures 01
 

Viewers also liked

Hadoop at LinkedIn
Hadoop at LinkedInHadoop at LinkedIn
Hadoop at LinkedInKeith Dsouza
 
Employee_Retention_Neha
Employee_Retention_NehaEmployee_Retention_Neha
Employee_Retention_NehaNeha More
 
Vivi l'estate con energia
Vivi l'estate con energiaVivi l'estate con energia
Vivi l'estate con energiaviviconenergia
 
Heuristic approch monika sanghani
Heuristic approch  monika sanghaniHeuristic approch  monika sanghani
Heuristic approch monika sanghaniMonika Sanghani
 
How to avoid being marked as spam christoph pass next lead generation (long v...
How to avoid being marked as spam christoph pass next lead generation (long v...How to avoid being marked as spam christoph pass next lead generation (long v...
How to avoid being marked as spam christoph pass next lead generation (long v...Christoph Pass
 
IBM Connections Cloud
IBM Connections CloudIBM Connections Cloud
IBM Connections Cloud유 김
 
Memory management of datatypes
Memory management of datatypesMemory management of datatypes
Memory management of datatypesMonika Sanghani
 
Conceptos de linealización gráficas lineales
Conceptos de linealización gráficas linealesConceptos de linealización gráficas lineales
Conceptos de linealización gráficas linealesIsaias Ponce
 
Ajaran buddha dan kematian
Ajaran buddha dan kematianAjaran buddha dan kematian
Ajaran buddha dan kematianunitperpustakaan
 
methods and tools for directed creativity
methods and tools for directed creativitymethods and tools for directed creativity
methods and tools for directed creativityDharania Abirami
 
Model & method of managerial job
Model & method of managerial jobModel & method of managerial job
Model & method of managerial jobDharania Abirami
 
Enhancing Teaching and Learning Process
Enhancing Teaching and Learning Process Enhancing Teaching and Learning Process
Enhancing Teaching and Learning Process Pravin Nikumbh
 

Viewers also liked (17)

CV Nissa Mukharomah SE -
CV Nissa Mukharomah SE  - CV Nissa Mukharomah SE  -
CV Nissa Mukharomah SE -
 
Hadoop at LinkedIn
Hadoop at LinkedInHadoop at LinkedIn
Hadoop at LinkedIn
 
Agile ppt final
Agile ppt finalAgile ppt final
Agile ppt final
 
Ensa tomo2
Ensa tomo2Ensa tomo2
Ensa tomo2
 
Employee_Retention_Neha
Employee_Retention_NehaEmployee_Retention_Neha
Employee_Retention_Neha
 
Vivi l'estate con energia
Vivi l'estate con energiaVivi l'estate con energia
Vivi l'estate con energia
 
POLYCARO
POLYCAROPOLYCARO
POLYCARO
 
Heuristic approch monika sanghani
Heuristic approch  monika sanghaniHeuristic approch  monika sanghani
Heuristic approch monika sanghani
 
How to avoid being marked as spam christoph pass next lead generation (long v...
How to avoid being marked as spam christoph pass next lead generation (long v...How to avoid being marked as spam christoph pass next lead generation (long v...
How to avoid being marked as spam christoph pass next lead generation (long v...
 
Union Budget 2016-2017
Union Budget 2016-2017Union Budget 2016-2017
Union Budget 2016-2017
 
IBM Connections Cloud
IBM Connections CloudIBM Connections Cloud
IBM Connections Cloud
 
Memory management of datatypes
Memory management of datatypesMemory management of datatypes
Memory management of datatypes
 
Conceptos de linealización gráficas lineales
Conceptos de linealización gráficas linealesConceptos de linealización gráficas lineales
Conceptos de linealización gráficas lineales
 
Ajaran buddha dan kematian
Ajaran buddha dan kematianAjaran buddha dan kematian
Ajaran buddha dan kematian
 
methods and tools for directed creativity
methods and tools for directed creativitymethods and tools for directed creativity
methods and tools for directed creativity
 
Model & method of managerial job
Model & method of managerial jobModel & method of managerial job
Model & method of managerial job
 
Enhancing Teaching and Learning Process
Enhancing Teaching and Learning Process Enhancing Teaching and Learning Process
Enhancing Teaching and Learning Process
 

Similar to Vectors,squence & list

Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1blessyboban92
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++•sreejith •sree
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)eShikshak
 
Data structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxData structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxAhmedEldesoky24
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringRAJASEKHARV8
 
NEW AP Computer Science Exam GridWorld Quick Reference Booklet
NEW AP Computer Science Exam GridWorld Quick Reference BookletNEW AP Computer Science Exam GridWorld Quick Reference Booklet
NEW AP Computer Science Exam GridWorld Quick Reference BookletA Jorge Garcia
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTSwapnil Mishra
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queueRai University
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1smruti sarangi
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structuresDeepa Rani
 
Java10 Collections and Information
Java10 Collections and InformationJava10 Collections and Information
Java10 Collections and InformationSoftNutx
 

Similar to Vectors,squence & list (20)

Lec3
Lec3Lec3
Lec3
 
Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1Ist year Msc,2nd sem module1
Ist year Msc,2nd sem module1
 
Data structures
Data structuresData structures
Data structures
 
JavaScript.pptx
JavaScript.pptxJavaScript.pptx
JavaScript.pptx
 
Queue
QueueQueue
Queue
 
standard template library(STL) in C++
standard template library(STL) in C++standard template library(STL) in C++
standard template library(STL) in C++
 
Array linear data_structure_2 (1)
Array linear data_structure_2 (1)Array linear data_structure_2 (1)
Array linear data_structure_2 (1)
 
ACP-arrays.pptx
ACP-arrays.pptxACP-arrays.pptx
ACP-arrays.pptx
 
DS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptxDS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptx
 
Arrays in C.pptx
Arrays in C.pptxArrays in C.pptx
Arrays in C.pptx
 
Data structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptxData structures and Algorithm analysis_Lecture 2.pptx
Data structures and Algorithm analysis_Lecture 2.pptx
 
Complexity in array
Complexity in arrayComplexity in array
Complexity in array
 
DS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and EngineeringDS Complete notes for Computer science and Engineering
DS Complete notes for Computer science and Engineering
 
NEW AP Computer Science Exam GridWorld Quick Reference Booklet
NEW AP Computer Science Exam GridWorld Quick Reference BookletNEW AP Computer Science Exam GridWorld Quick Reference Booklet
NEW AP Computer Science Exam GridWorld Quick Reference Booklet
 
DATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGESTDATA STRUCTURES USING C -ENGGDIGEST
DATA STRUCTURES USING C -ENGGDIGEST
 
STRINGS IN JAVA
STRINGS IN JAVASTRINGS IN JAVA
STRINGS IN JAVA
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
Data structure using c module 1
Data structure using c module 1Data structure using c module 1
Data structure using c module 1
 
Review of basic data structures
Review of basic data structuresReview of basic data structures
Review of basic data structures
 
Java10 Collections and Information
Java10 Collections and InformationJava10 Collections and Information
Java10 Collections and Information
 

Recently uploaded

Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.eptoze12
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catcherssdickerson1
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...121011101441
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction managementMariconPadriquez1
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptSAURABHKUMAR892774
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...asadnawaz62
 

Recently uploaded (20)

Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.Oxy acetylene welding presentation note.
Oxy acetylene welding presentation note.
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor CatchersTechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
TechTAC® CFD Report Summary: A Comparison of Two Types of Tubing Anchor Catchers
 
Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...Instrumentation, measurement and control of bio process parameters ( Temperat...
Instrumentation, measurement and control of bio process parameters ( Temperat...
 
computer application and construction management
computer application and construction managementcomputer application and construction management
computer application and construction management
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
young call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Serviceyoung call girls in Green Park🔝 9953056974 🔝 escort Service
young call girls in Green Park🔝 9953056974 🔝 escort Service
 
Arduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.pptArduino_CSE ece ppt for working and principal of arduino.ppt
Arduino_CSE ece ppt for working and principal of arduino.ppt
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...complete construction, environmental and economics information of biomass com...
complete construction, environmental and economics information of biomass com...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 

Vectors,squence & list

  • 1. Click to add Title Comparison between vector List & Sequence e-Infochips Institute of Training Research and Academics Limited Prepared By: Savani Nirali Sanghani Monika
  • 2. Sequence: Collection of elements organized in a specified order. Allows random access by rank or position. Stack: Sequence that can be accessed in LIFO fashion. Queue: Sequence that can be accessed in FIFO fashion. Vector: Sequence with random access by rank. The term rank to refer to the index of an element in a vector. List: Sequence with random access by position. The abstract node objects positions to refer to the elements of list ADT. Introduction
  • 3. • The rank of an element e in a sequence S is the number of elements that are before e in S. • A linear sequence that supports access to its elements by their ranks is called a vector. • The vector ADT extends the notion of array by storing a sequence of arbitrary objects. • An element can be accessed, inserted or removed by specifying its rank (number of elements preceding it) • An exception is thrown if an incorrect rank is specified (e.g., a negative rank) Vector ADT
  • 4. • Main vector ADT operations: elemAtRank(int r): returns the element at rank r without removing it replaceAtRank(int r, Object o): replace the element at rank r with o insertAtRank(int r, Object o): insert a new element o to have rank r removeAtRank(int r): removes the element at rank r • Additional operations: size() and isEmpty().
  • 5. A Simple Array-Based Implementation of Vector: • Use an array V of size N • A variable n keeps track of the size of the vector (number of elements stored). • Operation elemAtRank(r) is implemented in O(1) time by returning V[r]. Insertion: • In operation insertAtRank(r,o), we need to make room for the new element by shifting forward the n − r elements V[r], . . ., V[n − 1]. • In the worst case (r = 0), this takes O(n) time.
  • 6. Deletion: • In operation removeAtRank(r), we need to fill the hole left by the removed element by shifting backward the n − r − 1 elements V[r + 1], . . ., V[n − 1] • In the worst case (r = 0), this takes O(n) time
  • 7. Performance: •In the array based implementation of a vector ADT The space used by the data structure is O(n) size, isEmpty, elemAtRank and replaceAtRank run in O(1) time insertAtRank and removeAtRank run in O(n) time •If we use the array in a circular fashion, insertAtRank(0) and removeAtRank(0) run in O(1) time •In an insertAtRank operation, when the array is full, instead of throwing an exception, we can replace the array with a larger one
  • 8. Node-Based Operations and Positions: Position: • We view a list ADT as a container of elements that stores each element at a position and positions are arranged in a linear order • The position ADT models the notion of place within a data structure where a single object is store. • A special nullposition refers to no object • Positions provide a unified view of many ways of storing data, such as a cell of an array a node of a linked list List ADT
  • 9. • Member functions: •Object& element(): returns the element stored at this position •boolisNull(): returns true if this is a null position • A position is always defined relatively, that is in term of its neighbors. p will always be "after" some position q and "before" some position s (unless p is the first or last position).
  • 10. The List Abstract Data Type • It establishes a before/after relation between positions • Generic methods: size(), isEmpty() • Query methods: isFirst(p), isLast(p) • Accessor methods: first(), last() before(p), after(p) • Update methods: replaceElement(p, o), swapElements(p, q) insertBefore(p, o) insertAfter(p, o) insertFirst(o), insertLast(o) remove(p)
  • 11. Doubly Linked List Implementation: •A doubly linked list provides a natural implementation of the list ADT •Nodes implement positions and store: element link to the previous node link to the next node •Special trailer and header nodes
  • 12. Insertion: • We visualize operation insertAfter(p, X) which returns position q.
  • 13. Deletion: • We visualize remove(p), where p = last()
  • 14. The Sequence Abstract Data Type • The sequence ADT is the union of the vector and list ADTs • Elements accessed by Rank, or Position • Generic methods: size(), isEmpty() • Vector-based methods: elemAtRank(r), replaceAtRank(r, o), insertAtRank(r, o), removeAtRank(r) • List-based methods: first(), last(), before(p), after(p), replaceElement(p, o), swapElements(p, q), insertBefore(p, o), insertAfter(p, o), insertFirst(o), insertLast(o), remove(p) Sequence ADT
  • 15. Implementing a Sequence with an Array • We use a circular array storing positions • A position object stores: Element Rank • Indices f and l keep track of first and last positions
  • 16. Operation Array List size, isEmpty 1 1 atRank, rankOf, elemAtRank 1 n first, last, before, after 1 1 replaceElement, swapElements 1 1 replaceAtRank 1 n insertAtRank, removeAtRank n n insertFirst, insertLast 1 1 insertAfter, insertBefore n 1 remove n 1 Sequence Implementation:

Editor's Notes

  1. 1