Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Searching Prudence Wong

Slides:



Advertisements
Similar presentations
Convolutional Codes Mohammad Hanaysheh Mahdi Barhoush.
Advertisements

Lecturer: Sebastian Coope Ashton Building, Room G.18 COMP 201 web-page: Lecture.
Efficient Probe Selection in Micro-array Design Speaker: Cindy Y. Li Joint work with: Leszek G ą sieniec, Paul Sant, and.
Revision.
Order Analysis of Algorithms Debdeep Mukhopadhyay IIT Madras.
TOPIC : Finite State Machine(FSM) and Flow Tables UNIT 1 : Modeling Module 1.4 : Modeling Sequential circuits.
Al-Karma Language School Computer Department Prep. 3.
CSE115/ENGR160 Discrete Mathematics 02/24/11 Ming-Hsuan Yang UC Merced 1.
Text Chapters 1, 2. Sorting ä Sorting Problem: ä Input: A sequence of n numbers ä Output: A permutation (reordering) of the input sequence such that:
CS 140 Lecture 18 Professor CK Cheng 6/04/02. Part IV. System Designs Algorithm: { Input X, Y type bit-vector, start type boolean; Local-Object A, B type.
Introduction to Algorithm – part one Jennifer Elmer Form 3 Computing.
Final Exam Review Instructor : Yuan Long CSC2010 Introduction to Computer Science Apr. 23, 2013.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Maximum-sum contiguous subarray Prudence Wong.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Greedy methods Prudence Wong
COMP108 Time Complexity of Pseudo Code. Example 1 sum = 0 for i = 1 to n do begin sum = sum + A[i] end output sum O(n)
Introduction to Algorithms By Mr. Venkatadri. M. Two Phases of Programming A typical programming task can be divided into two phases: Problem solving.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Basics Prudence Wong
1 Section 2.1 Algorithms. 2 Algorithm A finite set of precise instructions for performing a computation or for solving a problem.
Math – What is a Function? 1. 2 input output function.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Basics Prudence Wong
CSC 111. Solving Problems with Computers Java Programming: From Problem Analysis to Program Design, Third Edition3 Solving Problems Stages 1.Problem.
1 State Reduction Goal: reduce the number of states while keeping the external input-output requirements unchanged. State reduction example: a: input 0.
Iconic Programmer A Visualization Tool for Teaching Concepts without Context.
COMP108 Algorithmic Foundations Polynomial & Exponential Algorithms
Introduction to Complexity Analysis. Computer Science, Silpakorn University 2 Complexity of Algorithm algorithm คือ ขั้นตอนการคำนวณ ที่ถูกนิยามไว้อย่างชัดเจนโดยจะ.
Flowchart. a diagram of the sequence of movements or actions of people or things involved in a complex system or activity. a graphical representation.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Divide and Conquer Prudence Wong
Flowcharts C++ Lab. Algorithm An informal definition of an algorithm is: a step-by-step method for solving a problem or doing a task. Input data A step-by-step.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Mathematical Induction Prudence Wong
亚洲的位置和范围 吉林省白城市洮北区教师进修学校 郑春艳. Q 宠宝贝神奇之旅 —— 亚洲 Q 宠快递 你在网上拍的一套物理实验器材到了。 Q 宠宝贝打电话给你: 你好,我是快递员,有你的邮件,你的收货地址上面 写的是学校地址,现在学校放假了,能把你家的具体 位置告诉我吗? 请向快递员描述自己家的详细位置!
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong.
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Algorithm efficiency Prudence Wong
Starter Complete the Word Search. CG3.7 Algorithms (The Insertion Sort (Chapter 46) & Algorithm Testing)
Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Basics Prudence Wong
DEVRY COMP 122 L AB 1 L AB R EPORT AND S OURCE C ODE C HECK THIS A+ TUTORIAL GUIDELINE AT HTTP :// WWW. ASSIGNMENTCLOUD. COM / COMP -122/ COMP LAB.
The New Primary National Curriculum
ICS 3UI - Introduction to Computer Science
Pseudo-code 1 Running time of algorithm is O(n)
Learning outcomes 2 Developing Code – Input Output Model
COMP108 Algorithmic Foundations Mathematical Induction
COMP108 Algorithmic Foundations Basics
COMP108 Algorithmic Foundations Polynomial & Exponential Algorithms
COMP108 Algorithmic Foundations Greedy methods
COMP108 Algorithmic Foundations Algorithm efficiency
COMP108 Algorithmic Foundations Divide and Conquer
COMP108 Algorithmic Foundations Divide and Conquer
Lab. on Finite State Machine
Sequential Circuit: Counter
Numbering System TODAY AND TOMORROW 11th Edition
Introduction to Algorithm – part 1
Sorting Data are arranged according to their values.
Alyce Brady CS 470: Data Structures CS 510: Computer Algorithms
شاخصهای عملکردی بیمارستان
Databases Lesson 2.
مدل زنجیره ای در برنامه های سلامت
فرق بین خوب وعالی فقط اندکی تلاش بیشتر است
Sorting Data are arranged according to their values.
Algorithms Take a look at the worksheet. What do we already know, and what will we have to learn in this term?
Function Notation “f of x” Input = x Output = f(x) = y.
Computer Science Sorting Pre-Test Discussion/program
Sequential Design Example
Homing sequence: to identify the final state.
Sorting Develop a sorting algorithm
COMP108 Algorithmic Foundations Dynamic Programming
COMP108 Algorithmic Foundations Basics
COMP108 Algorithmic Foundations Searching
EXPLICIT RULES: INPUT-OUTPUT FORMULAS
COMP108 Algorithmic Foundations Searching
Homework #2 Due May 29 , Consider a (2,1,4) convolutional code with g(1) = 1+ D2, g(2) = 1+ D + D2 + D3 a. Draw the.
COMP108 Algorithmic Foundations Mathematical Induction
Presentation transcript:

Algorithmic Foundations COMP108 COMP108 Algorithmic Foundations Searching Prudence Wong

Algorithmic Foundations COMP108 Searching  Input: n numbers a 1, a 2, …, a n ; and a number X  Output: determine if X is in the sequence or not  Algorithm (Sequential search): 1. From i=1, compare X with a i one by one as long as i <= n. 2. Stop and report "Found!" when X = a i. 3. Repeat and report "Not Found!" when i > n. 2 (Searching)

Algorithmic Foundations COMP108 Sequential Search  six numbers 7number X   found! To find 7 3 (Searching)

Algorithmic Foundations COMP108 Sequential Search (2)   not found! To find 10 4 (Searching)

Algorithmic Foundations COMP108 Sequential Search – Pseudo Code i = 1 while i <= n do begin if X == a[i] then report "Found!" and stop else i = i+1 end report "Not Found!" Challenge: Modify it to include stopping conditions in the while loop 5 (Searching)

Algorithmic Foundations COMP108 Sequential Search – Pseudo Code i = 1 found = false while i <= n && found==false do begin if X == a[i] then found = true else i = i+1 end if found==true then report "Found!" else report "Not Found!" 6 (Searching)

Algorithmic Foundations COMP108 Number of comparisons? i = 1 while i <= n do begin if X == a[i] then report "Found!" & stop else i = i+1 end report "Not Found!" Best case: X is 1st no.  1 comparison Worst case: X is last OR X is not found  n comparisons 7 (Searching) How many comparisons this algorithm requires?

Algorithmic Foundations COMP108 Finding maximum / minimum... 2 nd max / min…

Algorithmic Foundations COMP108 9 (Searching) Finding max from n +ve numbers input: a[1], a[2],..., a[n] M = 0 i = 1 while (i <= n) do begin M = max(M, a[i]) i = i + 1 end output M What about minimum? For simplicity, we assume the function max(X, Y) returns the larger of X & Y

Algorithmic Foundations COMP (Searching) Finding min from n +ve numbers input: a[1], a[2],..., a[n] M = a[1] i = 1 while (i <= n) do begin M = min(M, a[i]) i = i + 1 end output M How many comparisons? n

Algorithmic Foundations COMP (Searching) Finding 1 st and 2 nd min input: a[1], a[2],..., a[n] M1 = min(a[1], a[2]) M2 = max(a[1], a[2]) i = 3 while (i <= n) do begin if (a[i] < M1) then M2 = M1, M1 = a[i] else if (a[i] < M2) then M2 = a[i] i = i + 1 end output M1, M2 Two variables: M1, M2 How to update M1, M2?

Algorithmic Foundations COMP (Searching) Finding location of minimum input: a[1], a[2],..., a[n] loc = 1 // location of the min number i = 2 while (i <= n) do begin if (a[i] < a[loc]) then loc = i i = i + 1 end output a[loc] end of) Iteration loca[loc]i Example a[]={50,30,40,20,10}

Algorithmic Foundations COMP108 Finding min using for-loop  Rewrite the above while-loop into a for-loop input: a[1], a[2],..., a[n] loc = 1 for i = 1 to n do begin if (a[i] < a[loc]) then loc = i end output a[loc] 13 (Searching)