SlideShare a Scribd company logo
1 of 13
Chapter:4
Sequence Types

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
Dequeue: sequence accessed by added to or
removing
from either end
Vector: sequence with random access by rank
List: sequence with random access by position
Places in a Sequence

Rank
• Place specified by number of places before the
place in question
• Abstraction of the concept of array index

Position

• Place specified by which place precedes and
which place follows the place in question
• Abstraction of the concept of (doubly) linked
list node
Vector ADT

elemAtRank(r) : return element at specified rank
replaceAtRank(r,e) : replace element at specified
rank with new element

• provided for efficiency
insertAtRank(r,e) : insert new element at specified
rank
• existing places at that rank or higher are
incremented
removeAtRank(r) : remove element at specified
rank
• places following that rank are decremented
Array-based Vector Implementation
insertAtRank(r, e) {
if (size == A.length)
for (int i=size-1; i>=r; i--)
A[i+1]= A[i];
A[r]= e;
size++;
}
removeAtRank(r) {
Object e = A[r];
for (int i=r; i<size-1; i++)
A[i] = A[i+1];
size--;
}
Analysis

elemAtRank: O(1)

replaceAtRank: O(1)

insertAtRank: O(n)

removeAtRank: O(n)
List ADT

size( ), isEmpty( ), isFirst(p), isLast(p)

first/last( ): Return first/last position

before/after(p) : Return preceding/following position

replaceElement(p,e) : Set the element for a position

swapElements(p,q) : Exchange elements for two
Positions

insertBefore/After(p,e) : Create new position
before/after p containing element e
remove(p) : Remove the position p and the
element it
contains
insertFirst, insertLast(e) : Create new position at
start/end of list and set its element
What’s a position, again?

interface Position {
public Object element();
}
May be implemented as singly- or doubly-linked
list
node, array element, etc.
List containing the position must have some way
of
locating the position before and after a given
position
Analysis




All methods of List using doubly linked list
are O(1)
Sequence ADT

Supports ADT of vector and list
Plus:


• atRank(r) : Converts a rank to a position

• rankOf(p) : Converts a position to a rank
Sequence Interface
interface Sequence extends List, Vector
 {
public Position atRank(int rank);
//Returns the Position Containing the Element at
the Give Rank.

public int rankOf(Position position);
//Returns the Rank of Element Stored at the given
Position.
}
Comparison

Operation Array List
size, isEmpty O(1) O(1)
first, last, before, after O(1) O(1)
insertFirst, insertLast O(1) O(1)
replaceElement,swapElementO(1) O(1)
insertAfter, insertBefore O(n) O(1)
remove O(n) O(1)
atRank, rankOf, elemAtRankO(1) O(n)
replaceAtRank O(1) O(n)
insertAtRank, remvAtRank O(n) O(n)

More Related Content

What's hot (20)

stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
List interface
List interfaceList interface
List interface
 
Collections
CollectionsCollections
Collections
 
Priority Queue
Priority QueuePriority Queue
Priority Queue
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
Queues-handouts
Queues-handoutsQueues-handouts
Queues-handouts
 
Data Structure -List Stack Queue
Data Structure -List Stack QueueData Structure -List Stack Queue
Data Structure -List Stack Queue
 
stacks and queues
stacks and queuesstacks and queues
stacks and queues
 
Lambdas HOL
Lambdas HOLLambdas HOL
Lambdas HOL
 
Queue
QueueQueue
Queue
 
Collections
CollectionsCollections
Collections
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Queue-Data Structure
Queue-Data StructureQueue-Data Structure
Queue-Data Structure
 
Algorithms: I
Algorithms: IAlgorithms: I
Algorithms: I
 
Data structures and algorithms
Data structures and algorithmsData structures and algorithms
Data structures and algorithms
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
Data structures2
Data structures2Data structures2
Data structures2
 
358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9
 

Viewers also liked

Migrant mother prewriting activity
Migrant mother prewriting activityMigrant mother prewriting activity
Migrant mother prewriting activitynitmat81
 
Meet and Greet w/ New VP of Programs Sandra Nathan.
Meet and Greet w/ New VP of Programs Sandra Nathan.Meet and Greet w/ New VP of Programs Sandra Nathan.
Meet and Greet w/ New VP of Programs Sandra Nathan.MarinGrassroots
 
Gmba english presentation
Gmba english presentationGmba english presentation
Gmba english presentationJeremy Schaar
 
Heterotrophic nutrition
Heterotrophic nutritionHeterotrophic nutrition
Heterotrophic nutritionmkavita72
 
Fynepix ltd profile
Fynepix ltd profileFynepix ltd profile
Fynepix ltd profilePaul Ngonga
 
Wildlife photographer of_the_year_2013-
Wildlife photographer of_the_year_2013-Wildlife photographer of_the_year_2013-
Wildlife photographer of_the_year_2013-Nam Nguyen
 
Art-secret garden vườn địa đàng
Art-secret garden vườn địa đàngArt-secret garden vườn địa đàng
Art-secret garden vườn địa đàngNam Nguyen
 
The JSON Architecture - BucharestJS / July
The JSON Architecture - BucharestJS / JulyThe JSON Architecture - BucharestJS / July
The JSON Architecture - BucharestJS / JulyConstantin Dumitrescu
 

Viewers also liked (11)

Migrant mother prewriting activity
Migrant mother prewriting activityMigrant mother prewriting activity
Migrant mother prewriting activity
 
Meet and Greet w/ New VP of Programs Sandra Nathan.
Meet and Greet w/ New VP of Programs Sandra Nathan.Meet and Greet w/ New VP of Programs Sandra Nathan.
Meet and Greet w/ New VP of Programs Sandra Nathan.
 
A product
A productA product
A product
 
Gmba english presentation
Gmba english presentationGmba english presentation
Gmba english presentation
 
Heterotrophic nutrition
Heterotrophic nutritionHeterotrophic nutrition
Heterotrophic nutrition
 
Ford motor company
Ford motor companyFord motor company
Ford motor company
 
Fynepix ltd profile
Fynepix ltd profileFynepix ltd profile
Fynepix ltd profile
 
Wildlife photographer of_the_year_2013-
Wildlife photographer of_the_year_2013-Wildlife photographer of_the_year_2013-
Wildlife photographer of_the_year_2013-
 
Art-secret garden vườn địa đàng
Art-secret garden vườn địa đàngArt-secret garden vườn địa đàng
Art-secret garden vườn địa đàng
 
Ajustagem
AjustagemAjustagem
Ajustagem
 
The JSON Architecture - BucharestJS / July
The JSON Architecture - BucharestJS / JulyThe JSON Architecture - BucharestJS / July
The JSON Architecture - BucharestJS / July
 

Similar to Vector list nd sequence

Similar to Vector list nd sequence (20)

Lec3
Lec3Lec3
Lec3
 
Lec3
Lec3Lec3
Lec3
 
Lecture2
Lecture2Lecture2
Lecture2
 
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
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
Linked list
Linked listLinked list
Linked list
 
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docxJAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
JAVA Demonstrate the use of your APL in a PartB_Driver class by doing.docx
 
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
 
Bsc cs ii dfs u-2 linklist,stack,queue
Bsc cs ii  dfs u-2 linklist,stack,queueBsc cs ii  dfs u-2 linklist,stack,queue
Bsc cs ii dfs u-2 linklist,stack,queue
 
07 java collection
07 java collection07 java collection
07 java collection
 
Queues
QueuesQueues
Queues
 
ACP-arrays.pptx
ACP-arrays.pptxACP-arrays.pptx
ACP-arrays.pptx
 
Mca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queueMca ii dfs u-3 linklist,stack,queue
Mca ii dfs u-3 linklist,stack,queue
 
9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
 
Collection and framework
Collection and frameworkCollection and framework
Collection and framework
 

Recently uploaded

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Recently uploaded (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Vector list nd sequence

  • 2. Sequence Types 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 Dequeue: sequence accessed by added to or removing from either end Vector: sequence with random access by rank List: sequence with random access by position
  • 3. Places in a Sequence Rank • Place specified by number of places before the place in question • Abstraction of the concept of array index Position • Place specified by which place precedes and which place follows the place in question • Abstraction of the concept of (doubly) linked list node
  • 4. Vector ADT elemAtRank(r) : return element at specified rank replaceAtRank(r,e) : replace element at specified rank with new element • provided for efficiency insertAtRank(r,e) : insert new element at specified rank • existing places at that rank or higher are incremented removeAtRank(r) : remove element at specified rank • places following that rank are decremented
  • 5. Array-based Vector Implementation insertAtRank(r, e) { if (size == A.length) for (int i=size-1; i>=r; i--) A[i+1]= A[i]; A[r]= e; size++; } removeAtRank(r) { Object e = A[r]; for (int i=r; i<size-1; i++) A[i] = A[i+1]; size--; }
  • 7. List ADT size( ), isEmpty( ), isFirst(p), isLast(p) first/last( ): Return first/last position before/after(p) : Return preceding/following position replaceElement(p,e) : Set the element for a position swapElements(p,q) : Exchange elements for two Positions insertBefore/After(p,e) : Create new position before/after p containing element e
  • 8. remove(p) : Remove the position p and the element it contains insertFirst, insertLast(e) : Create new position at start/end of list and set its element
  • 9. What’s a position, again? interface Position { public Object element(); } May be implemented as singly- or doubly-linked list node, array element, etc. List containing the position must have some way of locating the position before and after a given position
  • 10. Analysis All methods of List using doubly linked list are O(1)
  • 11. Sequence ADT Supports ADT of vector and list Plus: • atRank(r) : Converts a rank to a position • rankOf(p) : Converts a position to a rank
  • 12. Sequence Interface interface Sequence extends List, Vector { public Position atRank(int rank); //Returns the Position Containing the Element at the Give Rank. public int rankOf(Position position); //Returns the Rank of Element Stored at the given Position. }
  • 13. Comparison Operation Array List size, isEmpty O(1) O(1) first, last, before, after O(1) O(1) insertFirst, insertLast O(1) O(1) replaceElement,swapElementO(1) O(1) insertAfter, insertBefore O(n) O(1) remove O(n) O(1) atRank, rankOf, elemAtRankO(1) O(n) replaceAtRank O(1) O(n) insertAtRank, remvAtRank O(n) O(n)