Data Structures in C Networking Laboratory Chap. 1-1 Copyright(c) 2000, Sungkyunkwan University Chapter #1: BASIC CONCEPTS Fundamentals of Data Structures.

Slides:



Advertisements
Similar presentations
MATH 224 – Discrete Mathematics
Advertisements

CHAPTER 2 ALGORITHM ANALYSIS 【 Definition 】 An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition,
HST 952 Computing for Biomedical Scientists Lecture 10.
Analysys & Complexity of Algorithms Big Oh Notation.
Chapter 1 – Basic Concepts
1 Data Structures Performance Analysis. 2 Fundamental Concepts Some fundamental concepts that you should know: –Dynamic memory allocation. –Recursion.
CHAPTER 11 Space and Time Complexity in Chapter 1 All the programs in this file are selected from Ellis Horowitz, Sartaj Sahni, and Susan Anderson-Freed.
Object (Data and Algorithm) Analysis Cmput Lecture 5 Department of Computing Science University of Alberta ©Duane Szafron 1999 Some code in this.
1 Data Structures A program solves a problem. A program solves a problem. A solution consists of: A solution consists of:  a way to organize the data.
Data Structures Performance Analysis.
CHAPTER 10 Recursion. 2 Recursive Thinking Recursion is a programming technique in which a method can call itself to solve a problem A recursive definition.
CHAPTER 1 BASIC CONCEPT All the programs in this file are selected from Ellis Horowitz, Sartaj Sahni, and Susan Anderson-Freed “Fundamentals of Data Structures.
What is Program  A Set of Instructions  Data Structures + Algorithms  Data Structure = A Container stores Data  Algoirthm = Logic + Control.
Algorithm Analysis (Big O)
CHAPTER 2 ALGORITHM ANALYSIS 【 Definition 】 An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition,
COMP s1 Computing 2 Complexity
1 Chapter 2 Program Performance – Part 2. 2 Step Counts Instead of accounting for the time spent on chosen operations, the step-count method accounts.
Prof. Hsin-Mu (Michael) Tsai ( 蔡欣穆 ) Department of Computer Science and Information Engineering National Taiwan University BASICS.
Program Performance & Asymptotic Notations CSE, POSTECH.
CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a CSC 201 Analysis and Design of Algorithms Lecture 03: Introduction to a lgorithms.
Week 2 CS 361: Advanced Data Structures and Algorithms
C. – C. Yao Data Structure. C. – C. Yao Chap 1 Basic Concepts.
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.
1 R. Johnsonbaugh, Discrete Mathematics Chapter 4 Algorithms.
Discrete Structures Lecture 11: Algorithms Miss, Yanyan,Ji United International College Thanks to Professor Michael Hvidsten.
Basic Concepts 2014, Fall Pusan National University Ki-Joune Li.
Chapter 1 1. Overview: System life cycle Requirements Analysis Bottom-up Top-down Design Data objects (abstract data type) and operations (algorithm)
Unit III : Introduction To Data Structures and Analysis Of Algorithm 10/8/ Objective : 1.To understand primitive storage structures and types 2.To.
CS Data Structures Chapter 1 Basic Concepts.
Analysis of Algorithms
Program Efficiency & Complexity Analysis. Algorithm Review An algorithm is a definite procedure for solving a problem in finite number of steps Algorithm.
Data Structure Introduction.
Algorithm Analysis CS 400/600 – Data Structures. Algorithm Analysis2 Abstract Data Types Abstract Data Type (ADT): a definition for a data type solely.
Algorithms and data structures: basic definitions An algorithm is a precise set of instructions for solving a particular task. A data structure is any.
Chapter 5 Algorithms (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
Java Methods Big-O Analysis of Algorithms Object-Oriented Programming
Algorithm Analysis (Big O)
Software Learning Resource Service Platform BASIC CONCEPT CHAPTER 1 BASIC CONCEPT 1.
1 Chapter 2 Algorithm Analysis All sections. 2 Complexity Analysis Measures efficiency (time and memory) of algorithms and programs –Can be used for the.
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.
1 Chapter 2 Program Performance. 2 Concepts Memory and time complexity of a program Measuring the time complexity using the operation count and step count.
BITS Pilani Pilani Campus Data Structure and Algorithms Design Dr. Maheswari Karthikeyan Lecture1.
1 Chapter 2 Algorithm Analysis Reading: Chapter 2.
Basic Concepts 2011, Fall Pusan National University Ki-Joune Li.
Complexity of Algorithms Fundamental Data Structures and Algorithms Ananda Guna January 13, 2005.
Analysis of Algorithms Spring 2016CS202 - Fundamentals of Computer Science II1.
SPACE COMPLEXITY & TIME COMPLEXITY 1. ALGORITHMS COMPLEXITY 2.
Chapter 2 Algorithm Analysis
Data Structures 1st Week
Analysis of Algorithms
Analysis of Algorithms
Introduction to Algorithms
What is an Algorithm? Algorithm Specification.
Data Structures (1/2) 內容:Basic Concepts, Arrays and Structures, Stacks and Queues, Lists, Trees, Graphs, Sorting, Hashing, Heap Structures, and Search.
Data Structure 김용성 Data Structure in C.
What is CS 253 about? Contrary to the wide spread belief that the #1 job of computers is to perform calculations (which is why the are called “computers”),
Data Structures-CSE207.
CS 201 Fundamental Structures of Computer Science
Analysis of Algorithms
Asst. Dr.Surasak Mungsing
Performance analysis of algorithms
At the end of this session, learner will be able to:
Discrete Mathematics 7th edition, 2009
CHAPTER 1 BASIC CONCEPT All the programs in this file are selected from Ellis Horowitz, Sartaj Sahni, and Susan Anderson-Freed “Fundamentals of Data Structures.
Data structures & Algorithm Strategies
Analysis of Algorithms
Algorithms and data structures: basic definitions
Algorithm Analysis How can we demonstrate that one algorithm is superior to another without being misled by any of the following problems: Special cases.
2019, Fall Pusan National University Ki-Joune Li
Presentation transcript:

Data Structures in C Networking Laboratory Chap. 1-1 Copyright(c) 2000, Sungkyunkwan University Chapter #1: BASIC CONCEPTS Fundamentals of Data Structures in C Horowitz, Sahni, and Anderson-Freed Computer Science Press Revised by H. Choo, August 2000.

Data Structures in C Networking Laboratory Chap. 1-2 Copyright(c) 2000, Sungkyunkwan University Overview : System life cycle Requirements - describe information for project including input and output Analysis - bottom-up, top-down Design - data objects and operations performed on them Refinement and Coding - choose representations for data objects - write algorithms for each operation

Data Structures in C Networking Laboratory Chap. 1-3 Copyright(c) 2000, Sungkyunkwan University Overview : System life cycle Verification - correctness proofs by using techniques abound in mathematics - testing requires working code and sets of test data - error removal If done properly, the correctness proofs and system test will indicate erroneous code.

Data Structures in C Networking Laboratory Chap. 1-4 Copyright(c) 2000, Sungkyunkwan University Algorithm specification Definition - a finite set of instructions to accomplish a particular task Criteria - zero or more inputs - at least one output - definiteness(clear, unambiguous) - finiteness(terminates after a finite number of steps) é different to programs - effectiveness

Data Structures in C Networking Laboratory Chap. 1-5 Copyright(c) 2000, Sungkyunkwan University Algorithm specification  Ex 1.1 [Selection sort] sort n(1) integers From those integers that are currently unsorted, find the smallest and place it next in the sorted list. for (i=0; i<n; i++) { Examine list[i] to list[n-1]; Let the smallest integer be at list[min]; Interchange list[i] and list[min]; }

Data Structures in C Networking Laboratory Chap. 1-6 Copyright(c) 2000, Sungkyunkwan University Algorithm specification finding the smallest integer assume that minimum is list[i] compare current minimum with list[i+1] to list[n-1] and find smaller number and make it the new minimum interchanging minimum with list[i] function call swap(&a,&b) void swap(int *x, int *y) {int temp=*x; *x=*y; *y=temp;} macro swap(x,y,t) no type-checking #define swap(x,y,t) ((t)=(x), (x)=(y), (y)=(t))

Data Structures in C Networking Laboratory Chap. 1-7 Copyright(c) 2000, Sungkyunkwan University Algorithm specification  Ex 1.2 [Binary search] assumption assumption sorted n(1) distinct integers stored in the array list return return i if  i, list[i] = searchnum; -1 if no such index exists denote denote left and right as left and right ends of the list to be searched (left=0 and right=n-1) let let middle=(left+right)/2 middle position in the list compare adjust compare list[middle] with searchnum and adjust left or right

Data Structures in C Networking Laboratory Chap. 1-8 Copyright(c) 2000, Sungkyunkwan University Algorithm specification compare compare list[middle] with searchnum 1)searchnum < list[middle] set right to middle-1 2)searchnum = list[middle] return middle 3)searchnum > list[middle] set left to middle+1 not if searchnum has not been found and there are more integers to check recalculate recalculate middle continue and continue search

Data Structures in C Networking Laboratory Chap. 1-9 Copyright(c) 2000, Sungkyunkwan University Algorithm specification While (there are more integers to check) { middle=(left+right)/2; if (searchnum < list[middle]) right=middle-1; else if (searchnum == list[middle]) return middle; else left=middle+1; } u determining if there are any elements left to check u handling the comparison (through a function or a macro)

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Algorithm specification int binsearch(int list[],int searchnum, int left, int right) {int middle; while (left <= right) { middle = (left + right) / 2; switch(COMPARE(list[middle],searchnum)) { case -1: left = middle + 1; break; case 0: return middle; case 1: right = middle - 1; } return -1; } ê COMPARE() returns -1, 0, or 1 #define COMPARE(x,y) ((x)<(Y) ? -1: ((x)==(y)) ? 0 : 1)

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Recursive Algorithms direct recursion - call themselves indirect recursion - call other function that invoke the calling function again recursive mechanism - extremely powerful - allows us to express a complex process in very clear terms u any function that we can write using assignment, if-else, and while statements can be written recursively

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Recursive Algorithms  Ex 1.3 [Binary search] transform iterative version of a binary search into a recursive one establish boundary condition that terminates the recursive call 1)success list[middle]=searchnum 2)failure left & right indices cross implement the recursive calls so that each call brings us one step closer to a solution

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Recursive Algorithms int binsearch(int list[], int searchnum, int left, int right) {int middle; if (left <= right) { middle = (left+right)/2; switch(COMPARE(list[middle], searchnum)) { case -1 : return binsearch(list,searchnum,middle+1,right); case 0 : return middle case 1 : return binsearch(list,searchnum,left,middle-1); } return -1; }

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Recursive Algorithms  Ex 1.4 [Permutations] given a set of n(1) elements print out all possible permutations of this set eg) if set {a,b,c} is given, then set of permutations is {(a,b,c), (a,c,b), (b,a,c), (b,c,a), (c,a,b), (c,b,a)}

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Recursive Algorithms if look at the set {a,b,c,d}, the set of permutations are 1)a followed by all permutations of (b,c,d) 2)b followed by all permutations of (a,c,d) 3)c followed by all permutations of (a,b,d) 4)d followed by all permutations of (a,b,c) è “followed by all permutations” : clue to the recursive solution

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Recursive Algorithms void perm(char *list,int i,int n) { int j,temp; if(i==n) { for(j=0;j<=n;j++) printf(“%c”, list[j]); printf(“ “);} else { for(j=i;j<=n;j++) { SWAP(list[i],list[j],temp); perm(list,i+1,n); SWAP(list[i],list[j],temp); } } } Generate Generate all permutations of list[i] to list[n] [initially perm(list,0,n-1), e.g. perm(list,0,2)] recursively generates recursively generates permutations until i=n

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Data Abstraction Definition (data type): Definition (data type): a collection of objects and a set of operations that act on those objects basic data type in C language char 1-byte, int 2, float 4, double 8 keyword: short 2, long 4, unsigned 2 composite data type: array,structure int list[5]; struct student { char last_name; int student_id; char grade; } pointer data type: int, double, char, float int j, *pj; user-defined data type

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Data Abstraction  Abstract data type (ADT) definition - data type that is organized in a following way that - the specification of the objects and the specification of the operations on the objects are separated from - the representation of the objects and the implementation of the operations - (e.g.) Ada: package, C++: class

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Data Abstraction specification - names of every function - type of its arguments - type of its result - description of what the function does classifying classifying functions of data type - creator/constructor - transformers - observers/reporters

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Data Abstraction  Ex 1.5 [Abstract data type] structure Natural_Number (Nat_No) objects: an ordered subrange of the integers starting at zero and ending at the max. integer on the computer functions: for all x, y  Natural_Number; TRUE, FALSE  Boolean and where +, -, <, and == are the usual integer operations. Nat_No Zero() ::= 0 Nat_No Add(x,y) ::= if ((x+y)<=INT_MAX)return x+y else return INT_MAX Nat_No Subtract(x,y) ::= if (x<y) return 0 else return x-y Boolean Equal(x,y) ::= if (x==y) return TRUE else return FALSE Nat_No Successor(x) ::= if (x==INT_MAX) return x else return x+1 Boolean Is_Zero(x) ::= if (x) return FALSE else return TRUE end Natural_Number

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Data Abstraction objects and functions are two main sections in the definition function “Zero” is a constructor/creator functions “Add, Subtract, Successor” are transformers functions “Is_Zero” and “Equal” are reporters

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Performance Analysis Performance evaluation - performance analysis machine independent time & space complexity theory - performance measurement machine dependent running time space complexity the amount of memory that it needs to run to completion time complexity the amount of computer time that it needs to run to completion

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Space Complexity fixed space requirements do not depend on the number and size of the program’s inputs and outputs (e.g.) instruction space, variables, constants, fixed size structured variables variable space requirements the space needed by structured variable whose size depends on the particular instance, I, of the problem being solved (e.g.) variable space, stack

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Space Complexity total space requirement S(P) S(P) = c + S P (I) where c: constant representing the fixed space requirements S p (I): function of some characteristics of the instance I (variable space)  Ex 1.6 float abc(float a, float b, float c) { return a+b+b*c+(a+b-c)/(a+b)+4.00; } input: 3 variables, output: 1 variable fixed space requirements only! Hence, S abc (I) = 0

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Space Complexity  Ex 1.7 [Iterative version] float sum(float list[], int n) { float tempsum = 0; int i; for(i = 0; i < n; i++) tempsum += list[i]; return tempsum; } Pascal passes arrays by values entire array is copied into temporary storage before the function is executed S sum (I) = S sum (n) = n C passes arrays by pointers passing the address of the first element of the array S sum (n) = 0

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Space Complexity  Ex 1.8 [Recursive version] float rsum(float list[],int n) { if (n) return rsum(list,n-1) + list[n-1]; return 0; } handled recursively compiler must save the parameters the local variables the return address for each recursive call

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Space Complexity one recursive call space needed for one recursive call number of bytes required for the two parameters and the return address 6 bytes needed on bytes for pointer list[] 2 bytes for integer n 2 bytes for the return address assume array has n=MAX_SIZE numbers, total variable space S rsum (MAX_SIZE) S rsum (MAX_SIZE) = 6 * MAX_SIZE

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Time Complexity The time T(P),taken by a program P, is the sum of its compile time and its run(or execution) time concerned only with the program’s execution time, Tp - We really concerned only with the program’s execution time, Tp count the number of operations the program performs - machine-independent estimation program step A program step is a syntactically or semantically meaningful program segment whose execution time is independent of the instance characteristics.

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Time Complexity  Ex 1.9 [Iterative summing of a list of numbers] float sum(float list[], int n) { float tempsum=0; count++; /* for assignment */ int i; for(i = 0; i < n; i++) { count++; /* for the for loop */ tempsum += list[i]; count++; /*for assignment*/ } count++; /* last execution of for */ count++; /* for return */ return tempsum; }

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Time Complexity eliminate most of the program statements from Program 1.12 (p.23) to obtain a simpler program Program 1.13 that computes the same value for count float sum(float list[], int n) { float tempsum=0; int i; for(i = 0; i < n; i++) count+=2; count += 3; return 0; } How many steps? (2n + 3) steps

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Time Complexity  Ex 1.10 [Recursive summing of a list of numbers] float rsum(float list[], int n) { count++;/* for if conditional */ if(n) { count++; /* for return & rsum invocation */ return rsum(list,n-1)+list[n-1]; } count++; /* for return */ return list[0]; }

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Time Complexity when n=0 only the if conditional and the second return statement are executed (termination condition) step count for n = 0 : 2 each step count for n > 0 : 2 total step count for function : 2n less step count than iterative version, but - take more time than those of the iterative version

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Time Complexity  Ex 1.11 [Matrix addition] determine the step count for a function that adds two-dimensional arrays(rows, cols) void add(int a[][M_SIZE],int b[][M_SIZE], int c[][M_SIZE],int rows,int cols) { int i, j; for(i = 0; i < rows; i++) for(j = 0; j < cols; j++) c[i][j] = a[i][j] + b[i][j]; }

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Time Complexity apply step counts apply step counts to add function void add(int a[][M_SIZE],int b[][M_SIZE], int c[][M_SIZE],int rows,int cols) { int i,j; for(i = 0; i < rows; i++) { count++; for(j = 0; j < cols; j++) { count++; c[i][j] = a[i][j] + b[i][j]; count++; } count++; } count++; } count statements Matrix addition with count statements

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Time Complexity combine counts void add(int a[][M_SIZE],int b[][M_SIZE],int c[][M_SIZE],int rows,int cols) { int i, j; for(i = 0; i < rows; i++) { for(j = 0; j < cols; j++) count += 2; } count++; } initially count = 0; total step count on termination : 2·rows·cols + 2·rows + 1; rows >> cols  exchange rows & cols

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Time Complexity  Tabular method construct a step count table 1) first determine the step count for each statement steps/execution(s/e) - steps/execution(s/e) 2) next figure out the number of times that each statement is executed frequency - frequency 3) total steps for each statement ( total steps)=(s/e)*(frequency) - (total steps)=(s/e)*(frequency)

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Time Complexity  Ex 1.12 [Iterative function to sum a list of numbers]: Step count table

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Time Complexity  Ex 1.13 [Recursive function to sum a list of numbers] Step count table for recursive summing function

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Time Complexity  Ex 1.14 [Matrix addition] Step count table for matrix addition

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Time Complexity factors: time complexity T(n) 1)input size depends on size of input(n) 2)input form depends on different possible input formats best case: B(n) = ? average case: A(n) = ? worst case: W(n) = ? - concerns mostly for “worst case” - worst case gives “upper bound”

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Asymptotic Notation comparing time complexities - exist different algorithms for the same task - which one is faster ? algorithm 1 task count f(n)g(n)

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Asymptotic Notation  Big “Oh” - O def) f(n) = O(g(n)) iff there exists a positive constant c and n 0 such that f(n)  c·g(n) for all n, n  n 0 n0n0 n g(n) f(n)

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Asymptotic Notation  Ex) [ f(n) = 25·n, g(n) = 1/3·n 2 ] 25·n = O(n 2 /3) let c = 1 and see there exists a positive constant 1 and n 0 such that |25·n|  1·|n 2 /3| for all n  n 0 (=75)

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Asymptotic Notation f(n) = O(g(n)) upper bound - g(n) is an upper bound on the value of f(n) for all n, n  n 0 does not - However, it does not say anything about how good this bound is, i.e. n = O(n 2 ), n = O(n 2.5 ) n = O(n 3 ), n = O(2 n ) - g(n) should be as small a function of n as one can come up with for which f(n) = O(g(n)) f(n) = O(g(n))  O(g(n)) = f(n)

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Asymptotic Notation Theorem if f(n) = a m n m a 1 n + a 0, then f(n) = O(n m ) proof) f(n)  |a k |·n k + |a k-1 |·n k |a 1 |·n + |a 0 | = {|a k | + |a k-1 |/n |a 1 |/n k-1 + |a 0 |/n k }·n k  {|a k | + |a k-1 | |a 1 | + |a 0 |}·n k = c·n k (c = |a k |+|a k-1 |+...+|a 1 |+|a 0 |) = O(n k )

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Asymptotic Notation  Big “Omega” -  def) f(n) = (g(n)) iff there exists a positive constants c and n 0 such that f(n)  c·g(n) for all n, n n 0 lower bound - g(n) is a lower bound on the value of f(n) for all n, n  n 0 as large a function of n as possible - should be as large a function of n as possible theorem) if f(n) = a m n m a 1 n + a 0 and a m > 0, then f(n) = (n m )

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Asymptotic Notation  Theta -  def) f(n) = (g(n)) iff there exists a positive constants c 1, c 2, and n 0 such that c 1 ·g(n)  f(n) c 2 ·g(n) for all n, n n 0 - more precise than both the “big oh” and “big omega” notations - g(n) is both an upper and lower bound on f(n)

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Asymptotic Notation  Ex 1.18 complexity of matrix addition] time complexity of matrix addition

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Practical Complexities class of time complexities O(1): constant O(log 2 n): logarithmic O(n): linear O(n·log 2 n): log-linear O(n 2 ): quadratic O(n 3 ): cubic O(2 n ): exponential O(n!): factorial polynomial time exponential time

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Practical Complexities polynomial time - tractable problem exponential time - intractable (hard) problem e.g.) - sequential search - binary search - insertion sort - heap sort - satisfiability problem - testing serializable scheduling

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Practical Complexities function value

Data Structures in C Networking Laboratory Chap Copyright(c) 2000, Sungkyunkwan University Practical Complexities If a program needs 2 n steps for execution n= number of steps = 1.1*10 12 in computer systems 1 billion steps/sec min n= days n= years n= *10 13 years If a program needs n 10 steps for execution n= sec n= years