Download presentation
Presentation is loading. Please wait.
1
G64ADS Advanced Data Structures
Guoping Qiu Room C34, CS Building
2
Abstract Data Type (ADT)
In Object Oriented Programming data and the operations that manipulate that data are grouped together in classes Abstract Data Types (ADTs) or data structures or collections store data and allow various operations on the data to access and change it
3
Why Abstraction Specify the operations of the data structure and leave implementation details to later Java uses an interface to specify operations Many, many different ADTs Picking the right one for the job is an important step in design High level languages often provide built in ADTs, The C++ STL, the Java standard library
4
The List ADT List of size N: A0, A1, …, AN-1
Each element Ak has a unique position in the list Elements can be arbitrarily complex Operations insert(X, k), remove(k), find(X), findKth(k), printList()
5
Lists Using Arrays Operations insert(X,k) – O(N) remove(k) – O(N)
find(X) – O(N) findKth(k) – O(1) printList() – O(N)
6
Linked Lists Elements not stored in contiguous memory
Nodes in list consist of data element and next pointer
7
Linked Lists Operation – insertion Insert (X, A) – O(1)
8
Linked Lists Operation – deletion delete (A) – O(1)
9
Linked Lists Operations find(X) – O(N) findKth(k) – O(N)
printList() – O(N)
10
Linked Lists Doubly-linked list
11
List Implementation In Java
12
List Implementation Example: Using remove on a linkedlist
Quadratic time on all list
13
List Implementation Example: Using remove on a linkedlist
Quadratic time on arraylist, linear time on linkedlist
14
Stack Stack is a list where insert and remove take place only at the “top” Operations Push (insert) element on top of stack Pop (remove) element from top of stack Top: return element at top of stack LIFO (Last In First Out)
15
Stack Implementation Stack is a list, any list implementation will do
Linked list implementation Array implementation
16
Stack Applications Balancing Symbols
17
Stack Applications Balancing Symbols
18
Stack Applications Postfix Expressions
19
Stack Applications Infix to Postfix Conversion
20
Stack Applications Method Calls
21
Queue Queue is a list where insert takes place at back, but remove takes place at the front Operations Enqueue (insert) element at the back of the queue Dequeue (remove and return) element from the front of the queue FIFO (First In First Out)
22
Queue
23
Queue Implementation Array implementation of Queue
24
Queue Application Job Scheduling Priority queues Graph traversals
Queuing theory
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.