Data Structures and Database Applications Dictionaries in C#

Slides:



Advertisements
Similar presentations
Data Structures and Collections
Advertisements

Computer Science 112 Fundamentals of Programming II Overview of Collections.
FEN 2012UCN Technology - Computer Science 1 Data Structures and Collections Principles revisited.NET: –Two libraries: System.Collections System.Collections.Generics.
CS212: DATA STRUCTURES Lecture 10:Hashing 1. Outline 2  Map Abstract Data type  Map Abstract Data type methods  What is hash  Hash tables  Bucket.
111 © 2002, Cisco Systems, Inc. All rights reserved.
LECTURE 36: DICTIONARY CSC 212 – Data Structures.
Data structures Abstract data types Java classes for Data structures and ADTs.
1 Joe Meehean.  List of names  Set of names  Map names as keys phone #’s as values Phil Bill Will Phil Bill Will Phil Bill Will Phil: Bill:
Building Java Programs Bonus Slides Hashing. 2 Recall: ADTs (11.1) abstract data type (ADT): A specification of a collection of data and the operations.
1 DATABASE TECHNOLOGIES (Part 2) BUS Abdou Illia, Fall 2015 (September 9, 2015)
Hash Tables ADT Data Dictionary, with two operations – Insert an item, – Search for (and retrieve) an item How should we implement a data dictionary? –
1 Principles revisited.NET: Two libraries: System.Collections System.Collections.Generics Data Structures and Collections.
9/27/2016IT 1791 Abstraction A tool (concept) to manage complexity Hide irrelevant details; focus on the features needed Primitive date types are already.
CS203 Lecture 14. Hashing An object may contain an arbitrary amount of data, and searching a data structure that contains many large objects is expensive.
Introduction toData structures and Algorithms
Slides by Donald W. Smith
Using the Java Collection Libraries COMP 103 # T2
Chapter 27 Hashing Jung Soo (Sue) Lim Cal State LA.
11 Map ADTs Map concepts. Map applications.
Data Structure By Amee Trivedi.
Fundamentals of Programming II Overview of Collections
September 29 – Stacks and queues
Now with a speaking professor! (hopefully...)
Abstraction A tool (concept) to manage complexity
Hashing - Hash Maps and Hash Functions
JAVA COLLECTIONS LIBRARY
JAVA COLLECTIONS LIBRARY
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
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.
JCF Hashmap & Hashset Winter 2005 CS-2851 Dr. Mark L. Hornick.
Data Structures and Database Applications Abstract Data Types
Data Structures and Database Applications Hashing and Hashtables in C#
Road Map CS Concepts Data Structures Java Language Java Collections
Data Structures and Database Applications Queues in C#
structures and their relationships." - Linus Torvalds
Chapter 28 Hashing.
CS313D: Advanced Programming Language
Database Linked List Representation
structures and their relationships." - Linus Torvalds
Data Structures and Database Applications Stacks in C#
Data Structures and Algorithms
Sets (11.2) set: A collection of unique values (no duplicates allowed) that can perform the following operations efficiently: add, remove, search (contains)
Data Structures and Database Applications Hashing and Hashtables in C#
Chapter 21 Hashing: Implementing Dictionaries and Sets
Lesson 6. Types Equality and Identity. Collections.
CSE 373: Data Structures and Algorithms
CSE 373 Data Structures and Algorithms
CSE 373: Data Structures and Algorithms
Hash Tables Chapter 12 discusses several ways of storing information in an array, and later searching for the information. Hash tables are a common.
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.
CS2110: Software Development Methods
CH 9 : Maps And Dictionary
Sets (11.2) set: A collection of unique values (no duplicates allowed) that can perform the following operations efficiently: add, remove, search (contains)
Hash Tables Chapter 12 discusses several ways of storing information in an array, and later searching for the information. Hash tables are a common.
How to use hash tables to solve olympiad problems
CSE 373 Separate chaining; hash codes; hash maps
Hash Tables By JJ Shepherd.
slides created by Marty Stepp
Fundaments of Game Design
slides created by Marty Stepp
CS210- Lecture 16 July 11, 2005 Agenda Maps and Dictionaries Map ADT
CS 240 – Advanced Programming Concepts
CO4301 – Advanced Games Development Week 12 Using Trees
structures and their relationships." - Linus Torvalds
Week 6 - Monday CS221.
Dictionary.
Chengyu Sun California State University, Los Angeles
Dictionaries and Hash Tables
Presentation transcript:

Data Structures and Database Applications Dictionaries in C#

Dictionary Overview System.Collections.Generic.Dictionary Automatic resizing and homogeneous, unordered list Represents a collection of key-value pairs

The Dictionary ADT A dictionary is a data structure that stores entries. Each entry contains two parts: a key and a value. The value can be any data type. The key is usually an integer, but it doesn’t have to be. It can be any type of value that has a Hash Function which can convert it to a number. x[key] = value; v[14] = "Another Thing“; w["first"] = "Something“; We will discuss Hash Functions in more details in the next unit, however, for now you just need to know that a string can be converted to a number using a Hash Function.

The Dictionary ADT The key in the key value pair is also called a search key, which is used to search for the corresponding value. For example, a dictionary can be stored in a data structure where the words are the keys and the definitions of the words are the values, just like the analogous Webster’s Dictionary.

The Dictionary ADT A dictionary data structure can also be referred to in other applications as a map, an associative array, or a hash table. With a dictionary you essentially map entries to key values that will be useful to use when you need to locate a specific entry later. A numeric index is used in this way for an array, but something more complicated might be needed. For instance, if you have a set of people from a neighborhood in your dictionary, a string representing the Street Address might be used as the key. Each key must be unique to a single entry value in the dictionary.

Creating and Traversing a Dictionary Example: Dictionary<string, string> openWith = new Dictionary<string, string>(); openWith.Add("txt", "notepad.exe"); openWith.Add("bmp", "paint.exe"); openWith.Add("dib", "paint.exe"); openWith.Add("rtf", "wordpad.exe"); try { openWith.Add("txt", "winword.exe"); } catch (ArgumentException) { Console.WriteLine("An element with Key = \"txt\" already exists."); } if (openWith.ContainsKey("bmp")) { Console.WriteLine("\nbmp is opened with {0}\n", openWith["bmp"]); foreach (KeyValuePair<string, string> item in openWith) { Console.WriteLine("Key: {0}, Value: {1}", item.Key, item.Value);

Creating and Traversing a Dictionary The previous code prints out the following: An element with Key = "txt" already exists. bmp is opened with paint.exe Key: txt, Value: notepad.exe Key: bmp, Value: paint.exe Key: dib, Value: paint.exe Key: rtf, Value: wordpad.exe

Common C# Dictionary Methods Add() ContainsKey() ContainsValue() Remove() Clear()

Dictionary Database Implementation To create an efficient Database implementation of a Dictionary we will continue using the Tables we created for Stacks, Queues and LinkedLists operations. We shall also add a new table called the DLists Table which will have a string Key field and an EntryID field for a DList entry. Although the Key field will always be a string in this case, the EntryID field in the DList entry could point to an Entry of any type of data in theory, but for now, just to Entries of Names, Phones and Emails.

Dictionary Database Implementation The DLists Table:

Dictionary Database Implementation The entity name the new table will be bound to is db5, like so:

Dictionary Database Implementation Using db5, the following method gets a normal Entry from the DList Table for a given key:

Dictionary Database Implementation Using db5, this method adds or replaces an Entry in the DList Table for a given key:

Dictionary Database Implementation Using db5, this method removes an Entry in the DList Table for a given key: