Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
thumb_up100%
The Polish mathematician Wacław Sierpiński described the pattern in 1915, but it has appeared in Italian art since the 13th century. Though the Sierpinski triangle looks complex, it can be generated with a short recursive function. Your main task is to write a recursive function sierpinski() that plots a Sierpinski triangle of order n to standard drawing. Think recursively: sierpinski() should draw one filled equilateral triangle (pointed downwards) and then call itself recursively three times (with an appropriate stopping condition). It should draw 1 filled triangle for n = 1; 4 filled triangles for n = 2; and 13 filled triangles for n = 3; and so forth.
API specification. When writing your program, exercise modular design by organizing it into four functions, as specified in the following API:
public class Sierpinski {
// Height of an equilateral triangle whose sides are of the specified length. public static double height(double length)
// Draws a filled equilateral triangle whose bottom vertex is (x, y)
// of the specified side length.
public static void filledTriangle(double x, double y, double length)
// Draws a Sierpinski triangle of order n, such that the largest filled
// triangle has bottom vertex (x, y) and sides of the specified length.
public static void sierpinski(int n, double x, double y, double length)
// Takes an integer command-line argument n;
// draws the outline of an equilateral triangle (pointed upwards) of length 1; // whose bottom-left vertex is (0, 0) and bottom-right vertex is (1, 0); and
// draws a Sierpinski triangle of order n that fits snugly inside the outline. public static void main(String[] args) }
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Give a recursive definition of the following set of ordered pairs of positive integers: S = {(a, b)| (a is element of positive integer), (b is an integer multiplied by 3)}arrow_forwardneed help with R2arrow_forwardIn C programming Mathematically, given a function f, we recursively define fk(n) as follows: if k = 1, f1(n) = f(n). Otherwise, for k > 1, fk(n) = f(fk-1(n)). Assume that there is an existing function f, which takes in a single integer and returns an integer. Write a recursive function fcomp, which takes in both n and k (k > 0), and returns fk(n). int f(int n);int fcomp(int n, int k){arrow_forward
- What is the return value of the function call Comp(4, 5), given the recursive function Comp defined below: int Comp(int a, int b) { if (a + b <= 6) return 3; else return Comp(a-1, b) + Comp(a, b-1); }arrow_forwardPlease help me make a a t square fractal using recursion. if you can please also make a sierpenski triangle ( and comment it). You do not have to comment the first task.arrow_forwardin java Computing Powers, p(x,n)=xn1. Describe the definition of recursive function.oBase case(s)oRecursive case(s)2. Write the codearrow_forward
- This is a MATLAB Coding problem: Implement a recursive function, called count, that takes two inputs, an array of integers and target integer. count should search the array for the target integer and return the number of occurrences of the target integer in the array. For example: disp(count([1, 2, 4, 1, 2, 1], 1)) % Generates 3disp(count([1, 2, 4, 1, 2, 1], 2)) % Generates 2disp(count([1, 2, 4, 1, 2, 1], 4)) % Generates 1disp(count([1, 2, 4, 1, 2, 1], 9000)) % Generates 0arrow_forwardI am working on this recursive function, and I am drawing a blank. Line 15 else if(s.charAt(0) != s.length () -1 && ............ )) Is there a String method that looks for intergers ? Suppose to look to see if it is the last value and if it is a Integer, if it is , add the vaules that intergers together for a total sum public class Finder { //Write two recursive functions, both of which will parse any length string that consists of digits and numbers. Both functions //should be in the same class and have the following signatures. //use the if/else statement , Find the base case and -1 till you get to base case //recursive function that adds up the digits in the String public static int sumIt(String s) { int sumOfNumbers =0; //if String length is less or equal to 1 retrun 1. for (int i = 0; i >= 0 ;i++) if (s.length()<= 1)//Base case = 1 return 1; //else if the CharAt(value in index at 0 = 1) is not equal to the last vaule in the string else if(s.charAt(0) != s.length ()…arrow_forwardPlease help me with this using java and recursionarrow_forward
- What is s(s(0))*s(s(s(s(0))))*arrow_forwardWrite and test a Java/Python recursive method for finding the minimum element in an array, A, of n elements. What the running time? Hint: an array of size 1 would be the stop condition. The implementation is similar to linearSum method in lecture 5 examples. You can use the Math.min method for finding the minimum of two numbers.arrow_forwardCan you please help me solve problem 2?arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education