CIS3355:
Business Data Structures |
What is a Binary Search and What is an example of one?
A sequential list is the simplest way of traversing a list in order to find an element. If a list is ordered, whether in ascending or descending order, we do not have to search every element on the list. A binary search is performed on data that is sorted whether it is in the form of a tree, array, list or other structure. A binary search is when we split a sorted list in half each time in order to reduce our list of potential candidates as quickly as possible. It locates the middle entry of the array and the key value it is searching for. If it happens to be the middle element, then it completes its search, if not then it performs the search based on where the key value is greater or less than the middle element.
Consider the following example.
Now its time to answer some questions: Question 1 When you first perform a binary search you: a) Search starting from the lef b) Search starting from the middle c) Search starting from the right d) Find the largest character and search from there Answer b) Search starting from the middleQuestion 2 What are some of the disadvantages of a binary search? a) Extensive Maintenance b) Must have an equal amount to locate the middle c) Programmatically more complex d) a and c Answer a and c) Extensive Maintenance and Programmatically more complex Question 3 What are some of the advantages of a binary search? a) Not as much maintenance involved b) Program not as complex c) Easy to find elements and good for longer lists d) All of the above Answer c) Easy to find elements and good for longer lists Question 4 Before doing a binary search, the information must be ? a) unsorted b) sorted c) long d) None of of the above Answer b) sorted Question 5 True or False. Sorted information can only be in ascending order. Answer False. The sorted information can be in ascending or descending order. Here are some excellent websites to look at: http://www.cs.bristol.ac.uk/Teaching/Resources/COMS30119/slides/ds2/sld039.htm?o=8002 http://www.cs.uregina.ca/Links/class-info/170/bsearch.html http://www.cprogramming.com/tutorial.html http://homepages.ius.edu/JDRUIN/html_pages/C++_examples.htm
|