{ "metadata": { "name": "", "signature": "sha256:fe52e80aefa7cef4c97d80a1d8ac06d5a056bd7deebddce40f058e873b9c3a02" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "9 Recurrence relations and recursive algorithms" ] }, { "cell_type": "heading", "level": 2, "metadata": {}, "source": [ "Example 15:Page 421" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print \"MERGE SORT\"\n", "alist=[65,43,22,54,87,11,76,48,30,60,19,75,94,27,58,80]#List to be sorted\n", "def mergesort(alist):\n", " print \"Splitting\",alist\n", " if len(alist)>1:\n", " \n", " mid=len(alist)/2\n", " left_half=alist[:mid]\n", " right_half=alist[mid:]#Spltting into halves\n", " mergesort(left_half)\n", " mergesort(right_half)#Recirsive split to obtain values\n", " i=0\n", " j=0\n", " k=0#Varaibles for indexing\n", " while i