COMP 250 Lecture Notes - Lecture 11: Call Stack, Memory Stick, Ex-Gay Movement

9 views5 pages

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.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents