recursion program

Problems

 

power

  1. Write a 
    public static function named 
    power that takes in two integers, 
    a and 
    b, and returns 
    a^
    b, the first argument to the power of the second argument. You may 
    NOT use 
    Math.pow(), because that would be boring.
  2. The base case in this method is when the second argument is 0: 
    n^0 = 1, by definition.
  3. Hint: 3^5 = 3*(3^4)
  4. Why is recursion not the best solution for this problem? If you do not know, ask a TA.
    1. Create a similar method named 
      power2 that is functionally identical but does not use recursion. It should still NOT use 
      Math.pow().

fileCount

  1. Write a 
    public static function named 
    fileCount that takes as input a directory (as a File object) and returns the total number of files in all sub-directories
    1. Directories count as files, too.
  2. Your method should look through all files and sub-directories in the directory that was passed in. While searching through the directory, use the 
    java.io.File.isDirectory() method to check if the File you are looking at is a file or directory. If it is a normal file, count it. If it is a directory, count it and use a recursive call to count its contents.
  3. Hint: 
    1. What is the base case?
    2. What is the recursive step?
    3. What is the combination?
  4. You should consult the 
    java.io.File API for more information.
  5. The following directory structure has 14 files:
root_dir          1
+--dir            2
|  +--file        3
+--dir            4
|  +--dir         5
|  |  +--dir      6
|  |  |  +--file  7
|  |  +--file     8
|  +--file        9
+--dir           10
|  +--dir        11
|  |  +--file    12
|  +--file       13
+--file          14

hanoi

  1. Write a 
    public static function named 
    hanoi that recursively solves the Tower of Hanoi puzzle (see the description below).
  2. Your function should take 1 integer and 3 chars as input (in this order): 
    n, 
    src, 
    dest, 
    aux.
    1. n is the number of disks.
    2. src (source), 
      dest (destination), and 
      aux (auxiliary) are tower letters.
    3. For example, to solve the 3 disk puzzle, you would call 
      hanoi(3,'A','C','B');
      1. hanoi(3,'A','C','B'); means “move 3 disks from tower A to tower C using tower B”
  3. Your function should print the solution to the puzzle to standard output in the following format:
    1. “move [disk] from [tower1] to [tower2]”
      1. [disk] is the number of the disk being moved. Disks are numbered 1 to 
        n, 1 being the smallest and 
        n being the largest.
      2. [tower1] is the letter of the tower 
        from which the disk is being moved.
      3. [tower2] is the letter of the tower 
        to which the disk is being moved.
    2. For example: “move 1 from A to C” is the first step of solving the 3 disk problem.
    3. Print each step on its own line.
  4. The base case is the 0-disk problem, for which nothing must be done (just return).
    1. What is the recursive step?
    2. What is the combination?
  5. Hints:
    1. Solve the puzzle by hand (
      one of many online versions or 
      another).
    2. Divide and Conquer.
      1. How do you use the solution to the 1-disk problem to help you solve the 2-disk problem? 
      2. How about using the 2-disk solution to solve the 3-disk problem? 
      3. And so on.
    3. The whole function is just 5 lines of code.
      1. 2 of these are the base case
      2. The other 3 are the steps to use the (n-1)-disk solution to solve the n-disk problem.

About the Tower of Hanoi

There is a temple in Kashi Vishwanath which contains a large room with three time-worn posts, on which are stacked 64 golden disks. Brahmin priests, acting out the command of an ancient prophecy, have been moving these disks, in accordance with the immutable rules of the Brahma, since that time. When the last move of the puzzle is completed, the world will end. Despite the location of the legendary temple, the puzzle is most often called the Tower of Hanoi.

The objective of the puzzle is to move the entire stack of disks from the first post to the third post, obeying the following simple rules:

  1. Only one disk may be moved at a time.
  2. Each move consists of taking the upper disk from one of the stacks and placing it on top of another stack.
  3. No disk may be placed on top of a smaller disk.

mysterySeries

  1. Figure out the pattern from the table below.
  2. Write a 
    public static function named 
    mysterySeries that take integers 
    i and 
    j as input and returns the (
    i,
    j)-th mystery number (the number in the 
    i-th row and 
    j-th column).
    1. mysterySeries(6,2) should return 15
  3. Base Cases:
    1. If 
      i < 0 or 
      j < 0 or 
      i < 
      j, then A(
      i,
      j) = 0
    2. The above 3 base cases are 
      not sufficient, what other base case(s) do you need?
  4. Hint: Each element of the 
    i-th row can be computed from elements in the (
    i-1)-th row.
A(i,j)  0  1  2  3  4  5  6  … 
0  1               
1  1  1             
2  1  2  1           
3  1  3  3  1         
4  1  4  6  4  1       
5  1  5  10  10  5  1     
6  1  6  15  20  15  6  1   
…  …  …  …  …  …  …  …  … 

 

Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code “Newclient” for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.

The post recursion program appeared first on Essay Writers.

 

“Are you looking for this answer? We can Help click Order Now”


death and dying 3

Please answer THREE of the following questions. EACH answer should be in the form of a single paragraph (no less than 5 sentences, no more than one page). Be as complete as possible in your answers. No works cited page. Use in-text citations if you are paraphrasing or quoting an author, e.g., (Hampton et al., 9). Some of the online articles do not have page numbers. In such cases, the author’s name is sufficient.

1) How does Ellen Badone’s anthropological approach to death and dying differ from the historical and sociological approach of Aries and Walter?

2) Is transhumanism a “secular” movement? Why or why not?

3) How have some Black Americans used literature, art, and religion to resist and make meaning out of their experiences of racialized violence and death?

4) How has and does the Aboriginal experience of death and dying in Canada differ from that of non-Aboriginal Canadians? What does that tell us about the shortcomings of some descriptions of death and dying in the West?

5) How do the Aboriginal elders interviewed by Hampton et al. describe their approach to death and dying? How do their cultural and spiritual resources help them in their journey from life to death?

https://nickbostrom.com/old/transhumanism.html

https://www.theglobeandmail.com/news/politics/missing-children-unmarked-burials-a-legacy-of-residential-schools/article27772367/https://theintercept.com/2018/05/31/missing-and-murdered-indigenous-women/

https://theintercept.com/2018/05/31/missing-and-murdered-indigenous-women/

 

Do you need a similar assignment done for you from scratch? We have qualified writers to help you. We assure you an A+ quality paper that is free from plagiarism. Order now for an Amazing Discount!
Use Discount Code “Newclient” for a 15% Discount!

NB: We do not resell papers. Upon ordering, we do an original paper exclusively for you.

The post death and dying 3 appeared first on The Nursing Hub.

 

“Are you looking for this answer? We can Help click Order Now”


Deliverable 3 Classical Physics Comparecontrast Paper 19798483

  Competency

Explore the physical principles of classical physics. Instructions

In a two-page paper, identify the classical physics principles contained within the following scenario. Explain how these principals connect to work done by Galileo or Newton. Finally, consider the different fields in which Galileo and Newton did research, and give an example of one of these fields in use in your life. For instance, Newton developed the field of optics. If you wear glasses or contact lenses, you are using Newton’s physical optics theories every day. Aside from glasses or contacts, how do the theories of Newton or Galileo affect you in your daily life? Scenario

Mandy took a trip to Rome, Italy. She gazed out over the open ocean 20,000 feet below as her airplane began its descent to her final destination. She could watch the Sun setting in the west. Over the Eastern horizon peeked a full moon, just rising, displaying its cratered face. As the plane neared the ground, Mandy could not help but think that she was in a giant metal object hurtling through the sky. Without the specific shape of its wings, the plane would fall to the ground no differently than a large metal projectile.

The post Deliverable 3 Classical Physics Comparecontrast Paper 19798483 appeared first on My Perfect Tutors.

 

“Are you looking for this answer? We can Help click Order Now”


Microeconomics – Diminishing Marginal Utility

Topic: Diminishing Marginal Utility

  1. Pretend that you have just been surprised with a genuine email that says you have just been selected by your favorite pizza delivery company that every day for the next month you will receive your favorite pizza for lunch and another of that same favorite pizza for dinner, delivered to your home and ready to eat.
    1. Using the concept of diminishing marginal utility, discuss how excited you will be on the first day of your winning.
    2. What about your excitement on the 10th day?
    3. What about your excitement on the 30th day?
  2. Now, pretend that your favorite national brand gasoline company informs you that you have won as much as you want free gasoline, as much as you want, from any of their gas stations, anywhere in the country every day for a year.
    1. Using the concept of diminishing marginal utility, discuss how excited you will be on the first day of your winning
    2. What about your excitement on the 10th day?
    3. What about your excitement on the 30th day?
  3. Again, considering the concept of utility, what makes these two scenarios different?

The post Microeconomics – Diminishing Marginal Utility appeared first on Brainy Term Papers.


Microeconomics – Diminishing Marginal Utility was first posted on March 13, 2021 at 11:54 pm.
©2019 "Brainy Term Papers". Use of this feed is for personal non-commercial use only. If you are not reading this article in your feed reader, then the site is guilty of copyright infringement. Please contact me at support@nursingessayswriters.com

 

“Are you looking for this answer? We can Help click Order Now”