“Sense shines with a double luster when it is set in humility. An able and yet humble man is a jewel worth a kingdom.” – William Penn Thought for the Day.

Slides:



Advertisements
Similar presentations
Linked Lists CSC220 Winter
Advertisements

Lecture 11 oct 6 Goals: hashing hash functions chaining closed hashing application of hashing.
Theory I Algorithm Design and Analysis (5 Hashing) Prof. Th. Ottmann.
Lecture: Algorithmic complexity
Fundamentals of Python: From First Programs Through Data Structures
CMPT 225 Sorting Algorithms Algorithm Analysis: Big O Notation.
Complexity Analysis (Part I)
Complexity Analysis (Part I)
CS 206 Introduction to Computer Science II 11 / 12 / 2008 Instructor: Michael Eckmann.
Lecture 11 oct 7 Goals: hashing hash functions chaining closed hashing application of hashing.
TTIT33 Algorithms and Optimization – Lecture 1 Jan Maluszynski - HT Analysis of Algorithms Introductory Example Principles of Analysis Big-Oh notation.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Elementary Data Structures and Algorithms
Cmpt-225 Simulation. Application: Simulation Simulation  A technique for modeling the behavior of both natural and human-made systems  Goal Generate.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Analysis of Algorithms Dilemma: you have two (or more) methods to solve problem, how to choose the BEST? One approach: implement each algorithm in C, test.
Describing algorithms in pseudo code To describe algorithms we need a language which is: – less formal than programming languages (implementation details.
Algorithm Analysis (Big O)
Spring2012 Lecture#10 CSE 246 Data Structures and Algorithms.
COMP s1 Computing 2 Complexity
COSC 2007 Data Structures II
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
Algorithm Analysis & Complexity We saw that a linear search used n comparisons in the worst case (for an array of size n) and binary search had logn comparisons.
CS2110: SW Development Methods Textbook readings: MSD, Chapter 8 (Sect. 8.1 and 8.2) But we won’t implement our own, so study the section on Java’s Map.
Introduction to Analysing Costs 2015-T2 Lecture 10 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Rashina.
Week 2 CS 361: Advanced Data Structures and Algorithms
1 Recursion Algorithm Analysis Standard Algorithms Chapter 7.
Data Structures and Algorithms Lecture 5 and 6 Instructor: Quratulain Date: 15 th and 18 th September, 2009 Faculty of Computer Science, IBA.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture8.
Analysis of Algorithms
1 7.Algorithm Efficiency What to measure? Space utilization: amount of memory required  Time efficiency: amount of time required to process the data Depends.
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
1 7.Algorithm Efficiency What to measure? Space utilization: amount of memory required  Time efficiency: amount of time required to process the data.
90-723: Data Structures and Algorithms for Information Processing Copyright © 1999, Carnegie Mellon. All Rights Reserved. 1 Lecture 9: Searching Data Structures.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
CSC 211 Data Structures Lecture 13
“Enthusiasm releases the drive to carry you over obstacles and adds significance to all you do.” – Norman Vincent Peale Thought for the Day.
March 23 & 28, Hashing. 2 What is Hashing? A Hash function is a function h(K) which transforms a key K into an address. Hashing is like indexing.
Chapter 11 Hash Anshuman Razdan Div of Computing Studies
Algorithms and data structures: basic definitions An algorithm is a precise set of instructions for solving a particular task. A data structure is any.
“Never doubt that a small group of thoughtful, committed people can change the world. Indeed, it is the only thing that ever has.” – Margaret Meade Thought.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
RUNNING TIME 10.4 – 10.5 (P. 551 – 555). RUNNING TIME analysis of algorithms involves analyzing their effectiveness analysis of algorithms involves analyzing.
Review 1 Selection Sort Selection Sort Algorithm Time Complexity Best case Average case Worst case Examples.
Data Structures Using C++ 2E
Hashing Fundamental Data Structures and Algorithms Margaret Reid-Miller 18 January 2005.
1 Algorithms  Algorithms are simply a list of steps required to solve some particular problem  They are designed as abstractions of processes carried.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
ENEE150 – 0102 ANDREW GOFFIN Project 4 & Function Pointers.
COSC 1030 Lecture 10 Hash Table. Topics Table Hash Concept Hash Function Resolve collision Complexity Analysis.
ANALYSING COSTS COMP 103. RECAP  ArrayList: add(), ensuring capacity, iterator for ArrayList TODAY  Analysing Costs 2 RECAP-TODAY.
COM S 228 Algorithms and Analysis Instructor: Ying Cai Department of Computer Science Iowa State University Office: Atanasoff 201.
1 Data Structures CSCI 132, Spring 2014 Lecture 33 Hash Tables.
Peter Andreae Computer Science Victoria University of Wellington Copyright: Peter Andreae, Victoria University of Wellington2012 Analysing Costs COMP 103.
CSC 212 – Data Structures Lecture 15: Big-Oh Notation.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
Section 1.7 Comparing Algorithms: Big-O Analysis.
Chapter 15 Running Time Analysis. Topics Orders of Magnitude and Big-Oh Notation Running Time Analysis of Algorithms –Counting Statements –Evaluating.
Introduction to Analysing Costs 2013-T2 Lecture 10 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Rashina.
1 7.Algorithm Efficiency These factors vary from one machine/compiler (platform) to another  Count the number of times instructions are executed So, measure.
COMP 103 Course Review. 2 Menu  A final word on hash collisions in Open Addressing / Probing  Course Summary  What we have covered  What you should.
Complexity Analysis (Part I)
Analysis of Algorithms
Course Description Algorithms are: Recipes for solving problems.
Analysis of Algorithms
Course Description Algorithms are: Recipes for solving problems.
Complexity Analysis (Part I)
Analysis of Algorithms
Complexity Analysis (Part I)
Presentation transcript:

“Sense shines with a double luster when it is set in humility. An able and yet humble man is a jewel worth a kingdom.” – William Penn Thought for the Day

External Hash Table: Iterators Slightly more complicated: –need to work through array –and work through linked lists table... key value key value key value

The HashTableIterator Class private class HashTableIterator... { private int index; private EntryNode nextEntry; public HashTableIterator () { for (index = 0; index < table.length; index++) if (table[index] != null) break; // First non-empty bucket if (index < table.length) // Have data nextEntry = table[index]; } // constructor public Pair get () { return nextEntry; } // get... } // class HashTableIterator

public void next () { nextEntry = nextEntry.next; if (nextEntry == null) // Look for next non-empty bucket while (++index < table.length) { if (table[index] != null) // Found more data { nextEntry = table[index]; break; } } // next public boolean atEnd () { return index >= table.length; } // atEnd

Uses of the Hash Table Classes SSame interface ( Dictionary ) as the ListDictionary class Similar applications –more efficient –But: unordered

Dictionary ADT Summary ADTAdvantagesDisadvantages List- Dictionary Ordered Flexible size Slow access Internal- HashTable Fast accessUnordered Fixed size External- HashTable Fast access Flexible size Unordered

O Section 3 Algorithm Analysis Big-O

Chapter 8: Big-O Objectives –Introduce algorithm analysis –Study methods for measuring algorithm efficiency and thus comparing algorithms –Consider some common results –Show some simple applications of the techniques of algorithm analysis

Analysing Algorithms Many algorithms may appear simple and efficient This may not be true in fact!

Example Solving simultaneous equations Cramer’s Rule Calculate the determinant For n equations, it takes n! operations

Example (cont.) If n = 30 (a very small set of equations) n! = 30! = 3 × Computers are very fast Assume 10 9 operations per second (1GHz) Time taken = years Longer than the estimated life of the universe!

Example (cont.) Another approach is needed! The tri-diagonal method Needs about 10n operations If n = 30, time taken = seconds

Implications Need to choose algorithms very carefully This example focussed on time –other resources (memory, disk space, etc.) may also be important

Algorithmic Complexity Not how difficult it is to understand! How it behaves with respect to time (or other resources) Example: we say that Cramer’s Rule has a complexity of n!

Algorithmic Complexity Need to measure complexity in a way that is independent of external factors –compiler optimisations, speed of computers, etc. Find some important operation(s) –Often comparisons, or data exchanges –Count them

Use to Compare Algorithms Algorithm 1 –20 comparisons –30 exchanges Algorithm 2 –100 comparisons –150 exchanges  On Apple II (1MHz) –30s On Pentium 4 (3GHz) –3s

The Impact of the Input Data Vitally important Must compare “apples with apples” But we don’t want to get into specific details! Use some abstract measure of data Example: –Cramer’s Rule: n equations

Input Data (cont.) Often the number of data items But not always! Example: text searching algorithms –length of search string x length of document

Input Data (cont.) Often three cases we need to consider: –average case –best case –worst case

Big-O Notation Or order notation Assume we can find a function giving the number of operations: f(n) = 3.5n n + 45 Dominant term Order n 2 or more simply: O(n 2 )