Week 4 - Wednesday.  What did we talk about last time?  Started linked lists.

Slides:



Advertisements
Similar presentations
Linked Lists Geletaw S..
Advertisements

JAVA & Linked List Implementation
Chapter 24 Lists, Stacks, and Queues
Lists and the Collection Interface Chapter 4. Chapter Objectives To become familiar with the List interface To understand how to write an array-based.
Chapter 3 – Lists A list is just what the name implies, a finite, ordered sequence of items. Order indicates each item has a position. A list of size 0.
ITEC200 Week04 Lists and the Collection Interface.
Double-Linked Lists and Circular Lists
Chapter 17 Linked List Saurav Karmakar Spring 2007.
Chapter 6 Linked Structures © 2006 Pearson Education Inc., Upper Saddle River, NJ. All rights reserved.
Variations on Linked Lists Ellen Walker CPSC 201 Data Structures Hiram College.
COMP 121 Week 11: Linked Lists. Objectives Understand how single-, double-, and circular-linked list data structures are implemented Understand the LinkedList.
CS 106 Introduction to Computer Science I 12 / 06 / 2006 Instructor: Michael Eckmann.
1 Chapter 24 Lists Stacks and Queues. 2 Objectives F To design list with interface and abstract class (§24.2). F To design and implement a dynamic list.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Fall 2007CS 2251 Lists and the Collection Interface Chapter 4.
1 Data Structures Data Structures Topic #2. 2 Today’s Agenda Data Abstraction –Given what we talked about last time, we need to step through an example.
Data Structures Topic #3. Today’s Agenda Ordered List ADTs –What are they –Discuss two different interpretations of an “ordered list” –Are manipulated.
Chapter 3: Arrays, Linked Lists, and Recursion
Chapter 101 Dynamic Data Structures and Generics Chapter 10.
Week 3 - Wednesday.  What did we talk about last time?  Started linked lists.
Doubly Linked Lists Deleting from the end of the list – Have to traverse the entire list to stop right in front of tail to delete it, so O(n) – With head.
Iterators CS 367 – Introduction to Data Structures.
Week 3 – Wednesday.  What did we talk about last time?  ADTs  List implementation with a dynamic array.
CS 1031 Linked Lists Definition of Linked Lists Examples of Linked Lists Operations on Linked Lists Linked List as a Class Linked Lists as Implementations.
CSS446 Spring 2014 Nan Wang  Java Collection Framework ◦ LinkedList ◦ Set ◦ Map 2.
Linked Lists Tonga Institute of Higher Education.
Week 3 - Friday.  What did we talk about last time?  Stacks  Array implementation of a stack.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
Week 4 - Monday.  What did we talk about last time?  Queues  Implementing queues with circular arrays.
Linked List Chapter Data Abstraction separates the logical properties of a data type from its implementation LOGICAL PROPERTIES – What are the.
Week 7 - Friday.  What did we talk about last time?  Trees in general  Binary search trees.
Winter 2006CISC121 - Prof. McLeod1 Stuff Deadline for assn 3 extended to Monday, the 13 th. Please note that the testing class for assn 3 has changed.
COMP 121 Week 11: Linked Lists.
Chapter 15 Linked Data Structures Slides prepared by Rose Williams, Binghamton University Kenrick Mock University of Alaska Anchorage Copyright © 2008.
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Week 5 - Wednesday.  What did we talk about last time?  Recursion  Definitions: base case, recursive case  Recursive methods in Java.
Week 2 - Friday.  What did we talk about last time?  Computing Big Oh.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
CS 201 Data Structures and Algorithms Chapter 3: Lists, Stacks, and Queues - I Text: Read Weiss, §3.1 – 3.5 1Izmir University of Economics.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Linked Lists. Introduction In linked list each item is embedded in a link Each item has two parts – Data – Pointer to the next item in the list Insert,
Week 7 - Wednesday.  What did we talk about last time?  Recursive running time  Master Theorem  Symbol tables.
2/21/20161 List Operations Advanced Programming Ananda Gunawardena.
Week 4 - Friday.  What did we talk about last time?  Continued doubly linked list implementation  Linked lists with iterators.
CS 46B: Introduction to Data Structures July 23 Class Meeting Department of Computer Science San Jose State University Summer 2015 Instructor: Ron Mak.
Queues CS 367 – Introduction to Data Structures. Queue A queue is a data structure that stores data in such a way that the last piece of data stored,
CS32 Discussion Section 1B Week 3 TA: Hao Yu (Cody)
Lists List Implementations. 2 Linked List Review Recall from CMSC 201 –“A linked list is a linear collection of self- referential structures, called nodes,
Linked Lists Data Structures and Algorithms CS 244 Brent M. Dingle, Ph.D. Department of Mathematics, Statistics, and Computer Science University of Wisconsin.
 2015, Marcus Biel, Linked List Data Structure Marcus Biel, Software Craftsman
LINKED LISTS.
Week 15 – Monday.  What did we talk about last time?  Tries.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
Linked List ADT used to store information in a list
Week 4 - Monday CS221.
Week 4 - Friday CS221.
CSCI-255 LinkedList.
UNIT – I Linked Lists.
CMSC202 Computer Science II for Majors Lecture 12 – Linked Lists
CE 221 Data Structures and Algorithms
CS 1114: Implementing Search
COP3530- Data Structures Advanced Lists
Week 3 - Friday CS221.
Week 15 – Monday CS221.
Sequences 9/18/ :20 PM C201: Linked List.
Prof. Neary Adapted from slides by Dr. Katherine Gibson
Arrays and Linked Lists
Linked Lists.
Programming Abstractions
CMPT 225 Lecture 5 – linked list.
Presentation transcript:

Week 4 - Wednesday

 What did we talk about last time?  Started linked lists

Bitmap Manipulator

 You are given a singly linked list  It may have a loop in it, that is, a node that points back to an earlier node in the list  If you try to visit every node in the list, you’ll be in an infinite loop  How can you see if there is a loop in a linked list?

 Node consists of data, a next pointer, and a previous pointer  Advantages: bi-directional movement  Disadvantages: slower, 4 pointers must change for every insert/delete X head X tail

 Let’s try a simple definition for a linked list: public class LinkedList { private static class Node { public int data; public Node next; public Node previous; } private Node head = null; private Node tail = null; public int size = 0; … }

Assuming that the list has been kept in order

 The generic part is really easy once you get the syntax set up  You use T instead of int (or whatever type you designed your linked lists to hold)  The trickier thing is to define an iterator class that can keep track of where you are inside the list  It has to be a non-static inner class!

public class LinkedList implements Iterable { private class Node { public T data; public Node next; public Node previous; } private class ListIterator implements Iterator { public Node current; } private Node head = null; private Node tail = null; public int size = 0; … }

Create a new iterator that points at the head of the list

Whether or not there is something in the current spot in the list

Get the current thing in the list

Remove the current item from the list (optional)

 Linked lists can be made circular such that the last node points back at the head node  This organization is good for situations in which we want to cycle through all of the nodes in the list repeatedly tail

 Insert at front (or back)  Θ(1)  Delete at front  Θ(1)  Delete at back costs Θ(n) unless we used doubly linked lists  Search Θ(n)Θ(n)

 We can design linked lists with multiple pointers in some nodes  We want ½ of the nodes to have 1 pointer, ¼ of the nodes to have 2 pointers, 1/8 of the nodes to have 3 pointers… head X X X

 If ordered, search is  Θ(log n)  Go to index is  Θ(log n)  Insert at end  Θ(log n)  Delete  Totally insane, at least Θ(n)  Trees end up being a better alternative

 We want to make items that are used frequently easy to get at  Several different approaches, mostly based on finding items repeatedly  Move to front: After finding an item, put it in the front  Transpose: After finding an item, move it up by one  Count: Keep the list ordered by how often you get a particular item (requires a counter in each node)  Ordering: Sort the list according to some feature of the data

 Special kinds of linked lists  Circular lists  Skip lists  Self-organizing lists  Stack implementation with linked lists  Queue implementation with linked lists

 Keep reading Chapter 3  Keep working on Project 1  Due this Friday, September 18 by 11:59pm  My office hours this Friday from 3:30-5pm are canceled due to travel  CS Club tonight at 6pm  Anyone want to work for ITS?  For women in CS:  Speaking-Lancaster/