

















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
During the study of discrete mathematics, I found this course very informative and applicable.The main points in these lecture slides are:Type of Algorithm, Finite Set of Precise Instructions, Maximum Element, Programming Language, Pseudocode, Element Running Time, Worst Case Scenario, Properties of Algorithms, Searching Algorithms, Linear Search
Typology: Slides
1 / 25
This page cannot be seen from the preview
Don't miss anything!
procedure max ( a 1 , a 2 , …, a (^) n : integers) max := a 1 for i := 2 to n if max < a (^) i then max := a (^) i
{ max is the largest element}
procedure linear_search ( x : integer; a 1 , a 2 , …, a (^) n : integers) i := 1 while ( i ≤ n and x ≠ a (^) i ) i := i + 1 if i ≤ n then location := i else location := 0
{ location is the subscript of the term that equals x, or it is 0 if x is not found}
Algorithm 2: Linear search, take 1
11
procedure linear_search ( x : integer; a 1 , a 2 , …, an : integers)
i := 1 while ( i ≤ n and x ≠ ai )
i := i + 1 if i ≤ n then location := i
else location := 0
i := 1 while ( i ≤ n and x ≠ ai )
i := i + 1 if i ≤ n then location := i
else location := 0
a 1 a 2 a 3 a 4 a 5 a 6 a 7 a 8 a 9 a 10
i 23456781
x 3
location 8
procedure binary_search ( x : integer; a 1 , a 2 , …, an : increasing integers) i := 1 { i is left endpoint of search interval } j := n { j is right endpoint of search interval } while i < j begin m := ( i + j )/2 { m is the point in the middle } if x > am then i := m + else j := m end if x = ai then location := i else location := 0 { location is the subscript of the term that equals x, or it is 0 if x is not found}
Algorithm 3: Binary search, take 2
16
a 1 a 2 a 3 a 4 a 5 a 6 a 7 a 8 a 9 a 10
i m j
i := 1 j := n
procedure binary_search ( x : integer; a 1 , a 2 , …, a (^) n : increasing integers) while i < j begin m := ( i + j )/2 if x > am then i := m + else j := m end
if x = ai then location := i else location := 0
i := 1 j := n
while i < j begin m := ( i + j )/2 if x > am then i := m + else j := m end
if x = ai then location := I else location := 0
x 15
location 0
procedure bubble_sort ( a 1 , a 2 , …, a (^) n ) for i := 1 to n - for j := 1 to n - i if a (^) j > a (^) j + then interchange a (^) j and a (^) j + { a 1 , …, a (^) n are in increasing order }