Hassan Khosravi / Geoffrey Tien

Slides:



Advertisements
Similar presentations
Linked Lists CSE 2451 Matt Boggus. Dynamic memory reminder Allocate memory during run-time malloc() and calloc() – return a void pointer to memory or.
Advertisements

Singly Linked List BTECH, EE KAZIRANGA UNIVERSITY.
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
Dynamic Memory Allocation (also see pointers lectures) -L. Grewe.
CP104 Introduction to Programming Structure II Lecture 32 __ 1 Data Type planet_t and Basic Operations Abstract Data Type (ADT) is a data type combined.
CS Data Structures Chapter 4 Lists.
Lists 1. Introduction Data: A finite sequence of data items. Operations: Construction: Create an empty list Empty: Check if list is empty Insert: Add.
Pointers OVERVIEW.
(1 - 1) Introduction to C Data Structures & Abstract Data Types Instructor - Andrew S. O’Fallon CptS 122 (August 26, 2015) Washington State University.
Department of Computer Science Data Structures Using C++ 2E Chapter 5 Linked Lists.
1 Chapter 16 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion and.
Lists Chapter 8. 2 Linked Lists As an ADT, a list is –finite sequence (possibly empty) of elements Operations commonly include: ConstructionAllocate &
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
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:
 Memory from the heap  Dynamic memory allocation using the new operator  Build a dynamic linked list  Another way of traversing a linked list 
Data Structure & Algorithms
1 Linked List. 2 List A list refers to a sequence of data items  Example: An array The array index is used for accessing and manipulation of array elements.
Data Structure and Algorithm: CIT231 Lecture 6: Linked Lists DeSiaMorewww.desiamore.com/ifm1.
LINKED LISTS.
© Oxford University Press All rights reserved. Data Structures Using C, 2e Reema Thareja.
Insertion sort Loop invariants Dynamic memory
COSC160: Data Structures Linked Lists
ADT description Implementations
Chapter 12 – Data Structures
Cinda Heeren / Geoffrey Tien
Lectures linked lists Chapter 6 of textbook
Program based on queue & their operations for an application
Linked Lists Chapter 6 Section 6.4 – 6.6
Review Deleting an Element from a Linked List Deletion involves:
12 C Data Structures.
Hassan Khosravi / Geoffrey Tien
Dynamic Memory Allocation Strings
Data Structure and Algorithms
Prepared by, Jesmin Akhter, Lecturer, IIT, JU
Data Structure Dr. Mohamed Khafagy.
UNIT-3 LINKED LIST.
Hassan Khosravi / Geoffrey Tien
Linked List Variations
Hassan Khosravi / Geoffrey Tien
Linked Lists head One downside of arrays is that they have a fixed size. To solve this problem of fixed size, we’ll relax the constraint that the.
Lists.
Programmazione I a.a. 2017/2018.
Stack Lesson xx   This module shows you the basic elements of a type of linked list called a stack.
Lists.
Chapter 16-2 Linked Structures
Quicksort analysis Bubble sort
Sequences 11/27/2018 1:37 AM Singly Linked Lists Singly Linked Lists.
Linked Lists (continued)
Hassan Khosravi / Geoffrey Tien
Double hashing Removal (open addressing) Chaining
Programming Linked Lists.
Dynamic Memory Allocation
Hassan Khosravi / Geoffrey Tien
EENG 212 ALGORITHMS And DATA STRUCTURES
Review & Lab assignments
Dynamic Memory A whole heap of fun….
Linked List.
Chapter 17: Linked Lists.
Chapter 16 Linked Structures
Linked Lists Adapted from Dr. Mary Eberlein, UT Austin.
Dynamic Memory A whole heap of fun….
Chapter 9: Pointers and String
Linked Lists.
(1 - 2) Introduction to C Data Structures & Abstract Data Types
Tree traversals BST properties Search Insertion
Chapter 15 Debugging.
EECE.3220 Data Structures Instructor: Dr. Michael Geiger Spring 2019
Variable Storage Memory Locations (Logical) Variable Classes Stack
Dynamic Data Structures
Presentation transcript:

Hassan Khosravi / Geoffrey Tien Linked Lists October 06, 2017 Hassan Khosravi / Geoffrey Tien

Hassan Khosravi / Geoffrey Tien Unordered arrays Arrays are easy to code and to visualise, and offer rapid access to elements using the [] operator e.g. printf("salary is $%.2f\n", staff[85].salary); Consider an array with a capacity of 𝑛 Note that capacity may be different from the number of items stored in the array October 06, 2017 Hassan Khosravi / Geoffrey Tien

Hassan Khosravi / Geoffrey Tien Unordered arrays What is the time complexity of inserting an item into an array without holes, when order does not matter? 18 9 26 41 12 75 37 60 Insert 15? What is the time complexity of removing an item into an array without holes, when order does not matter? 18 9 26 41 12 75 37 60 Remove 18? October 06, 2017 Hassan Khosravi / Geoffrey Tien

Hassan Khosravi / Geoffrey Tien Ordered arrays What is the time complexity of inserting an item into an array without holes, when order matters? 9 12 18 26 37 41 60 75 Insert 15? What is the time complexity of removing an item into an array without holes, when order matters? 9 12 18 26 37 41 60 75 Remove 18? October 06, 2017 Hassan Khosravi / Geoffrey Tien

Hassan Khosravi / Geoffrey Tien Linked list nodes A linked list is a dynamic data structure that consists of nodes linked together A node is a data structure that contains data the location (address) of the next node The data portion of a node can contain one or more items or structures typedef struct node { int data; struct node* next; } node; typedef struct player { int jersey_number; char* name; struct player* next; } player; October 06, 2017 Hassan Khosravi / Geoffrey Tien

Hassan Khosravi / Geoffrey Tien Linked lists A linked list is a chain of nodes, where each node indicates where in (heap) memory the next item can be found stack heap front 32 76 11 54 32 76 11 54 October 06, 2017 Hassan Khosravi / Geoffrey Tien

Modifying linked lists Inserting an item into a linked list 32 76 54 11 76 22 11 54 32 22 New nodes created using malloc() as needed Removing an item from a linked list 32 76 22 54 11 32 76 11 54 Removed nodes must be deallocated using free()! October 06, 2017 Hassan Khosravi / Geoffrey Tien

Linked list dis/advantages Linked list is constructed from nodes in the heap, can be added as needed, and removed at runtime The size of the list does not need to be "guessed" ahead of time Disadvantages To access a particular node (starting from the front of the list), may need to traverse the list to reach – 𝑂 𝑛 Linked list nodes have additional overhead to store pointers Harder to program, debug, and test October 06, 2017 Hassan Khosravi / Geoffrey Tien

Hassan Khosravi / Geoffrey Tien Linked list traversal Traversal through a linked list can be done with a node pointer variable e.g. to access the 4th element in a list: // assuming we have node* front node* ptr = front; int i; for (i = 0; i < 4; i++) { ptr = ptr->next; } // exited loop, ptr references 4th node printf("%d", ptr->data); ptr front 76 22 11 54 32 October 06, 2017 Hassan Khosravi / Geoffrey Tien

Readings for this lesson Thareja Chapter 6 (Linked lists) Algorithm and data structure visualisations Linked list: http://visualgo.net/list.html October 06, 2017 Hassan Khosravi / Geoffrey Tien