Data Structures academy.zariba.com 1. Lecture Content 1.Linear Data Structures 2.Trees and Graphs* 3.Dictionaries and Hash Tables 4.Homework 2.

Slides:



Advertisements
Similar presentations
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:
Advertisements

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.
Topological Sort and Hashing
Hashing Techniques.
Maps, Dictionaries, Hashtables
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
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.
CS102 – Data Structures Lists, Stacks, Queues, Trees, Hash Collections Framework David Davenport Spring 2002.
CS 104 Introduction to Computer Science and Graphics Problems Data Structure & Algorithms (4) Data Structures 11/18/2008 Yang Song.
Tirgul 8 Universal Hashing Remarks on Programming Exercise 1 Solution to question 2 in theoretical homework 2.
Course Review COMP171 Spring Hashing / Slide 2 Elementary Data Structures * Linked lists n Types: singular, doubly, circular n Operations: insert,
The Most Commonly-used Data Structures
Data Structures, Spring 2004 © L. Joskowicz 1 DAST – Final Lecture Summary and overview What we have learned. Why it is important. What next.
© 2006 Pearson Addison-Wesley. All rights reserved13 B-1 Chapter 13 (excerpts) Advanced Implementation of Tables CS102 Sections 51 and 52 Marc Smith and.
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.
Lists, Stacks, Queues Svetlin Nakov Telerik Corporation
C o n f i d e n t i a l HOME NEXT Subject Name: Data Structure Using C Unit Title: Graphs.
Maps A map is an object that maps keys to values Each key can map to at most one value, and a map cannot contain duplicate keys KeyValue Map Examples Dictionaries:
Instructor: Dr. Sahar Shabanah Fall Lectures ST, 9:30 pm-11:00 pm Text book: M. T. Goodrich and R. Tamassia, “Data Structures and Algorithms in.
Compiled by: Dr. Mohammad Alhawarat BST, Priority Queue, Heaps - Heapsort CHAPTER 07.
FEN 2012UCN Technology - Computer Science 1 Data Structures and Collections Principles revisited.NET: –Two libraries: System.Collections System.Collections.Generics.
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.
Introduction to Data Structures. Definition Data structure is representation of the logical relationship existing between individual elements of data.
Chapter 3 List Stacks and Queues. Data Structures Data structure is a representation of data and the operations allowed on that data. Data structure is.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Computer Science Department Data Structures and Algorithms Lecture 1.
0 Course Outline n Introduction and Algorithm Analysis (Ch. 2) n Hash Tables: dictionary data structure (Ch. 5) n Heaps: priority queue data structures.
Brought to you by Max (ICQ: TEL: ) February 5, 2005 Advanced Data Structures Introduction.
Java Collections An Introduction to Abstract Data Types, Data Structures, and Algorithms David A Watt and Deryck F Brown © 2001, D.A. Watt and D.F. Brown.
IT 60101: Lecture #151 Foundation of Computing Systems Lecture 15 Searching Algorithms.
Hashing Chapter 20. Hash Table A hash table is a data structure that allows fast find, insert, and delete operations (most of the time). The simplest.
© 2006 Pearson Addison-Wesley. All rights reserved13 B-1 Chapter 13 (continued) Advanced Implementation of Tables.
Advanced Data Structure Hackson Leung
Chapter 9 (modified) Abstract Data Types and Algorithms Nell Dale John Lewis.
Chapter 9 Abstract Data Types and Algorithms Nell Dale John Lewis.
DATA STRUCTURES & C# GENERICS Trent Spangler | Greg Phelps.
Review for Final Andy Wang Data Structures, Algorithms, and Generic Programming.
HIT2037- HIT6037 Software Development in Java 22 – Data Structures and Introduction.
CS Data Structures II Review & Final Exam. 2 Topics Review Final Exam.
Correction of quizzes. ADTs and implementations Hash tables Graphs.
CS 206 Introduction to Computer Science II 11 / 16 / 2009 Instructor: Michael Eckmann.
Hashing 8 April Example Consider a situation where we want to make a list of records for students currently doing the BSU CS degree, with each.
Ihab Mohammed and Safaa Alwajidi. Introduction Hash tables are dictionary structure that store objects with keys and provide very fast access. Hash table.
Tirgul 11 Notes Hash tables –reminder –examples –some new material.
Computational Complexity of Fundamental Data Structures, Choosing a Data Structure.
A Introduction to Computing II Lecture 11: Hashtables Fall Session 2000.
Hashtables. An Abstract data type that supports the following operations: –Insert –Find –Remove Search trees can be used for the same operations but require.
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.
Hashing 1 Hashing. Hashing 2 Hashing … * Again, a (dynamic) set of elements in which we do ‘search’, ‘insert’, and ‘delete’ n Linear ones: lists, stacks,
Week 10 - Friday.  What did we talk about last time?  Graph representations  Adjacency matrix  Adjacency lists  Depth first search.
Dictionaries, Hash Tables, Collisions Resolution, Sets Svetlin Nakov Telerik Corporation
Advanced Data Structure By Kayman 21 Jan Outline Review of some data structures Array Linked List Sorted Array New stuff 3 of the most important.
Data Structures and Collections Principles.NET: –Two libraries: System.Collections System.Collections.Generics FEN 2014UCN Teknologi/act2learn1 Deprecated.
Week 15 – Wednesday.  What did we talk about last time?  Review up to Exam 1.
Data-structure-palooza Checkout DataStructures from SVN.
CSCI 383 Object-Oriented Programming & Design Lecture 25 Martin van Bommel.
1 Principles revisited.NET: Two libraries: System.Collections System.Collections.Generics Data Structures and Collections.
Chapter 9 Abstract Data Types and Algorithms Nell Dale John Lewis.
CSC 212 – Data Structures Lecture 28: More Hash and Dictionaries.
Set Collection A Bag is a general collection class that implements the Collection interface. A Set is a collection that resembles a Bag with the provision.
COMP 53 – Week Eleven Hashtables.
Week 11 - Friday CS221.
Hashing Exercises.
structures and their relationships." - Linus Torvalds
structures and their relationships." - Linus Torvalds
Lesson 6. Types Equality and Identity. Collections.
structures and their relationships." - Linus Torvalds
Lecture-Hashing.
Presentation transcript:

Data Structures academy.zariba.com 1

Lecture Content 1.Linear Data Structures 2.Trees and Graphs* 3.Dictionaries and Hash Tables 4.Homework 2

3 Linear Data Types – Array Revision Can you remember what is specific for the arrays in.Net?

4 Linear Data Types – List Revision Can you remember what is specific for List in.Net?

5 Linear Data Types – Linked List LinkedList is an alternative way of implement a List. It has its advantages and disadvantages over the regular List.

6 Linear Data Types – Linked List Advantages Disadvantages Click here

7 Linear Data Types – Stack Stack is another useful linear data structure. You can add and remove elements only from the “top” (the bucked). It can be implemented in two ways – similarly to the list.

8 Linear Data Types – Queue The Queue data structure is self-explanatory from it’s name. You add elements to the “top” and remove them from the bottom (same as the queue at the store). It can be implemented in two ways – similarly to the list.

9 Non-Linear Data Structures - Graphs There is a really good workshop that you should look at. We implement Graphs with C# from scratch. It is a workshop from the second course – Introduction to Graph Theory – Hacking Wordz. Take a look at that one.

10 Non-Linear Data Structures - Tree The tree is a type of Graph. Generally speaking, when you imeplement a tree, you can inherit the Graph Class and go from there, but there is a simpler way to implement trees in general. A tree has a bunch of vertices connected to each other. Each vertex has a single parent and children nodes. The vertex at the “top” of the tree has no parent and is called a root.

11 Non-Linear Data Structures - Tree Balanced binary search trees are useful. How many steps would it take to find a specific value?

12 Dictionary A Dictionary maps keys to values. It contains a set of (key,value) pairs. The operations are Add(key, value) FindByKey(key) -> value Delete(key)

13 Hash Table Hash Tables are NOT dictionaries. You can implement a Dictionary in many ways and one of them is with the use of a Hash Table A hash table is an array that holds a set of (key, value) pairs, along with a hashing function which maps keys to a specific position in the array. The hash function takes values as keys and transforms them into a number (0,1,…, n-1) where n is Is the number of elements we have. Whenever you increase the size of the array, you always have to rehash.

14 Hashing functions There are no perfect hash functions -> h(k) is one-to-one mapping of every key in the range {0,1,2,…, n-1}, i.e. h(k1) could be the same as h(k2). A hash function normally maps most of the keys in to unique integers, but not all. A collision is where two keys have the same hash value, i.e. h(k1)=h(k2) where k1 is different from k2. There are different ways to handle collisions: chaining in a list, using the neighbouring slots, re-hashing, among others.

15 Collisions with LinkedList

16 Collisions with Neighbours Collisions with neighbours (linear probing) is done as follows:

17 Hash Tables and Efficiency Using Hash Tables to implement a dictionary is the most efficient way. The functions Add, Remove and Find have a constant complexity O(1). In a standard Dictionary the order in which you add elements is not necessarily the way you get them (foreach loop for example). The elements in a Dictionary a random order. There are also Sorted Dictionaries which use Balanced Trees for their implementation.

18 Homework 1.) Finish the implementation of the Linked List with the following methods: AddFirst, AddBefore, AddAfter, Remove, Count, Contains and Clear (as given in the Link in the presentation) 2.) Implement generic classes Stack and Queue. You can choose which method to use (resizeable array or similarly to LinkedList) Stack Methods: Peek(), Pop(), Push(), Count(), Contains(), Clear() Queue Methods: Clear(), Count(), Contains, Enqueue(), Dequeue(), Peek() 3.) Inside the Tree class, implement BFS and DFS. Test it with a tree of your choice (sufficiently large). 4.)* Download the Graph Theory Demo and implement a minimum spanning tree algorithm by Kruskal (the algorithm is easy but you will need to understand the original code written in lectures). Test it with a sufficiently large Graph. 5.)* Implement a simple Hash-Table, using the LinkedList method for collisions 6.)** If you are feeling adventurous, try handling collisions with linear probing

19 References

20 Zariba Academy Questions