9: write an algorithm, in which you are creating a counter logic loop from 1 to 10.print elements with jump 1 index [increment twice). 10. Write pseudo-code for question 9.
Q: L = ['arya', 'bran', 'drogon', 'gendry', 'hodor', 'jon', 'sansa', 'tyrion'] how do you fill out the…
A: Assumptions: Array index starts from 0. middle = floor((first+last)/2). and Arya is given value 0,…
Q: True/False 8. Loops are more general than recursion
A: Loops can be easily conceptualized and programmed since it's execution is straightforward. On other…
Q: using C++ Read a[8]. Then CHECK whether its elements are all even (print YES) or not (print NO)?
A: Ans: Code: #include <iostream>using namespace std;int main() { int a[8]; int countEven=0;…
Q: Given the unsorted list [6, 5, 4, 3, 7, 1, 2], show what the contents of the list would be after…
A: a. Selection sort:[6, 5, 4, 3, 7, 1, 2][1, 5, 4, 3, 7, 6, 2][1, 2, 4, 3, 7, 6, 5][1, 2, 3, 4, 7, 6,…
Q: B5. Using recursion, write a program in java to reverse a given string.
A: import java.util.Scanner;public class Main{ public static void strReverse(String a) {…
Q: convert this python code into java? Python code is as shown below: # recursive function def…
A: Given: convert this python code into java? Python code is as shown below: # recursive function def…
Q: Ridbit begins with an integer n. In one action, he can perform one of the accompanying tasks:…
A: Here have to determine about the Subtract or Divide programming problem statement.
Q: Perform the Bubble Sort on the following list. You can use the sample algorithm presented during…
A: Bubble sort is one of the sorting techniques that work on the logic of repeatedly swapping the…
Q: All. Write an algorithm that reads strings on screen and write them back on screen again. Al2. Write…
A: Algorithm A11: Algorithm that reads strings on screen and writes them back on screen. Here is the…
Q: The rows are sorted in ascending order: a [0], a [1],…, a [n-1] b [0], b [1],…, b [m-1] Write a…
A: Required: In C++ The rows are sorted in ascending order: a [0], a [1],…, a [n-1] b [0], b [1],…, b…
Q: 1. On Receipt, you show all prices entered. - save all prices to a list 2. print all elements in…
A: define an empty list. use while True loop read a float value append value to list end loop…
Q: ztalloc ecneuqes def ztalloc (shape): The famous Collatz sequence was used in the lectures as an…
A: Hey there, I am writing the required solution based on the above given question. Please do find the…
Q: Example Output 1 ehicles = ['car', 'Truck', 'boat', 'PLANE’] Enter a search letter: a ar contains…
A: #printing listprint("vehicles = ['car', 'Truck', 'boat', 'PLANE']")#printing…
Q: Write a function dups to double each char of a string. Recursion must on list not string.…
A: Note: As no language is specified, the below code is in Java programming language. Algorithm:…
Q: def count_vowels(self, a_string): """ Given a string, count the number of vowels one character at a…
A: Please find the answer below:
Q: Program to remove the ith occurrence of the given word in list where words can repeat. Example…
A: Python Program: # Declare an empty listl = [] # Taking the size of list and enter the elementsSize =…
Q: An algorithm that requires operations to complete its task on n data elements is said to have a…
A:
Q: 41 Aigonim 1. Initialize i= 0 and max = t-p+1/ *t and p are respectively lengths of strings T and P*…
A: /******************************************************************************…
Q: Use Figure 10.8 as an example to show how to apply the binary search approach to a search for key 10…
A: The binary search algorithm is mentioned below. STEP 1: In the first step, sort the list in…
Q: Create a function: -that takes a list and an integer v, -and returns the number of occurrences of v…
A: Have a look at the below code. I have put comments wherever required for better understanding. Code…
Q: Use list comprehension to create list num_list for the following for loop num = 123450 num_list =…
A: I give the code in Python along with output and code screenshot
Q: POP is a term used to ... an element from a Stack Select one: a. Delete O b. Sort c. Search d.…
A: Different operation in stack 1. Push: Adds an item in the stack. 2.Pop: Removes (delete) an item…
Q: L(G) = {a"b"c"d":n,m ≥ 0} then trace to following string: abbccd (show the stack)
A: Given language is, L(G)= {ambncndm :n,m >=0} It contains input variables a, b, c, d. Given string…
Q: 1. def listsum(numlist, size): # --base case-- # if the list is empty if size== 0: return 0 # if the…
A: In the given program you have to fill in the blanks in order to complete the program. You need to…
Q: If A is an array of size 3. Each element of the array holds a reference to the root of a…
A: Non-linear structure that stores user-defined data types is called Tree. Tree can have zero or any…
Q: If A is an array of size 3. Each element of the array holds a reference to the root of a…
A: Given size of the array is 3. And the pseudocode segment is printing A[0].preorderToString(); It is…
Q: 5) Add 2 numbers of any arbitrary base. Your addition algorithm MUST perform the addition IN THE…
A: Given, Two strings- s1 and s2 we have to add s1 and s2 and store their sum into a sum character…
Q: L = ['arya', 'bran', 'drogon', 'gendry', 'hodor', 'jon', 'sansa', 'tyrion'] Fill out the below…
A: Some basic assumptions made here while answering the question: Array index starts from 0.…
Q: Python code is as shown below: # recursive function def row_puzzle_rec(row, pos, visited): # if the…
A: Given:
Q: Task 2: Write a program to implement Binary search. Count numbers of comparison you have made to…
A: implement binary search . use one global variable count=0 with each return statement do count++…
Q: How can I create a list by asking for input (x) and create a list from 1 to x using recursion?…
A: Algorithm: Start Declare an empty nums in global scope Implement a method newlist() which takes n…
Q: gorithm that takes as input distinct integers and finds the location of the largest even integer in…
A: We need to loop through each and every element so that we can determine the largest even number
Q: Write a program that sorts a list in ascending order. Don’t use sort method. Ask user number of list…
A: Please find the answer below
Q: 1. Initialize i = 0 and max = t – p + 1 / * t and p are respectively lengths of strings T and P * /…
A: Given: 1. Initialize i = 0 and max = t – p + 1 / * t and p are respectively lengthsof strings T and…
Q: Fill in the blank to make code below sum up only odd numbers of a given list L in a recursive…
A: I am trying a code like and you run it and get some error then I try to modify it and run it and…
Q: Python Using recursion only No loops If the list is empty or does not contain any sets, the…
A: #function code with explanation#simplest logic to solve this problem is:#first check if list is…
Q: Trace the following recursion code. Draw and Write down the outputs. Please, show the recursive flow…
A: Here hMB() is a recursive function, in which we call this function again until we reach on base…
Q: IIi you most likely see in a non-recursive implementation of a recursive algorithm? A A stack B An…
A: Answer : stack
Q: Introduction to C++ Code a Selection Sort for an array of integers and then code a Selection…
A: Selection sort: Selection sort is used to sort the group of data. Selection sort finds the smallest…
Q: a) The node u that the algorithm will select next is: Answer: u= b) The first iteration of the outer…
A: Nodes for the network graph are 1, 2, 3, 4 and the source node is 2 Mark every node with its minimum…
Q: Complex numbers create the Mandelbrot set, where each of those recursive sequence goes to 0. The…
A: import numpy as np import matplotlib.pyplot as plt # create the mandelbrot function def…
Q: Write a recursive function for printing n box shapes [ ] in a row. Hint: Print one [], then print n…
A: Complete recursive function for printing n box shapes [] in a row :- #include <iostream> using…
Q: 5. Let x, y, and z be arrays of length n, where x and y are already initialized. Let sum be a real…
A: Answer: I have given answered in the handwritten format and also i have code in C+ programming…
Q: int i-1,j; while(1){ j-i; i=j+i; What is the time complexity of above loop.
A: Time complexity of a loop is the time dependency of the termination of loop on the loop variable.
Q: h moves 5 disks from Pole 2 to Pole 3 recursively for the Towers screen.
A:
Q: 4. Two words are anagrams if they contain all of the same letters, but in a different order. For…
A: Input the two strings. Create an dictionary for both the strings. Traverse both the strings and…
Q: 1. Analyze the word finder with wild card characters scenario to form the algorithm and compute the…
A: Answer: I have explain in brief.
Q: Unfortunately, the code itself executes but recursively in infinite loop. Is there a reason why it…
A: the code itself executes but recursively in infinite loop, because of the (first < last)…
Step by step
Solved in 2 steps
- TAKE A LIST OF STRING FROM THE USER AND COUNT THE NUMBER OF UNIQUE ELEMENTS WITHOUT USING THE FOR, WHILE, Do-WHILE LOOPS. PREFERRED PROGRAMMING LANGUAGE: JAVA/C++Java - Write a method that uses a loop to figure out the factorial (n!). The method will take an integer n and return the value of n! (return answer, don’t print) Take the method above and convert it to a recursive method.Review Loops Write a java program to ask three people three questions about name, number of courses, and number of credit hours. Also, print result in columns as below. Note: the input.nextInt() method reads only the integer value from input buffer.The "\n" is still staying in the input buffer. If you continue reading with input.nextLine(),you will receive the "\n" and CPU will not wait for any input. To fix this problem, you addthe statement input.nextLine() to flush out the "\n" from the input buffer.
- Write this program in Java using a custom method. Implementation details You will implement this program in a specific way in order to gain some experience with loops, arrays and array lists. Use an array of strings to store the 4 strings listed in the description. Use a do-while loop for your 'game engine'. This means the game starts once the user enters money. The decision to stop occurs at the bottom of the loop. The do-while loop keeps going until the user quits, or there is no money left. The pseudocode for this 'game engine' is shown below: determine the fruits to display (step 3 below) and print them determine if there are 3 or 4 of the same image display the results update the customer balance as necessary prompt to play or quit continue loop if customer wants to play and there's money for another game. Use the Random class to generate a random number between 0 and 3. This random number will be an index into the array of strings. Add the string at that index to an…True/False 8. Loops are more general than recursionUnion-Find: Maze Write a program that generates mazes of arbitrary size using the union-find algorithm. A simple algorithm to generate the maze is to start by creating an N x M grid of cells separated by walls on all sides, except for entrance and exit. Then continually choose a wall randomly, and knock it down if the cells are not already connected to each other. If we repeat the process until the starting and ending cells are connected, we have a maze. It is better to continue knocking down the walls until every cell is reachable from every cell as this would generate more false leads in the maze. Test you algorithm by creating a 15 x 15 grid, and print all the walls that have been knocked down. D
- Rewrite as a while loop SUIT = 1 BLACK = 0RED = 1 SUIT_COLOURS = {'S': BLACK,'H': RED,'D': RED,'C': BLACK} def same_colour(cards):for i in range(len(cards)):if i == 0:colour = SUIT_COLOURS[cards[i][SUIT]]elif SUIT_COLOURS[cards[i][SUIT]] != colour:return Falsereturn TrueLab Goal : This lab was designed to teach you more about recursion. Lab Description : Take a number and recursively determine how many of its digits are even. Return the count of the even digits in each number. % might prove useful to take the number apart digit by digit Sample Data : 453211145322224532714246813579 Sample Output : 23540Java - Write a method that uses a loop to figure out the factorial (n!). The method will take an integer n and return the value of n! (return answer, don’t print)
- ntegers outerRange and innerRange are read from input. Complete the outer while loop so the inner loop executes (outerRange + 1) * innerRange times. Ex: If the input is 6 5, then the output is: Inner loop ran 35 times import java.util.Scanner; public class LoopCounter { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); int outerRange; int innerRange; int count; int i; int j; outerRange = scnr.nextInt(); innerRange = scnr.nextInt(); count = 0; i = 0; while (/* Your code goes here */) { j = 0; while (j < innerRange) { ++count; ++j; } ++i; } System.out.println("Inner loop ran " + count + " times"); } }*in java* Write a loop that subtracts 1 from each element in lowerScores. If the element was already 0 or negative, assign 0 to the element. Ex: lowerScores = {5, 0, 2, -3} becomes {4, 0, 1, 0}. import java.util.Scanner;public class StudentScores {public static void main (String [] args) {Scanner scnr = new Scanner(System.in);final int SCORES_SIZE = 4;int[] lowerScores = new int[SCORES_SIZE];int i; for (i = 0; i < lowerScores.length; ++i) {lowerScores[i] = scnr.nextInt();} /* Your solution goes here */ for (i = 0; i < lowerScores.length; ++i) {System.out.print(lowerScores[i] + " ");}System.out.println();}}Lab Goal : This lab was designed to teach you more about recursion. Lab Description : Take a string and remove all occurrences of the word chicken and count how many chickens were removed. Keep in mind that removing a chicken might show a previously hidden chicken. You may find substring and indexOf useful. achickchickenen - removing the 1st chicken would leave achicken behindachicken - removing the 2nd chicken would leave a behindSample Data : itatfunitatchickenfunchchickchickenenickenchickchickfunchickenbouncetheballchickenSample Output : 01302