Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: nded with a constant the amount of hay that find will accept (and because the value of sort’s second parameter is bounded by an int’s 32 bits) the running time of sort, however implemented, is arguably O(1). Even so, for the sake of this asymptotic challenge, think of the size of sort’s input as n. 4 Leverage that assumption! 7 < 13 This is CS50. Harvard College Fall 2010 Incidentally, check out Resources on the course’s website for a great little quick ­reference guide for gdb. If you’d like to play with the staff’s own implementation of find on cloud.cs50.net, you may execute the below. ~cs50/pub/solutions/hacker3/find Need help? Head to help.cs50.net! Now that sort (presumably) works, it’s time to improve upon search, the other function that lives in helpers.c. Notice that our version implements “linear search,” whereby search looks for value by iterating over the integers in array linearly, from left to right. Rip out the lines that we’ve written and re ­implement search as binary search, that divide ­and ­conquer strategy that we employed in Week 0 in order to search through phone book.5 You are welcome to take an iterative or a recursive approach. If you pursue the latter, though, know that you may not change our declaration of search, but you may write a new, recursive function (that perhaps takes different parameters) that search itself calls. The Game Begins. And now it’s time to play. The Game of Fifteen is a puzzle played on a square, two ­dimensional board with numbered tiles that slide. The goal of this puzzle is to arrange the board’s tiles from smallest to largest, left to right, top to bottom, with an empty space in board’s bottom ­right corner, as in the below.6 5 No need to tear anything in half. Figure from http://en.wikipedia.org/wiki/Fifteen_puzzle. 6 8 < 13 This is CS50. Harvard College Fall 2010 Sliding any tile that borders the board’s empty space into that space constitutes a “move.” Although the configuration above depicts a game already won, notice how the tile numbered 12 or the tile numbered 15 could be slid into the empty space. Tiles may not be moved diagonally, though, or forcibly removed from the board. Depicted below is just one configuration from which the puzzle is solva...
View Full Document

Ask a homework question - tutors are online