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
9
votes
3 answers

Longest path in a particular type of graph

I know that the longest path problem is NP-hard for a general graph. However, I am considering a particular kind of graph, consisting of one cycle, plus one additional edge incident on each vertex of the cycle. For example, for a cycle of length 7,…
a06e
  • 18,594
  • 33
  • 93
  • 169
8
votes
17 answers

Algorithm for generating a random number

I'm looking to generate a random number and issue it to a table in a database for a particular user_id. The catch is, the same number can't be used twice. There's a million ways to do this, but I'm hoping someone very keen on algorithms has a clever…
Coocoo4Cocoa
  • 48,756
  • 50
  • 150
  • 175
8
votes
4 answers

help in the Donalds B. Johnson's algorithm, i cannot understand the pseudo code (PART II)

i cannot understand a certain part of the paper published by Donald Johnson about finding cycles (Circuits) in a graph. More specific i cannot understand what is the matrix Ak which is mentioned in the following line of the pseudo code…
C.LS
  • 1,319
  • 2
  • 17
  • 35
8
votes
3 answers

Job scheduling problem

I'm working on an application where I need to automatically schedule jobs for members on a rotating schedule. I'm not very good at explaining rules, so here's some data to help out: Positions: A job title, with rules such as Mondays and Wednesdays…
Zahymaka
  • 6,523
  • 7
  • 31
  • 37
8
votes
1 answer

How does the Twitter timeline algorithm work?

I'm trying to design a system similar to Twitter's timeline, but I can't wrap my head around how to get updates from so many followers while remaining efficient. Let's say I'm following 1000 people on Twitter. When I go to my feed, how does it know…
Snowman
  • 31,411
  • 46
  • 180
  • 303
8
votes
4 answers

What is the best hash function for Rabin-Karp algorithm?

I'm looking for an efficient hash function for Rabin-Karp algorithm. Here is my actual code (C programming language). static bool f2(char const *const s1, size_t const n1, char const *const s2, size_t const n2) { uintmax_t hsub =…
md5
  • 23,373
  • 3
  • 44
  • 93
8
votes
2 answers

Solving String reduction Algorithm

I am preparing myself for an interview that I have on monday and I found this problem to resolve called "String Reduction". The problem is stated like this : Given a string consisting of a,b and c's, we can perform the following operation: Take…
Dimitri
  • 8,122
  • 19
  • 71
  • 128
7
votes
2 answers

How does `Skipcond` work in the MARIE assembly language?

I am trying to understand the MARIE assembly language. I don't quite understand skipcond for doing things like <, or >, or multiply or divide. I am taking this simple program: x = 1 while x < 10 do x = x +1 endwhile; What I don't understand is how…
user249375
7
votes
3 answers

I'm trying to find if a rectangle intersects a concave polygon. Does this algorithm accomplish that?

I'm trying to find if a rectangle intersects a concave polygon. I found this algorithm: double determinant(Vector2D vec1, Vector2D vec2){ return vec1.x*vec2.y-vec1.y*vec2.x; } //one edge is a-b, the other is c-d Vector2D…
jmasterx
  • 52,639
  • 96
  • 311
  • 557
7
votes
10 answers

Interleaving sparse sorted arrays

I've got a set of lists of events. The events always happen in a given order, but not every event always happens. Here's an example input: [[ do, re, fa, ti ], [ do, re, mi ], [ do, la, ti, za ], [ mi, fa ], [ re, so, za ]] The input values…
Plutor
  • 2,867
  • 2
  • 25
  • 29
7
votes
6 answers

An algorithm to solve a simple(?) array problem

For this problem speed is pretty crucial. I've drawn a nice image to explain the problem better. The algorithm needs to calculate if edges of a rectangle continue within the confines of the canvas, will the edge intersect another rectangle? We…
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456
7
votes
2 answers

Understanding the pseudocode in the Donald B. Johnson's algorithm

Does anyone know the Donald B. Johnson's algorithm, which enumerates all the elementary circuits (cycles) in a directed graph? I have the paper he had published in 1975, but I cannot understand the pseudocode. My goal is to implement this algorithm…
C.LS
  • 1,319
  • 2
  • 17
  • 35
7
votes
3 answers

What does “:” mean in Pseudocode?

I'm a little new to pseudocode, What does : mean in pseudocode? For example: X ← copy(C[s − a : s + len])
7
votes
2 answers

Code a linear programming exercise by hand

I have been doing linear programming problems in my class by graphing them but I would like to know how to write a program for a particular problem to solve it for me. If there are too many variables or constraints I could never do this by…
7
votes
3 answers

What's a fast and stable algorithm for a random path in a node graph?

I have a graph which consists of nodes and I need a fast algorithm that generates a random path between two nodes. I designed several algorithms from scratch for this but can't seem to get it right. Either the algorithm gets stuck in loops, or when…
Marnix v. R.
  • 1,638
  • 4
  • 22
  • 33