Introduction to RealTime Systems - PowerPoint PPT Presentation

1 / 24
About This Presentation
Title:

Introduction to RealTime Systems

Description:

Introduction to RealTime Systems – PowerPoint PPT presentation

Number of Views:15
Avg rating:3.0/5.0
Slides: 25
Provided by: scie241
Category:

less

Transcript and Presenter's Notes

Title: Introduction to RealTime Systems


1
CS2302 Data Structures and Algorithms
Aim Provide a practical introduction to data
structures and algorithms.
2
Students will acquire the following
  • Apply basic algorithm design techniques
  • Use abstract data types in algorithm design
  • Have basic understanding in algorithm analysis

3
Materials to Be Covered
  • Abstract data type (ADT), stacks, queues
  • Priority queues, linked list, binary (search)
    trees
  • Hash tables
  • .
  • Divide--Conquer
  • Greedy
  • Dynamic Programming
  • .

4
Pre-cursor
  • CS2301 Problem Solving and Programming

5
Assessment
  • At least 30 examination marks are required to
    pass.
  • Coursework 40
  • 10 marks for exercises given at each lecture,
    it is required to complete during the tutorials.
  • 20 marks for quiz conducted in class, a couple
    of times, two maximum quizes will be taken into
    consideration of your mark.
  • 10 marks for a group project.
  • Examination 60
  • one 2-hour examination.

6
Textbook and reference books
  • Text Book
  • Algorithms, by Cormen, Leiserson, and Rivest
    (McGraw-Hill, 1990)
  • Reference books
  • Data structures, a pseudocode approach with C,
    by R.F. Gilberg, B.A. Forouzan (Brooks/Cole
    Thomson Learning, 2001).

7
Some helpful web sites
  • http//www.math.gatech.edu/randall/algorithms.htm
    l
  • http//www.cs.fit.edu/wds/classes/algorithms/Intro
    /intro/intro.html
  • http//www.eli.sdsu.edu/courses/fall96/cs660/notes
    /index.html
  • http//www.cs.toronto.edu/bor/366s01/

8
Teaching/Learning Methods
  • Before lecture read relevant chapters.
  • Lectures focus on key issues in relevant topics.
  • After Lecture study lecture notes and work on
    assigned exercises, test your learning using
    computer programs.
  • Tutorials working on selected problems

9
Introduction
1. Specification and design 2. Running time
analysis 3. Testing and Debugging
10
Design Strategy
1. Specify the input and the output 2. Design
the algorithm and data structures 3. Translate
the algorithm into a C codes 4. Testing and
debugging the program.
11
Prototype preconditions postconditions
  • Precondition a statement giving the condition
    that is supposed to be true when a function is
    called
  • postcondition a statement describing what will
    be true when a function call is completed.
  • Prototyping a function
  • the functions return type
  • the functions name
  • the functions parameter list
  • comments about the functions pre/post-conditions

12
An example of prototype
  • int max(int x, int y)
  • //Precondition two integers x and y as input
  • //postcondition the maximum number of x and //y
    is returned
  • //for example, max(2,3) is equivalent to 3

NOTE Here // is the prefix for comments. In
C, everything after // is ignored.
13
A Simple C Program Using max(,)
  • include ltiostream.hgt
  • int max (int, int)
  • int main()
  • cout ltlt The maximum of 2 and 3 is
  • cout ltlt max(2,3)
  • return 0

14
  • include ltiostream.hgt
  • it includes library codes for input/output
  • int max (int, int)
  • prototype of the function max(int, int)
  • int main()
  • the main function requires a return type of
    integer, execution of program starts from this
    function.
  • the content of the main function is within this
    pair of parenthesis.
  • cout ltlt The maximum of 2 and 3
  • cout is standard output (the screen, is the
    content of output.
  • cout ltlt max (2,3)
  • the number 3 is output to the screen

15
Typical Layout of a C Program
  • include ltiostream.hgt
  • //prototype of functions
  • int main()
  • //variable declarations
  • //statements
  • return 0
  • //implementation of functions

16
  • Algorithm is a sequence of precise instructions
    that leads to a solution.
  • Example 1 The word derives from the name of a
    ninth century Arabic mathematician Al-Khowarizmi
    who wrote a book about rules for solving
    numerical equations.
  • Example 2The Euclidean algorithm for finding the
    greatest common divisor of two integers.
  • Example 3 Guassian elimination method for
    solving linear equations in multiple variables.

17
  • An algorithm for solving axb0
  • test whether a0?
  • if yes, test whether b0?
  • if yes, any value of x is a solution.
  • else, no solution
  • else x-b/a is the solution.

18
Program Design Process
It consists of two phases
  • Implementation phase
  • In this phase, an algorithm for solving the
    problem is known.
  • The result is a program in c which implements
    the algorithm obtained in the previous phase.
  • Problem solving phase
  • In this phase, a problem specification is given.
  • The result of this phase is an algorithm (in a
    natural language) describing how to find a
    required solution for this problem.

19
Time Analysis
1. The time that takes a program to finish
depends on the input size. 2. We usually use n to
represent to input size. 3. We use the big-O
notation to describe the time that takes a
program to finish f(n)O(g(n)) iff there is a
constant Cgt0 and an integer N such that
f(n)ltCg(n) for all ngtN. 4. For a given input
size, different data sets may cause the program
to finish in different numbers of operations. We
use the maximum as the time complexity of the
program.
20
Debugging, Testing and Checking
  • bug a mistake in a program
  • debugging the process of eliminating bugs
  • testing Searching for bugs.
  • checking Make sure the output for an input is
    correct even though the program may contain bugs.

21
Errors
  • syntax errors
  • the compiler can help in locating this type of
    errors
  • error messages the program contains a bug
  • warning messages the program is correct in
    grammar but may contain errors.
  • run-time errors
  • Mistakes occurred during execution of the program
  • E.g., divide a number by zero.
  • logic errors
  • The implementation does not do what specified by
    the algorithm.

22
Elementary Tools for Debugging
  • Line by line execution of the program
  • C provides this mode of execution
  • Break lines in the program for execution to stop
  • It is also possible in C
  • Print out values of variables from locations
    where there may be an error.
  • The most convenient way to find out whether the
    values computed by the program are as expected.

23
Checking an Execution of a Program
  • Verifying correctness of a solution is usually
    easier than finding a solution of the problem.
  • We may write a function to test the correctness
    of the answer provided by a program without
    looking into the details of the program.
  • This is even more important when numerical
    stability comes into play one correct but not
    numerically stable program may return wrong
    answers to the original problem.

24
Question for next Tutorial
  • How to find the largest common divisor of two
    integers?
  • What is the complexity of your algorithm?
Write a Comment
User Comments (0)
About PowerShow.com