L14-LinkedList

L14-LinkedList - CSE205 Concepts of Computer Science and...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
CSE205 Concepts of Computer Science and Data Structures
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Slides Modified for CSE205 Lists – An Abstract Data Type An abstract data type (ADT) is an organized collection of information and a set of operations used to manage that information The set of operations defines the interface to the ADT Collection classes use two major storage to hold the elements: 1. Array that store references in a contiguous memory (static data structure) 2. A linked structure where one element refer to another element, anywhere in memory (dynamic data structure) non static
Background image of page 2
Slides Modified for CSE205 Static vs. Dynamic Structures A static data structure has a fixed size example: arrays (Note: this meaning is different from those associated with static modifier) A dynamic data structure grows and shrinks as required by the information it contains example: linked lists
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Slides Modified for CSE205 Linked list An object reference is a variable that stores the address of an object. A reference is also called a pointer . Object references can be used to create links between objects
Background image of page 4
Slides Modified for CSE205 Linked List Continue: 1. The Node instance variable named data is of type Object. Will allow one linked structure to store an object 2. The variable named next is of type Node. Allows one Node object to refer to another instance of the same class
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Linked Lists Consider an object that contains a reference to another object of the same type: private class Node { public Object data; public Node next; }
Background image of page 6
Slides Modified for CSE205 Graphical representations of Linked list This structure requires at least one external reference to get the first element; usually called head or first The second node is reached by following the link from the first node.
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Slides Modified for CSE205 Deleting a Node An example of deleting a node from the linked list
Background image of page 8
Slides Modified for CSE205 Inserting a Node Example of inserting a node in the list
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Slides Modified for CSE205 Efficiency of operations of LinkedList Linked List class is in java.util package. It is important to know how to implement a linked list as a programmer. ---------------------------------------------------------------------------- Operation ArrayList LinkedList ---------------------------------------------------------------------------- Access O(1) O(n) Add/Remove O(n) O(1)
Background image of page 10
Slides Modified for CSE205 Continue: In ArrayList, we can access any element by specifying its index in constant time. – O(1) In LinkedList, we need to go through n/2 elements on average to get to an element. – O(n) In ArrayList, adding or removing an element can take O(n) (O(n/2) on average) because of shifting all elements. In LinkedList, adding or removing an element can be done in constant time, assuming that
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 28

L14-LinkedList - CSE205 Concepts of Computer Science and...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online