Computer Science 2 Data Structures and Algorithms V22.0102 section 2 Intro to “big o” Lists Professor: Evan Korth New York University 1.

Slides:



Advertisements
Similar presentations
Chapter 1: INTRODUCTION TO DATA STRUCTURE
Advertisements

Algorithms Algorithm: what is it ?. Algorithms Algorithm: what is it ? Some representative problems : - Interval Scheduling.
Program Efficiency & Complexity Analysis
MATH 224 – Discrete Mathematics
The Efficiency of Algorithms Chapter 4 Copyright ©2012 by Pearson Education, Inc. All rights reserved.
HST 952 Computing for Biomedical Scientists Lecture 10.
Razdan with contribution from others 1 Algorithm Analysis What is the Big ‘O Bout? Anshuman Razdan Div of Computing.
Computational Complexity 1. Time Complexity 2. Space Complexity.
Chapter 1 – Basic Concepts
Fall 2006CENG 7071 Algorithm Analysis. Fall 2006CENG 7072 Algorithmic Performance There are two aspects of algorithmic performance: Time Instructions.
CS 307 Fundamentals of Computer Science 1 Asymptotic Analysis of Algorithms (how to evaluate your programming power tools) based on presentation material.
Not all algorithms are created equally Insertion of words from a dictionary into a sorted list takes a very long time. Insertion of the same words into.
CISC220 Spring 2010 James Atlas Lecture 06: Linked Lists (2), Big O Notation.
Cmpt-225 Algorithm Efficiency.
The Efficiency of Algorithms
Algorithm Efficiency and Sorting Bina Ramamurthy CSE116A,B.
Data Structures and Algorithms1 Basics -- 2 From: Data Structures and Their Algorithms, by Harry R. Lewis and Larry Denenberg (Harvard University: Harper.
Analysis of Algorithms 7/2/2015CS202 - Fundamentals of Computer Science II1.
CS2336: Computer Science II
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.
Analysis of Algorithms Spring 2015CS202 - Fundamentals of Computer Science II1.
Algorithm Analysis (Big O)
COMP s1 Computing 2 Complexity
Comp 249 Programming Methodology Chapter 15 Linked Data Structure - Part B Dr. Aiman Hanna Department of Computer Science & Software Engineering Concordia.
Introduction to Analysing Costs 2015-T2 Lecture 10 School of Engineering and Computer Science, Victoria University of Wellington  Marcus Frean, Rashina.
Program Performance & Asymptotic Notations CSE, POSTECH.
Week 2 CS 361: Advanced Data Structures and Algorithms
For Wednesday Read Weiss chapter 3, sections 1-5. This should be largely review. If you’re struggling with the C++ aspects, you may refer to Savitch, chapter.
Basic Concepts 2014, Fall Pusan National University Ki-Joune Li.
Lecture 2 Computational Complexity
© 2011 Pearson Addison-Wesley. All rights reserved 10 A-1 Chapter 10 Algorithm Efficiency and Sorting.
Fundamentals CSE 373 Data Structures Lecture 5. 12/26/03Fundamentals - Lecture 52 Mathematical Background Today, we will review: ›Logs and exponents ›Series.
1 Introduction to Data Structures. 2 Course Name : Data Structure (CSI 221) Course Teacher : Md. Zakir Hossain Lecturer, Dept. of Computer Science Stamford.
1 Week 9 A little more GUI, and threads. Objectives: Discuss the Swing set of classes. Incorporate animation into applets. Define the term thread. Explain.
INTRODUCTION TO DATA STRUCTURES. INTRODUCTION A data structure is nothing but an arrangement of data either in computer's memory or on the disk storage.
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
Efficiency of Algorithms. Node - data : Object - link : Node + createNode() + getData() + setData() + getLink() + setLink() + addNodeAfter() + removeNodeAfter()
Asymptotic Notations By Er. Devdutt Baresary. Introduction In mathematics, computer science, and related fields, big O notation describes the limiting.
ADS 1 Algorithms and Data Structures 1 Syllabus Asymptotical notation (Binary trees,) AVL trees, Red-Black trees B-trees Hashing Graph alg: searching,
Algorithm Analysis (Big O)
CS 150: Analysis of Algorithms. Goals for this Unit Begin a focus on data structures and algorithms Understand the nature of the performance of algorithms.
Searching Topics Sequential Search Binary Search.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To introduce the basic concepts of linked lists ❏ To introduce the basic concepts.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
GC 211:Data Structures Week 2: Algorithm Analysis Tools Slides are borrowed from Mr. Mohammad Alqahtani.
AP National Conference, AP CS A and AB: New/Experienced A Tall Order? Mark Stehlik
UNIT-V ABSTRACT DATA TYPE 1.LIST 2.STACK 3.QUEUE EC6301-II-ECE-C.
2017, Fall Pusan National University Ki-Joune Li
Algorithm Analysis 1.
GC 211:Data Structures Week 2: Algorithm Analysis Tools
Introduction to Algorithms
GC 211:Data Structures Algorithm Analysis Tools
Lecture 06: Linked Lists (2), Big O Notation
Building Java Programs
Chapter 2: Fundamentals of the Analysis of Algorithm Efficiency
2018, Fall Pusan National University Ki-Joune Li
CS 201 Fundamental Structures of Computer Science
Chapter 2.
PAC Intro to “big o” Lists Professor: Evan Korth New York University
GC 211:Data Structures Algorithm Analysis Tools
Performance Evaluation
Big-O & Asymptotic Analysis
Analysis of Algorithms
Presentation transcript:

Computer Science 2 Data Structures and Algorithms V section 2 Intro to “big o” Lists Professor: Evan Korth New York University 1

Road Map for Today A cursory introduction to Big Oh Abstract Data Types Lists –Array implementation –Linked Lists Reading: –Chapter 2: only the parts concerning Big O and even then not in quite as much detail –Chapter 3:

Abstract Data Type An abstract data type (ADT) is a set of objects together with a set of operations. For example: –Stacks –Queues –Dictionary –Trees –Priority queue 3

4 Analyzing Data Structures In order to discuss what makes a good data structure, we need a way to analyze the execution behavior of a data structure. Two of the most important considerations we need to keep in mind are: –Time complexity –Space complexity There are other important considerations such as code complexity but we will concentrate on time and space for now.

5 Time Complexity For each of the data structure's operations we want to know how many instructions must be executed. Perhaps we can determine a program will execute a maximum of 4n n n + 15 instructions for a dataset of size n. Do we need to be so precise if we are only concerned with the growth rate of our program’s execution time?

6 Time Complexity How long will the program take: –For each of the data structure's operations we want to know how many instructions must be executed. We don't need to know the exact number of instructions because that depends on the compiler and instruction set of our environment. In other words, we want this system to be machine and compiler independent. –For small sets of data, it does not matter much. –We need a theoretical system to quantify how the execution time grows as our data size grows.

7 Asymptotic analysis Asymptotic analysis is based on the idea that as the problem size grows, the complexity can be described as a simple proportionality to some known function. This idea is incorporated in the "Big Oh" notation for asymptotic performance. Definition: T(n) = O(f(n)) if and only if there are constants c 0 and n 0 such that T(n) = n 0. The expression "T(n) = O(f(n))" is read as "T of n is in Big Oh of f of n." Big Oh is sometimes said to describe an "upper-bound" on the complexity. Other forms of asymptotic analysis ("Big Omega", "Little Oh", "Theta") are similar in spirit to Big Oh, but will not be discussed in this class. Thomas A. Anastasio, Richard Chang

8 Big O: What does it mean in English? Big O defines the upper bound of the running time of an operation or algorithm without regard to constants or machine / compiler factors. We just throw away leading constants and low order terms.

9 Some common functions which describe growth rates (in order) O(1): constant O(log n) logarithmic O(n) linear O(n log n) linearithmic O(n 2 ) quadratic O(n 3 ) cubic O(2 n ) exponential

10 One quick example Linear search versus binary search: See this applet: – undan/dsal/appldsal.htmlhttp:// undan/dsal/appldsal.html What is the big oh for linear search? What is the big oh for binary search? We will discuss the time complexity for the operations of every ADT and algorithm we look at in this class.

11 List List (data structure) Definition: A collection of items accessible one after another beginning at the head and ending at the tail. Head: The first item in a list Tail: The last item in a list Source:

12 List operations (example in book) printList makeEmpty find findKth insert remove isEmpty zeroth first findPrevious

13 First idea: Use an array Need to estimate size for the array from the beginning. If we need to expand the array it is expensive (in Java) or impossible (in some other languages). This wastes considerable space. Also insertions and deletions are expensive because we may need to move elements in order to execute the operation (on average half are moved – worse case all must be moved).

14 Better idea: linked list Basic idea is to create a node for each element. The node will contain the element as well as a pointer to the next node. –We need to keep track of the head and the tail somehow. This change means when we insert and delete nodes, all we need to do is move the pointers around. –Let’s look at the book’s example.