ITEC 2620M Introduction to Data Structures

Slides:



Advertisements
Similar presentations
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 2 Some of the sides are exported from different sources.
Advertisements

Efficiency of Algorithms Csci 107 Lecture 6-7. Topics –Data cleanup algorithms Copy-over, shuffle-left, converging pointers –Efficiency of data cleanup.
CS 206 Introduction to Computer Science II 12 / 03 / 2008 Instructor: Michael Eckmann.
Chapter 16: Searching, Sorting, and the vector Type.
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
ITEC 2620A Introduction to Data Structures
 DATA STRUCTURE DATA STRUCTURE  DATA STRUCTURE OPERATIONS DATA STRUCTURE OPERATIONS  BIG-O NOTATION BIG-O NOTATION  TYPES OF DATA STRUCTURE TYPES.
ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: TEL 3049.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: Tel 3049.
CS 206 Introduction to Computer Science II 04 / 22 / 2009 Instructor: Michael Eckmann.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Array Lists Array Lists Dale.
HeapSort 25 March HeapSort Heaps or priority queues provide a means of sorting: 1.Construct a heap, 2.Add each item to it (maintaining the heap.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: TEL 3049.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 20m.htm Office: TEL 3049.
3/19/2016 5:40 PMLinked list1 Array-based List v.s. Linked List Yumei Huo Department of Computer Science College of Staten Island, CUNY Spring 2009.
Chapter 16: Searching, Sorting, and the vector Type.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: TEL 3049.
Chapter 16: Searching, Sorting, and the vector Type
CS222: Principles of Data Management Lecture #4 Catalogs, Buffer Manager, File Organizations Instructor: Chen Li.
Data Structures I (CPCS-204)
May 17th – Comparison Sorts
Multiway Search Trees Data may not fit into main memory
CSCI-255 LinkedList.
Design & Analysis of Algorithm Priority Queue
Review Deleting an Element from a Linked List Deletion involves:
Heaps, Heapsort, and Priority Queues
Priority Queues and Heaps
Sections 8.7 – 8.8 Balancing a Binary Search Tree.
Alg2_1c Extra Material for Alg2_1
Introduction to Algorithms
B+ Trees What are B+ Trees used for What is a B Tree What is a B+ Tree
Sorting by Tammy Bailey
October 30th – Priority QUeues
Binary Search Tree Chapter 10.
Teach A level Computing: Algorithms and Data Structures
ITEC 2620M Introduction to Data Structures
Tree data structure.
Hash tables Hash table: a list of some fixed size, that positions elements according to an algorithm called a hash function … hash function h(element)
Extendible Indexing Dina Said
CPSC 531: System Modeling and Simulation
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
Arrays and Linked Lists
Tree data structure.
Heaps, Heapsort, and Priority Queues
B+ Trees What are B+ Trees used for What is a B Tree What is a B+ Tree
Linked List Intro CSCE 121 J. Michael Moore.
ITEC 2620M Introduction to Data Structures
Data Structures and Algorithms
Bin Sort, Radix Sort, Sparse Arrays, and Stack-based Depth-First Search CSE 373, Copyright S. Tanimoto, 2002 Bin Sort, Radix.
Introduction to Algorithms Analysis
CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions
ITEC 2620M Introduction to Data Structures
ITEC 2620M Introduction to Data Structures
ITEC 2620M Introduction to Data Structures
Searching CLRS, Sections 9.1 – 9.3.
Algorithmic Complexity
ITEC 2620M Introduction to Data Structures
Bin Sort, Radix Sort, Sparse Arrays, and Stack-based Depth-First Search CSE 373, Copyright S. Tanimoto, 2001 Bin Sort, Radix.
Introduction to Data Structures
Hashing Sections 10.2 – 10.3 Lecture 26 CS302 Data Structures
ITEC 2620M Introduction to Data Structures
General External Merge Sort
Data Structures & Algorithms
Indexing, Access and Database System Architecture
Linked List Intro CSCE 121.
Data Structures Using C++ 2E
Module 8 – Searching & Sorting Algorithms
Algorithm Analysis How can we demonstrate that one algorithm is superior to another without being misled by any of the following problems: Special cases.
CMPT 225 Lecture 16 – Heap Sort.
Presentation transcript:

ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: http://people.math.yorku.ca/~zyang/itec2620m.htm Office: DB 3049

Complexity Estimation

Key Points Estimation of non-recursive algorithms Best, Worst, and Average cases How many times? What does it cost each time?

Best, Worst, and Average Cases Why do people buy lottery tickets? Win a million dollars Case?  Best Why should you invest in the stock market? Best long term investment (compared to bonds and cash) Case?  Average Lottery Average case  waste your money Stock market Worst case  crash – lose everything

Which case should we use to make decisions Average case  most often Best case  when reasonable expectation exists Worst case  when guarantees are required

Best, Worst, and Average cases in Algorithm Analysis Is there a conditional execution? while loops branching with different cost alternatives Best Case minimal execution Worst Case maximal execution Average Case median (50-50) case not necessarily (Best + Worst)/2 !

Using Complexity The most important thing about algorithm analysis is to determine big-Oh – the approximate complexity why? need to be able to estimate program running times Do we need all the math? not really

Complexity Estimation and Complexity Analysis Two key questions How many times? What does it cost? Relating Complexity Estimation to Complexity Analysis “How many times?” is the summation “What does it cost?” is what is inside the summation More accurate questions What does it cost each time? What does it cost on average? Example

Linked List

Key Points Maintaining data records Inserting into sorted arrays Dynamic data structures Linked-lists

Inserting into Sorted Arrays How is this done? loop – larger values get moved into the next slot when done, copy new value into next slot What is the complexity for inserting into a sorted array? Is there a best, worst, and average case? do you always insert into the same location? How many times, what does it cost? Best  0 moves  O(1) Worst  n moves, 1 swap per  O(n) Avg  n/2 moves, 1 swap per  O(n)

Inserting into Full Arrays What happens if we want to insert another element into this array? Copy entire array into a larger array (time consuming) How do we avoid this? Store data in an array with extra space Time-Space trade-off What saves time can often waste space What saves space can often waste time

Dynamic Data Structures Would like to create extra memory slots one at a time… Creating Links Inserting Links

Arrays vs. Linked-Lists fixed length contiguous memory locations direct access Linked-Lists dynamic length arbitrary memory locations access by following links

Comparing Arrays and Linked-Lists Find and delete a value in a sorted array and a linked-list . Arrays find value with binary search (assume value is in array) shuffle all higher values down what is the complexity for find? Best  O(1) Worst  O(logn) Avg  O(logn)

Comparing Arrays and Linked-Lists (Cont’d) What is the complexity for delete? Best  last element  O(1) Worst  first element  O(n) Avg  middle element  O(n) What is the overall complexity? Best  last element  O(logn)+O(1) = O(logn) Worst  first element  O(logn)+O(n) = O(n) Avg  mid-area element  O(logn)+O(n) = O(n)

Comparing Arrays and Linked-Lists (Cont’d) find value by following links link past target link (garbage collecting will remove it) what is the complexity for find? Best  first element  O(1) Worst  last element  O(n) Avg  middle element  O(n)

Comparing Arrays and Linked-Lists (Cont’d) What is the complexity for delete? Always  O(1) What is the overall complexity? Best  first element  O(1)+O(1) = O(1) Worst last element  O(n)+O(1) = O(n) Avg middle element  O(n)+O(1) = O(n)