Download presentation
Presentation is loading. Please wait.
1
Problem Understanding
Recall Pseudocode 👍 The ‘Lifecycle’ of a Solution 2 Examples Notes are available on my webpage now. Problem Understanding Design Pseudocode Coding Testing
2
Outline What is a Data Structure Very Fundamental Data Structures
Arrays What Arrays are good for What Arrays do poorly Linked Lists
3
What is a Data Structure
Arrangement or organization of data [in memory or anywhere] The arrangement is to make something possible or make it easer, faster, or more effecent.
4
Arrays Array is a sequence of n items of the same data type that are stored contiguously in computer memory and made accessible by specifying a value of the index Each and every element of an array can be accessed in the same constant amount of time regardless of where in the array the element in question is located. Length is set in ‘declaration’
5
Arrays An array can store primitive elements, such as characters
An array can also store references to objects
6
Arrays and dynamic scenarios
To add an entry e into array board at index i, we need to make room for it by shifting forward the n - i entries
7
Arrays and dynamic scenarios
To remove the entry e at index i, we need to fill the hole left by e by shifting backward the n - i - 1 elements
8
Dynamic scenarios So what is good for a changing structure ? Lists
9
Singly Linked List A singly linked list is a concrete data structure consisting of a sequence of nodes, starting from a head pointer Each node stores element link to the next node next node element head A B C D
10
A Nested Node Class
11
Accessor Methods
12
Inserting at the Head Allocate new node Insert new element
Have new node point to old head Update head to point to new node
13
Inserting at the Tail Allocate a new node Insert new element
Have new node point to null Have old last node point to new node Update tail to point to new node
14
Java Methods
15
Update head to point to next node in the list
Removing at the Head Update head to point to next node in the list Allow garbage collector to reclaim the former first node
16
Java Method
17
Removing at the tail of a singly linked list is not efficient!
There is no constant-time way to update the tail to point to the previous node
18
A doubly linked list can be traversed forward and backward
Nodes store: element link to the previous node link to the next node Special trailer and header nodes prev next element node trailer header nodes/positions elements
19
p A B C p q A B C X p q A B X C Insertion
Insert a new node, q, between p and its successor. p A B C p q A B C X p q A B X C
20
A B C D p A B C p D A B C Deletion
Remove a node, p, from a doubly linked list. A B C D p A B C p D A B C
21
Doubly-Linked List in Java
© 2014 Goodrich, Tamassia, Goldwasser
22
Doubly-Linked List in Java, 2
© 2014 Goodrich, Tamassia, Goldwasser
23
Doubly-Linked List in Java, 3
© 2014 Goodrich, Tamassia, Goldwasser
24
Doubly-Linked List in Java, 4
© 2014 Goodrich, Tamassia, Goldwasser
25
Reading [G] Section 3.1 [G] Section 3.2, 3.3, and 3.4
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.