Use a random number generator to create 10 numbers, Data Structure & Algorithms

Use a random number generator to create 10 numbers between 1 and 1000 and store them in 2 different arrays.  The first array should contain the numbers as they are generated.  The second should store the same numbers in a tree implemented as acomputed link array using the strategy described below:

  • the first element generated will be the root
  • the rest of the elements will be stored in the left subtree if it is smaller than the root (or parent), otherwise it is stored in the right subtree
    1. when entering the left subtree, the same strategy must be used to find the proper place in the left subtree (if new element is less than the parent, go into left subtree, otherwise go into right subtree)
    2. continue this pattern until an empty spot is found in the array, and store the element there

I suggest you make your computed link array capable of holding at least 20 items, since there will be wasted space. Once you've created the binary tree, then implement the inorder visit code from the lecture slides and conduct an inorder visit on the tree you created printing out each parent as you visit it.  If you've set up the tree correctly, the output numbers should be sorted.

For this problem, output the original data, the data as stored in the computed link array (and draw lines on your output to show the children of each parent), and the output obtained from the inorder visit.

 

Posted Date: 3/21/2013 2:40:40 AM | Location : United States







Related Discussions:- Use a random number generator to create 10 numbers, Assignment Help, Ask Question on Use a random number generator to create 10 numbers, Get Answer, Expert's Help, Use a random number generator to create 10 numbers Discussions

Write discussion on Use a random number generator to create 10 numbers
Your posts are moderated
Related Questions
This question deals with AVL trees. You must use mutable pairs/lists to implement this data structure: (a) Define a procedure called make-avl-tree which makes an AVL tree with o

Can a Queue be shown by circular linked list with only single pointer pointing to the tail of the queue? Yes a Queue can be shown by a circular linked list with only single p


HEAP  A heap is described to be a binary tree with a key in every node, such that  1-All the leaves of the tree are on 2 adjacent levels. 2- All leaves on the lowest leve

Handout 15 COMP 264: Introduction to Computer Systems (Section 001) Spring 2013 R. I. Greenberg Computer Science Department Loyola University Water TowerCampus, Lewis Towers 524 82

Consider the following 5-city traveling salesman problem. The distance between each city (in miles) is shown in the following table: (a) Formulate an IP whose solution will

Question 1. How can you find out the end of a String? Write an algorithm to find out the substring of a string. 2. Explain the insertion and deletion operation of linked lis

The Linked list is a chain of structures wherein each structure contains data in addition to pointer, which stores the address (link) of the next logical structure in the list.

AVL trees are applied into the given situations: There are few insertion & deletion operations Short search time is required Input data is sorted or nearly sorted

How many nodes in a tree have no ancestors 1 node in atree have no ancestors.