F4104 : ALGORITHM & DATA STRUCTURE

advertisement
F4104 : ALGORITHM & DATA STRUCTURE
Laboratory
Exercises
LAB 9: Linear Search
Duration: 2 Hours
Learning Outcomes
This Labsheet encompasses activities 9A.
By the end of this laboratory session, you should be able to:
1. Define searching.
2. Explain linear searching algorithm.
3. Apply linear searching method to solve a given problem.
Exercise 9A
Outcome: Use linear searching to solve problems
In linear search, items in a list are searched one by one (starting from the first) and
compared to given key value. The search ends when the key value matches with the given
item.
The following is unsorted list. By using linear searching, find how many steps needed to find
the desired value. Illustrate the process.
i.
ii.
Find 12 in : {90 4 20 11 88 38
Find M in : {C O M P U T E R}
12
3
15}
(8 marks)
(PLO2, CLO4, LD2)
Conclusion
(2 marks)
(PLO2, CLO4, LD2)
Page 1 of 1
Download