Problem Understanding

Slides:



Advertisements
Similar presentations
Singly linked lists Doubly linked lists
Advertisements

Chapter 17 Linked List Saurav Karmakar Spring 2007.
M180: Data Structures & Algorithms in Java
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
Data Structures: A Pseudocode Approach with C
Linked Lists1 Part-B3 Linked Lists. Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data structure consisting of a sequence.
Main Index Contents 11 Main Index Contents Abstract Model of a List Obj. Abstract Model of a List Obj. Insertion into a List Insertion into a List Linked.
Doubly Linked Lists1 © 2014 Goodrich, Tamassia, Goldwasser Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition,
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
Chapter 3: Arrays, Linked Lists, and Recursion
Arrays & Linked Lists Last Update: Aug 21, 2014EECS2011: Arrays & Linked Lists1.
CS212D : DATA STRUCTURES 1 Week 5-6 Linked List. Outline 2  Singly Linked Lists  Doubly Linked Lists  Recursions.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
Lecture5: Linked Lists Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
© 2014 Goodrich, Tamassia, Goldwasser Singly Linked Lists1 Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition,
1 Linked Lists (Lec 6). 2  Introduction  Singly Linked Lists  Circularly Linked Lists  Doubly Linked Lists  Multiply Linked Lists  Applications.
Arrays, Link Lists, and Recursion Chapter 3. Sorting Arrays: Insertion Sort Insertion Sort: Insertion sort is an elementary sorting algorithm that sorts.
1 Data Organization Example 1: Heap storage management Maintain a sequence of free chunks of memory Find an appropriate chunk when allocation is requested.
Chapter 3 Lists, Stacks, Queues. Abstract Data Types A set of items – Just items, not data types, nothing related to programming code A set of operations.
Linked List, Stacks Queues
Chapter 3: Fundamental Data Structures: The Array and Linked Structures Data Structures in Java: From Abstract Data Types to the Java Collections Framework.
Lecture 6 of Computer Science II
Unit – I Lists.
Lists and Iterators 5/3/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Data Structure By Amee Trivedi.
Vectors 5/31/2018 9:25 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and.
Ch7. List and Iterator ADTs
Sequences 6/3/2018 9:11 AM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Doubly Linked Lists 6/3/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Big-O notation Linked lists
Review Deleting an Element from a Linked List Deletion involves:
John Hurley Cal State LA
Data Structure Dr. Mohamed Khafagy.
Linked Lists Linked Lists 1 Sequences Sequences 07/25/16 10:31
Sequences 8/1/2018 4:38 AM Linked Lists Linked Lists.
Sequences 8/2/ :13 AM Linked Lists Linked Lists.
Sequences 8/2/ :16 AM Linked Lists Linked Lists.
EEL 4854 IT Data Structures Linked Lists
Lists.
LINKED LISTS CSCD Linked Lists.
Lists.
Object Oriented Programming COP3330 / CGS5409
Ch7. List and Iterator ADTs
Lists and Iterators 3/9/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Arrays and Linked Lists
Sequences 11/27/2018 1:37 AM Singly Linked Lists Singly Linked Lists.
" A list is only as strong as its weakest link. " - Donald Knuth
Linked Lists.
Sequences 12/8/2018 3:02 AM Linked Lists Linked Lists.
Doubly Linked Lists or Two-way Linked Lists
11-3 LINKED LISTS A linked list is a collection of data in which each element contains the location of the next element—that is, each element contains.
CS212D: Data Structures Week 5-6 Linked List.
CS2013 Lecture 4 John Hurley Cal State LA.
Lists CSE 373 Data Structures.
Doubly Linked Lists Lecture 21 Tue, Mar 21, 2006.
Chapter 24 Implementing Lists, Stacks, Queues, and Priority Queues
Linked Lists Chapter 4.
Problem Understanding
Recall What is a Data Structure Very Fundamental Data Structures
Chapter 17: Linked Lists.
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Linked Lists & Iterators
Data Structures & Algorithms
Lists CSE 373 Data Structures.
CS210- Lecture 6 Jun 13, 2005 Announcements
Linked List Intro CSCE 121.
Arrays © 2014 Goodrich, Tamassia, Goldwasser Arrays Vectors
BY PROF. IRSHAD AHMAD LONE.
Chapter 9 Linked Lists.
LINEAR DATA STRUCTURES
Presentation transcript:

Problem Understanding Recall Pseudocode 👍 The ‘Lifecycle’ of a Solution 2 Examples Solution is available on my webpage now. Problem Understanding Design Pseudocode Coding Testing

Outline What is a Data Structure Very Fundamental Data Structures Arrays What Arrays are good for What Arrays do poorly Linked Lists Singly linked list Doubly linked list Equivalence Testing Cloning a data structure

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 efficient. www.youtube.com/watch?v=EYq-VtyAd2s Quipu

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’

Arrays An array can store primitive elements, such as characters An array can also store references to objects

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

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

So what is good for a changing structure ? Dynamic scenarios So what is good for a changing structure ? Lists

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

A Nested Node Class

Methods

Inserting at the Head Allocate new node Insert new element Have new node point to old head Update head to point to new node

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

Java Methods

Removing at the Head Update head to point to next node in the list Allow garbage collector to reclaim the former first node

Java Method

Removing at the tail of a singly linked list is not efficient! There is no quick way to update the tail to point to the previous node

Finding the second to last node Very Important technique public Node<E> penultimate( ) { Node<E> walk = head; while (walk.next != tail) walk = walk.next; return walk; }

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

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

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

Doubly-Linked List in Java

Doubly-Linked List in Java, 2

Doubly-Linked List in Java, 3

Doubly-Linked List in Java, 4

قَالَ رسول الله صلى الله عليه وسلم لشداد بن أوس: Break قَالَ رسول الله صلى الله عليه وسلم لشداد بن أوس: يَا شَدَّادُ ، إِذَا رَأَيْتَ النَّاسَ يَكْنِزُونَ الذَّهَبَ وَالْفِضَّةَ ، فَاكْنِزْ هَؤُلَاءِ الْكَلِمَاتِ:  اللَّهُمَّ إِنِّي أَسْأَلُكَ الثَّبَاتَ فِي الأَمْرِ، وَالعَزِيمَةَ على الرُّشْدِ، وَأَسْأَلُكَ مُوجِبَاتِ رَحمَتِك وَعَزَائِمَ مَغْفِرَتِك، وَأَسْأَلُكَ شُكْرَ نِعْمَتِكَ وَحُسْنَ عِبَادَتِكَ ، وَأَسْأَلُكَ قَلْبًا سَلِيمًا وَلِسَانًا صَادِقًا، وَأَسْأَلُكَ مِنْ خَيْرِ مَا تَعْلَمُ ، وَأَعُوذُ بِكَ مِنْ شَرِّ مَا تَعْلَمُ ، وَأَسْتَغْفِرُكَ لِمَا تَعْلَمُ إِنَّكَ أَنْتَ عَلَّامُ الْغُيُوبِ 

Equivalence Testing Object. equals With Arrays a == b a.equals(b) Arrays.equals(a,b) With Nested Arrays Arrays.deepEquals(a,b) See Book for LL details.

Singly Linked List equals method

Cloning Data Structures backup = data; shallow copy: backup = data.clone( ); But for references:

deep copy of a two-dimensional array

deep copy of a singly linked list

Cloning Data Structures shallow copy <deep> copy ?! How deep do you want to go ?

Reading [G] all Chapter 3