1,939 questions
5
votes
2
answers
130
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
votes
1
answer
55
views
How could I turn a variable into a number of seconds equal to that variable's number of minutes
I want to turn a variable (let's say with a current value of 20) into a value that is <variable> minutes (in to), so a variable of 20 turns into 1200 (the number of seconds in 20 minutes)
How ...
1
vote
1
answer
130
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 ...
2
votes
1
answer
139
views
Can the A* search algorithm be implemented without a closed list?
The A* search algorithm is usually implemented using an open and a closed list (or other data structures). Recently I read in Wikpedia a pseudocode that makes use only of an open list.
Is the closed ...
1
vote
1
answer
279
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 ...
1
vote
2
answers
77
views
Producer-consumer queue in multithreading, shutdown mechanism
I wrote the following pice of pseudocode. It is about the classic producer-consumer queue in multithreading, but I am trying to add a graceful shutdown mechanism. I want consumeItem to keep working ...
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 ...
-1
votes
1
answer
89
views
What is the worst-case runtime of this algorithm (in big-oh notation)? [closed]
The input is an N by N matrix of numbers. Each individual row is increasing from left to right. Each individual column is increasing from top to bottom. The example of a matrix is given below with N = ...
-2
votes
1
answer
84
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
2
answers
164
views
POSIX-Extended RE for substrings that start with a prefix, end with a suffix and whose inner part does not contain any element of a given set [closed]
I have an input string S and three parameters: a prefix string (denoted by A), a suffix string (denoted by B) and a set N of strings.
Given these three parameters, is it possible to generate a single ...
2
votes
1
answer
115
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 ...
-1
votes
1
answer
89
views
Curious if this problem can be solved more elegantly (maybe using recursion?) [closed]
I'm a graduate student in biology that encountered a problem that I really struggled solving in my project. I solved it using an iterative approach (will describe more below) but was curious if there ...
2
votes
1
answer
99
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
0
answers
110
views
Maximum Sum of Vertices in DAG Excluding Directly Connected Vertices
How can I calculate the maximum possible sum of vertices in a weighted DAG excluding vertices directly connected by an edge? This is a vertex selection problem where each vertex has a weight.
In this ...
1
vote
1
answer
108
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 ...
0
votes
1
answer
73
views
I am trying to convert this pseudo code into hack language saved as an .asm file
I have been stuck trying to figure out how to translate pseudo code into hack language formatted as .asm, that will run successfully using the CPUEmulator.sh in the Nand2Tetris, with attached .tst &...
-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
77
views
Find the coordinates of the minimum bounding rectangle enclosing two rectangles
Given the coordinates of the top left corners of two rectangles (x1, y1), (x2, y2), their respective widths and heights (w1, h1), (w2, h2) (They may or may not overlap). How do I find the coordinates ...
1
vote
1
answer
273
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 ...
-1
votes
2
answers
189
views
How do I convert if else to && || in if the result is the same
how do i replace if else to && || if the output for each condition is the same in these cases
there are multiple different conditions to be met before reaching the outputs and each case has ...
-4
votes
1
answer
268
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 ...
-1
votes
1
answer
132
views
Merge step of the Merge sort algorithm [closed]
I have a question and I hope someone could help me. I really don't understand the pseudo code of the merge step of the merge sort algorithm. I understand how it works but not the code. Would be ...
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
2
answers
89
views
figuring out if a seat is available for a specific itinerary
So I've got an interesting problem here that I'd like to find an elegant solution to. In this case, I don't really have any code written as what I'm looking for is more of an algorithm. Once I know ...
1
vote
3
answers
232
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
2
answers
341
views
Need help in understanding the pseudocode function that aims to delete an element in a specified memory address in a linked list
I was studying about Linked Lists from the book, "Introduction to Algorithms" by T Cormen.
There was an portion in the book as follows:
Given an element x in the list, x.next points to its ...
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
1
answer
133
views
How can I optimize my algorithm by replacing if-then-else statements with case statements?
One may consider using case rather than if-then-else statements. If there are different cases, then the code goes to the right choice. This will save time without going through everything.
If f_op is ...
0
votes
0
answers
171
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.
...
2
votes
2
answers
465
views
How would I articulate the time complexity of an O(n^3) function?
For a pseudocode algorithm like this:
Algorithm fn(A, S):
Inputs: array A of n integers
integer S
for i from 0 up to n - 1:
for j from i + 1 up to n - 1:
for k ...
0
votes
1
answer
600
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 ...
1
vote
1
answer
134
views
Find length of biggest common contiguous subsequence in specific time complexity
Suppose we have 2 sequences(Arrays) A[1..m] and B[1..n] of integers.
How can we find the length of the biggest common contiguous subsequence of A and B in O(nlogn + mlogm + k^2) where k is the number ...
0
votes
1
answer
56
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 ...
-1
votes
1
answer
209
views
problem while sorting a linked list (pseudocode)?
I was trying to figure out a way to sort a linked list in ascending or descending order, but because a linked list is accessed only sequentially, I don't know how to do it, let me explain it better,
...
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, ...
1
vote
0
answers
235
views
How to iterate a tree using BFS using a for loop?
I am iterating a tree using Breadth first search and I want to check whenever the iteration goes to a lower level in the tree each time to display a message and that using a pseudo code. I don't want ...
-2
votes
1
answer
79
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
3
answers
773
views
While and Do-While Loops
Would this be the correct way to use a WHILE and DO…WHILE loop?
These two examples of a loop were suggested to me by another user so, I thought I would pop them into my pseudocode to see how they ...
0
votes
1
answer
526
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
2k
views
Pseudocode for BMI
I was asked to design a pseudocode that calculates and displays a person's body mass index (BMI) based upon their weight and height.
I would like to know if I'm headed in the right direction or if I'm ...
0
votes
1
answer
81
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....
-2
votes
1
answer
557
views
Iterative version of the Bron–Kerbosch algorithm with pivoting
I need much a correct pseudocode of Bron–Kerbosch algorithm (it enumerates all maximal cliques in an undirected unweighted graph). I need iterative (non-recursive) solution with a stack. And the ...
0
votes
1
answer
599
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 ...
0
votes
0
answers
160
views
Stuck in for loop while generating pseudocode from three address code in Python
I need help in writing a python code that takes in the Three Address Code for the Java source code and returns pseudo code. I have successfully generated pseudo code for 1-D array initialization by ...
-1
votes
1
answer
704
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
votes
1
answer
42
views
How do you loop through already existing values in an arrray after populating it?
I need to loop through an array and be able to create a populate an array using pseudocode or python.
I have tried to create and populate an array, but cannot loop through the values.
1
vote
1
answer
103
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 ...
2
votes
1
answer
658
views
How to implement Sieve of Eratosthenes Algorithm in C?
In my book, Programming in C (fourth edition) by Stephen G. Kochan, I have a task to implement the Sieve of Eratosthenes algorithm as follows:
Display All Prime Numbers Between 1 and n = 150
Step 1: ...
-1
votes
1
answer
252
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 ...
0
votes
0
answers
62
views
writing 'count' as the first item of the output file for this algorithm
I was attempting a problem regarding pointers from a book called problem solving and program design in C. we were formally introduced to functions fscanf() and fprintf() where they accept both input ...