CE 221 Data Structures and Algorithms

Slides:



Advertisements
Similar presentations
Linked Lists Geletaw S..
Advertisements

Lists CS 3358.
COMP171 Fall 2005 Lists.
DATA STRUCTURES AND ALGORITHMS Prepared by İnanç TAHRALI
Chapter 3: Abstract Data Types Lists, Stacks Lydia Sinapova, Simpson College Mark Allen Weiss: Data Structures and Algorithm Analysis in Java.
Chapter 3: Arrays, Linked Lists, and Recursion
Lists, Stacks, and Queues Abstract Data Types (ADTs) The List ADT The Stack ADT The Queue ADT.
Data Structures and Algorithm Analysis Lecturer: Jing Liu Homepage:
A first look an ADTs Solving a problem involves processing data, and an important part of the solution is the careful organization of the data In order.
4-1 Topic 6 Linked Data Structures. 4-2 Objectives Describe linked structures Compare linked structures to array- based structures Explore the techniques.
1 Linked-list, stack and queue. 2 Outline Abstract Data Type (ADT)‏ Linked list Stack Queue.
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.
Linked List by Chapter 5 Linked List by
CE 221 Data Structures and Algorithms
CE 221 Data Structures and Algorithms Chapter 3: Lists, Stacks, and Queues - II Text: Read Weiss, §3.6 1Izmir University of Economics.
Chapter 5 Linked List by Before you learn Linked List 3 rd level of Data Structures Intermediate Level of Understanding for C++ Please.
Chapter Lists Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
CS 201 Data Structures and Algorithms Chapter 3: Lists, Stacks, and Queues - I Text: Read Weiss, §3.1 – 3.5 1Izmir University of Economics.
Data Structures Doubly and Circular Lists Lecture 07: Linked Lists
1 Linked List. Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion.
CE 221 Data Structures and Algorithms Chapter 3: Lists, Stacks, and Queues - II Text: Read Weiss, §3.6 1Izmir University of Economics.
LINKED LISTS.
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.
Lists and the Collection Interface Chapter 4. Chapter 4: Lists and the Collection Interface2 Chapter Objectives To become familiar with the List interface.
1 Linked List. List vs Arrays Two built-in data structures that can be used to organize data, or to create other data structures: Lists Arrays.
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.
Lecture 6 of Computer Science II
Unit – I Lists.
Review Array Array Elements Accessing array elements
C++ Programming:. Program Design Including
Cpt S 122 – Data Structures Abstract Data Types
Data Structures Using C, 2e
G64ADS Advanced Data Structures
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.
Linked Lists Chapter 6 Section 6.4 – 6.6
Data Structure Interview Question and Answers
Big-O notation Linked lists
CE 221 Data Structures and Algorithms
Lists CS 3358.
UNIT-3 LINKED LIST.
Chapter 4 Linked Lists.
Stacks and Queues.
Queues Queues Queues.
Data Structures Interview / VIVA Questions and Answers
LINKED LISTS CSCD Linked Lists.
CMSC 341 Lecture 5 Stacks, Queues
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.
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.
Lists CSE 373 Data Structures.
Doubly Linked List Implementation
The List, Stack, and Queue ADTs
Cs212: Data Structures Computer Science Department Lecture 7: Queues.
Chapter 17: Linked Lists.
CE 221 Data Structures and Algorithms
CE 221 Data Structures and Algorithms
CS210- Lecture 5 Jun 9, 2005 Agenda Queues
Queues Jyh-Shing Roger Jang (張智星)
CE 221 Data Structures and Algorithms
CE 221 Data Structures and Algorithms
Lecture No.02 Data Structures Dr. Sohail Aslam
Lists CSE 373 Data Structures.
CS210- Lecture 6 Jun 13, 2005 Announcements
CS210- Lecture 7 Jun 14, 2005 Agenda Practice Session Vector
Doubly Linked List Implementation
17CS1102 DATA STRUCTURES © 2018 KLEF – The contents of this presentation are an intellectual and copyrighted property of KL University. ALL RIGHTS RESERVED.
LINEAR DATA STRUCTURES
Presentation transcript:

CE 221 Data Structures and Algorithms Chapter 3: Lists, Stacks, and Queues - I Text: Read Weiss, §3.1 – 3.5 Izmir University of Economics

Izmir University of Economics Introduction We will discuss three of the most simple and basic data structures. Virtually every significant program will use at least one of these structures explicitly, and a stack is always implicitly used in a program, whether or not you declare one. Izmir University of Economics

Abstract Data Types (ADTs) An abstract data type (ADT) is a set of objects. ADTs are mathematical abstractions; implementation is not considered. Objects such as lists, sets, and graphs along with their operations can be viewed as abstract data types just as integers, reals, and booleans are data types. There is no rule telling which operations must be supported for each ADT; this is a design issue. Izmir University of Economics

Izmir University of Economics The List ADT - I A general list of the form: A0, A1, A2, ..., AN-1 The size of this list is N. Special list of size 0 is an empty list. For any list except empty list, Ai follows or succeeds Ai-1 (i<N); Ai-1 precedes Ai,(i>0). The predecessor of A0 and the successor of AN-1 are not defined. First element of the list is A0 and the last element is AN-1. The position of element Ai is i. Izmir University of Economics

Izmir University of Economics The List ADT - II Associated with these definitions are some popular operations on the list ADT: printList, makeEmpty, find (returns the position of the first occurence of an item), insert and remove ( generally insert and remove from some position), findKth (returns the element in some position). Example: 34, 12, 52, 16, 12. find(52)2; insert(x, 2) 34, 12, x, 52, 16, 12. Izmir University of Economics

Simple Array Implementation of Lists Use arrays for the underlying implementation. Arrays are created with a fixed capacity; grow it when needed by doubling its capacity. With this implementation mechanism; printList takes O(N) time; findKth takes O(1) time. Insertions and deletions are expensive. In the worst case, inserting into position 0 (at the front of the list) requires pushing the entire array down one spot to make room, and deleting the first requires shifting all up by one: O(N). On the average half the list is moved: still O(N). Best case occurs when they are performed at the higher end: O(1). Izmir University of Economics

Izmir University of Economics Simple Linked Lists - I In order to avoid the linear cost of insertion and deletion, we need to ensure that the list is not stored contiguously, since otherwise entire parts of the list will need to be moved. The linked list consists of a series of nodes. Each node contains the element and a link (next) to the successor node. To execute printList() or find(x), start at the first node and then traverse the list by following the next links: O(N) findKth(i) takes O(i) (but you can sort the calls by i) Izmir University of Economics

Simple Linked Lists - II The remove operation can be executed in one next pointer change. The insert command requires obtaining a new node from the system by using a new call and then executing two pointer maneuvers. Izmir University of Economics

Simple Linked Lists - III If we know where a change is to be made, inserting or removing an item from a linked list involves only a constant number of changes to node links. The special case of adding to the front or removing the first item is thus a constant-time operation if there exists a link to the front of the list. The same holds when adding at the end as long as another link is provided to the last node. Removing the last item is trickier! Why? We need to find the next-to-last item and change its next link to NULL and then update the pointer to the last node. A third link to next-to-last node does not work (it too needs to be updated.) Solution: each node maintain a link to its previous node: Doubly linked list Izmir University of Economics

Vector: Array Implementation - I Vector implementation: Advantage: indexable in constant time; Disadvantage: insertion and removal of items at locations other than the end are expensive. List implementation: Advantage: Insertions and removals are cheap; Disadvantage: is not easily indexable. Izmir University of Economics

Vector: Array Implementation - II Izmir University of Economics

Vector: Array Implementation - III Izmir University of Economics

Vector: Array Implementation - IV Izmir University of Economics

Vector: Array Implementation – V(optional) Izmir University of Economics

Linked List Implementation - I The List will,this time, be implemented as a doubly linked list. We will also maintain pointers to both ends of the list. The two extra nodes created at the front and at the back of the list are header node and tail node respectively (sentinels nodes). Izmir University of Economics

Linked List Implementation - IIa Izmir University of Economics

Linked List Implementation - IIb later Izmir University of Economics

Linked List Implementation - III Izmir University of Economics

Linked List Implementation - IV Izmir University of Economics

Linked List Implementation - V Izmir University of Economics

Linked List Implementation - VI Izmir University of Economics

Linked List Implementation – VII (optional) Izmir University of Economics

Linked List Implementation – VIII (optional) Izmir University of Economics

Linked List Implementation – IX (optional) this Izmir University of Economics

Izmir University of Economics Homework Assignments 3.2, 3.4, 3.5, 3.15, 3.29, 3.34.a, 3.34.b, 3.36, 3.37 You are requested to study and solve the exercises. Note that these are for you to practice only. You are not to deliver the results to me. Izmir University of Economics