{"revision": {"id": "f3a64e55-2f95-11f1-b6d6-e86a64d24d78", "node_id": "f3a5a031-2f95-11f1-8053-e86a64d24d78", "user_id": "edc3f576-2f95-11f1-900f-e86a64d24d78", "author": "foxhop", "data": "Find the largest number in a list or array of numbers.\r\n========================================================\r\n\r\n.. code-block:: python\r\n\r\n numbers = [5,6,2,7,6,2,0,4]\r\n\r\n max = a[0]\r\n\r\n for number in numbers:\r\n\r\n    if number > max:\r\n        max = number\r\n\r\n**The Big-0 of this program is n  O(n)**\r\n\r\n\r\nSearch for a number in an array or list\r\n=============================================\r\n\r\nTry to search and see if the number 0 is in the list or array\r\n\r\n.. code-block:: python \r\n\r\n numbers = [5,6,2,7,6,2,0,4]\r\n\r\n for number in numbers:\r\n     if number == 0:\r\n         return True\r\n\r\n**The Big-0 of this program is n  O(n)**\r\n\r\n\r\nSearch for a number in a Sorted array or list\r\n===================================================\r\n\r\nTry to search to see if the number 7 is in the list or array.\r\n\r\nthe needle is the number we are searching for.\r\n\r\nnumbers = [-1,0,2,2,4,5,6,6,7,8,9]\r\nneedle = 7\r\n\r\ni = 1\r\nj = len(numbers) # or 11\r\n\r\nwhile i < j:\r\n\r\n    m = int( i + j / 2 )\r\n    if needle < numbers[ m ]:\r\n        i = m + 1\r\n    else:\r\n        j = m\r\n\r\nif needle == m:\r\n    print True\r\n\r\n\r\n* Worst case in  8 item list is 3 compares.\r\n* Worst case in 16 item list is 4 compares.\r\n* Worst case in 32 item list is 5 compares.\r\n\r\n**The Big-0 of this program is n O(logn) - base 2**\r\n\r\nThis is a very good algorythm!\r\n", "source_format": "rst", "revision_number": 6, "created": 1315855506000}}