Sparse matrices, hash tables, cell arrays

Slides:



Advertisements
Similar presentations
1 Designing Hash Tables Sections 5.3, 5.4, Designing a hash table 1.Hash function: establishing a key with an indexed location in a hash table.
Advertisements

© 2004 Goodrich, Tamassia Hash Tables1  
Tirgul 9 Amortized analysis Graph representation.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 48 Hashing.
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
Hash Tables1 Part E Hash Tables  
CS 221 Analysis of Algorithms Data Structures Dictionaries, Hash Tables, Ordered Dictionary and Binary Search Trees.
Hash Tables1   © 2010 Goodrich, Tamassia.
David Luebke 1 10/25/2015 CS 332: Algorithms Skip Lists Hash Tables.
1 CSE 326: Data Structures: Hash Tables Lecture 12: Monday, Feb 3, 2003.
© 2004 Goodrich, Tamassia Hash Tables1  
Searching Given distinct keys k 1, k 2, …, k n and a collection of n records of the form »(k 1,I 1 ), (k 2,I 2 ), …, (k n, I n ) Search Problem - For key.
Chapter 12 Hash Table. ● So far, the best worst-case time for searching is O(log n). ● Hash tables  average search time of O(1).  worst case search.
David Luebke 1 11/26/2015 Hash Tables. David Luebke 2 11/26/2015 Hash Tables ● Motivation: Dictionaries ■ Set of key/value pairs ■ We care about search,
Tirgul 11 Notes Hash tables –reminder –examples –some new material.
CHAPTER 9 HASH TABLES, MAPS, AND SKIP LISTS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++,
Hash Tables 1/28/2018 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Sections 10.5 – 10.6 Hashing.
Hashing (part 2) CSE 2011 Winter March 2018.
Chapter 27 Hashing Jung Soo (Sue) Lim Cal State LA.
Hashing & HashMaps CS-2851 Dr. Mark L. Hornick.
COMP 53 – Week Eleven Hashtables.
Maps, Hash tables, Skip Lists– Interesting problems
CS 332: Algorithms Hash Tables David Luebke /19/2018.
EGR 115 Introduction to Computing for Engineers
EGR 115 Introduction to Computing for Engineers
Other Kinds of Arrays Chapter 11
Other Kinds of Arrays Chapter 11
Dictionaries Dictionaries 07/27/16 16:46 07/27/16 16:46 Hash Tables 
© 2013 Goodrich, Tamassia, Goldwasser
Dictionaries 9/14/ :35 AM Hash Tables   4
Hash Tables 3/25/15 Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia, and M.
Hash Tables Part II: Using Buckets
CSc 110, Autumn 2017 Lecture 31: Dictionaries
Map interface Empty() - return true if the map is empty; else return false Size() - return the number of elements in the map Find(key) - if there is an.
structures and their relationships." - Linus Torvalds
Hashing CS2110 Spring 2018.
Chapter 28 Hashing.
بردارها و ماتريس ها ساختمان داده ها
Hashing CS2110.
Bin Sort, Radix Sort, Sparse Arrays, and Stack-based Depth-First Search CSE 373, Copyright S. Tanimoto, 2002 Bin Sort, Radix.
Chapter 21 Hashing: Implementing Dictionaries and Sets
Dictionaries Collection of pairs. Operations. (key, element)
Data Structures and Algorithms
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
CSCI 3333 Data Structures Array
Hash tables in C.
Dictionaries 1/17/2019 7:55 AM Hash Tables   4
CH 9.2 : Hash Tables Acknowledgement: These slides are adapted from slides provided with Data Structures and Algorithms in C++, Goodrich, Tamassia and.
CSE 373, Copyright S. Tanimoto, 2002 Hashing -
Hash Tables Computer Science and Engineering
Bin Sort, Radix Sort, Sparse Arrays, and Stack-based Depth-First Search CSE 373, Copyright S. Tanimoto, 2001 Bin Sort, Radix.
Hashing Sections 10.2 – 10.3 Lecture 26 CS302 Data Structures
Hash Tables Computer Science and Engineering
EE 312 Software Design and Implementation I
Dictionaries 4/5/2019 1:49 AM Hash Tables  
Hash Tables By JJ Shepherd.
Efficient data structures in Delphi – reimplementing a dictionary
Hash Tables Buckets/Chaining
Data Structures & Algorithms
CS210- Lecture 17 July 12, 2005 Agenda Collision Handling
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
Matrices An appeaser is one who feeds a crocodile—hoping it will eat him last. Winston Churchhill.
EE 312 Software Design and Implementation I
structures and their relationships." - Linus Torvalds
ENERGY 211 / CME 211 Lecture 20 November 5, 2008.
Dictionaries and Hash Tables
Lecture-Hashing.
CSE 373: Data Structures and Algorithms
Presentation transcript:

Sparse matrices, hash tables, cell arrays CS1114 Section http://www.cs.cornell.edu/courses/cs1114

Useful new data types Matlab has many useful data structures for handling different scenarios We’ll cover a few that will be useful for A6: Sparse matrices Hash tables Cell arrays

Transition matrices For A6, you’ll be creating very large matrices Storing these in memory will be an issue

Small transition matrix 2/3 1/3 1 dog is man’s best (blank entries are zeros) friend it’s eat world out there . a is . dog it’s best eat out man’s friend world there

Bigger example – “A Tail of Two Cities” 0.004 0.17 0.005 0.002 0.06 0.001 0.003 0.26 0.017 0.23 0.04 0.47 0.5 0.025 0.036 was the best of times worst … birthday … far better it of … … far was the best times worst 13253 cols better birthday 13253 rows

Very large matrices Jane Austen’s Pride and Prejudice: 8,828 unique words  8,828 x 8,828 transition matrix (77,933,584 entries) What about 1,000,000 words? Matlab runs out of memory (1M x 1M = 1T entries) Try this: >> zeros(1000000, 1000000); But the matrix is mostly empty Most pairs (e.g. “and and”) have zero probability

Solution: sparse matrices Matlab has a special type of sparse matrix Only stores the non-zero elements, and the position in the matrix of those elements A bit like a linked list >> S = sparse(1000000, 1000000); >> whos S Name Size Bytes Class Attributes S 1000000x1000000 8000024 double sparse

Sparse matrices Most operations on dense matrices work on sparse matrices sometimes produce a sparse matrix, sometimes a dense matrix S = sparse(1000000,1000000); S(100,100) = 3; % S is still sparse S = S + 1; % S is now dense Error using + Out of memory. Type HELP MEMORY for your options.

Hash tables Suppose we want to create a mapping from strings to numbers E.g., from animals to number of legs ‘human’  2 ‘horse’  4 ‘octopus’  8 ‘centipede’  100 (?)

Hash tables We can use a hash table for this (Also called dictionary or associative array) Maps keys (e.g. `horse’) to values (e.g. 4) Hash tables are interesting to implement, but we’ll just use them as a tool In Matlab: >> hash = java.util.Hashtable; % For some reason in Matlab, % you can create Java objects

Hash tables We can add key,value pairs to a hash table using put and retrieve values using get with the key >> hash.put(‘horse’, 4); >> hash.push(‘octopus’, 8); % We just added two entries % to the hash table >> hash.get(‘horse’) ans = 10

Call arrays Arrays can hold numbers or strings Q: What is the result of the following? [ ‘abc’, ‘def’ ] Matlab has another kind of array: a cell array A cell array can hold different types of objects A = { ‘abc’, ‘def’, 103, [ 10 40 ; 40 10 ] } We’ll use these for A6 as well…