Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists...
-
Upload
francis-austin-shepherd -
Category
Documents
-
view
229 -
download
1
Transcript of Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists...
![Page 1: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/1.jpg)
Data Structures:Advanced
Damian Gordon
![Page 2: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/2.jpg)
Advanced Data Structure
• We’ll look at:– Linked Lists– Trees– Stacks– Queues
![Page 3: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/3.jpg)
Linked Lists
• Imagine we wanted to have an array where we can dynamically add elements into it, and take them away.
• We can do this with a linked list.
![Page 4: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/4.jpg)
Linked Lists
• A linked list is made up of nodes.
![Page 5: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/5.jpg)
Linked Lists
• A linked list is made up of nodes.
• Each node has two parts to it:
![Page 6: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/6.jpg)
Linked Lists
• A linked list is made up of nodes.
• Each node has two parts to it:
PointerValue
![Page 7: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/7.jpg)
Linked Lists
• For example
![Page 8: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/8.jpg)
Linked Lists
• For example
23
![Page 9: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/9.jpg)
Linked Lists
• For example
23 62
![Page 10: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/10.jpg)
Linked Lists
• For example
23 62 37
![Page 11: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/11.jpg)
Linked Lists
• For example
23 62 37 31
![Page 12: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/12.jpg)
Linked Lists
• For example
23 62 37 31 NULL
![Page 13: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/13.jpg)
Linked Lists
• For example
23 62 37 31 NULL
Startof List
Endof List
![Page 14: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/14.jpg)
Linked Lists
• To add a value in:
23 62 37 31 NULL
![Page 15: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/15.jpg)
Linked Lists
• To add a value in:
23 62 37 31 NULL
26
![Page 16: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/16.jpg)
Linked Lists
• To add a value in:
23 62 37 31 NULL
26
![Page 17: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/17.jpg)
Linked Lists
• To add a value in:
23 62 37 31 NULL
26
![Page 18: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/18.jpg)
Linked Lists
• To add a value in:
23 62 37 31 NULL26
![Page 19: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/19.jpg)
Linked Lists
• To delete a value:
23 62 37 31 NULL26
![Page 20: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/20.jpg)
Linked Lists
• To delete a value:
23 62 37 31 NULL26
![Page 21: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/21.jpg)
Linked Lists
• To delete a value:
23 62 37 31 NULL
![Page 22: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/22.jpg)
Trees
• We can also have a tree:
![Page 23: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/23.jpg)
Trees
• We can also have a tree:
• A tree is made up of nodes.
• Each node has three parts.
![Page 24: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/24.jpg)
Trees
• We can also have a tree:
• A tree is made up of nodes.
• Each node has three parts.
• A value and two pointers, a left and a right one.
Value
RightLeft
![Page 25: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/25.jpg)
Trees
• This is what it looks like:
23
68 14
33 831153
77 27
![Page 26: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/26.jpg)
Trees
• This is what it looks like:
23
68 14
33 831153
Root
Parent
Child
77Leaf 27
![Page 27: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/27.jpg)
Stacks
• We can also have a stack:
![Page 28: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/28.jpg)
Stacks
• We can also have a stack:
![Page 29: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/29.jpg)
Stacks
• We can also have a stack:
• It’s a structure that conforms to the principle of Last In, First Out (LIFO).
• The last item to join the stack is the first item to be served.
![Page 30: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/30.jpg)
Stacks
314159265359
![Page 31: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/31.jpg)
Stacks
314159265359 Top
Bottom
![Page 32: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/32.jpg)
Stacks
• Values are added to the top:
![Page 33: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/33.jpg)
Stacks
• Values are added to the top:
314159265359
67
![Page 34: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/34.jpg)
Stacks
• Values are added to the top:
314159265359
67
![Page 35: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/35.jpg)
Stacks
• Values are added to the top:
314159265359
67
![Page 36: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/36.jpg)
Stacks
• Values are removed from the top:
314159265359
67
![Page 37: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/37.jpg)
Stacks
• Values are removed from the top:
314159265359
67
![Page 38: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/38.jpg)
Stacks
• Values are removed from the top:
314159265359
![Page 39: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/39.jpg)
Queues
• We can also have a queue:
![Page 40: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/40.jpg)
Queues
• We can also have a queue:
![Page 41: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/41.jpg)
Queues
• We can also have a queue:
• It’s a structure that conforms to the principle of First In, First Out (FIFO).
• The first item to join the queue is the first item to be served.
![Page 42: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/42.jpg)
Queues
314159265359
![Page 43: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/43.jpg)
Queues
314159265359
Back Front
![Page 44: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/44.jpg)
Queues
• Values are added to the back:
314159265359
86
![Page 45: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/45.jpg)
Queues
• Values are added to the back:
314159265359
86
![Page 46: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/46.jpg)
Queues
• Values are added to the back:
31415926535986
![Page 47: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/47.jpg)
Queues
• Values are removed from the front:
31415926535986
![Page 48: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/48.jpg)
Queues
• Values are removed from the front:
31
415926535986
![Page 49: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/49.jpg)
Queues
• Values are removed from the front:
31
415926535986
![Page 50: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/50.jpg)
Queues
• Values are removed from the front:
415926535986
![Page 51: Data Structures: Advanced Damian Gordon. Advanced Data Structure We’ll look at: – Linked Lists – Trees – Stacks – Queues.](https://reader035.fdocuments.net/reader035/viewer/2022070404/56649f355503460f94c53868/html5/thumbnails/51.jpg)
etc.