recursion

Calculate Complexity of T(n)? [duplicate]

两盒软妹~` 提交于 2020-12-13 03:48:07
问题 This question already has answers here : T(n) = T(n/10) + T(an) + n, how to solve this? (3 answers) Closed last month . Given: T(n) = T(n/10) + T(an) + n for some a (which I know nothing about its value), and that: T(n) = 1 if n < 10 . I want to check if the following is possible (for some a values, and I want to find the smallest possible a ): For every c > 0 there is n 0 > 0 such that for every n > n 0 , T(n) >= c * n Or in other words T(n)=omega(n) Any help is appreciated. 回答1: Suppose

Sierpinski Carpet with recursion in C using SVG

我只是一个虾纸丫 提交于 2020-12-13 03:27:54
问题 I am trying to create a Sierpinski carpet using the C language. I successfully created the first iteration. When the second iteration begins, the function correctly generates squares just around the first square. One more problem is that my code generates the middle square too (normally it should be 8 squares, not 9). Below is a picture and the code. I'm just out of ideas and I can't find where I went wrong. #include <stdio.h> #include<stdlib.h> void draw(FILE *file, int size, int x, int y);

Sierpinski Carpet with recursion in C using SVG

故事扮演 提交于 2020-12-13 03:27:17
问题 I am trying to create a Sierpinski carpet using the C language. I successfully created the first iteration. When the second iteration begins, the function correctly generates squares just around the first square. One more problem is that my code generates the middle square too (normally it should be 8 squares, not 9). Below is a picture and the code. I'm just out of ideas and I can't find where I went wrong. #include <stdio.h> #include<stdlib.h> void draw(FILE *file, int size, int x, int y);

Prolog - Recursively append numbers to a list

谁都会走 提交于 2020-12-11 08:59:56
问题 I am just starting to learn Prolog, and I am having troubles wrapping my head around recursive concepts. Right now, solely for the purpose of practice, I am trying to write a program that appends 10 numbers to a list and then prints out that list. The self-imposed rule for this program is that the list has to be 'declared' (I am not sure if that is the correct word for Prolog) in a main predicate, which calls another predicate to append numbers to the list. This is what I have so far, and I

Prolog - Recursively append numbers to a list

点点圈 提交于 2020-12-11 08:58:05
问题 I am just starting to learn Prolog, and I am having troubles wrapping my head around recursive concepts. Right now, solely for the purpose of practice, I am trying to write a program that appends 10 numbers to a list and then prints out that list. The self-imposed rule for this program is that the list has to be 'declared' (I am not sure if that is the correct word for Prolog) in a main predicate, which calls another predicate to append numbers to the list. This is what I have so far, and I

How to count all the palindromes in a string using recursion?

寵の児 提交于 2020-12-11 06:01:23
问题 I have a recursive function that checks if a string is a palindrome, but my assignment asks me to count the number of palindromes in a string (for example kayak has 2). I'm really confused about how I can implement a recursive function that counts the number of palindromes. Here's my current code: function isPalindrome(string) { if (string.length <= 1) { return true; } let [ firstLetter ] = string; let lastLetter = string[string.length - 1]; if (firstLetter === lastLetter) { let

How to count all the palindromes in a string using recursion?

筅森魡賤 提交于 2020-12-11 06:01:22
问题 I have a recursive function that checks if a string is a palindrome, but my assignment asks me to count the number of palindromes in a string (for example kayak has 2). I'm really confused about how I can implement a recursive function that counts the number of palindromes. Here's my current code: function isPalindrome(string) { if (string.length <= 1) { return true; } let [ firstLetter ] = string; let lastLetter = string[string.length - 1]; if (firstLetter === lastLetter) { let

Recursive function to sort an array [closed]

我的未来我决定 提交于 2020-12-10 16:53:58
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 3 months ago . Improve this question I'm having trouble building a recursive function that sorts an integer array. At this point, I don't know any sorting algorithms, this is only my second CS course. I've seen a lot of solutions on here, but the issue with those solutions is that they have

How to Label groups within a 2D array using recursion

百般思念 提交于 2020-12-06 15:49:25
问题 I need to write a a method in my code that can take a two dimensional array and return how many different groups there are within the array. A group is defined as, "all cells connected directly to other cells in the up/down/left/right (not diagonal) directions" where a cell in the array would be represented by an asterisk. I need to write a method that iterates through the entire array that also calls a recursive method that changes every asterisk into a letter that is unique to that group.

Python: Map a function over recursive iterables

随声附和 提交于 2020-12-01 09:23:08
问题 I have an arbitrarily nested iterable like so: numbers = (1, 2, (3, (4, 5)), 7) and I'd like to map a function over it without changing the structure. For example, I might want to convert all the numbers to strings to get strings = recursive_map(str, numbers) assert strings == ('1', '2', ('3', ('4', '5')), '7') Is there a nice way to do this? I can imaging writing my own method to manually traverse numbers , but I'd like to know if there's a general way to map over recursive iterables. Also,