Computer Science Elementary Data Structures, Dictionaries CS 330: Algorithms Elementary Data Structures, Dictionaries Gene Itkis.

Slides:



Advertisements
Similar presentations
David Luebke 1 6/7/2014 CS 332: Algorithms Skip Lists Introduction to Hashing.
Advertisements

The Dictionary ADT Definition A dictionary is an ordered or unordered list of key-element pairs, where keys are used to locate elements in the list. Example:
AVL Trees1 Part-F2 AVL Trees v z. AVL Trees2 AVL Tree Definition (§ 9.2) AVL trees are balanced. An AVL Tree is a binary search tree such that.
Transform and Conquer Chapter 6. Transform and Conquer Solve problem by transforming into: a more convenient instance of the same problem (instance simplification)
Data Abstraction and Problem Solving with JAVA Walls and Mirrors Frank M. Carrano and Janet J. Prichard © 2001 Addison Wesley Data Abstraction and Problem.
CS 171: Introduction to Computer Science II
Hashing Techniques.
Computer Science CS 330: Algorithms Priority Queues Gene Itkis.
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
Computer Science Dictionaries: Red-Black CS 330: Algorithms Dictionaries: and Red-Black Trees Gene Itkis.
1 Chapter 9 Maps and Dictionaries. 2 A basic problem We have to store some records and perform the following: add new record add new record delete record.
© 2006 Pearson Addison-Wesley. All rights reserved13 A-1 Chapter 13 Hash Tables.
Introduction to Data Structure, Spring 2007 Slide- 1 California State University, Fresno Introduction to Data Structure Introduction of Concepts Ming Li.
CS102 – Data Structures Lists, Stacks, Queues, Trees, Hash Collections Framework David Davenport Spring 2002.
Course Review COMP171 Spring Hashing / Slide 2 Elementary Data Structures * Linked lists n Types: singular, doubly, circular n Operations: insert,
Computer Science Red-Black CS 330: Algorithms and Red-Black Trees Gene Itkis.
CS 206 Introduction to Computer Science II 11 / 12 / 2008 Instructor: Michael Eckmann.
CSE 326: Data Structures Lecture #13 Extendible Hashing and Splay Trees Alon Halevy Spring Quarter 2001.
© 2006 Pearson Addison-Wesley. All rights reserved13 B-1 Chapter 13 (continued) Advanced Implementation of Tables.
© 2006 Pearson Addison-Wesley. All rights reserved13 B-1 Chapter 13 (excerpts) Advanced Implementation of Tables CS102 Sections 51 and 52 Marc Smith and.
Algorithms and Data Structures Hash Tables and Associative Arrays.
Data Structures Hashing Uri Zwick January 2014.
ICS220 – Data Structures and Algorithms Lecture 10 Dr. Ken Cosh.
CS 221 Analysis of Algorithms Data Structures Dictionaries, Hash Tables, Ordered Dictionary and Binary Search Trees.
Compiled by: Dr. Mohammad Alhawarat BST, Priority Queue, Heaps - Heapsort CHAPTER 07.
1 Hash Tables  a hash table is an array of size Tsize  has index positions 0.. Tsize-1  two types of hash tables  open hash table  array element type.
Dictionaries CS 105. L11: Dictionaries Slide 2 Definition The Dictionary Data Structure structure that facilitates searching objects are stored with search.
1 B Trees - Motivation Recall our discussion on AVL-trees –The maximum height of an AVL-tree with n-nodes is log 2 (n) since the branching factor (degree,
Min Chen School of Computer Science and Engineering Seoul National University Data Structure: Chapter 1.
1 Road Map Associative Container Impl. Unordered ACs Hashing Collision Resolution Collision Resolution Open Addressing Open Addressing Separate Chaining.
IT 60101: Lecture #151 Foundation of Computing Systems Lecture 15 Searching Algorithms.
© 2006 Pearson Addison-Wesley. All rights reserved13 B-1 Chapter 13 (continued) Advanced Implementation of Tables.
Chapter 13 B Advanced Implementations of Tables – Balanced BSTs.
Chapter 5: Hashing Collision Resolution: Separate Chaining Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
Advanced Data Structure Hackson Leung
CS Data Structures II Review & Final Exam. 2 Topics Review Final Exam.
Hashing Sections 10.2 – 10.3 CS 302 Dr. George Bebis.
CSE221/ICT221 Analysis and Design of Algorithms CSE221/ICT221 Analysis and Design of Algorithms Analysis of Algorithm using Tree Data Structure Asst.Prof.
Can’t provide fast insertion/removal and fast lookup at the same time Vectors, Linked Lists, Stack, Queues, Deques 4 Data Structures - CSCI 102 Copyright.
CS223 Advanced Data Structures and Algorithms 1 Review for Midterm Neil Tang 03/06/2008.
HASHING PROJECT 1. SEARCHING DATA STRUCTURES Consider a set of data with N data items stored in some data structure We must be able to insert, delete.
Final Exam Review CS Total Points – 60 Points Writing Programs – 50 Points Tracing Algorithms, determining results, and drawing pictures – 50.
Hashing Chapter 7 Section 3. What is hashing? Hashing is using a 1-D array to implement a dictionary o This implementation is called a "hash table" Items.
Dictionaries CS /02/05 L7: Dictionaries Slide 2 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved.
CS102 – Data Structures Lists, Stacks, Queues, Trees & HashTables. David Davenport.
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
A Introduction to Computing II Lecture 11: Hashtables Fall Session 2000.
Review for Final Exam – cs411/511 Definitions (5 questions, 2 points each) Algorithm Analysis (3 questions, 3 points each) General Questions (3 questions,
Data Structure II So Pak Yeung Outline Review  Array  Sorted Array  Linked List Binary Search Tree Heap Hash Table.
Data Structures Chapter 6. Data Structure A data structure is a representation of data and the operations allowed on that data. Examples: 1.Array 2.Record.
Data Structure II. Outline Heap Binary Search Tree Hash Table Binary Indexed Tree Segment Tree.
CSS446 Spring 2014 Nan Wang.  to study trees and binary trees  to understand how binary search trees can implement sets  to learn how red-black trees.
Lecture 8 : Priority Queue Bong-Soo Sohn Assistant Professor School of Computer Science and Engineering Chung-Ang University.
ISOM MIS 215 Module 5 – Binary Trees. ISOM Where are we? 2 Intro to Java, Course Java lang. basics Arrays Introduction NewbieProgrammersDevelopersProfessionalsDesigners.
Data Structure & Algorithm Lecture 8 – Hashing JJCAO Most materials are stolen from Prof. Yoram Moses’s course.
CHAPTER 9 HASH TABLES, MAPS, AND SKIP LISTS ACKNOWLEDGEMENT: THESE SLIDES ARE ADAPTED FROM SLIDES PROVIDED WITH DATA STRUCTURES AND ALGORITHMS IN C++,
1 Hashing by Adlane Habed School of Computer Science University of Windsor May 6, 2005.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Exam 3 Review Data structures covered: –Hashing and Extensible hashing –Priority queues and binary heaps –Skip lists –B-Tree –Disjoint sets For each of.
Searching Tables Table: sequence of (key,information) pairs (key,information) pair is a record key uniquely identifies information, so no duplicate records.
 Saturday, April 20, 8:30-11:00am in B9201  Similar in style to written midterm exam  May include (a little) coding on paper  About 1.5 times as long.
Dictionaries CS 110: Data Structures and Algorithms First Semester,
CSC 2300 Data Structures & Algorithms March 13, 2007 Chapter 6. Priority Queues.
Nov 2, 2001CSE 373, Autumn Hash Table example marking deleted items + choice of table size.
Hashing Exercises.
CSE 326: Data Structures: Midterm Review
ADTs so far.
Advanced Implementation of Tables
Ch Hash Tables Array or linked list Binary search trees
Presentation transcript:

Computer Science Elementary Data Structures, Dictionaries CS 330: Algorithms Elementary Data Structures, Dictionaries Gene Itkis

Computer Science CS-330: Algorithms, Fall 2004Gene Itkis2 Primitive DS  Linked lists (singly- and doubly- linked)  “Stretchable”, efficient, but…  Sequential access  Arrays  Even more efficient, but not “stretchable”  Random Access

Computer Science CS-330: Algorithms, Fall 2004Gene Itkis3 Simple Data Structures SStacks llllast inserted QQueues ffffirst inserted PPriority Queues hhighest priority Methods for all:  isEmpty()  size()  insert()  insert(elem)  remove()  which element ?

Computer Science Dictionaries by key Search/Retrieve by key

Computer Science CS-330: Algorithms, Fall 2004Gene Itkis5 Dictionary Examples  Phone directory  Name is key; phone # is the info  Reverse lookup: phone # is key  Student records  Possible keys: name, ID#  Credit cards DB; PKI Certificate Revocation Lists (CRLs)  E.g. check that the given credit card / certificate is valid  Extra: “Authenticate” the result  ETC.

Computer Science CS-330: Algorithms, Fall 2004Gene Itkis6 Dictionary Interface  isEmpty()  size()  find(key)  insert()  insert(elem)  remove()  remove(key) Dynamic

Computer Science CS-330: Algorithms, Fall 2004Gene Itkis7 Implementations  Simple/naïve  Lists  Better implementations Hash Tables  Probabilistic methods, Expected values Ordered trees  “Good enough” approximations; Augmenting (  order stats )  Other Skip-lists

Computer Science CS-330: Algorithms, Fall 2004Gene Itkis8 Naïve: Lists  Unordered List  insert & delete  O(1) – fast  find  O(n) – slow  Ordered list  Linked-List  find & insert  O(n) – slow  Array  find O(lg n)  Binary search: O(lg n) – pretty fast  insert  O(n) – slow

Computer Science CS-330: Algorithms, Fall 2004Gene Itkis9 Ordered Trees  Order  x< y, z : min at root – heap (  )  y < x < z  y < x < z : search   Depth  Shallow  Balanced  There might be exceptions:  e.g., Leftist heaps  “Strong” balance  Approximate   E.g., depth of leaves within factor of 2 (R-B trees) heap x z y

Computer Science CS-330: Algorithms, Fall 2004Gene Itkis10 Ordered Trees  Searching  Easy  Insert/Delete  Naïve: destroys balance  Fix balance  How?  AVL trees Nodes keep children heights Rotate when needed: when children heights are >1 apart  Red-Black2-3-4  Red-Black / trees “Almost balanced”

Computer Science CS-330: Algorithms, Fall 2004Gene Itkis11 Hash tables  Example  Find professors by office number  Find tools in a tool-box  Might not work for everyone  Idea  “Figure” info location from the key

Computer Science CS-330: Algorithms, Fall 2004Gene Itkis12 Hash Tables: Idea  Hash function  H(key)=i  If it works…  find  O(1)  insert & delete  O(1)  Problem?  Collisions:  H(key’)=H(key) … … key H Hash table i key info key’

Computer Science CS-330: Algorithms, Fall 2004Gene Itkis13 Hash Table: Issues  Good Hash functions  Minimize collision chances  “Random looking”  Collision Resolution  Chaining  Open Addressing  Linear Probing: d=1  Quadratic Probing: d=i 2  Double Hashing: d=H2(key’) key info … … key H Hash table key’ key’ info key info key’ info d key” key” info d

Computer Science CS-330: Algorithms, Fall 2004Gene Itkis14 Collision Resolution Methods Comparison  Chaining  Requires extra space  As with linked list  Stretchable  Can degenerate to linked-list search  Open Addressing  No extra space needed   Has size limit  Also can degenerate to unordered list search  Perfect Hashing