I have coded an AVL Tree and my logic for the rotations is correct but I am still not able to get it working properly. For rotations on the root node my rotations work properly but if the rotation is further down the tree, the parent node does not point to the new node that has been rotated into place
Tag: recursion
Using Recursion to check for sum of tuples in a list
I have a func which takes a list of tuples, each tuple contains two items: item name and value. I need the func to return True if it’s possible to divide the tuple list into two equal valued groups and False otherwise. The function should be recursive and should not use any loops. for example, should result in True, because
How to calculate time complexity of these two functions? (recursion)
The first function: The second function: Now I can see why both of the function’s space complexity is O(n) since the recursion depth is equal to n. But about time complexity, I’m not being able to calculate it like I used to do with the equation for normal recursion, lets say instead of f(f(n-1)) we had f(n-1) in the first
while-loop problem for acess a list element
I want to append each element of [1,2] to [[1], [2], [3]] and as a consequence, the final array that I want is [[1,1], [1,2], [2,1], [2,2], [3,1], [3,2]] But my code has a mistake I couldn’t recognize it yet, and the result of the python code below is [[1, 1, 2], [1, 1, 2], [2, 1, 2], [2, 1,
Replace All Specific Characters in String using Python
I have a problem with a function I am trying to implement that needs to replace some letters (in a given string), for some other characters, defined on a dictionary. I have this dictionary: I want to pass a string that when a character matches any key from the dictionary (case insensitive match), it tries to save all the possible
Recursively searching for a string in a list of characters
I have a problem to solve which is to recursively search for a string in a list (length of string and list is atleast 2) and return it’s positions. for example: if we had ab with the list [‘a’,’b’,’c’], the function should return ‘(0,2)’, as ab starts at index 0 and ends at 1 (we add one more). if we
I want to extract all the values that a class object holds
I have an object Vm of Type <class ‘azure.mgmt.compute.v2019_07_01.models._models_py3.VirtualMachine’> I want to iterate over this object by a loop so that I don’t have to manually extract the values. Yes I’ve tried isinstance to check whether the value is of type <class ‘azure.mgmt.compute.v2019_07_01.models._models_py3.VirtualMachine’> and extract but in the next iteration it fails. For example let’s consider vm to be an
function that prints counding down numbers and up but in a pattern
I already know how to count down and up using reccurssive function but I cant figure out how to define another function to have spaces in a pattern like this: Desired output My code for counting down and up: Answer I am posting this to contrast the other answers provided here – The program could be further simplified, if desired
Python Return Command In Recursion Function
While learning Python and browsing the internet I stumble upon a piece of code in w3schools.com. I tried to run it using their built-in site Python IDLE and using my own Python 3.9.0 Shell. What I got is two different outputs. I want to know which output is the correct output and why is it providing two different outputs. The
Efficient reverse-factorization of a number given list of divisors
Given a number n and a list of divisors A, how can I efficiently find all the combinations of divisors that, when multiplied, yield to the number? e.g. Output: This is what I managed to do so far (code that I re-adapted from one of the many find-prime-factorization questions on stackoverflow): This code seems to work properly but it’s very