CS240: Data Structures And Algorithms

Slides:



Advertisements
Similar presentations
Data Structures A data structure is a collection of data organized in some fashion that permits access to individual elements stored in the structure This.
Advertisements

1 Problem Solving Abstraction Oftentimes, different real-world problems can be modeled using the same underlying idea Examples: Runtime storage, Undo operation.
CHAPTER 3 COLLECTIONS Abstract Data Types. 2 A data type consists of a set of values or elements, called its domain, and a set of operators acting on.
CS 307 Fundamentals of Computer Science 1 Abstract Data Types many slides taken from Mike Scott, UT Austin.
Data Structures Introduction. What is data? (Latin) Plural of datum = something given.
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
CSE 143 Lecture 14 Interfaces; Abstract Data Types (ADTs) reading: 9.5, 11.1; 16.4 slides created by Marty Stepp
Abstract Data Types (ADTs) Data Structures The Java Collections API
Abstract Data Types (ADTs) and data structures: terminology and definitions A type is a collection of values. For example, the boolean type consists of.
Data Structures and Abstract Data Types "Get your data structures correct first, and the rest of the program will write itself." - David Jones.
Cosc 2150: Computer Organization
Object Oriented Programming Computer Engineering Department JAVA Programming Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2014.
Lists Ellen Walker CPSC 201 Data Structures Hiram College.
Chapter 7 Objects and Classes 1 Fall 2012 CS2302: Programming Principles.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
CS 206 Introduction to Computer Science II 09 / 10 / 2009 Instructor: Michael Eckmann.
Data structures Abstract data types Java classes for Data structures and ADTs.
Data Structures and Algorithms Lecture 3 Instructor: Quratulain Date: 8 th September, 2009.
Stacks and Queues. 2 3 Runtime Efficiency efficiency: measure of computing resources used by code. can be relative to speed (time), memory (space), etc.
Lecture4: Arrays Bohyung Han CSE, POSTECH CSED233: Data Structures (2014F)
Types in programming languages1 What are types, and why do we need them?
Aug 9, CMSC 202 ArrayList. Aug 9, What’s an Array List ArrayList is  a class in the standard Java libraries that can hold any type of object.
Data Structures and Algorithms Dr. Tehseen Zia Assistant Professor Dept. Computer Science and IT University of Sargodha Lecture 1.
Page 1 Adapted after Dr. Menezes Recurrence 1 …..
ITI 1120 Lab #3 Tracing and Branching Contributors: G. Arbez, M. Eid, D. Inkpen, A. Williams, D. Amyot.
1 CS 311 Data Structures. 2 Instructor Name : Vana Doufexi Office : 2-229, Ford Building Office hours: By appointment.
1 Today’s Material List ADT –Definition List ADT Implementation: LinkedList.
Computer Science 209 Software Development Inheritance and Composition.
Data Design and Implementation. Definitions Atomic or primitive type A data type whose elements are single, non-decomposable data items Composite type.
CSE 1201 Object Oriented Programming ArrayList 1.
Boolean expressions, part 1: Compare operators. Compare operators Compare operators compare 2 numerical values and return a Boolean (logical) value A.
CMSC 202 Containers and Iterators. Container Definition A “container” is a data structure whose purpose is to hold objects. Most languages support several.
©The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter Chapter 18 List ADT Animated Version.
1 The copy constructor in the BankAccounts class. Two alternatives here: /** copy constructor */ public BankAccounts(BankAccounts L){ theAccounts = L.theAccounts.clone();
Unit 1 - Introducing Abstract Data Type (ADT) Part 1.
Coming up Implementation vs. Interface The Truth about variables Comparing strings HashMaps.
Lecture No.05 Data Structures Dr. Sohail Aslam.  Josephus Problem #include "CList.cpp" void main(int argc, char *argv[]) { CList list; int i, N=10, M=3;
Building Java Programs Interfaces reading: , 16.4.
Prof. I. J. Chung Data Structure #1 Professor I. J. Chung.
Section 2.2 The StringLog ADT Specification. 2.2 The StringLog ADT Specification The primary responsibility of the StringLog ADT is to remember all the.
Data Structures Dr. Abd El-Aziz Ahmed Assistant Professor Institute of Statistical Studies and Research, Cairo University Springer 2015 DS.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
Lecture 1 Data Structures Aamir Zia. Introduction Course outline Rules and regulations Course contents Good Programming Practices Data Types and Data.
Advanced Data Structures Lecture 1
Structures and Classes
Sixth Lecture ArrayList Abstract Class and Interface
G64ADS Advanced Data Structures
Lists A List ADT Types of Lists Using ordered lists – Tournament Maker
Chapter 5 Ordered List.
John Hurley Cal State LA
CS Week 14 Jim Williams, PhD.
structures and their relationships." - Linus Torvalds
Lecture 2: Implementing ADTs
Chapter 5 Ordered List.
structures and their relationships." - Linus Torvalds
CS148 Introduction to Programming II
CSE 143 Lecture 2 Collections and ArrayIntList
CS2013 Lecture 4 John Hurley Cal State LA.
Arrays and Collections
Collections Not in our text.
slides created by Ethan Apter
Introduction to Data Structure
CS2013 Lecture 7 John Hurley Cal State LA.
slides created by Marty Stepp
Two-Dimensional Arrays
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
Data Structures and Algorithms 2/2561
structures and their relationships." - Linus Torvalds
A type is a collection of values
Presentation transcript:

CS240: Data Structures And Algorithms Nathan Sprague Fall, 2017

LinkedList or ArrayList? import java.util.ArrayList; import java.util.LinkedList; public class ListDemo { public static void main(String[] args) { LinkedList<String> list = new LinkedList<String>(); for (int i = 0; i < 200000; i++) { list.add(0, "A"); } list.remove(0);

To Socrative! Room Name: CS240 Enter Your Name: Your eid e.g.: spragunr

What is the result of changing the code snippet to use an ArrayList instead of a LinkedList? for (int i = 0; i < 200000; i++) { list.add(0, "A"); } list.remove(0); No change in correctness or execution time. No one notices you made the change. An ArrayList will not work correctly in this case. You've broken the code! You're Fired! The new implementation is slightly slower than the original implementation. The new implementation is slightly faster than the original implementation. The new implementation is MUCH faster than the original version. Nice Job! Promoted on your first day! The new implementation is MUCH slower than the original version. You're fired!

Abstract Data Types and Data Structures “A type is a collection of values. For example, the Boolean type consists of the values true and false.” “A data type is a type together with a collection of operations to manipulate the type.” “An abstract data type (ADT) is the specification of a data type within some language, independent of an implementation. The interface for the ADT is defined in terms of a type and a set of operations on that type. An ADT does not specify how the data type is implemented. These implementation details are hidden from the user of the ADT and protected from outside access.” “A data structure is the implementation for an ADT. In an object-oriented language, an ADT and its implementation together make up a class.” (OpenDSA 1.2.1)

List, ArrayList, LinkedList Java interfaces can be thought of as ADT’s*: List Java collection classes are data structures: ArrayList LinkedList *Some authors would argue that an ADT is an abstract mathematical description that is not tied to any particular language construct.

Two Steps Back: CS261 MIPS Assembly language example: lw $t0, 0($s0) add $t0, $t0, $t0 sw $t0, 0($s0) The structure of memory... Contiguous vs. Linked Structures...

Key Goals For This Course Selecting appropriate ADT’s Based on the logical requirements of the problem: How will we need to interact with our data

Key Goals For This Course Selecting appropriate ADT’s Based on the logical requirements of the problem: How will we need to interact with our data Selecting appropriate Data Structures How can we organize our data so that we can interact with it efficiently in both time and space.

Key Goals For This Course Selecting appropriate ADT’s Based on the logical requirements of the problem: How will we need to interact with our data Selecting appropriate Data Structures How can we organize our data so that we can interact with it efficiently in both time and space. Algorithm Analysis How can we determine the performance characteristics of our code before we write it

Back to Linked List vs. ArrayList... LinkedList CRUSHED ArrayList in our earlier code snippet. Which, if any, of these will be much faster for an ArrayList (assuming a large number of entries)? A) list.get(0); B) list.get(list.size() - 1); C) list.get(list.size() / 2); D) None of the above.

For Wednesday Do the posted reading for Wednesday (and today). Sign into Canvas and log into Piazza. Complete the course survey.