Questions tagged [pseudocode]
60 questions
27
votes
6 answers
Is there a "Standard Algorithm" language, as used in academic papers?
In many academic papers algorithms are described. They seem to use similar "syntax".
Is there a standard for this language? If I want to describe an algorithm, would I improvise my description?
For example, note that papers in general use
a <--…
Makketronix
- 391
- 3
- 7
14
votes
2 answers
Will this program terminate for every Integer?
In a Part Test for GATE Preparation there was a question :
f(n):
if n is even: f(n) = n/2
else f(n) = f(f(n-1))
I answered "It will terminate for all integers", because even for some negative integers, it will terminate as Stack Overflow…
Prakhar Londhe
- 251
- 2
- 7
2
votes
1 answer
Help writing a dynamic programming algorithm in English
It’s Friday night and you have $n$ parties to go to. Party $i$ has a start time $s_i$ end time $t_i$ and a value $v_i \ge 0$. Think of the value as an indicator of how excited you are about that party. You want to pick a subset of the parties to…
Colin Null
- 35
- 4
2
votes
1 answer
Notation for field access in Algorithm
While writing array index in an algorithm $a[i]\gets v$ is conventionally used. Is the notation $a_{i}\gets v$ also used ?
If the algorithm uses struct or equivalent, some notation is required for property access. In some occasions $p(s)$ is used…
Neel Basu
- 141
- 7
2
votes
0 answers
How does quantum computing pseudocode look like?
In classical programming, pseudocode follows some informal but widely understood standards, focusing on clarity and abstraction while omitting low-level implementation details. However, quantum computing introduces a fundamentally different…
Muhammad Ikhwan Perwira
- 560
- 4
- 15
2
votes
1 answer
Declaring a JavaScript object in pseudocode
What's the proper way to declare an object in pseudocode.
For example:
const car = {type:"Fiat", model:"500", color:"white"};
Would it be correct to write
object car {
type: "Fiat"
model: "500"
color: "white"
}
Or should a different format be…
waldo
- 21
- 2
2
votes
2 answers
Algorithm that will find the minimum number of steps to get from state $j$ to state $i$
Consider an adjacency matrix $A$ with elements $[A]_{ij}=1$ if one can reach state $i$ from state $j$ in one timestep, and $0$ otherwise. The matrix $[A^k]_{ij}$ represents the number of paths that lead from state $j$ to $i$ in $k$ timesteps. Derive…
Slim Shady
- 155
- 4
2
votes
1 answer
Sort a $d$-sorted array
An array is $d$-sorted if every key in the array is located at a distance at most $d$ from its location in the sorted array.
I need to write an algorithm that get a $d$-sorted array of length $n$ and sort it in the following running…
Omri Braha
- 29
- 4
2
votes
1 answer
Transitions between lexicographical orders
I have six characters: (,),[,],{,}. They are stored lexicographically: '(' < ')' < '[' < ']' < '{' < '}'. So I can store all balanced parenthesis sequences of length $n$ lexicographically and each sequence will have unique number $1 \dots…
Grigori
- 125
- 6
2
votes
1 answer
What is the SetHorspool string searching algorithm and how is it implemented?
What is the SetHorspool string searching algorithm with pseudo-code so it can be easily implemented in a language of choice?
This has been implemented in 2 libraries I have come…
2
votes
0 answers
Minimizing the sum of differences in a pair
You have two arrays, a and b
Both contain n elements, all positive and distinct.
you have to create a pair, by taking one number from each array, such that the sum of the differences of the pairs are minimized.
for example, a = [1, 2, 3], b = [4, 5,…
Sharhad Bashar
- 21
- 1
2
votes
1 answer
Pseudo code of recursive method of printing all permutations of $n$ given integers
I really don't understand this pseudo code. The function prints all permutations of $n$ given integers, assuming that all numbers are different.
Is there a way to explain this code more easily as I really don't get the purpose of the…
NimaJan
- 363
- 1
- 11
2
votes
0 answers
Determine the number of self-crossings for an irregular orientation of an n-pointed star, whose vertices lie on the boundary of a circle
I need to create an algorithm that will output the number of self-crossings for an irregular orientation of an n-pointed star, whose vertices lie on the boundary of a circle. The sample input is as follows:
5
24.0
168.0
312.0
96.0
240.0
Where the…
flutterbug98
- 53
- 4
1
vote
1 answer
Probability that a random hash from a universal family is injective
This is a homework question, I don't want an actual answer, but rather guidance on how to obtain the correct answer. The question is as follows:
In class we saw universal hashing as the solution to processing N elements in the range {0,1,...u-1},…
Colin Null
- 35
- 4
1
vote
1 answer
Answering questions about the recurrence of certain aspects of an algorithm
I am thoroughly confused by a problem that was brought up in class:
Given the following pseudocode for a function RANDOM which generates a random number based off of recursion:
function RANDOM(n)
1. if n = 1 then
1.1 return 1
1.2 else
2.1 …
Nat Porter
- 35
- 2