a. Write a function which will take a binary tree as input and return the total number of nodes in: the tree. Your code must count the nodes by traversing the tree.
Q: Write a function starting_A that takes a list of strings called words as a parameter, and returns a…
A: Hi. As you have not mentioned any programming language, I will attempt it using Python. Let's…
Q: Write an ML function that inputs a 3-tuple of integers and returns a list of the integers in sorted…
A: Actually, python is a easiest programming language. It is a dynamically typed programming language.…
Q: Write a function flat_list() which takes a list that contains unknown number of lists. This function…
A: Since Python is weakly typed, you can encounter regular and irregular lists of lists. Every element…
Q: C++, Write a recursion function that counts the positive elements multiple of 5 in a binary search…
A: //make f1 and f2 as class variable and initialize with 0 int traverse(struct node *root) { if…
Q: Use Standard ML Code: Write a function that returns the factorial of a number. Write a function…
A: The above question is solved in step 2:-
Q: Home Work Write a function to create four separate nodes in a circular link list and then work on…
A: Note - Making the program in C++ as no specific language is defined. Define a struct node of the…
Q: Write a string function multi_find (some_string, sub_string, [,start] [ ,end]) where start and end…
A: Python used to answer this question
Q: Write a function called check_third_element that takes in a list of tuples, lst_tups as a parameter.…
A: Please find thee answer below :
Q: In PYTHON Given a list of ints, a start index, and an end index (not inclusive), function should…
A: Below is the code in python and sample output:
Q: I'm looking over my code for my tree and I keep receiving segmentation faults when I try to add or…
A: The segmentation fault receives when memory location is not accessible to use because either it is…
Q: Given a singly linked list and a number k, write a function to find the (n/k)-th element, where n is…
A: Code: #include <iostream>#include<math.h>using namespace std; struct node{ int data;…
Q: Write the following function: The function gets a root of a Binary Tree of ints, and a function f.…
A: Below i have given code:
Q: Write a function toSentence : string list -> string = that takes a string list and concatenates its…
A: Since no programming language is mentioned, I am using python. Code: def toSentence(stringList):…
Q: Write a function that takes in the head of a Singly Linked List and an integer k , shifts the list…
A: The code of the above given question is as given below:
Q: Write a C++ Function that returns the data of the middle node in a linked list and in case the…
A: Write a C++ Function that returns the data of the middle node in a linked list and in case the…
Q: function to find out whether a given list is a palindrome in Racket.
A: c++ program is an giveb below ; /* Java program to check if linked list is palindrome recursively */…
Q: Write a function (Ocaml) that takes an ’a list and an int list of values and returns second list,…
A: In Ocaml, an expression is a function. Thus, a value representing a function is called a function.…
Q: Write a function that will duplicate every list element using recursion. Example: List: ['I',…
A: Based on Python
Q: in c++, apply non-linear data structures to solve simple problems. Question - imagine having a List…
A: // Java program to segregate even and odd nodes in a// Linked Listclass LinkedList{ Node head; //…
Q: This code is for python Searching for Data In this lab we'll compare the time it takes to search for…
A: Instructions for solving the given problem:In part 1, use random.randint() function to generate…
Q: A a. A Pythagorean triple is a list [a, b, c] of positive integers a < b <c so that a + b? = c2.…
A: Python used to answer this question
Q: a function f1 that takes the root of a binary tree as a parameter and returns the sum of the nodes…
A: NOTE: - The working code is given in step implemented in c++ language. PROGRAM EXPLANATION: -…
Q: 4. Write a function, "outdegree", of two arguments, a node and the graph, which returns the…
A: Code: # Out degree for a vertex is the count# of direct paths from that vertex to other verticesdef…
Q: Given a number and a sorted binary tree, write function that inserts the number into the tree. Given…
A: The code for the above given question is given below:
Q: write a function thab takes a list of strings and retums a list of inbegers representing the lenth…
A: def lengthOfStrings(strings): lengths = [] for string in strings:…
Q: Write a program to implement the address book using namic singly linked list, the node should…
A: Note: Since you have not provided the language to write the code, I am using Java language to write…
Q: 3 Listdiff Use the built-in higher order functions² and write a non-recursive function val listdiff…
A: OCAML programming : a general purpose programming language with an importance on expressiveness. It…
Q: Given a sorted array, write a program named as ProblemB.cpp that creates a Binary Search Tree.…
A: Algorithm: 1) Get the Middle of the array and make it root. 2) Recursively do same for left half and…
Q: Write a function flat_list() which takes a list that contains unknown number of lists. This function…
A: new_li.append(ele): append ele in new_li in last position previous: new_li = [1, 2, 3] after…
Q: unt, that takes a root node (as a pointer) of a binary tree to its function parameter. nte a…
A: Since multiple questions are asked so first three parts will be answered. Please upload remaining…
Q: I have an assignment that requires me to read strings from a text file and insert them into a binary…
A: A C program for the given criteria is as…
Q: Write a function f1 that takes the root of a binary tree as a parameter and returns the sum of the…
A: The logic behind a function that takes the root of a binary tree as a parameter and returns the sum…
Q: Given two lists A and B, write a function to compute the difference A – B, where A – B is the list…
A: 1) Since you have not specified programming language, I have written program in python language 2)…
Q: get tokens_from_equation(line): Takes one string as input that contains any combination of digits…
A: 1) Below is program to define a function get_token_from_equation and test with line inputs It…
Q: Python Please Implement a function dedup(lst: list) -> list: that returns a de-duplicated version…
A: 1) Below is the python program to implement a function dedup(lst: list) -> list: that returns a…
Q: write a c++ code that will do the adding a node to a Doubly Linked-List in the three cases (insert a…
A: CODE IN C++: insert a node at the beginning - middle - end three separate functions are there in the…
Q: Please write it in Python Write a delete function that takes as an argument a list l and an elem…
A: Python Code: def delete( l, x ): l.remove(x) return x Explaination : Define a function…
Q: Write a function that takes a list as an input and returns all the pairs of numbers whose GCD…
A: Here, we have to write python program to find the pairs whose gcd is 1.
Q: Edsgar Dijkstra is known for his work on programming languages. He came up with a neat problem that…
A: def dutch_flag(color_list):""" (list of str) -> list of strReturn color_list rearranged so that…
Q: Write a function sumLength() that takes a list of strings as parameter, finds and returns the total…
A: A list is a collection that holds multiple data items using one variable. The values of the list can…
Q: Consider the following function: int enigma(NodeInt32* node) { if(node == NULL) return 0; else…
A: The given Function is int enigma(NodeInt32* node){if(node == NULL)return 0; elsereturn 1 +…
Q: Question 2: Write a function that takes a list of distinct integers l, and an integer k. Your…
A: Program Approach: Defining a method "removeOne" that holds two parameters "l,k" inside the method a…
Q: Write a function flat_list() which takes a list that contains unknown number of lists. This function…
A: In the following python code , we need to perform the following operations : Define the python…
Q: a) Suppose we are trying to hide a secret message by embedding it in random extra letters. Write a…
A: Below is the code in python as language not specified and sample output:
Q: 1. Please give the type of function f and g f: shuffle two lists with any type of elements. Example:…
A: I have provided PYTHON CODE along with CODE SCREENSHOT and OUTPUT SCREENSHOT--------------
Q: Consider the following pseudocode: // Utility function to swap left and right public static void…
A: The above pseudocode is recursively reversing the left node to the right node by using the swap…
Q: Q3. a. Write a C function to INSERT a node in a priority queue using double pointer. b. Write an…
A: Given: we have to provide answer for a and b. A. C function to insert a node in a priority queue…
Q: Exercise B Implement the Prelude function init (which returns a list with the last element renoved)…
A: Given:- init : : [a] -> [a]init xs = Perlude function:- There are different kind of functions in…
Q: Given main(), complete the SongNode class to include the function PrintSongInfo(). Then write the…
A: Here have to determine about c++ code for node problem statement.
Q: Write a function f1 that takes the root of a binary tree as a parameter and returns the sum of the…
A: For writing the function with given description follow below points: Include header file iostream.…
Step by step
Solved in 4 steps with 4 images
- Use c++ 1. A Red-Black tree is said to be beautiful if all nodes in the alternate levels of the tree are of the same color. Write a program to check whether a Red-Black tree created from the given input is beautiful or not. Your program should include the following functions. • INSERTREDBLACK (struct node* root, key): Inserts a new node with the 'key' into the tree. • CHECKBEAUTIFUL (struct node* root): Checks whether the given tree is beautiful or not. Input format: Output format: • The output will be 1 if the Red-Black tree is beautiful else -1. Sample Input 1: 9 12 • The first line of input will be an integer 'n' which is the number of nodes in the tree. • After which 'n' integer inputs will be given subsequently which will be the keys of nodes of the tree. The keys are unique and values are in the range [1,1000]. 8 25 3 5 27 22 32 9 Sample Output 1: 1Computer Science Exercise: depth [★★] Write a function depth : 'a tree -> int that returns the number of nodes in any longest path from the root to a leaf. For example, the depth of an empty tree (simply Leaf) is 0, and the depth of tree t above is 3. Hint: there is a library function max : 'a -> 'a -> 'a that returns the maximum of any two values of the same type. please use Ocaml for the coding] ] is_proper You are to write a function is_proper(graph,color) that has two inputs: one a graph, and the other a labelling of the vertices, and determines whether or not the labelling is a proper vertex-coloring of the given graph. In other words, return the Boolean value True if it is, and False if it is not. After compiling the above cell, you should be able to compile the following cell and obtain the desired outputs. print (is_proper({"A": ["B", "C"], "B": ["A", "C"], "C": ["A", "B"]}, {"A": 1, "B": 2, "C": 3}), is_proper({"A": ["B", "C"], "B": ["A", "C"], "C": ["A", "B"]}, {"A": 1, "B": 1, "C": 3})) This should return True False Python Python
- Assume this method is given within the KWLinkedList class, which answer is be correct public void Unknown() { if (size cur = head; Node prev = tail; for(int i=0; i< size/2; i++) { tail.prev.data = cur.data; cur= cur.next; } }1.) Design a Binary Search Tree ADT by using following functions. Include the function definitions & run the program (Kindly include header files as well). Paste the output as a screenshot and write the code in your answer sheet. insert(int val)find(int x)************************************************************************************ class btNode { public: int info; btNode *lLink; btNode *rLink; btNode(int e, btNode *l = NULL, btNode *r = NULL) { info = e; lLink = l; rLink = r; } btNode() { lLink = NULL; rLink = NULL; } }; class binarySTADT { private: btNode *root; int count = 0; public: binarySTADT() { root = NULL; } void insert(int val); // function to insert a given value in the tree.…D. Write a program named as ProblemD_.cpp that constructs a BST from a given preorder traversal of that tree. For example, if the given traversal is (10, 5, 1, 7, 40, 50), then the output should be following tree. 10 40 1 7 50 Hints: • Write a recursive function to do the followings: a) Get the first element of the array and make it root of the BST. b) Find the index i such that the value in i+1 is the first value bigger than the root. c) Recursively call a function to do the same for left subarray (1.. i) and right subarray (i+1.size-1). i) Get the first element of left half and make it left child of the root created in step a. ii) Get the first element of right half and make it right child of the root created in step a. d) return root.
- CodeW X bFor fun X C Solved x b Answer + x https://codeworko... CodeWorkout X265: Recursion Programmlng Exercise: GCD The greatest common divisor (GCD) for a pair of numbers is the largest positive integer that divides both numbers without remainder. For function GCD , write the missing base case condition and action. This function will compute the greatest common divisor of x and y.You can assume that x and y are both positive integers and that x > y. Greatest common divisor is computed as follows: = x and GCD(x, y) = GCD(y, x % y). Examples: GCD (6, 4) -> 2 Your An swer: 1 public int GCD(int x, int y) { if > { 2. > 3. } else { 4. return GCD(y, x % y); 9. { 7. 1:09 AM 50°F Clear 1V 1. 12/4/2021 甲Part II: Implement text compression. In this part, use a text file as input, read through the text file, calculate the frequencies of each character, apply your Huffman Algorithm to encode the text file into a new file. You program should have the following functions, besides the above functions. Encode: takes a text file name, calls the Huffman coding algorithm, traverse the tree to get the code word, and then encode the text file into a new file. Decode: takes a prefix tree, and an encoded file, decode the file. What to turn in: Well documented source code in C++. Run your algorithm for 20 files and show the compression ratio of the size of the original file and the size of the compressed file. Show the ratios in the table. //code // C++ program for Huffman Coding #include <iostream> #include<queue> #include<vector> #include<string> #include<map> using namespace std; /*structure to represent node of huffman tree*/ struct node { // One of the…Write a program in c++ which should create a weighted graph of the values entered by the user andthen write functions that perform the following: 1. Depth first search of source and destination vertex2. Breadth first search of source and destination vertex3. Shortest path search of source and all destination vertices (Dijkstra’s algorithm)4. Shortest path search of source and destination vertex (Dijkstra’s algorithm) The program should present a menu of the options and should run until the user opts to quit.
- Part (a) Write a python function that computes the binomial coefficient ("). The function should return the correct answer for any positive integer n and k where k=m pass Part (c) Suppose that the number of people in the trial is 100. Then: • Plot a curve that shows how the probability of type 1 error changes with the choice of m, for m = 1,...n assuming that the null hypothesis holds (in red), • On the same picture, plot the probability of type 2 error vs the value of m in the case in which the new drug is effective with proability 0.68 (in blue). You can plot the two curves using matplotlib.pyplot. You can select the color by passing color='r' or color='b' to the plt.plot() function. [4]: n - 100 # your code here def plot_curve (): pass [5]: plot_curve() Part (d) Based on the picture above, what value of m do you think would be suitable to keep both type 1 and type 2 error small at the same time? (You may assume that the company claims the new drug has 68% accuracy) [6]: # your…In c++ please pleasee donot copy from internet and also add comment to each line of the code explaining its working. Draw the tree after the insertion of keys 33, 31, 60,90,86,81,96,87,94, 21, 11 and 18, in this order. Consider the above values and perform The Following: 1) Write code for Insertion of above values in trees. 2) perform Breadth First Search AND Depth First Search and display results. 3) Perform Preorder, in order, and post order traversal and show the outputs. 4) Write a code to delete 87 and 21, and 90 from above tree. 5) Array Representation of above tree.Old MathJax webview Old MathJax webview In Java Some methods of the singly linked list listed below can be implemented efficiently (in different respects) (as opposed to an array or a doubly linked list), others not necessarily which are they and why? b. Implement a function to add an element before the first element. c. Implement a function to add an item after the last one element. d. Implement a function to output an element of the list. e. Implement a function to output the entire list. f. Implement a function to output the number of elements. G. Implement a function to delete an item. H. Implement a function to clear the entire list. I. Implement functionality to search for one or more students by first name, last name, matriculation number or course of study. J. Implement functionality to sort the records of the student, matriculation number and course according to two self-selected sorting methods.