Questions tagged [pseudocode]

Pseudocode is a compact and informal high-level description of a computer programming algorithm. It represents the code and may look similar to the code or code constructs, but it isn't actual code. It is a representation of the code or code construct. Use this tag for questions which are about pseudocode. Do not use this tag for questions which include pseudocode incidentally.

An easy way of understanding pseudocode is by comparing it to the actual programming language.

For example, you would like to write a code that checks if the student's grade is above the permissible threshold, and if it is then you would like to indicate that the student passed.

This is how it is achieved in Python:

if studentsGrade >= 70:
    print("Student passed")
else
    print("Student failed")

Pseudocode to describe the abovementioned code will be as follows:

if a student's grade is greater than or equal to 70
    Print "Student passed"
else
    Print "Student failed"
1942 questions
28
votes
5 answers

How to distribute points evenly on the surface of hyperspheres in higher dimensions?

I am interested in evenly distributing N points on the surface of spheres in dimensions 3 and higher. To be more specific: Given a number of points N and number of dimensions D (where D > 1, N > 1) The distance of every point to the origin must be…
F Chopin
  • 574
  • 7
  • 23
28
votes
11 answers

Optimizing queries for the next and previous element

I am looking for the best way to retrieve the next and previous records of a record without running a full query. I have a fully implemented solution in place, and would like to know whether there are any better approaches to do this out there.…
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
27
votes
1 answer

Pathfinding (routing, trip planning, ...) algorithms on graphs with time restrictions

I have a database of bus/train/... stops and the arrival/departure times on each date and so on. I'm looking for a way to do a search for the fastest(shortest/cheapest/least transitions) trip between two locations. I would like to have arbitrary…
lacop
  • 2,024
  • 4
  • 22
  • 36
27
votes
5 answers

Pseudocode to compare two trees

This is a problem I've encountered a few times, and haven't been convinced that I've used the most efficient logic. As an example, presume I have two trees: one is a folder structure, the other is an in-memory 'model' of that folder structure. I…
ianmayo
  • 2,256
  • 3
  • 26
  • 44
25
votes
6 answers

Heap's algorithm for permutations

I'm preparing for interviews and I'm trying to memorize Heap's algorithm: procedure generate(n : integer, A : array of any): if n = 1 then output(A) else for i := 0; i < n; i += 1 do generate(n - 1, A) …
25
votes
37 answers

Java balanced expressions check {[()]}

I am trying to create a program that takes a string as an argument into its constructor. I need a method that checks whether the string is a balanced parenthesized expression. It needs to handle ( { [ ] } ) each open needs to balance with its…
Jess Anastasio
  • 687
  • 5
  • 18
  • 26
24
votes
4 answers

Check which side of a plane points are on

I'm trying to take an array of 3D points and a plane and divide the points up into 2 arrays based on which side of the plane they are on. Before I get to heavily into debugging I wanted to post what I'm planning on doing to make sure my…
GameDever
  • 243
  • 1
  • 2
  • 5
24
votes
3 answers

SHA 256 pseuedocode?

I've been trying to work out how SHA-256 works. One thing I've been doing for other algorithms is I've worked out a sort of step by step pseudocode function for the algorithm. I've tried to do the same for SHA256 but thus far I'm having quite a bit…
codelion
  • 319
  • 1
  • 2
  • 11
23
votes
13 answers

Finding shortest repeating cycle in word?

I'm about to write a function which, would return me a shortest period of group of letters which would eventually create the given word. For example word abkebabkebabkeb is created by repeated abkeb word. I would like to know, how efficiently…
jack44
  • 293
  • 1
  • 2
  • 5
22
votes
6 answers

Create sine lookup table in C++

How can I rewrite the following pseudocode in C++? real array sine_table[-1000..1000] for x from -1000 to 1000 sine_table[x] := sine(pi * x / 1000) I need to create a sine_table lookup table.
user466444
  • 469
  • 3
  • 7
  • 14
21
votes
3 answers

marking node as visited on BFS when dequeuing

Just a quick and silly question, about BFS traversal on graphs I found on many sites the pseudocode for a BFS is pretty much something like this: BFS (Graph, root): create empty set S create empty queue Q add root to S //mark as visited…
sir psycho sexy
  • 780
  • 7
  • 19
21
votes
8 answers

Pseudocode interpreter?

Like lots of you guys on SO, I often write in several languages. And when it comes to planning stuff, (or even answering some SO questions), I actually think and write in some unspecified hybrid language. Although I used to be taught to do this…
17
votes
6 answers

Interview puzzle: Jump Game

Jump Game: Given an array, start from the first element and reach the last by jumping. The jump length can be at most the value at the current position in the array. The optimum result is when you reach the goal in minimum number of jumps. What is…
user973931
  • 515
  • 1
  • 4
  • 13
16
votes
4 answers

Create a Hash Table with two arrays

Does anyone know how to do this and what the pseudo code would look like? As we all know a hash table stores key,value pairs and when a key is a called, the function will return the value associated with that key. What I want to do is understand the…
locoboy
  • 38,002
  • 70
  • 184
  • 260
16
votes
4 answers

Kth largest element in a max-heap

I'm trying to come up with something to solve the following: Given a max-heap represented as an array, return the kth largest element without modifying the heap. I was asked to do it in linear time, but was told it can be done in log time. I…
Alstor
  • 161
  • 1
  • 1
  • 4