CS321 Data Structures Jan 15 2016 Lecture 2 Introduction.

Slides:



Advertisements
Similar presentations
MATH 224 – Discrete Mathematics
Advertisements

The Efficiency of Algorithms Chapter 4 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
Lecture3: Algorithm Analysis Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
CMPT 225 Sorting Algorithms Algorithm Analysis: Big O Notation.
Review. What to know You are responsible for all material covered in lecture, the readings, or the programming assignments There will also be some questions.
What is an Algorithm? (And how do we analyze one?)
Stacks.
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
CS 206 Introduction to Computer Science II 10 / 14 / 2009 Instructor: Michael Eckmann.
Course Review COMP171 Spring Hashing / Slide 2 Elementary Data Structures * Linked lists n Types: singular, doubly, circular n Operations: insert,
Computer Science 2 Data Structures and Algorithms V section 2 Intro to “big o” Lists Professor: Evan Korth New York University 1.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
Elementary Data Structures and Algorithms
1 ES 314 Advanced Programming Lec 2 Sept 3 Goals: Complete the discussion of problem Review of C++ Object-oriented design Arrays and pointers.
DAST, Spring © L. Joskowicz 1 Data Structures – LECTURE 1 Introduction Motivation: algorithms and abstract data types Easy problems, hard problems.
Cmpt-225 Simulation. Application: Simulation Simulation  A technique for modeling the behavior of both natural and human-made systems  Goal Generate.
Chapter 1 Introduction Definition of Algorithm An algorithm is a finite sequence of precise instructions for performing a computation or for solving.
Computer Science 2 Data Structures and Algorithms V Intro to “big o” Lists Professor: Evan Korth New York University 1.
DATA STRUCTURE Subject Code -14B11CI211.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Abstract Data Types (ADTs) Data Structures The Java Collections API
CSCE 3110 Data Structures & Algorithm Analysis Binary Search Trees Reading: Chap. 4 (4.3) Weiss.
Comp 249 Programming Methodology Chapter 15 Linked Data Structure - Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
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.
Program Performance & Asymptotic Notations CSE, POSTECH.
Week 2 CS 361: Advanced Data Structures and Algorithms
Analysis CS 367 – Introduction to Data Structures.
Data Structures and Algorithms Lecture 5 and 6 Instructor: Quratulain Date: 15 th and 18 th September, 2009 Faculty of Computer Science, IBA.
IKI 10100: Data Structures & Algorithms Ruli Manurung (acknowledgments to Denny & Ade Azurat) 1 Fasilkom UI Ruli Manurung (Fasilkom UI)IKI10100: Lecture8.
Unit III : Introduction To Data Structures and Analysis Of Algorithm 10/8/ Objective : 1.To understand primitive storage structures and types 2.To.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 19: Searching and Sorting Algorithms.
Chapter 19: Searching and Sorting Algorithms
Jessie Zhao Course page: 1.
L. Grewe.  An array ◦ stores several elements of the same type ◦ can be thought of as a list of elements: int a[8]
Complexity of Algorithms
CSE332: Data Abstractions Lecture 8: Memory Hierarchy Tyler Robison Summer
Pointers OVERVIEW.
CSC 211 Data Structures Lecture 13
Data Structure Introduction.
Robustness and speed Prof. Noah Snavely CS1114
1 CS 177 Week 12 Recitation Slides Running Time and Performance.
Chapter 18: Searching and Sorting Algorithms. Objectives In this chapter, you will: Learn the various search algorithms Implement sequential and binary.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Review 1 Arrays & Strings Array Array Elements Accessing array elements Declaring an array Initializing an array Two-dimensional Array Array of Structure.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
CS 361 – Chapter 5 Priority Queue ADT Heap data structure –Properties –Internal representation –Insertion –Deletion.
Searching Topics Sequential Search Binary Search.
2005MEE Software Engineering Lecture 7 –Stacks, Queues.
Week 13 - Wednesday.  What did we talk about last time?  NP-completeness.
Program Performance 황승원 Fall 2010 CSE, POSTECH. Publishing Hwang’s Algorithm Hwang’s took only 0.1 sec for DATASET1 in her PC while Dijkstra’s took 0.2.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
CSE373: Data Structures & Algorithms Lecture 5: Dictionary ADTs; Binary Trees Lauren Milne Summer 2015.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
LECTURE 22: BIG-OH COMPLEXITY CSC 212 – Data Structures.
COMP 53 – Week Fourteen Trees.
Analysis of Algorithms
Introduction to Analysis of Algorithms
Introduction to complexity
Analysis of Algorithms
Introduction to Algorithms
DATA STRUCTURES AND OBJECT ORIENTED PROGRAMMING IN C++
Introduction to Algorithms
Algorithm Analysis CSE 2011 Winter September 2018.
Cse 373 April 26th – Exam Review.
Algorithm An algorithm is a finite set of steps required to solve a problem. An algorithm must have following properties: Input: An algorithm must have.
Analysis of Algorithms
PAC Intro to “big o” Lists Professor: Evan Korth New York University
Amortized Analysis and Heaps Intro
Analysis of Algorithms
Presentation transcript:

CS321 Data Structures Jan Lecture 2 Introduction

Topics Take Attendance Assignment #1 General Ideas behind Data Structures

Assignment #1 Implement a Two Level Cache for words. Due Friday Jan 23 rd 11:00PM

Primary Notation Types O(n) = Asymptotic upper bound. Longest Ω(n) = Asymptotic lower bound. Quickest. Θ(n) = Both lower and upper bound. *side note these are capital greek letters, hence ‘Big O’.

Find Item in Linked List Have a list of N strings. Want to see if the string ‘cs321’ is in the list. What is the worst case search time? What is the best case search time? What is the average case search time? Is there a Θ bound? A A B B C C D D cs321

Find Item in Linked List Have a list of N strings. Want to see if the string ‘cs321’ is in the list. What is the worst case search time? O(n) What is the best case search time?O(1) What is the average case search time?O(n/2) Is there a Θ bound?No A A B B C C D D cs321

Linked List Cache Basic Algorithm: Initialize data structures – Cache, temp variables. Read in text file as a single string. For each word in text file: – Is word in cache? // a cache method. – Yes – continue for loop. – No – addWordToCache. //cache method Print Cache Statistics – // a cache method.

Word In Cache? inCache(w) { Increment cache 1 reference count. Search Linked List cache1 for w // Big O time? If w in cache1 {increment cache1.hit, Move item to front of list. return true} Else if no cache2 return false. Increment cache2 reference Search linked list cache2 for w // Big O time? If w in cache2 {increment cache2.hit, move to front of Cache 2 and add to cache 1, return true} }

addCacheWord addWord(w) // add word to cache. // not counting this as a cache reference, why? If(cache1 full){ remove last item in list}.//cost? Add w to front of cache1. If (cache2) { If (cache2 full) { remove last item in list // cost? Add w to front of cache2 } What Causes Cache1 to be different from Cache2?

Introduction to Data Structures Why do we have data structures?

Introduction to Data Structures Why do we have data structures? – To look up data later! All data structures are designed to really do one thing: Let us find the data we want, later, quickly and efficiently. All data structures trade off between: – Space: memory use. – Time: time to add or change data. – Complexity: complexity of the algorithm.

Introduction to Data Structures This trade off is done for one reason: – To optimize the speed at which a data item can be retrieved when an algorithm needs that data item to solve a problem. The best data structure for an algorithm is the one that provides the fastest retrieval of a specific data item exactly when it is needed. All other costs being equal.

Introduction to Data Structures Good programming is about: – Writing good Data Structures that are reliable, robust, efficient, and provide quick access to needed data to the components of the program that need that data. – If you want to write good code write good data structures and organize them carefully.

Oil Rig Story An Oil Company needed to stop all oil rigs simultaneously and recalculate their calibration. This took 24 hours of computation time. This amounts to many millions of dollars in lost revenue.

Oil Rig Story Hired a Computer Scientist to work on this. He spent 3 weeks studying the software. Discovered it was basically 3 nested for loops. In the center of the for loop was a call to a long computation function. This computation computed: A CONSTANT! So run time was O(n^3 * C).

Oil Rig Story The Fix! Compute the CONSTANT outside of the for loops and store it in a variable for later use. The variable is our data structure! This reduced the total run time from 24 hours to 8 hours! The Computer Scientist enjoyed a notable bonus!

So what does this mean? Triangle of optimization Space, Time, Complexity. Memory Use Number of Operations Code Complexity Increasing

Sorting Data Structures Compared Method/StructureSpaceComplexityTime Insertion Sort/ArrayO(n)SimpleO(n 2 ) Quicksort/ArrayO(2*n)ComplexO(n 2 ) Heapsort/TreeO(n)ComplexO(n*log(n)) Mergesort/ArrayO(2*n)SimpleO(n*log(n)) Counting Sort/ArrayO(k = range of n)SimpleO(n)

Binary Search Trees Method/StructureSpaceComplexityTime Binary Search TreeO(n)SimpleO(n) AVL TreeO(n)ComplexO(log(n)) Abstract Data Type Search Tree Object Variant #1 Atree = createTree(); insertKey (int key, Data *data); deleteKey(key); Data *findKey(key); deleteTree(); Search Tree Object Variant #2 Atree = createTree(); Node *insertKey (int key, Data *data); Node *deleteKey(key); Node *findKey(key); deleteTree();

Abstract Data Type An abstract data type (ADT) is the set of minimal methods necessary to define a data structure without regard to how the structure is actually implemented.

Abstract Data Type: Examples Stack Astack = newStack(); Astack.push(int value); Astack.pop(int value); deleteStack(astack); The internals of the stack could be implemented as an array, tree, linked list but the ADT does not change. Linked List Llist = newList(); Llist.append(int value); Llist.delete(int value); Llist.find(int value); deleteList(astack); This is a linked list ADT but an extremely limited one.

Why Does this Matter? It defines a standard by which data structures can be compared and analyzed. You can switch different implementations of a linked list without worrying about compatibility if their ADT’s are the same. It lets you select the specific implementation of an ADT that best matches your applications requirements: speed versus size versus complexity. Java has lots of these.

Binary Search Trees Both have exactly the same ADT. However, a BST with no balancing will have very simple code. A Balanced BST (AVL) will have more complex code but better run time performance. Both have same memory consumption.

Linked List Linked List as an Array: wastes space but simple to code and fixed size! Liked List using pointers: space efficient, possible to corrupt memory, or lose pointers, not a fixed size.

Stacks? Stack as a linked list? Stack implemented using an array?

How do we select a Data Structure? Does its ADT have the methods we need? How much space does it use? What is its worst and best case performance? How complex is the code to implement it?

Coming Up Tuesday: Heap-sort using a Max Heap. Assignment 1 Due Friday Jan 11pm.