- By
**cael** - Follow User

- 132 Views
- Uploaded on

Download Presentation
## Algorithms

**An Image/Link below is provided (as is) to download presentation**

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

The Project for the Establishing the Korea ㅡ Vietnam College of Technology in BacGiang

Algorithms

April-May 2013

Dr. Youn-Hee Han

Name: Youn-Hee Han

Department: Computer Science and Engineering

Contact: 010-3912-0900

E-mail:yhhan@koreatech.ac.kr

- <Education Background>
- 1992 ~ 1996: B.S. in mathematics, Korea University
- 1996 ~ 1998: M.S. in Computer Science and Engineering, Korea University
- 1998 ~ 2002: Ph.D. in Computer Science and Engineering, Korea University
- <Working Experience>
- 2002 ~ 2006: Senior Researcher, Samsung Advanced Institute of Technology
- 2006 ~ Current: Prof., Korea University of Technology and Education

- <Research>
- Mobile Computing
- Sensor & Actuator Networks
- Social Network
- Web Science & Engineering

2/17

Lecture Guide

- Goal
- Introduce some important parts of the undergraduate-level “algorithms” course offered by KoreaTech
- You learn the core algorithm design strategies and specific algorithms
- You can practice Java programming for the specific algorithms
- Lecture Contents & Schedule
- 1st day (3 hours): Introduction of Algorithm, Algorithm Efficiency
- 2nd day (3 hours): Algorithm Complexity
- 3rd day (3 hours): Algorithm Design Strategy 1 – Divide & Conquer
- 4th day (3 hours): Algorithm Design Strategy 2 – Dynamic Programming
- 5th day (3 hours): Algorithm Design Strategy 3 – Greedy Approach
- 6thday (3 hours): Algorithm Design Strategy 4 – Backtracking
- Lecture Homepage
- http://link.koreatech.ac.kr/courses/2013_1/AP-KOICA/AP-KOICA20131.html

Whatis Algorithms?

- A computer program is composed of individual modules, understandable by a computer, that solve specific tasks (such as sorting).
- These specific tasks are called problems.
- A problem may contain variables that are not assigned specific values in the statement of the problem.
- These variables are called parameters to the problem.
- Each specific assignment of values to the parameters is called an instance of the problem.

Whatis Algorithms?

- To produce a computer program that can solve all instances of a problem, we must specify a general step-by-step procedure for producing the solution to each instance.
- This step-by-step procedure is called an algorithm.
- We say that the algorithm solves the problem.
- A problem can be solved by many different algorithms.
- Features of algorithm
- Correct
- Finite length
- Terminate for all inputs.

Importance of Efficient Algorithms

- Sequential Search vs. Binary Search
- Sequential Search
- It begins at the first position in the array and looks at each value in turn until the item is found.

index seqsearch(intn,type[] S, type x){

index location;

location = 1;

while (location <= n && S[location] != x)

location++;

if (location > n)

location = 0;

return location;

}

Importance of Efficient Algorithms

- Sequential Search vs. Binary Search
- Binary Search (with sorted array)
- It first compares x with the middle item of the array.
- If they are equal, the algorithm is done.
- If x is smaller than the middle item,
- then x must be in the first half of the array
- and the algorithm repeats the searching procedure on the first half of the array.
- If x is larger than the middle item,
- then the search is repeated on the second half of the array.
- This procedure is repeated until x is found or it is determined that x is not in the array.

Importance of Efficient Algorithms

- Sequential Search vs. Binary Search
- Binary Search (with sorted array)

index binsearch(intn, keytype[] S, keytypex)

{

index location, low, high, mid;

low = 1; high = n;

location = 0;

while (low <= high && location == 0) {

mid = (low + high) / 2; if (x == S[mid]) location = mid;

else if (x < S[mid]) high = mid – 1;

else low = mid + 1;

}

return location;

}

Importance of Efficient Algorithms

- Sequential Search vs. Binary Search
- What is the number of times the algorithm does the basic (or critical) operation for an instance of size n?
- Sequential Search
- Minimum (Best): 1
- Maximum (Worst): n
- Binary Search
- Minimum (Best): 1
- Maximum (Worst): log2n+1
- Array size – 16(=24) # of the operation executions – 5
- Array size – 32(=25) # of the operation executions – 6
- Array size – 64(=26) # of the operation executions – 7
- …
- Array size – 2k # of the operation executions – k+1
- Array size – n # of the operation executions – log2n+1

Importance of Efficient Algorithms

- Sequential Search vs. Binary Search

Importance of Efficient Algorithms

- Fibonacci Sequence
- 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, …

Importance of Efficient Algorithms

- Fibonacci Sequence: Recursive vs. Iterative
- Recursive Algorithm
- Recursive algorithms have…
- Stopping condition
- Recursive call of the function itself

long fib(int n)

{

if (n <= 1)

return n;

else

return (fib(n-1) + fib(n-2));

}

Importance of Efficient Algorithms

- Fibonacci Sequence: Recursive vs. Iterative
- Recursive Algorithm
- Demerits
- So many “duplicate calculation” of the same values

Importance of Efficient Algorithms

- Fibonacci Sequence: Recursive vs. Iterative
- Recursive Algorithm
- The number of function calls
- For an even number n

n=2 above 2

n=4 above 22=4

n=6 above 23=8

…

n=50 above 225=33554432

Importance of Efficient Algorithms

- Fibonacci Sequence: Recursive vs. Iterative
- Iterative Algorithm

long fib2 (int n)

{

index i;

long[] f = new long[n+1];

f[0] = 0;

if (n > 0) {

f[1] = 1;

for (i = 2; i <= n; i++)

f[i] = f[i-1] + f[i-2];

}

return f[n];

}

Importance of Efficient Algorithms

- Fibonacci Sequence: Recursive vs. Iterative
- Iterative Algorithm
- The number of f[i] calculations : n + 1
- Assume that it takes 1 nano second for each of “calculation” and “function call”

[Programming Practice 1]

- Sequential Search vs. Binary Search
- Visit
- http://link.koreatech.ac.kr/courses/2013_1/AP-KOICA/AP-KOICA20131.html
- Download “SearchMain.java” and run it
- Analyze the source codes
- Complete the source codes while insert right codes within the two functions
- public static intsequentialSearch()
- public static intbinarySearch()
- Compare the execution times of the two functions

Download Presentation

Connecting to Server..