Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. Hi all,
  2.  
  3. As I was sat in the meeting today I was thinking about testing and how to demonstrate the point about how we need to test and document everything, even if we think it's simple/obvious.
  4.  
  5. So I'm giving you all a task that I'd like you to take seriously. I'd like you all to implement the binary search algorithm, by yourself without reference to the internet.
  6.  
  7. The binary search is a simple and effective algorithm to determine whether a presorted array contains a target element "t". If the array contains "t", the program returns its position in the array, otherwise it returns -1. For the purposes of this, assume that "t" is an integer.
  8.  
  9. The algorithm works by keeping track of the range within the array that holds "t". Initially, the range is the entire array. The range is shrunk by comparing its middle element to "t" and discarding half the range. The process
  10. continues until "t" is discovered in the array or until the range in which it must lie is known to be empty.
  11.  
  12. Implement it in any language you like with as much testing as you see fit. If you want to make my life easier then implement it in C as a function that looks like this:
  13.  
  14. int binary_search(int target, const inst *array, int count);
  15.  
  16. where target is what is being searched for, array is the pre-sorted array and count is the number of elements in the array.
  17.  
  18. After you've finished, send me the source.
  19.  
  20. The point of this is not about getting it "right", it's about seeing the different pitfalls that each of you come up against even with something that is much simpler than the problems we're dealing with. With that in mind, I'll treat any no replies as a much bigger failure than non-working code :)
  21.  
  22. Do you think you could manage this by Friday end of play?
  23.  
  24. Cheers
  25. ,
  26. <<<Boss>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement