CSCE 3110 Data Structures & Algorithm Analysis

Slides:



Advertisements
Similar presentations
Analysis of Computer Algorithms
Advertisements

Chapt.2 Machine Architecture Impact of languages –Support – faster, more secure Primitive Operations –e.g. nested subroutine calls »Subroutines implemented.
CSCE 3110 Data Structures & Algorithm Analysis
CHAPTER 2 ALGORITHM ANALYSIS 【 Definition 】 An algorithm is a finite set of instructions that, if followed, accomplishes a particular task. In addition,
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Lecture 1: Overview of Computers & Programming
Algorithms and Problem Solving
Chapter 1 – Basic Concepts
16/13/2015 3:30 AM6/13/2015 3:30 AM6/13/2015 3:30 AMIntroduction to Software Development What is a computer? A computer system contains: Central Processing.
Wednesday, 9/4/02, Slide #1 1 CS 106 Intro to CS 1 Wednesday, 9/4/02  Today: Introduction, course information, and basic ideas of computers and programming.
Data Structures Performance Analysis.
Basic Definitions Data Structures: Data Structures: A data structure is a systematic way of organizing and accessing data. Or, It’s the logical relationship.
PRE-PROGRAMMING PHASE
Design and Analysis of Algorithms
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Cmpe 589 Spring Software Quality Metrics Product  product attributes –Size, complexity, design features, performance, quality level Process  Used.
Simple Program Design Third Edition A Step-by-Step Approach
High level & Low level language High level programming languages are more structured, are closer to spoken language and are more intuitive than low level.
C. – C. Yao Data Structure. C. – C. Yao Chap 1 Basic Concepts.
CSCE 3110 Data Structures & Algorithm Analysis Algorithm Analysis I Reading: Weiss, chap.2.
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.
Data Structures & AlgorithmsIT 0501 Algorithm Analysis I.
1 Computing Software. Programming Style Programs that are not documented internally, while they may do what is requested, can be difficult to understand.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
CSC-115 Introduction to Computer Programming
CS Data Structures Chapter 1 Basic Concepts.
Software Life Cycle Requirements and problem analysis. –What exactly is this system supposed to do? Design –How will the system solve the problem? Coding.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
Lecture 4. RAM Model, Space and Time Complexity
Prepared By Ms.R.K.Dharme Head Computer Department.
Introduction to Algorithms By Mr. Venkatadri. M. Two Phases of Programming A typical programming task can be divided into two phases: Problem solving.
Complexity of Algorithms
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
IXA 1234 : C++ PROGRAMMING CHAPTER 1. PROGRAMMING LANGUAGE Programming language is a computer program that can solve certain problem / task Keyword: Computer.
Algorithms & Flowchart
Algorithm Analysis Problem Solving Space Complexity Time Complexity
Data Structures Using C++ 2E
CS404 Design and Analysis of Algorithms BBy DDr. M V S Peri Sastry BB.E, PhD(BITS-Pilani)
Computer science is a field of study that deals with solving a variety of problems by using computers. To solve a given problem by using computers, you.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
MIT App Inventor Lesson 3 Algorithms Variables Procedures.
Onlinedeeneislam.blogspot.com1 Design and Analysis of Algorithms Slide # 1 Download From
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
Algorithm Analysis Lakshmish Ramaswamy. What Constitutes Good Software? Code correctness Good design Code reusability OO design can help us in achieving.
Software. Introduction n A computer can’t do anything without a program of instructions. n A program is a set of instructions a computer carries out.
PROGRAMMING FUNDAMENTALS INTRODUCTION TO PROGRAMMING. Computer Programming Concepts. Flowchart. Structured Programming Design. Implementation Documentation.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
Software Engineering Algorithms, Compilers, & Lifecycle.
SPACE COMPLEXITY & TIME COMPLEXITY 1. ALGORITHMS COMPLEXITY 2.
Maitrayee Mukerji. INPUT MEMORY PROCESS OUTPUT DATA INFO.
ICS 3UI - Introduction to Computer Science
Learning outcomes 2 Developing Code – Input Output Model
INTRODUCTION TO PROBLEM SOLVING
Unit 3: ALGORITHMS AND FLOWCHARTS
Computer Programming (BCT 1113)
ALGORITHMS AND FLOWCHARTS
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Courtsey & Copyright: DESIGN AND ANALYSIS OF ALGORITHMS Courtsey & Copyright:
Developing Applications
Algorithm.
Unit# 9: Computer Program Development
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.
Chapter 1 Introduction(1.1)
POWERPOINT PRESENTATION
Visit for more Learning Resources
Revision of C++.
Algorithm: Word comes from Arabic Author Abū ‘Abdallāh Muḥammad ibn Mūsā al-Khwārizmī Algorism Algebra: Kitab al-Mukhtasar fi Hisab al-Jabr wal-Muqabala.
Basic Concepts of Algorithm
ICS103 Programming in C 1: Overview of Computers And Programming
Presentation transcript:

CSCE 3110 Data Structures & Algorithm Analysis Rada Mihalcea http://www.cs.unt.edu/~rada/CSCE3110 Algorithm Analysis I Reading: Weiss, chap.2

Problem Solving: Main Steps Problem definition Algorithm design / Algorithm specification Algorithm analysis Implementation Testing [Maintenance]

1. Problem Definition What is the task to be accomplished? Calculate the average of the grades for a given student Understand the talks given out by politicians and translate them in Chinese What are the time / space / speed / performance requirements ?

2. Algorithm Design / Specifications Algorithm: Finite set of instructions that, if followed, accomplishes a particular task. Describe: in natural language / pseudo-code / diagrams / etc. Criteria to follow: Input: Zero or more quantities (externally produced) Output: One or more quantities Definiteness: Clarity, precision of each instruction Finiteness: The algorithm has to stop after a finite (may be very large) number of steps Effectiveness: Each instruction has to be basic enough and feasible Understand speech Translate to Chinese

4,5,6: Implementation, Testing, Maintainance Decide on the programming language to use C, C++, Lisp, Java, Perl, Prolog, assembly, etc. , etc. Write clean, well documented code Test, test, test Integrate feedback from users, fix bugs, ensure compatibility across different versions  Maintenance

3. Algorithm Analysis Space complexity Time complexity How much space is required Time complexity How much time does it take to run the algorithm Often, we deal with estimates!

Space Complexity Space complexity = The amount of memory required by an algorithm to run to completion [Core dumps = the most often encountered cause is “memory leaks” – the amount of memory required larger than the memory available on a given system] Some algorithms may be more efficient if data completely loaded into memory Need to look also at system limitations E.g. Classify 2GB of text in various categories [politics, tourism, sport, natural disasters, etc.] – can I afford to load the entire collection?

Space Complexity (cont’d) Fixed part: The size required to store certain data/variables, that is independent of the size of the problem: - e.g. name of the data collection - same size for classifying 2GB or 1MB of texts Variable part: Space needed by variables, whose size is dependent on the size of the problem: - e.g. actual text - load 2GB of text VS. load 1MB of text

Space Complexity (cont’d) S(P) = c + S(instance characteristics) c = constant Example: void float sum (float* a, int n) { float s = 0; for(int i = 0; i<n; i++) { s+ = a[i]; } return s; Space? one word for n, one for a [passed by reference!], one for i  constant space!

Time Complexity Often more important than space complexity space available (for computer programs!) tends to be larger and larger time is still a problem for all of us 3-4GHz processors on the market still … researchers estimate that the computation of various transformations for 1 single DNA chain for one single protein on 1 TerraHZ computer would take about 1 year to run to completion Algorithms running time is an important issue

Running Time Problem: prefix averages Sol 1 Sol 2 Given an array X Compute the array A such that A[i] is the average of elements X[0] … X[i], for i=0..n-1 Sol 1 At each step i, compute the element X[i] by traversing the array A and determining the sum of its elements, respectively the average Sol 2 At each step i update a sum of the elements in the array A Compute the element X[i] as sum/I Big question: Which solution to choose?

Running time Suppose the program includes an if-then statement that may execute or not:  variable running time Typically algorithms are measured by their worst case

Experimental Approach Write a program that implements the algorithm Run the program with data sets of varying size. Determine the actual running time using a system call to measure time (e.g. system (date) ); Problems?

Experimental Approach It is necessary to implement and test the algorithm in order to determine its running time. Experiments can be done only on a limited set of inputs, and may not be indicative of the running time for other inputs. The same hardware and software should be used in order to compare two algorithms. – condition very hard to achieve!

Use a Theoretical Approach Based on high-level description of the algorithms, rather than language dependent implementations Makes possible an evaluation of the algorithms that is independent of the hardware and software environments  Generality

Algorithm Description How to describe algorithms independent of a programming language Pseudo-Code = a description of an algorithm that is more structured than usual prose but less formal than a programming language (Or diagrams) Example: find the maximum element of an array. Algorithm arrayMax(A, n): Input: An array A storing n integers. Output: The maximum element in A. currentMax  A[0] for i 1 to n -1 do if currentMax < A[i] then currentMax  A[i] return currentMax

Pseudo Code Expressions: use standard mathematical symbols use  for assignment ( ? in C/C++) use = for the equality relationship (? in C/C++) Method Declarations: -Algorithm name(param1, param2) Programming Constructs: decision structures: if ... then ... [else ..] while-loops while ... do repeat-loops: repeat ... until ... for-loop: for ... do array indexing: A[i] Methods calls: object method(args) returns: return value Use comments Instructions have to be basic enough and feasible!

Low Level Algorithm Analysis Based on primitive operations (low-level computations independent from the programming language) E.g.: Make an addition = 1 operation Calling a method or returning from a method = 1 operation Index in an array = 1 operation Comparison = 1 operation etc. Method: Inspect the pseudo-code and count the number of primitive operations executed by the algorithm

Example Algorithm arrayMax(A, n): Input: An array A storing n integers. Output: The maximum element in A. currentMax A[0] for i  1 to n -1 do if currentMax < A[i] then currentMax  A[i] return currentMax How many operations ?

Asymptotic Notation Need to abstract further Give an “idea” of how the algorithm performs n steps vs. n+5 steps n steps vs. n2 steps

Problem Fibonacci numbers Pseudo-code Number of operations F[0] = 0 F[i] = F[i-1] + F[i-2] for i  2 Pseudo-code Number of operations