ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: 2620a.htm Office: TEL 3049.

Slides:



Advertisements
Similar presentations
Linked Lists Linked Lists Representation Traversing a Linked List
Advertisements

Introduction to Algorithms Quicksort
Introduction to Algorithms Rabie A. Ramadan rabieramadan.org 2 Some of the sides are exported from different sources.
Efficiency of Algorithms Csci 107 Lecture 6-7. Topics –Data cleanup algorithms Copy-over, shuffle-left, converging pointers –Efficiency of data cleanup.
Chapter 4: Trees Part II - AVL Tree
CPSC 171 Introduction to Computer Science Efficiency of Algorithms.
Lecture 6 Hashing. Motivating Example Want to store a list whose elements are integers between 1 and 5 Will define an array of size 5, and if the list.
Sorting Algorithms. Motivation Example: Phone Book Searching Example: Phone Book Searching If the phone book was in random order, we would probably never.
Quicksort Divide-and-Conquer. Quicksort Algorithm Given an array S of n elements (e.g., integers): If array only contains one element, return it. Else.
 1 Sorting. For computer, sorting is the process of ordering data. [ ]  [ ] [ “Tom”, “Michael”, “Betty” ]  [ “Betty”, “Michael”,
CS 206 Introduction to Computer Science II 04 / 27 / 2009 Instructor: Michael Eckmann.
CSE332: Data Abstractions Lecture 12: Introduction to Sorting Tyler Robison Summer
1 CS 177 Week 12 Recitation Slides Running Time and Performance.
Chapter 3: The Efficiency of Algorithms Invitation to Computer Science, C++ Version, Third Edition Additions by Shannon Steinfadt SP’05.
CS 206 Introduction to Computer Science II 12 / 03 / 2008 Instructor: Michael Eckmann.
Chapter 3: The Efficiency of Algorithms Invitation to Computer Science, C++ Version, Fourth Edition.
Chapter 3: The Efficiency of Algorithms
Organizing files for performance Chapter Data compression Advantages of reduced file size Redundancy reduction: state code example Repeating sequences:
Heaps and heapsort COMP171 Fall 2005 Part 2. Sorting III / Slide 2 Heap: array implementation Is it a good idea to store arbitrary.
Lecture 6 Hashing. Motivating Example Want to store a list whose elements are integers between 1 and 5 Will define an array of size 5, and if the list.
Data Structures Introduction Phil Tayco Slide version 1.0 Jan 26, 2015.
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
计算机科学概述 Introduction to Computer Science 陆嘉恒 中国人民大学 信息学院
Today  Table/List operations  Parallel Arrays  Efficiency and Big ‘O’  Searching.
Algorithm Evaluation. What’s an algorithm? a clearly specified set of simple instructions to be followed to solve a problem a way of doing something What.
 Pearson Education, Inc. All rights reserved Searching and Sorting.
Algorithm Course Dr. Aref Rashad February Algorithms Course..... Dr. Aref Rashad Part: 4 Search Algorithms.
 DATA STRUCTURE DATA STRUCTURE  DATA STRUCTURE OPERATIONS DATA STRUCTURE OPERATIONS  BIG-O NOTATION BIG-O NOTATION  TYPES OF DATA STRUCTURE TYPES.
CSC 211 Data Structures Lecture 13
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: Tel 3049.
Data Structures and Algorithms Lecture 1 Instructor: Quratulain Date: 1 st Sep, 2009.
New Mexico Computer Science For All Algorithm Analysis Maureen Psaila-Dombrowski.
ITEC 2620M Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: ec2620m.htm Office: TEL 3049.
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.
CS 206 Introduction to Computer Science II 04 / 22 / 2009 Instructor: Michael Eckmann.
Hash Table March COP 3502, UCF 1. Outline Hash Table: – Motivation – Direct Access Table – Hash Table Solutions for Collision Problem: – Open.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
B-TREE. Motivation for B-Trees So far we have assumed that we can store an entire data structure in main memory What if we have so much data that it won’t.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Array Lists Array Lists Dale.
Lecture 9COMPSCI.220.FS.T Lower Bound for Sorting Complexity Each algorithm that sorts by comparing only pairs of elements must use at least 
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Searching Topics Sequential Search Binary Search.
CS 162 Intro to Programming II Insertion Sort 1. Assume the initial sequence a[0] a[1] … a[k] is already sorted k = 0 when the algorithm starts Insert.
Chapter 9: Sorting1 Sorting & Searching Ch. # 9. Chapter 9: Sorting2 Chapter Outline  What is sorting and complexity of sorting  Different types of.
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.
LINKED LISTS.
Chapter 16: Searching, Sorting, and the vector Type
Multiway Search Trees Data may not fit into main memory
CSCI-255 LinkedList.
October 30th – Priority QUeues
ITEC 2620M Introduction to Data Structures
ITEC 2620M Introduction to Data Structures
Extendible Indexing Dina Said
Arrays and Linked Lists
ITEC 2620M Introduction to Data Structures
Chapter 3: The Efficiency of Algorithms
Introduction to Algorithms Analysis
ITEC 2620M Introduction to Data Structures
ITEC 2620M Introduction to Data Structures
Chapter 3: The Efficiency of Algorithms
Algorithmic Complexity
ITEC 2620M Introduction to Data Structures
Data Structures & Algorithms
Presentation transcript:

ITEC 2620A Introduction to Data Structures Instructor: Prof. Z. Yang Course Website: a.htm Office: TEL 3049

Complexity Estimation

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

4 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

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

6 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 !

7 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

8 Complexity Estimation and Complexity Analysis Complexity Estimation –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’s inside the summation More accurate questions –What does it cost each time? –What does it cost on average? Example

Linked List

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

11 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)

12 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

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

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

15 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( log n) –Avg  O( log n)

16 Comparing Arrays and Linked- Lists (Cont’d) Array –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( log n)+O(1) = O( log n) Worst  first element  O( log n)+O(n) = O(n) Avg  mid-area element  O(logn)+O(n) = O(n)

17 Comparing Arrays and Linked- Lists (Cont’d) Linked-Lists –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)

18 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)