0

I am a new computer engineering student. I want to create different sequences of nodes which give rise ro the same binary search trees.

For Example;

       5
     /   \
    4     7
   /     / \
  1     6   10

the outputs will be

5,4,1,7,6,10

5,4,7,6,10,1

5,7,6,10,4,1

etc. (I took the sample from a post)

I want to create it in c, but I can't figure it out.I can do the formula giving the total number of sequences that should occur.

Total Formula; [numberOfLeftChild * numberOfRightChild * Combination(numberOfAllNodes-1,numberOfLeftNodes)]

I read these post. Given a BST and its root, print all sequences of nodes which give rise to the same bst

Count number of unique node sequences producing the same BST

Find number of permutations of a given sequence of integers which yield the same binary search tree

How many level order BST sequences are possible given a preOrder and inOrder sequence?

I will be grateful if you could help me.

thekavak
  • 199
  • 11
  • What did you do? We won't do your homework for you. Try something and we will help you – Phantom Nov 28 '19 at 07:44
  • 1
    Welcome to Stack Overflow. Please read [the help pages](http://stackoverflow.com/help), take [the SO tour](http://stackoverflow.com/tour), read about [how to ask good questions](http://stackoverflow.com/help/how-to-ask), as well as [this question checklist](https://codeblog.jonskeet.uk/2012/11/24/stack-overflow-question-checklist/). Lastly please learn how to create a [mcve] of your own attempt to show us, and describe what problems you have with it. – Some programmer dude Nov 28 '19 at 07:45
  • @Phantom sorry I couldn't figure out its logic – thekavak Nov 28 '19 at 07:47
  • You want to list them by inorder postorder preorder traversal? Or you just want to list them with all given combinations? – Maqcel Nov 28 '19 at 08:17
  • @MerMonkeyI want to list all combinations that given the same bst – thekavak Nov 28 '19 at 08:24
  • @Phantom Sir, my array has 7 elements, and I have generated 5,440 probabilities with permustation.Then I created them one by one binary search tree and checked to see if they were the same as the first one binary search tree. My code works fine but my teacher said brute force forbidden :) – thekavak Nov 30 '19 at 21:05

0 Answers0