1,939 questions
5
votes
2
answers
128
views
Translate permutation algorithm by Sedgewick from Pseudocode into JavaScript
In his classical paper Permutation Generation Methods, Computing Surveys 1977, Robert Sedgewick presents his "Algorithm 1" on page 140 like this:
procedure permutations(N);
begin
...
1
vote
1
answer
126
views
Is it possible to find the average of a group of numbers and return the index of the number furthest from the average with one loop?
Specifically:
Write a function (in python, java or pseudocode) average(nums) that prints the mean of the numbers in list nums, and returns a tuple:
The tuple's first element is the index of the ...
1
vote
1
answer
258
views
Branch and bound problem, how to enumerate all of the possibilities?
Here is a problem that was in a past exam for Advanced algorithms in my studies,it's on 5 points over 3 hours so should take approximately 1H but I am struggling to find the solution for the first ...
0
votes
1
answer
75
views
Convert nested recursive algorithm (Ackermann's function) to iterative algorithm
I came across a practice problem:
I already wrote out the pseudocode for this, really easily too, just made the calls to the function as mention in the problem statement. But I was really struggling ...
-2
votes
1
answer
83
views
Average of non-negative integers using integer division [closed]
Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative integers as input, and outputs the average (using integer division) and max. A ...
2
votes
1
answer
113
views
Does this algorithm for converting a Binary Search Tree into a sorted linked list on Wikipedia have a bug in it?
I wanted to get a sanity check here. I believe the algorithm listed on the wikipedia page for the Day–Stout–Warren algorithm for balancing BSTs has a problem.
This pseudocode purports to turn a BST ...
2
votes
1
answer
98
views
Determine next building upgrade in Monopoly
Each street in Monopoly is comprised of 2 or 3 different properties.
When a user upgrades a street, it will build 1 of 3 buildings on the appropriate property.
House - least valuable, will build this ...
1
vote
1
answer
104
views
Hash table average complexity of functions
GOAL
The goal is to use a chained hash table, with a hashing function h that satisfies the Simple Uniform Hashing Assumption, to store some numbers (the same number, if inserted multiple times, is ...
-2
votes
1
answer
39
views
Optimizing R script for querying Teradata data dynamically and handling weekends [closed]
I currently have a process in place, but need to reformulate it to be more efficient. I will describe the new process and I would like to know if the new process is optimal and follows proper coding ...
1
vote
1
answer
269
views
How to find when the object changed its direction of motion
Problem:
A ball is thrown up after sometime it loses momentum and starts
falling back
A car moving in direction x and taking a U-turn & starts returning
A planet moving prograde and becomes ...
-4
votes
1
answer
259
views
What will be the output of the pseudocode below and why?
The answer for all three situations is supposedly 3, i dont understand why that is, can someone please explain what is going on and the reasoning behind it, why is the answer 3 for all situations ?
I ...
0
votes
0
answers
76
views
i have greedy and dijkstra algorithms with the same distance. My question is which distance to choose, B to C or B to D
The problem I marked in the picture is choosing the shortest path for the greedy and Dijkstra algorithms, now I'm confused because there are 2 identical paths, namely B to C and B to D. Which path ...
1
vote
3
answers
228
views
Increase the chance of a playing card being drawn from a deck?
I am trying to meet these requirements:
Cards should be drawn in a pseudo-random order, Hearts and the Ace of Spades will be considered special cards with increased chances of being drawn. Each Heart ...
0
votes
1
answer
1k
views
Is this pseudocode for implementation of a queue through an array valid?
Write a pseudocode on implementing a queue through an array named Q of size n with 1-based indexing( i.e the index of Q starts from 1 instead of the usual 0).
The two functions below called Q.head and ...
0
votes
0
answers
168
views
First time writing Pseudocode, can someone help me?
My assignment is to write Pseudocode for a program I was told to create.
The Color Mixer program in Python. Here are two examples of how to write the
Psuedocode out of the book I was told to read.
...
0
votes
1
answer
586
views
Creating a new column or row in flowgorithm
I am trying to create a multiplication table from 1 to 10, but print each line one at a time. I need to know how to do this in flowgorithm. I have the chart correct to print the multiplication table ...
0
votes
1
answer
53
views
How to understand that two lines go next to each other in the program?
I have a graph with two lines that measure the volume flow of some goods. Every 5 minutes I receive new points for two lines. When I visually see that two lines are next to each other and go through ...
0
votes
1
answer
51
views
Why isn't variable 'result' always declared?
I am working with pseudocode taken from Exploration Tools (section "Arm A64 Instruction Set Architecture", button "Download XML").
bits(16) BFSub(bits(16) op1, bits(16) op2, ...
-2
votes
1
answer
78
views
I don't understand the Pseudocode APCSP
I partially understand what the question is asking but why are all answer choices not right?
0
votes
1
answer
517
views
Using Loops in Pseudocode
I've been creating a program that determines the number of paint cans required to paint a room. My professor had us write the pseudocode for the program, and now wants us to modify the code by ...
0
votes
1
answer
75
views
IBM Module I Algorithm does not give me different probabilities at different number of iterations
I am trying to code the IBM Modele using its pseudo-code
And I believe my code should work but for different iteration numbers the output is printing the same and I have no idea why this is happening....
0
votes
1
answer
581
views
Declaring and Writing a For Loop in Pseudocode
I am working on writing the pseudocode for a calorie counting program that calculates the total weekly calories for breakfast. the program should allow the user to enter the number of calories ...
-1
votes
1
answer
701
views
Can someone explain what the pseudo-code below is trying to do?
Below is the pseudo-code. In my opinion, it is the pseudo-code is trying to find the peak elements along with their index in a list of tuples.
The output on my end is : [(1, 4), (4, -9), (7, 12), (9, -...
1
vote
1
answer
99
views
How to find the output when using an extremely large input in this algorithm?
During an interview I was given the following problem:
From the following puzzle, what would the output of puzzle(power(2022, 100)) be?
function puzzle(N) {
A, B, C, D = 1, 1, 1, 1
.repeat N ...
-1
votes
1
answer
251
views
Truth table for a pseudocode
I am looking at the truth table for following pseudocode.
IF year = 11 AND (grade < target OR target >7) THEN
SET revision_class TO true
END IF
I want to know whether the below truth table ...