Numerics – I need help writing Mathematica code in recursive programming style

Thank you for your reply to Mathematica Stack Exchange!

  • Please be sure too answer the question, Provide details and share your research!

But avoid

  • Ask for help, clarify or respond to other answers.
  • Make statements based on opinions; Cover them with references or personal experience.

Use MathJax to format equations. Mathjax reference.

For more information, see our tips for writing great answers.

Proofing – How to prove the function of a recursive big theta without using repeated substitution, mastering the sentence, or having the closed form?

I have defined a function: $ V (j, k) $ Where $ j, k in mathbb {N} $ and $ t> 0 in mathbb {N} $ and $ 1 leq q leq j – 1 $, Note $ mathbb {N} $ includes $ 0 $,

$ V (j, k) = begin {cases} tj & k leq 2 tk & j leq 2 tjk + V (q, k / 2) + T (j – q, k / 2) & j , k> 2 end {cases} $

I am not allowed to use repeated substitution and I want to prove this by induction. I can not use the main clause because the recursive part is not in that form. Any ideas how I can solve it with given limitations?

When I start induction: I fix $ j, q $ and introduce $ k $, Then the base case $ k = 0 $, Then $ V (j, 0) = tj $, The question indicated that the function may be $ Theta (jk) $ or maybe $ Theta (j ^ 2k ^ 2) $ (but it does not necessarily have to be either).

I choose $ Theta (j, k) $, In the base case, this would mean that I had to prove that $ tj = theta (j, k) $ when $ j = 0 $, But if I start with the big-oh, I have to show it $ km leq mn = m cdot0 = 0 $ which I currently do not think possible.

I am not sure if I did the basic case wrong or if there is another approach.

Proving techniques – How to prove the function of a recursive Big-Oh without using repeated substitution, master phrase or closed form?

I have a function as defined $ V (j, k) $ with two base cases with $ j, k $ and the recursive part has an additional variable $ q $ which it also uses. Also, $ 1 leq q leq j – 1 $, The recursive part has the form: $$ jk + V (q, k / 2) + V (j – q, k / 2) $$I am not allowed to use repeated substitution and I want to prove this by induction. I can not use the main clause because the recursive part is not in that form. Any ideas how I can solve it with given limitations?

java – Recursive Backtracking – Code Review Stack Exchange

The following code is what I have so far, if someone could explain how to trace a recursive function. I have taken some of the notes given by the professor in class. I think I need to track and check the last node and then trace back to try another node in the recursive function. This examines 7 cities and eventually returns the path of an arrayList example (1,0,3,2,4,5,6), which is an integer array list. I do not know if I should increase my array list by 1 because the original city has to be added at the end.

/*
 * To change this license header, choose License Headers in Project 
 * Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package butlergraph;

import java.util.ArrayList;

/**
 *
 * @author Bernard Bailey
 */
public class FindShortestPath extends ButlerGraph {
    double shortestDistance=Double.MAX_VALUE;
    double currentDistance=0.0;
    ButlerGraph recGraph = new ButlerGraph();
    String() shortestPath = new String (8);
    ArrayList bestPath = new ArrayList<>();
    ButlerGraph f = new ButlerGraph();
    double distanceRec = f.getDistance(1, 0);
    int nodeSize = f.getSize();

    public void findShortestDistance(int node,double cityDistance,ArrayList currentPath){
       // Add this node to the list of nodes visited so far
       currentPath.add(node);
        boolean nodeVisited;
       // If all nodes have been visited (the base case)
        if (currentPath.size() == nodeSize)// base case
        {
            // Complete the circuit by adding the distance back to the start
            cityDistance += f.getDistance(node, 1);
            currentPath.add(1);
            // If the distance is better than the best distance found so far,
            if (cityDistance currentPath = new ArrayList();
        cPath.findShortestDistance(1, 0, currentPath);
        // Extract shortest path from class
        System.out.println(cPath.shortestDistance);
    }

}

python – Recursive erase from bottom to top in the binary tree

I want to delete the sheets one by one in a BT (not BST!). I tried to clear it with Reverse Level Order Traversal, but once I found the left-most node and deleted it and try to get back, I can not handle the extra recursive calls.

I tried to break the recursion with exit (), and my entire program was stopped.

Enter image description here
At the first call only 1 should be deleted. The next call 6 should be deleted. The next call should be 17 deleted. Then 21, then 19, then 10 and stop when the root is reached (basically floating).

My current code looks like this

def del_leaf(node):
    if(root==None):
        return 1

    left = del_leaf(root.left)
    if (left == 2):
        root.left = None
        return 3
    if (left == 3):
        return 3

    right = del_leaf(root.right)
    if (right == 2):
        root.right = None
        return 3
    if (right == 3):
        return 3

    return 2

It does not delete items in the order in which I want to delete them. Reverse Order Traversal (https://www.geeksforgeeks.org/reverse-level-order-traversal/) also uses height.
I am not strong with trees and recursion in general. Any help is greatly appreciated.

Recursion – find recursive files of certain types and log their paths (C ++)

I've written a function that picks up a list of extensions, recursively searches for files of that type, and logs their paths in a text file.

Application example (finding image files in a home directory):

// set up filestream for unicode
const std::locale utf8_locale = std::locale(std::locale(), new std::codecvt_utf8());
std::wofstream log("image_paths.txt", std::ios::app); // append mode
log.imbue(utf8_locale);

const std::set image_extensions = {L".jpeg", L".jpg", L".tiff", L".gif", L".bmp", L".png"};
get_files(L"C:\Users\username", image_extensions, log);

Output in image_paths.txt:

C:Usersusernameimage.jpg
C:Usersusernameimage.png
C:Usersusernamedirectoryajdsk.bmp
C:Usersusernamedirectorysubdirectoryother file.tiff
C:Usersusernamedirectory with spacesfile with spaces.jpeg

Function code:

// return 0 -- all good
// return 1 -- root doesn't exist
// return 2 -- root isn't a directory
// return 3 -- no matching files found or error opening first file
// return 4 -- hit recursion limit
auto get_files(_In_ const std::wstring root, // root dir of search
        _In_  const std::set &ext, // extensions to search for
        _Out_ std::wofstream &log, // file to write paths to
        _In_  unsigned limit = 10 /* default recursion limit */) -> int
{
    if(limit == 0) return 4;

    // check root path
    {
        DWORD root_attrib = GetFileAttributesW(root.c_str());

        if(root_attrib == INVALID_FILE_ATTRIBUTES) return 1;    // root doesn't exist
        if(!(root_attrib & FILE_ATTRIBUTE_DIRECTORY)) return 2; // root isn't a directory
    }

    LPCWSTR dir; // root directory + "*"
    HANDLE file = INVALID_HANDLE_VALUE; // handle to found file
    WIN32_FIND_DATAW file_info; // attributes of found file

    // prepare path for use with FindFile functions
    std::wstring root_slash = root;
    root_slash.append(L"\*");
    dir = root_slash.c_str();

    file = FindFirstFileW(dir, &file_info);

    if(file == INVALID_HANDLE_VALUE) return 3; // no matching files found or error opening first file

    do { // for each file in directory

        // for some reason
        // file_info != L"." && file_info != L".."
        // won't work unless file_info.cFileName is assigned to a var
        std::wstring name = file_info.cFileName;

        std::wstring path = root; // full path to current file
        path.append(L"\").append(name);

        if(!(file_info.dwFileAttributes & FILE_ATTRIBUTE_READONLY)        // not read-only
                && !(file_info.dwFileAttributes & FILE_ATTRIBUTE_OFFLINE) // not physically moved to offline storage
                && !(file_info.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)  // not a system file
                && file_info.dwFileAttributes != INVALID_FILE_ATTRIBUTES  // not invalid
                && (name != L"." && name != L"..")) { // not "." or ".."
            if(file_info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) // file is a directory
                get_files(path, ext, log, --limit);
            else // file is not a directory
                if(ext.find(PathFindExtensionW(path.c_str())) != ext.end()) // extension matches
                    log << path << 'n' << std::flush; // log path to file
        }
    } while(FindNextFileW(file, &file_info) != 0);

    FindClose(file);

    return 0;
}

Proof Verification – Prove a recursive formula with induction

I have a question about string and connectivity:

I have 2n thread lengths in my hand, with each thread ending at my left and ending at my right. It is impossible to see how the ends on the left match the ends on the right. An assistant links the 2n ends randomly to n pairs on the left. They do the same with the ends on the right side. Pn is the likelihood that if I take my hand away and untangle things, I've created a single big loop of 2n pieces of string.

The question is not too important for this question, but there is a background to why I'm asking. So far I have found $ P_1 = 1 $. $ P_2 = frac {2} {3} $ and $ P_3 = frac {8} {15} $, Now I am looking for a general formula for $ P_n $, I look at my terms before I find the formula: $ P_n = P_ {n-1} times frac {2n-2} {2n-1} $, Now I wanted to try to prove this by induction.

So I have all my base cases up, all working.

Then I accepted for true $ n = k $,

Then think about it $ n = k + 1 $:

$$ P_ {k + 1} = P_ {k} times frac {2 (k + 1) -2} {2 (k + 1) -1} $$

But I am not sure how this can end my introduction from this last stage? Could someone help me point in the right direction?

Any method to make the function fast (recursive function)?

Speed ​​problem with the following function (recursive function).

I am testing the following code in my Sitefinity (CMS) project and it takes too long to load the page on which the code is rendered. After some research, I think it's the problem with the recursive function that I'm using. Can someone give some ideas to solve this problem?

Is there a way to speed up the functions listed below?

public static List GetClassificationsRecursiveNew(string mainClassificationName, string subClassificationName, string contentTypeName, string moduleName, List classificationList)
        {
            TaxonomyManager manager = TaxonomyManager.GetManager();
            IQueryable taxonomy_list = manager.GetTaxonomies().Where(t => t.Name == mainClassificationName);
            if (taxonomy_list.Count() > 0)
            {
                HierarchicalTaxonomy taxonomy_item = taxonomy_list.FirstOrDefault();
                if (taxonomy_item.Taxa.Count > 0)
                {
                    IList taxa_list = taxonomy_item.Taxa.Where(t => ((subClassificationName == "" && t.Parent == null) || (subClassificationName != "" && t.Parent != null && t.Parent.Name == subClassificationName))).ToList();
                    if (taxa_list.Count > 0)
                    {
                    //recursive   
                    foreach (Taxon obj in taxa_list)
                        {
                            
                            classificationList = GetClassificationsRecursiveNew(mainClassificationName, obj.Name, contentTypeName, moduleName, classificationList);
                        } 
                    //end
                       
                    }
                    else
                    {
                        if (bl.helper.CanUserViewNew(mainClassificationName, subClassificationName))
                        {
                            classificationList.Add(subClassificationName);
                        }
                    }
                }
            }

            return classificationList;
        }