Dr. Mark Humphrys

School of Computing. Dublin City University.

Online coding site: Ancient Brain

coders   JavaScript worlds

Search:

Free AI exercises


Binary tree exercise

  

Click to run World: Binary tree at Ancient Brain.
  
  

Exercise - Change some parameters

  1. Clone the World, and edit your own version.
  2. Change the range of numbers.
  3. Change how many nodes there are.
  4. What if you leave number of nodes the same but give it a large range?
  5. What if you leave range the same but give it a large number of nodes?
  6. Give it a massive problem with a huge number of nodes. Don't worry, you cannot damage your browser or the server!

  

Exercise - Copy the JS libraries

  1. Save the two JS libraries to your disk:
  2. Go to menu - User - Uploads
  3. Upload the two JS libraries.
  4. From the Uploads page you can Edit them.
  5. This is a special editor for Uploads. It does not know this is for a P5 World, so "Code help" is more generic. Also, multiple Worlds may use the JS library, so it cannot give you a "Run" button.

Q. How do you make sure your World uses your JS libraries?

  

Exercise

Edit the World and the JS libraries to:
  1. Change background color.
  2. Change ellipse size.
  3. Change text color of nodes.
  4. Change font size of text.

  


Exercise - Do not draw the graph

With AI tree search, you do not have to actually draw the graph.
The graph can just be an internal data structure. It does not have to be drawn.
Try the following:
  1. Run it with MAX = 5000.
  2. Time how long it takes to finish, using:

    var t = Date.now(); 	 // number of milliseconds since 1970  
    

  3. You can save the time at start, get time at end, subtract them, and console.log the difference.

  4. Draw tree or not:
    • Edit the code to turn drawing of the tree off.
    • Comment/uncomment tree.traverse();
    • Time how long it takes.

  5. Console messages or not:
    • Comment/uncomment all console.log messages, including in the JS libraries.
    • Time how long it takes.

  6. Console open or closed
    • It is much faster if the console is closed when it is writing messages and you just open it at the end.
    • Time how long it takes with console open or closed.


I got the following timings for MAX = 5000: