CSE 230 Computer Science II (Data Structure) Introduction

Similar documents
CSE 230 Intermediate Programming in C and C++ Recursion

CSE 214 Computer Science II Searching

CSE 230 Intermediate Programming in C and C++ Arrays and Pointers

CSE 214 Computer Science II Heaps and Priority Queues

CSE 230 Intermediate Programming in C and C++ Binary Tree

CSE 214 Computer Science II Final Review II

CSE 214 Computer Science II Introduction to Tree

CSE 230 Intermediate Programming in C and C++ Functions

CSE 214 Computer Science II Recursion

CSE 230 Intermediate Programming in C and C++

Programming II (CS300)

CSE 214 Computer Science II Java Classes and Information Hiding

CSE 230 Intermediate Programming in C and C++

CSC 273 Data Structures

Programming II (CS300)

Two Approaches to Algorithms An Example (1) Iteration (2) Recursion

Programming II (CS300)

Revision Statement while return growth rate asymptotic notation complexity Compare algorithms Linear search Binary search Preconditions: sorted,

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CSE 230 Intermediate Programming in C and C++ Arrays, Pointers and Strings

Faster Sorting Methods

Chapter 8 Algorithms 1

CSE 214 Computer Science II Stack

CS 163 Practice Final Exam Winter 2012

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

CS 206 Introduction to Computer Science II

CS Lecture 19: Loop invariants

CS 445: Data Structures Final Examination: Study Guide

CPSC 3740 Programming Languages University of Lethbridge. Control Structures

Lecture Notes for Chapter 2: Getting Started

Algorithm. Algorithm Analysis. Algorithm. Algorithm. Analyzing Sorting Algorithms (Insertion Sort) Analyzing Algorithms 8/31/2017

CMSC 330: Organization of Programming Languages

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

CS159. Nathan Sprague. November 9, 2015

CSE 230 Intermediate Programming in C and C++

CISC 1100: Structures of Computer Science

Complexity, Induction, and Recurrence Relations. CSE 373 Help Session 4/7/2016

CPSC 331 Term Test #2 March 26, 2007

CSC Java Programming, Fall Java Data Types and Control Constructs

CSE 130 Introduction to Programming in C Control Flow Revisited

CS102 Unit 2. Sets and Mathematical Formalism Programming Languages and Simple Program Execution

Outline. Introduction to Programming (in C++) Introduction. First program in C++ Programming examples

1 P a g e A r y a n C o l l e g e \ B S c _ I T \ C \

Chapter 4: Control Structures I (Selection) Objectives. Objectives (cont d.) Control Structures. Control Structures (cont d.

Chapter 9 Graph Algorithms

CS 231 Data Structures and Algorithms, Fall 2016

Introduction to Data Structure

Representation Invariants and Abstraction Functions

introduction to Programming in C Department of Computer Science and Engineering Lecture No. #40 Recursion Linear Recursion

CS171 Midterm Exam. October 29, Name:

CSE 2123 Recursion. Jeremy Morris

CSE 142/143 Unofficial Commenting Guide Eric Arendt, Alyssa Harding, Melissa Winstanley

This is a set of practice questions for the final for CS16. The actual exam will consist of problems that are quite similar to those you have

COMP 250 Fall Homework #4

ASYMPTOTIC COMPLEXITY

Data Structures and Algorithms

Programming Languages

Chapter 9 Graph Algorithms

CSE wi: Practice Midterm

Week 6. Data structures

S1) It's another form of peak finder problem that we discussed in class, We exploit the idea used in binary search.

CS302 Data Structures using C++

CSC 1052 Algorithms & Data Structures II: Recursion

x = 3 * y + 1; // x becomes 3 * y + 1 a = b = 0; // multiple assignment: a and b both get the value 0

COMP 250 Fall Solution - Homework #4

Exam Datastrukturer. DIT960 / DIT961, VT-18 Göteborgs Universitet, CSE

Big-O-ology. Jim Royer January 16, 2019 CIS 675. CIS 675 Big-O-ology 1/ 19

Introduction to Analysis of Algorithms

Sorting. Popular algorithms: Many algorithms for sorting in parallel also exist.

Lecture 7: Data Abstractions

COS 226 Algorithms and Data Structures Fall Midterm

Today s Outline. CSE 326: Data Structures Asymptotic Analysis. Analyzing Algorithms. Analyzing Algorithms: Why Bother? Hannah Takes a Break

CSE Data Structures and Introduction to Algorithms... In Java! Instructor: Fei Wang. Mid-Term Exam. CSE2100 DS & Algorithms 1

Algorithm Analysis. (Algorithm Analysis ) Data Structures and Programming Spring / 48

More Complicated Recursion CMPSC 122

Problem One: A Quick Algebra Review

SCHOOL OF COMPUTING, MATHEMATICAL AND INFORMATION SCIENCES Semester 2 Examinations 2008/2009. CI311 Specification and Refinement

Classic Data Structures Introduction UNIT I

9/19/12. Why Study Discrete Math? What is discrete? Sets (Rosen, Chapter 2) can be described by discrete math TOPICS

Outline. Computer Science 331. Information Hiding. What This Lecture is About. Data Structures, Abstract Data Types, and Their Implementations

Data Structures and Algorithms in Java. Second Year Software Engineering

10/5/2016. Comparing Algorithms. Analyzing Code ( worst case ) Example. Analyzing Code. Binary Search. Linear Search

CS171 Final Practice Exam

OF VICTORIA EXAMINATIONS- DECEMBER 2010 CSC

Types II. Hwansoo Han

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

ASYMPTOTIC COMPLEXITY

Input Space Partitioning

CSL 201 Data Structures Mid-Semester Exam minutes

Fun facts about recursion

Assertions. Assertions - Example

Introducing Hashing. Chapter 21. Copyright 2012 by Pearson Education, Inc. All rights reserved

Lecture 2: Sorting and the Big O. Wednesday, 16 September 2009

Selection (deterministic & randomized): finding the median in linear time

COMP 250 Winter Homework #4

axiomatic semantics involving logical rules for deriving relations between preconditions and postconditions.

Unit 10: Sorting/Searching/Recursion

CS2 Algorithms and Data Structures Note 1

Lecture 24: Loop Invariants

What is an algorithm? CISC 1100/1400 Structures of Comp. Sci./Discrete Structures Chapter 8 Algorithms. Applications of algorithms

Transcription:

CSE 230 Computer Science II (Data Structure) Introduction Fall 2017 Stony Brook University Instructor: Shebuti Rayana

Basic Terminologies Data types Data structure Phases of S/W development Specification Design Ø Algorithm Ø Pseudocode Implementation Ø Iterations Analysis of Complexity Shebuti Rayana (CS, Stony Brook University) 2

Data Types Intuitively, data can be of a certain type 1, 2, are INTEGER type a, b, are CHARACTER type ant, antelope, are STRING type Some basic data types are called primitive data types In Java, these can be (among others) int, char, boolean etc. Composite data types can be constructed using the primitive or non-primitive types. Example: an Array is a composite data type that stores a sequence of elements in a particular order. Shebuti Rayana (CS, Stony Brook University) 3

Abstract Data Types Mathematical specifications for data types Defined by their, (i) possible values (ii) possible operations on them and (iii) behavior of the operations Theoretical concept, may not have an actual implementation In reality, though, many abstract data types have implementation that captures their behavior Example: The abstract data type Set, it has proper mathematical behavior for union, intersection, checking membership, etc. Shebuti Rayana (CS, Stony Brook University) 4

What is a Data Structure? A data structure is a collection of data, organized so that items can be stored and retrieved by some fixed techniques. A data structure is an actual code implementation of abstract data types Example: a Java array is an implementation of a collection of elements, each identified by its location in the collection. In most programming languages this location is given by the index, denoted by A[0], A[1], etc. Shebuti Rayana (CS, Stony Brook University) 5

Data Structures In this course, we will learn to Implement many composite abstract data types using complex data structures (stacks, queues, binary trees, ) Use them in several algorithms to solve concrete computational problems (like sorting algorithms) See how the correct (or incorrect) use of data structures effect these Algorithms e.g., how the right use of a data structures can make an algorithm efficient. Learn how a data structure can be suitable for some algorithms but not suitable for others e.g., arrays can access any element really fast (good for searching algorithms) but an array can only hold elements of one data type (bad for mapping key-value pairs) Shebuti Rayana (CS, Stony Brook University) 6

Phases of S/W Development Problem statement Specification of the task Design of a solution Implementation (coding) of the solution Analysis of the solution Testing and debugging Documentation and Maintenance Obsolescence These phases do not necessarily occur one after another, in practice, they blur into each other Shebuti Rayana (CS, Stony Brook University) 7

Specification The specification is a precise description of the problem Example Problem: Sort a sequence of integers in ascending order Given a sequence of numbers as input (24, 10, 32, 19, 27, 39) Output the same numbers in ascending/increasing order (10, 19, 24, 27, 32, 39) For small problems sometimes a sample of the input and desired output is precise enough Shebuti Rayana (CS, Stony Brook University) 8

Specification of a Java Method Short Introduction Short description of the action of the method Parameter Description List of method s parameters Precondition Condition that is supposed to be true when the method is called Postcondition or the return condition Condition that is true when the method finishes Throwing exception When the precondition fails the method throws exception Shebuti Rayana (CS, Stony Brook University) 9

Example: Specification Sort a sequence of integers and return the sorted sequence public static int[] insertionsort(int [] a) Parameter: an array a containing the unsorted integers Precondition: array not empty Postcondition: returns the reference of a integer typed array a Throws: IllegalArgumentException Indicates the array is empty Shebuti Rayana (CS, Stony Brook University) 10

Design The design phase consists of formulating the steps (or algorithm) to solve the problem Algorithm: Informally, an algorithm is a welldefined computational procedure that takes some value (or values) as input and produces some value (or values) as output It is a sequence of computational steps or instructions that transform the input into the output transformation Output Input Shebuti Rayana (CS, Stony Brook University) 11

Pseudocode Algorithms are sometimes represented in a mixture of English and programming language, which is called Pseudocode. Not real code A high-level description of an algorithm that is Clear Concise Human-Readable Resembles (but is not) actual code. Shebuti Rayana (CS, Stony Brook University) 12

Example Algorithm Sorting Algorithm Sort a sequence of integer values in ascending order Given a sequence of numbers as input (24, 10, 32, 19, 27, 39) Output the same numbers in ascending/increasing order (10, 19, 24, 27, 32, 39) Shebuti Rayana (CS, Stony Brook University) 13

Example: Insertion Sort This is the method people normally use for sorting cards in hand 1. Start with an empty left hand (and the cards are face down table) on the 2. Remove one card at a time from the table and insert it into the correct position in the left hand. I. To find the correct position for a card, compare it with each of the cards already in the hand from left to right Shebuti Rayana (CS, Stony Brook University) 14

Example: Insertion Sort This is the method people normally use for sorting cards in hand Shebuti Rayana (CS, Stony Brook University) 15

Design: Subroutine As algorithms get more complex, the programming, too, gets more complicated. It becomes necessary to break down a single algorithm into smaller chunks. This allows us to organize, manage and debug even extremely long programs. These smaller chunks are called subroutines. Functions are subroutines that return values. Subroutines that, in turn, call themselves, are called recursive subroutine. Recursion allows us to write complex algorithms with shorter code In this course, we will study recursion to solve many complex problems Shebuti Rayana (CS, Stony Brook University) 16

Implementation The implementation is the actual code to carry out the design Java code for insertion sort Shebuti Rayana (CS, Stony Brook University) 17

Iteration Iterations are ways of moving through collections of statements Example: for( ) { } while( ){ } foreach() Shebuti Rayana (CS, Stony Brook University) 18

Complexity The complexity of an algorithm can be thought of as its running time. The running time of an algorithm on a particular input is the number of basic (?) operations needed for the algorithm to transform the input into the required output. The running time of the whole algorithm is the sum of the running times of each statement. Let s go back to insertion sort algorithm... Shebuti Rayana (CS, Stony Brook University) 19

Running Time of Insertion Sort Let n be the length of array A Shebuti Rayana (CS, Stony Brook University) 20

Running Time of Insertion Sort n n - 1 n - 1?? n - 1 Let n be the length of array A Shebuti Rayana (CS, Stony Brook University) 21

Running Time of Insertion Sort n n - 1 n - 1?? n - 1 Even for input of a given fixed size n, the running time depends on which input of size n is given. The number of times the while-loop must be executed depends on the values in the array! Shebuti Rayana (CS, Stony Brook University) 22

Running Time of Insertion Sort The running time of the algorithm is the sum of running times for each statement executed Shebuti Rayana (CS, Stony Brook University) 23

Running Time of Insertion Sort To compute T(n), the running time of INSERTION-SORT on an input of n values, we sum the products of the cost and times columns, obtaining In next class, we will learn how to represent this running time T(n) with Big O Notation Shebuti Rayana (CS, Stony Brook University) 24

Thank You Shebuti Rayana (CS, Stony Brook University) 25