Data Structures and Collections

Slides:



Advertisements
Similar presentations
Transparency No. 1 Java Collection API : Built-in Data Structures for Java.
Advertisements

Lists, Stacks, Queues Svetlin Nakov Telerik Corporation
Generics, Lists, Interfaces
Dictionaries, Hash Tables, Collisions Resolution, Sets Svetlin Nakov Telerik Corporation
Fun with Lists for the Novice and Expert Scott Reed Brain Hz Software (760)
Collections Chapter Java Collection Frameworks The Java collection framework is a set of utility classes and interfaces. Designed for working with.
1 Generic Collections Chapter Objectives You will be able to Use generic collection classes available in the.NET framework.
Collections Framework A very brief look at Java’s Collection Framework David Davenport May 2010.
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
 2006 Pearson Education, Inc. All rights reserved Collections.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L16 (Chapter 22) Java Collections.
Collections. 2 Objectives Explore collections in System.Collections namespace –memory management –containment testing –sorting –traversal.
C# Programming: From Problem Analysis to Program Design1 Advanced Collections C# Programming: From Problem Analysis to Program Design 3 rd Edition 8.
Chapter 19 Java Data Structures
Java Collections. Collections, Iterators, Algorithms CollectionsIteratorsAlgorithms.
CSE373 Optional Section Java Collections 11/12/2013 Luyi Lu.
Collection types Collection types.
SEG4110 – Advanced Software Design and Reengineering TOPIC G Java Collections Framework.
FEN 2012UCN Technology - Computer Science 1 Data Structures and Collections Principles revisited.NET: –Two libraries: System.Collections System.Collections.Generics.
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Chapter 22 Java Collections.
Java™ How to Program, 9/e Presented by: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Dictionaries, Hash Tables, Hashing, Collisions, Sets Svetlin Nakov Telerik Software Academy academy.telerik.com Technical Trainer
1 Java's Collection Framework By Rick Mercer with help from The Java Tutorial, The Collections Trail, by Joshua BlockThe Collections Trail.
Jan 12, 2012 Introduction to Collections. 2 Collections A collection is a structured group of objects Java 1.2 introduced the Collections Framework Collections.
Data structures and algorithms in the collection framework 1 Part 2.
111 © 2002, Cisco Systems, Inc. All rights reserved.
CSS446 Spring 2014 Nan Wang.  Java Collection Framework ◦ Set ◦ Map 2.
Generics Collections. Why do we need Generics? Another method of software re-use. When we implement an algorithm, we want to re-use it for different types.
Object Oriented Programming Ders 10: Data Structures Mustafa Emre İlal
Session 08 Module 14: Generics and Iterator Module 15: Anonymous & partial class & Nullable type.
Chapter 18 Java Collections Framework
Evolution of.NET Collections (C#) Chen Dong
תוכנה 1 תרגול 8 – מבני נתונים גנריים. 2 Java Collections Framework Collection: a group of elements Interface Based Design: Java Collections Framework.
Data structures and algorithms in the collection framework 1.
Generics Collections. Why do we need Generics? Another method of software re-use. When we implement an algorithm, we want to re-use it for different types.
Data Structures academy.zariba.com 1. Lecture Content 1.Linear Data Structures 2.Trees and Graphs* 3.Dictionaries and Hash Tables 4.Homework 2.
Interface: (e.g. IDictionary) Specification class Appl{ ---- IDictionary dic; dic= new XXX(); application class: Dictionary SortedDictionary ----
Collections Data structures in Java. OBJECTIVE “ WHEN TO USE WHICH DATA STRUCTURE ” D e b u g.
Computational Complexity of Fundamental Data Structures, Choosing a Data Structure.
Ordered Linked Lists using Abstract Data Types (ADT) in Java Presented by: Andrew Aken.
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
C# Collections & Generics C#.NET Software Development Version 1.0.
Session 07 Module 13 - Collections. Collections / Session 7 / 2 of 32 Review  A delegate in C# is used to refer to a method in a safe manner.  To invoke.
Dictionaries, Hash Tables, Collisions Resolution, Sets Svetlin Nakov Telerik Corporation
Data Structures and Collections Principles.NET: –Two libraries: System.Collections System.Collections.Generics FEN 2014UCN Teknologi/act2learn1 Deprecated.
1 Java's Collection Framework Map and Sets. 2 Collection Framework  A collections framework is a unified architecture for representing and manipulating.
1 Principles revisited.NET: Two libraries: System.Collections System.Collections.Generics Data Structures and Collections.
Collections Dwight Deugo Nesa Matic
3-1 Java's Collection Framework Another use of polymorphism and interfaces Rick Mercer.
Chapter  Array-like data structures  ArrayList  Queue  Stack  Hashtable  SortedList  Offer programming convenience for specific access.
C# Collections & Generics
Module 5: Programming with C#. Overview Using Arrays Using Collections Using Interfaces Using Exception Handling Using Delegates and Events.
CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics Advanced.NET Programming I 2 nd Lecture Pavel Ježek
Computing with C# and the .NET Framework
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.
Collections 24: Collections Programming C# © 2003 DevelopMentor, Inc.
Data Structures and Database Applications Abstract Data Types
Road Map CS Concepts Data Structures Java Language Java Collections
structures and their relationships." - Linus Torvalds
CS313D: Advanced Programming Language
Lesson 6. Types Equality and Identity. Collections.
Fundaments of Game Design
CS 240 – Advanced Programming Concepts
structures and their relationships." - Linus Torvalds
Presentation transcript:

Data Structures and Collections Principles .NET: System.Collections System.Collections.Generics Generics

Data Structures and Collections Read and write (use) specifications Data structure and algorithms Choose and use an adt, e.g. Map application ADT class: HashMap TreeMap ---- class Appl{ ---- Map m; ----- m= new XXXMap(); interface: (e.g. Map) Specification Choose and use a data structure, e.g. TreeMap Know about

Overview Algorithms: Data structures: Abstract data types: search sweep sorting divide & conquer recursion Data structures: static/dynamic array linked list trees: Search trees balanced hashing Abstract data types: lists/sequenses stack queue Table/Map/Dictionary Java-specific: Collections (generics) Collection Set List Map .NET-specific: Collections.Generics IDictionary IList

Collections Library System.Collections Data structures in .NET are normally called Collections Are found in namespace System.Collections Compiled into mscorlib.dll assembly Uses object and polymorphism for generic containers. Deprecated! Classes: Array ArrayList Hashtable Stack Queue

Collection Interfaces System.Collections implements a range of different interfaces in order to provide standard usage of different containers Classes that implements the same interface provides the same services Makes it easier to learn and to use the library Makes it possible to write generic code towards the interface Interfaces: ICollection IEnumerable IEnumerator IList IComparer IComparable

ArrayList ArrayList stores sequences of elements. duplicate values are ok – position- (index-) based Elements are stored in an resizable array. Implements the IList interface public class ArrayList : IList, IEnumerable, ... { // IList services ... // additional services int Capacity { get... set... } void TrimToSize() int BinarySearch(object value) int IndexOf (object value, int startIndex) int LastIndexOf (object value, int startIndex) } control of memory in underlying array searching

read/write existing element IList Interface 9. The FCL January 2003 IList defineres sequences of elements Access through index public interface IList : ICollection { int Add (object value); void Insert(int index, object value); void Remove (object value); void RemoveAt(int index); void Clear (); bool Contains(object value); int IndexOf (object value); object this[int index] { get; set; } bool IsReadOnly { get; } bool IsFixedSize { get; } } add new elements remove containment testing read/write existing element (see comment) C# supports class members called "indexers", which you see above: object this[int index] { get; set; ] Indexers are properties with an array-like syntax: collection[index] = value; // call to set .NET makes heavy use of indexers… structural properties Denmark .NET Workshop © 2003 Joe Hummel 7

Hashtable Hashtable supports collections of key/value pairs keys must be unique, values holds any data stores object references at key and value GetHashCode method on key determine position in the table. create Hashtable ages = new Hashtable(); ages["Ann"] = 27; ages["Bob"] = 32; ages.Add("Tom", 15); ages["Ann"] = 28; int a = (int) ages["Ann"]; add update retrieve

Hashtable Traversal Traversal of Hashtable each element is of type DictionaryEntry (struct) data is accessed using the Key and Value properties Hashtable ages = new Hashtable(); ages["Ann"] = 27; ages["Bob"] = 32; ages["Tom"] = 15; foreach (DictionaryEntry entry in ages) { string name = (string) entry.Key; int age = (int) entry.Value; ... } enumerate entries get key and value

.NET 2: System.Collections.Generics (key, value) -pair ICollection<T> IList<T> LinkedList<T> IDictionary<TKey, TValue> List<T> SortedDictionary<TKey, TValue> Dictionary <TKey, TValue> Index able Array-based Balanced search tree Hashtabel

Forskellige implememteringer ArrayList vs. LinkedList: ArrayList: Direkte access på index Statisk memory allokering Bøvlet indsæt og slet i midten LinkedList: Dynamisk memory allokering Kun sekventiel adgang Se eksempel: demos\lists

Forskellige implememteringer HashTable vs. SortedDictionary: Hashtable: Statisk memory allokering Meget hurtig i gennemsnit (konstant, men memory overhead)) Meget dårlig i worst case (linær) Nondeterministisk SortedDictionary: Dynamisk memory allokering Meget hurtig i worst case (logaritmisk) Se eksempel: demos\hashTest

Opgave Undersøg System.Collections.Generics