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

Assignment Help:

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.

 


Related Discussions:- Use a random number generator to create 10 numbers

Example of pre order traversal, Example of pre order traversal: Reading of...

Example of pre order traversal: Reading of a book, since we do not read next chapter unless we complete all sections of previous chapter & all its sections. Figure  : Rea

Representation of sets?, A set s is conveniently shown in a computer store ...

A set s is conveniently shown in a computer store by its characteristic function C(s). This is an array of logical numbers whose ith element has the meaning "i is present in s". As

Stacks, Q. Explain w hat are the stacks? How can we use the stacks  to chec...

Q. Explain w hat are the stacks? How can we use the stacks  to check whether an expression is correctly parentheses or not. For example (()) is well formed but (() or )()( is not w

Maximum degree of any vertex in a simple graph, The maximum degree of any v...

The maximum degree of any vertex in a simple graph with n vertices is (n-1) is the maximum degree of the vertex in a simple graph.

Sparse matrix, How sparse matrix stored in the memory of a computer?

How sparse matrix stored in the memory of a computer?

Implementing abstract data types, Implementing abstract data types A co...

Implementing abstract data types A course in data structures and algorithms is hence a course in implementing abstract data types. It may seem that we are paying a lot of atten

Define a tree and list its properties, QUESTION (a) Define a tree and l...

QUESTION (a) Define a tree and list its properties. (b) By showing all your workings, draw the spanning tree for the following graph based on the Breadth-First-Search algori

Array implementation of a circular queue, A circular queue can be implement...

A circular queue can be implemented through arrays or linked lists. Program 6 gives the array implementation of any circular queue. Program 6: Array implementation of any Circu

Data structures, #quCreate a flowchart to show the process that will allow ...

#quCreate a flowchart to show the process that will allow the implementation of Queue, Enqueue, and Dequeue operations.estion..

Avl tree rotations, AVL trees and the nodes it contains must meet strict ba...

AVL trees and the nodes it contains must meet strict balance requirements to maintain O(log n) search time. These balance restrictions are kept maintained via various rotation func

Write Your Message!

Captcha
Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd