Big O and Limits Abstract Data Types Data Structure Grand Tour. http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.

Similar documents
Data Structures. Jaehyun Park. CS 97SI Stanford University. June 29, 2015

Introduction to Data Structures

JAVA COLLECTIONS FRAMEWORK

Lecture 2: Data Structures Steven Skiena. skiena

This lecture. Abstract data types Stacks Queues. ADTs, Stacks, Queues Goodrich, Tamassia

CSE 326, Data Structures. Sample Final Exam. Problem Max Points Score 1 14 (2x7) 2 18 (3x6) Total 92.

Java Software Structures

Data Structures. Chapter 8

22c:31 Algorithms. Ch3: Data Structures. Hantao Zhang Computer Science Department

Common Data Structures

Data Structures in the Java API

1.00 Lecture 35. Data Structures: Introduction Stacks, Queues. Reading for next time: Big Java: Data Structures

Sequential Data Structures

1. The memory address of the first element of an array is called A. floor address B. foundation addressc. first address D.

CSE373: Data Structures and Algorithms Lecture 1: Introduction; ADTs; Stacks/Queues. Linda Shapiro Spring 2016

Cpt S 223. School of EECS, WSU

Data Structures and Algorithms Stacks and Queues

Binary Heaps. CSE 373 Data Structures

Linked Lists Linked Lists, Queues, and Stacks

1) The postfix expression for the infix expression A+B*(C+D)/F+D*E is ABCD+*F/DE*++

CompSci-61B, Data Structures Final Exam

Introduction to Data Structures and Algorithms

Sample Questions Csci 1112 A. Bellaachia

QUEUES. Primitive Queue operations. enqueue (q, x): inserts item x at the rear of the queue q

St S a t ck a ck nd Qu Q eue 1

Sorting revisited. Build the binary search tree: O(n^2) Traverse the binary tree: O(n) Total: O(n^2) + O(n) = O(n^2)

Collections in Java. Arrays. Iterators. Collections (also called containers) Has special language support. Iterator (i) Collection (i) Set (i),

I/O Management. General Computer Architecture. Goals for I/O. Levels of I/O. Naming. I/O Management. COMP755 Advanced Operating Systems 1

6 March Array Implementation of Binary Trees

Chapter 3: Restricted Structures Page 1

Data Structures and Algorithm Analysis (CSC317) Intro/Review of Data Structures Focus on dynamic sets

DATA STRUCTURE - QUEUE

Universidad Carlos III de Madrid

Algorithms and Data Structures

CS104: Data Structures and Object-Oriented Design (Fall 2013) October 24, 2013: Priority Queues Scribes: CS 104 Teaching Team

Quiz 4 Solutions EECS 211: FUNDAMENTALS OF COMPUTER PROGRAMMING II. 1 Q u i z 4 S o l u t i o n s

Home Page. Data Structures. Title Page. Page 1 of 24. Go Back. Full Screen. Close. Quit

Exam study sheet for CS2711. List of topics

Data Structures and Algorithms Written Examination

Questions 1 through 25 are worth 2 points each. Choose one best answer for each.

Hash Tables. Computer Science E-119 Harvard Extension School Fall 2012 David G. Sullivan, Ph.D. Data Dictionary Revisited

Class Overview. CSE 326: Data Structures. Goals. Goals. Data Structures. Goals. Introduction

The Java Collections Framework

Binary Search Trees. Data in each node. Larger than the data in its left child Smaller than the data in its right child

Practical Session 4 Java Collections

- Easy to insert & delete in O(1) time - Don t need to estimate total memory needed. - Hard to search in less than O(n) time

1/1 7/4 2/2 12/7 10/30 12/25

CmpSci 187: Programming with Data Structures Spring 2015

What is a Stack? Stacks and Queues. Stack Abstract Data Type. Java Interface for Stack ADT. Array-based Implementation

Why Use Binary Trees?

Krishna Institute of Engineering & Technology, Ghaziabad Department of Computer Application MCA-213 : DATA STRUCTURES USING C

CSE 2123 Collections: Sets and Iterators (Hash functions and Trees) Jeremy Morris

Stacks. Stacks (and Queues) Stacks. q Stack: what is it? q ADT. q Applications. q Implementation(s) CSCU9A3 1

5. A full binary tree with n leaves contains [A] n nodes. [B] log n 2 nodes. [C] 2n 1 nodes. [D] n 2 nodes.

Data Structures in Java. Session 15 Instructor: Bert Huang

PES Institute of Technology-BSC QUESTION BANK

Review of Hashing: Integer Keys

International Journal of Software and Web Sciences (IJSWS)

The Union-Find Problem Kruskal s algorithm for finding an MST presented us with a problem in data-structure design. As we looked at each edge,

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

MAX = 5 Current = 0 'This will declare an array with 5 elements. Inserting a Value onto the Stack (Push)

Symbol Tables. Introduction

Data Structure [Question Bank]

Data Structures and Data Manipulation

Linked Lists, Stacks, Queues, Deques. It s time for a chainge!

Lecture 9. Semantic Analysis Scoping and Symbol Table

CSE373: Data Structures & Algorithms Lecture 14: Hash Collisions. Linda Shapiro Spring 2016

DATA STRUCTURES USING C

Outline. The Stack ADT Applications of Stacks Array-based implementation Growable array-based stack. Stacks 2

1 of 1 24/05/ :23 AM

A binary search tree or BST is a binary tree that is either empty or in which the data element of each node has a key, and:

Data Structures Using C++

Chapter 7: Termination Detection

Queues and Stacks. Atul Prakash Downey: Chapter 15 and 16

Computer. Course Description

\Mankinds's progress is measured by the number of. Elementary data structures such as stacks, queues,

Binary Trees and Huffman Encoding Binary Search Trees

Timing of a Disk I/O Transfer

2. (a) Explain the strassen s matrix multiplication. (b) Write deletion algorithm, of Binary search tree. [8+8]

UIL Computer Science for Dummies by Jake Warren and works from Mr. Fleming

Data Structure and Algorithm I Midterm Examination 120 points Time: 9:10am-12:10pm (180 minutes), Friday, November 12, 2010

Module 2 Stacks and Queues: Abstract Data Types

INTERNATIONAL JOURNAL OF PURE AND APPLIED RESEARCH IN ENGINEERING AND TECHNOLOGY

Binary Heaps * * * * * * * / / \ / \ / \ / \ / \ * * * * * * * * * * * / / \ / \ / / \ / \ * * * * * * * * * *

Algorithms and Data Structures

Programming with Data Structures

Course: Programming II - Abstract Data Types. The ADT Queue. (Bobby, Joe, Sue, Ellen) Add(Ellen) Delete( ) The ADT Queues Slide Number 1

Chapter 8: Binary Trees

CS711008Z Algorithm Design and Analysis

Analysis of a Search Algorithm

Data Structures Using C++ 2E. Chapter 5 Linked Lists

Basic Programming and PC Skills: Basic Programming and PC Skills:

Atmiya Infotech Pvt. Ltd. Data Structure. By Ajay Raiyani. Yogidham, Kalawad Road, Rajkot. Ph : ,

Binary Heap Algorithms

CHAPTER 4 ESSENTIAL DATA STRUCTRURES

Class 32: The Java Collections Framework

Class Notes CS Creating and Using a Huffman Code. Ref: Weiss, page 433

Persistent Binary Search Trees

Transcription:

Big O and Limits Abstract Data Types Data Structure Grand Tour http://gcc.gnu.org/onlinedocs/libstdc++/images/pbds_different_underlying_dss_1.png

Consider the limit lim n f ( n) g ( n ) What does it say about asymptotic relationship between f and g if this limit is 0? finite and non-zero? infinite? Q5

Q6 1. n and n 2 2. log n and n (on these questions and solutions ONLY, let log n mean natural log) 3. n log n and n 2 4. log a n and log b n (a < b) 5. n a and a n (a > =1) 6. a n and b n (a < b) Recall l Hôpital s rule: under appropriate conditions, and:

What is data? What do we mean by structure?

A set of operations May be provided by the hardware (int and double) By software (java.math.biginteger) By software + hardware (int[])

A mathematical model of a data type Specifies: The type of data stored The operations supported Argument types and return types of these operations What each operation does, but not how

One special value: zero Three basic operations: succ pred iszero Derived operations include plus Sample rules: iszero(succ(n)) false pred(succ(n)) n plus(n, zero) n plus(n, succ(m)) succ(plus(n, m)) Q7

Application: how can you use that? Specification what is it? Implementation: How do you do that? CSSE220 CSSE230 Q8

Some review Some new All will appear again

Array List Array List Linked List Stack Queue Set Tree Set Hash Set Map Tree Map Hash Map Priority Queue Tree Graph Network Implementations for almost all of these are provided by the Java Collections Framework in the java.util package.

Size must be declared when the array is constructed Can look up or store items by index Example: nums[i+1] = nums[i] + 2; a a[0] a[1] a[2] a[i] L How is this done? a[n-2] a[n-1] Q9

A list is an ordered collection where elements may be added anywhere, and any elements may be deleted or replaced. Array List: Like an array, but growable and shrinkable. Linked List:

Operations Provided Array List Efficiency Linked List Efficiency Random access O(1) O(n) Add/remove item O(n) O(1) Q10

A last-in, first-out (LIFO) data structure Real-world stacks Plate dispensers in the cafeteria Pancakes! Some uses: Tracking paths through a maze Providing unlimited undo in an application Operations Provided Push item Pop item Efficiency O(1) O(1) Implemented by Stack, LinkedList, and ArrayDeque in Java

first-in, first-out (FIFO) data structure Real-world queues Waiting line at the BMV Character on Star Trek TNG Some uses: Scheduling access to shared resource (e.g., printer) Operations Provided Enqueue item Dequeue item Efficiency O(1) O(1) Implemented by LinkedList and ArrayDeque in Java

Q10-14 A collection of items without duplicates (in general, order does not matter) If a and b are both in set, then!a.equals(b) Real-world sets: Students Collectibles One possible use: Quickly checking if an item is in a collection Example from 220 Operations HashSet TreeSet Add/remove item O(1) O(log n) Contains? O(1) O(log n) Can hog space Sorts items!

How is a TreeMap like a TreeSet? How is it different? Associate keys with values Real-world maps Dictionary Phone book Some uses: Associating student ID with transcript Associating name with high scores Operations HashMap TreeMap Insert key-value pair O(1) O(log n) Look up the value associated O(1) O(log n) with a given key Can hog space Sorts items by key!

Not like regular queues! Each item stored has an associated priority Only item with minimum priority is accessible Operations: insert, findmin, deletemin Real-world priority queue : Airport ticketing counter Some uses Simulations Scheduling in an OS Huffman coding The version in Warm Up and Stretching isn t this efficient. Operations Efficiency Provided Insert O(log n) Find Min O(log n) Delete Min O(log n) Q15

Collection of nodes One specialized node is the root. A node has one parent (unless it is the root) A node has zero or more children. Real-world trees : Organizational hierarchies Some family trees Some uses: Directory structure on a hard drive Sorted collections Operations Provided Only if tree is balanced Efficiency Find O(log n) Add/remove O(log n)

A collection of nodes and edges Each edge joins two nodes Edges can be directed or undirected Real-world graph : Road map Some uses: Tracking links between web pages Facebook Operations Provided Find Efficiency O(n) Add/remove O(1) or O(n) or O(n 2 ) Depends on implementation (time/space trade off)

Graph whose edges have numeric labels Examples (labels): Road map (mileage) Airline's flight map (flying time) Plumbing system (gallons per minute) Computer network (bits/second) Famous problems: Shortest path Maximum flow Minimal spanning tree Traveling salesman Four-coloring problem for planar graphs

Array List Array List Linked List Stack Queue Set Tree Set Hash Set Map Tree Map Hash Map Priority Queue Tree Graph Network We ll implement and use nearly all of these, some multiple ways. And a few other data structures.

Structure find insert/remove Comments Array O(n) can't do it Constant-time access by position Stack top only top only Easy to implement as an array. O(1) O(1) Queue front only O(1) insert rear, remove front. O(1) ArrayList O(log N) O(N) Constant-time access by position Linked List O(n) O(1) O(N) to find insertion position. HashSet/Map O(1) O(1) If table not very full TreeSet/Map O(log N) O(log N) Kept in sorted order PriorityQueue O(log N) O(log N) Can only find/remove smallest Tree O(log N) O(log N) If tree is balanced Graph O(N*M)? O(M)? N nodes, M edges Network shortest path, maxflow Q16-17

If we have time left Make progress on Warm Up and Stretching problems Get help as needed, especially with Eclipse and SVN issues Work on WA2 if you have finished WarmUpAndStretching