0% found this document useful (0 votes)
10 views

Numerical Computation_Lec_2_Part 1.pdf

The document outlines the course material for a Numerical Computation lecture, focusing on algorithms, their time and space complexities, and sorting methods, particularly Insertion Sort. It emphasizes the importance of analyzing algorithms for efficiency and provides examples of sorting problems. The lecture is part of a broader curriculum that includes various algorithmic techniques and numerical methods.

Uploaded by

Jumayna Ghida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Numerical Computation_Lec_2_Part 1.pdf

The document outlines the course material for a Numerical Computation lecture, focusing on algorithms, their time and space complexities, and sorting methods, particularly Insertion Sort. It emphasizes the importance of analyzing algorithms for efficiency and provides examples of sorting problems. The lecture is part of a broader curriculum that includes various algorithmic techniques and numerical methods.

Uploaded by

Jumayna Ghida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Numerical

Computation
Lecture 2 (Part1)

Dr. Metwally Rashad


2023
Course Material
Book
T. H. Cormen, C. E. Leiserson, R.
L.Rivest, C. Stein. Introduction
to Algorithms , 3rd Edition, 2009.
Course Contents

Part 1 Part 2 Part 3


 Foundations  More Algorithms
- The Role of Algorithms in - Sorting Algorithms
Computing - Graph Algorithms
- Design and Analysis algorithms - Dynamic Programming
- Growth of Functions - Greedy Algorithms
 Numerical Methods
- Solving Nonlinear
Equations
- Solving Linear Systems
- Interpolation,
Polynomial Approximation
1/16
Lec.2: The Role of
Algorithms in
Computing
Time & Space Complexity
 Time Complexity is a function describing the
a mount of time required to run an algorithm in
terms of the size of the input.

 Space Complexity is a function describing the


a mount of memory an algorithm takes in terms
of the size of the input.

3/16
Comparing between two Algorithms

Algorithm A o Model of computation :


Hardware, Operating
Exec_Time = 10msec System, Processor, etc
RAM = 100KB

Algorithm B o If I change the model of


computation, the time
Exec_Time = 2msec and space may change
RAM = 10KB
4/16
Sorting Problem
 Sort a sequence of numbers into non-decreasing order

Example:
Input: 8 2 4 9 3 6
Output:
2 3 4 6 8 9
- Input sequence is called an instance of the sorting problem. 5/16
Sorting Problem (cont.)
 Efficiency
o Different algorithms devised to solve the same problem often
differ dramatically in their efficiency.
o These differences can be much more significant than differences
due to hardware and software
o In this chapter, we will see two algorithms for sorting problem

6/16
Insertion Sort
 Solves the sorting problem
 An efficient algorithm for sorting a small
number of elements
 Works the way many people sort a hand of playing
cards
 Start with an empty left hand and the cards face
down on the table
 Then remove one card at a time from the table and
insert it into the correct position in the left hand
 To find the correct position for a card, we compare
it with each of the cards already in the hand, from right to left
7/16
Insertion Sort (cont.)

keys: The numbers that


we wish to sort

8/16
Example of Insertion Sort

9/16
Analysis of Algorithms
 Analysis of Algorithms is the determination of the amount of time,
storage and/or other resources necessary to execute them.
 Analyzing algorithms is called Asymptotic Analysis
 We shall assume a generic one processor, random-access machine
(RAM) model of computation as our implementation technology and
understand that our algorithms will be implemented as computer
programs.
 In the RAM model, instructions are executed one after another
 The running time depends on the input: an already sorted sequence is
easier to sort and short sequences are easier to sort than long ones.
10/16
Analysis of Algorithms (cont.)
 We can have three cases to analyze an algorithm

2 3 5 4 1 7 6
11/16
Analysis of Algorithms (cont.)

2 3 5 4 1 7 6
12/16
Analysis of Algorithms (cont.)

13/16
Analysis of Algorithms (cont.)

time number of times 14/16


Analysis of Algorithms (cont.)
 Running time of insertion sort in worst case

 Running time of insertion sort in best case


- occurs if the array is already sorted.

15/16
Analysis of Algorithms (cont.)
 Best Case

 Worst Case

 Average Case

16/16
Lec.3: Design and Analysis
Divide & Conquer
Thank
you!

You might also like