COMP 250 Lecture Notes - Lecture 11: Call Stack, Memory Stick, Ex-Gay Movement
Document Summary
Converting to binary. k=0 while m>0 { b[k] = m% 2 m = m / 2 k++ It stirops off the bits of the binary representation. You can do this recursively. in binary needs approximately log m bits. // prints b[k], k =0, 1, tobinary(m){ if m>0{ print m % 2 tobinary(m/2) Print the bits instead of writing them to an array. Print the lowest order bit, then do the same thing on m%2. There are a lot of algorithms where the iterative and recursive versions are the same. If things are comparable in your set, you can always set up an ordering. We will assume that you have an ordered set. Checking linearly is not a good way, searching one-by-one. You aren"t taking advantage of the fact that it is sorted. Think of how you search for a term in an index.