Question
Haskell, where it says
--your code goes here
import Debug.Trace f- search takes the following parameters 1. A function to check if the search is done - this function takes: a. the global information for the problerm b. the partial solution - the function returns a bool indicating if solution is complete 2. A function to find the valid next states to go to - this function takes: a. the global information for the problerm b. a partial solution -the funtion returns a list of valid next states 3. Global information for the problem 4. A partial solution - a partial solution is a list of states in reverse search returns a list of all full solutions reachable from the partial solution - full solutions will be in forward order search :: (Show a, Show b) => p trace search show --search p) False = undefined -Your code goes here search

media%2Ff5d%2Ff5d65722-e920-4792-91dc-8b
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The C++ function to check whether the given tree is Binary Search Tree is as follows:

bool isBST(struct node* root)
{
   static struct node *prev = NULL;

   // traverse the tree in inorder fashion and keep track of the previous node
   if (root)
   {
       if (!isBST(root->left))
           return false;

       // Allows only distinct valued nodes
       if (prev != NULL && root->data <= prev->data)
           return false;

       prev = root;

       return isBST(root->right);
   }

   return true;
}

Code to copy:

// ConsoleApplication28.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<iostream>
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
using namespace std;

/* A binary tree node has data, pointer to left child
and a pointer to right child */
struct node
{
   int data;
   struct node* left;
   struct node* right;
};

bool isBST(struct node* root)
{
   static struct node *prev = NULL;

   // traverse the tree in inorder fashion and keep track of the previous node
   if (root)
   {
       if (!isBST(root->left))
           return false;

       // Allows only distinct valued nodes
       if (prev != NULL && root->data <= prev->data)
           return false;

       prev = root;

       return isBST(root->right);
   }

   return true;
}

/*This function allocates a new node with the
given data and NULL left and right pointers. */
struct node* newNode(int data)
{
   struct node* node = (struct node*)malloc(sizeof(struct node));
   node->data = data;
   node->left = NULL;
   node->right = NULL;

   return(node);
}

/* Driver program to test above functions*/
int main()
{
   struct node *root = newNode(7);
   root->left = newNode(5);
   root->right = newNode(10);
   root->left->left = newNode(1);
   root->left->right = newNode(6);
   root->right->left = newNode(9);
   root->right->right = newNode(8);


   if (isBST(root))
       cout<<"The given tree is a BST";
   else
       cout<<"The given tree is not a BST";

   getchar();
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Haskell, where it says --your code goes here import Debug.Trace f- search takes the following parameters...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please write a code in Java where it says your // your code here to run...

    Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please write the code according to functions assigned...

  • Please write a code in Java where it says your // your code here to run...

    Please write a code in Java where it says your // your code here to run the code smoothly. Import statements are not allowed for this assignment, so don't use them. _ A Java method is a collection of statements that are grouped together to perform an operation. Some languages also call this operation a Function. When you call the System.out.println() method, for example, the system actually executes several statements in order to display a message on the console. Please...

  • PHP code that is given : <?php // Here is where your preprocessing code goes //...

    PHP code that is given : <?php // Here is where your preprocessing code goes // An example is already given to you for the First Name $fname = $_GET['fname']; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Exercise 2 - GET Echo</title> <style> body { margin:0; padding:0; font-family: Arial; } form { margin:20px; } input[type="text"], input[type="password"] { width:150px; padding:3px; font-size:1em; } input[type="submit"] { padding:3px; font-size:1em; } label { display:inline-block; width:150px; } .input-container { padding:5px; } </style> </head> <body> <form...

  • Starting code: #include <stdio.h> #include <stdbool.h> #include <assert.h> bool checkSudoku(int sudoku[9][9]) { //code goes here }...

    Starting code: #include <stdio.h> #include <stdbool.h> #include <assert.h> bool checkSudoku(int sudoku[9][9]) { //code goes here } int main() { int sudoku[9][9] = {{7, 3, 5, 6, 1, 4, 8, 9, 2}, {8, 4, 2, 9, 7, 3, 5, 6, 1}, {9, 6, 1, 2, 8, 5, 3, 7, 4}, {2, 8, 6, 3, 4, 9, 1, 5, 7}, {4, 1, 3, 8, 5, 7, 9, 2, 6}, {5, 7, 9, 1, 2, 6, 4, 3, 8}, {1, 5, 7, 4,...

  • Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The...

    Do in Python please provide screenshots aswell. Here are the requirements for your game: 1. The computer must select a word at random from the list of avail- able words that was provided in words.txt. The functions for loading the word list and selecting a random word have already been provided for you in ps3 hangman.py. 2. The game must be interactive; the flow of the game should go as follows: • At the start of the game, let the...

  • Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA...

    Write code for RSA encryption package rsa; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class RSA {    private BigInteger phi; private BigInteger e; private BigInteger d; private BigInteger num; public static void main(String[] args) {    Scanner keyboard = new Scanner(System.in); System.out.println("Enter the message you would like to encode, using any ASCII characters: "); String input = keyboard.nextLine(); int[] ASCIIvalues = new int[input.length()]; for (int i = 0; i < input.length(); i++) { ASCIIvalues[i] = input.charAt(i); } String ASCIInumbers...

  • I need help with this assignment in C++, please! *** The instructions and programming style detai...

    I need help with this assignment in C++, please! *** The instructions and programming style details are crucial for this assignment! Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...

  • // CSE240 Spring 2019 HW 7 & 8 // Write your name here // Write the...

    // CSE240 Spring 2019 HW 7 & 8 // Write your name here // Write the compiler used: Visual studio or gcc // READ BEFORE YOU START: // You are given a partially completed program that creates a linked list of patient information. // The global linked list 'list' is a list of patients with each node being struct 'patientList'. // 'patientList' consists of struct 'patient' which has: patient name, room number, and a linked list of 'doctors'. // The...

  • C++ Binary Search Tree question. I heed help with the level 2 question please, as level...

    C++ Binary Search Tree question. I heed help with the level 2 question please, as level 1 is already completed. I will rate the answer a 100% thumbs up. I really appreciate the help!. Thank you! searching.cpp #include <getopt.h> #include <iostream> #include <sstream> #include <stdlib.h> #include <unistd.h> using namespace std; // global variable for tree operations // use to control tree maintenance operations enum Mode { simple, randomised, avl } mode; // tree type // returns size of tree //...

  • C++ Binary Search Tree question. I heed help with the level 2 question please, as level...

    C++ Binary Search Tree question. I heed help with the level 2 question please, as level 1 is already completed. I will rate the answer a 100% thumbs up. I really appreciate the help!. Thank you! searching.cpp #include <getopt.h> #include <iostream> #include <sstream> #include <stdlib.h> #include <unistd.h> using namespace std; // global variable for tree operations // use to control tree maintenance operations enum Mode { simple, randomised, avl } mode; // tree type // returns size of tree //...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT