Sequences 11/27/2018 1:37 AM Singly Linked Lists Singly Linked Lists.

Slides:



Advertisements
Similar presentations
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
Advertisements

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.
© 2004 Goodrich, Tamassia Linked Lists1. © 2004 Goodrich, Tamassia Linked Lists2 Singly Linked List (§ 4.4.1) A singly linked list is a concrete data.
Lists 1. Introduction Data: A finite sequence of data items. Operations: Construction: Create an empty list Empty: Check if list is empty Insert: Add.
The List ADT A sequence of zero or more elements A 1, A 2, A 3, … A N-1 N: length of the list A 1 : first element A N-1 : last element A i : position i.
© 2014 Goodrich, Tamassia, Goldwasser Singly Linked Lists1 Presentation for use with the textbook Data Structures and Algorithms in Java, 6 th edition,
APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.
Subject Name : Data Structure Using C Title : Linked Lists
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Linked list: a list of items (nodes), in which the order of the nodes is determined by the address, called the link, stored in each node C++ Programming:
Unit 1 - Introducing Abstract Data Type (ADT) Part 3 – Slides 1 to 11.
1 Data Organization Example 1: Heap storage management Maintain a sequence of free chunks of memory Find an appropriate chunk when allocation is requested.
UNIT-V ABSTRACT DATA TYPE 1.LIST 2.STACK 3.QUEUE EC6301-II-ECE-C.
Linked Lists Source: presentation based on notes written by R.Kay, A. Hill and C.Noble ● Lists in general ● Lists indexed using pointer arrays ● Singly.
Linked List, Stacks Queues
Lecture 6 of Computer Science II
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.
Chapter 12 – Data Structures
Linked List :: Basic Concepts
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.
UNIT – I Linked Lists.
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,
Data structures and algorithms
Review Deleting an Element from a Linked List Deletion involves:
Data Structure Dr. Mohamed Khafagy.
Linked Lists Linked Lists 1 Sequences Sequences 07/25/16 10:31
UNIT-3 LINKED LIST.
Data Structures and Algorithms
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 List Sudeshna Sarkar.
Programmazione I a.a. 2017/2018.
LINKED LISTS CSCD Linked Lists.
Lists.
Object Oriented Programming COP3330 / CGS5409
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
Data Structures ADT List
" A list is only as strong as its weakest link. " - Donald Knuth
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.
Hassan Khosravi / Geoffrey Tien
Lists CSE 373 Data Structures.
Review & Lab assignments
Data Structures and Algorithms
Problem Understanding
Recall What is a Data Structure Very Fundamental Data Structures
Chapter 17: Linked Lists.
LINKED LISTS.
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Data Structures ADT List
Lecture 16 Section 6.2 Thu, Mar 1, 2007
Linked Lists & Iterators
Lists CSE 373 Data Structures.
CS210- Lecture 6 Jun 13, 2005 Announcements
General List.
Linked Lists.
BY PROF. IRSHAD AHMAD LONE.
Chapter 9 Linked Lists.
CMPT 225 Lecture 5 – linked list.
Stacks and Linked Lists
Problem Understanding
Presentation transcript:

Sequences 11/27/2018 1:37 AM Singly Linked Lists Singly Linked 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 Singly Linked Lists

Review: struct in C Is myNode a. the created node, or struct Node { char element[4]; struct Node *next; }; typedef struct Node NODE; … NODE *myNode = (NODE *) malloc( sizeof(NODE) ); Is myNode a. the created node, or b. a pointer to the created node? Singly Linked Lists

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

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 Singly Linked Lists

Removing at the Head Update head to point to next node in the list Free the remove node Singly Linked Lists

Removing at the Tail 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 Singly Linked Lists

List ADT (Abstract Data Type) Operations: Insert an item Delete an item Replace the i-th item Singly Linked Lists

List ADT (Abstract Data Type) Operations: Insert an item Delete an item Replace the i-th item Representations: Sequential (arrays) Linked (linked lists) Singly Linked Lists

List ADT (size N, # of steps in the worst case) Sequential Representation (arrays) Linked Representation (linked lists) Insert an item Delete an item Replace the i-th item Singly Linked Lists

List ADT of size N # of steps in the worst case Sequential Representation (arrays) Linked Representation (linked lists) Insert an item Shift N items O(N) Traverse N items Delete an item Shift N-1 items Replace the i-th item Direct access to a[i] O(1) Singly Linked Lists

Space comparison List of size N Assume maximum Capacity MaxSize in array Assume data/element uses 4 bytes Next pointer uses 4 bytes Array Linked list Space Singly Linked Lists

Space comparison List of size N Assume maximum Capacity MaxSize in array Assume data/element uses 4 bytes Next pointer uses 4 bytes Array Linked list Space 4 * MaxSize 8 * N Singly Linked Lists

Circularly Linked Lists Singly Linked Lists

tail (but no head) Singly Linked Lists

Rotation What are the instructions? Singly Linked Lists

Insertion at (head) What are the instructions? (head) Singly Linked Lists