# Questions tagged [pseudocode]

The tag has no usage guidance.

50 questions
Filter by
Sorted by
Tagged with
22 views

### Is this A* pseudocode taking the condition of admisible ad consistent heuristic function hypothesis for granted?

This is the pseudocode for A* from wiki: ...
37 views

### A* pseudocode problem

What is the difference between this two pseudocode and which one should i implement? ...
1 vote
53 views

### First piece of code in scientific papers

What is the first/oldest piece of source code shown in an scientific paper or journal? I am looking for source code of assembly or a high level programming language which was real (implemented) and ...
• 111
390 views

### What is a pseudocode of try-catch?

What is a pseudocode of try-catch? Is it this? **Try** SOMETHING If you succeed Do nothing special Else, if you didn't succeed Do what's described in the **Catch** block Anyway, either if ...
• 11
65 views

### What would be a pseudocode of try-catch pattern, common in generally all programming languages?

What would be a pseudocode of try-catch pattern, common in generally all programming languages? Perhaps the following? ...
50 views

### 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 ...
• 155
78 views

...
• 103
113 views

### Minimize the average distance from each cities to the closest hospitals

There are n cities [1, 2, 3, .... n] and k available hospitals. k < n. We need to place hospitals into the cities. How to place these hospitals to minimize the average distance from each cities to ...
88 views

### Find distinict elements in an array in $O(n)$ time

Given this pseudo-code that finds the number of distinct elements in the given array: ...
132 views

### 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 ...
388 views

### Converting python/numpy code into pseudocode

I've written some code that uses numpy's array broadcasting logic and need to convert it to pseudocode. Basically, $w\in R^{T}$ and $\beta\in R^{T \times M}$. If you have the following code using ...
• 101
1 vote
20 views

### Two "bubble" loops in pseudocode; would they return the same thing?

I am trying to create a new form of a bubble loop and want to see if they would return the same truth values during runtime. Could I get a second pair of eyes to confirm if this is the case? Note: ...
• 11
69 views

### Combinations (repetition not allowed & order not important)

How to compute a table of numbers (all possibilities), where repetition is not allowed and order is not important. Example: I have a set of prime numbers. In this example I have four: {3,5,7,11}, but ...
122 views

### Transitions between lexicographical orders

I have six characters: (,),[,],{,}. They are stored lexicographically: '(' < ')' < '[' < ']' < '{' < '}'. So I can store all balanced parenthesis sequences of length $n$ ...
370 views

### Given a sorted array with n integers, how to find the element that has no duplicates?

I am given a sorted array with n integers. All of the elements repeat exactly twice, while there is one element without duplicate. I need to solve it as efficient as it is possible by divide-and-...
• 25
1 vote
28 views

### Notations for dealing with generators in algorithms

This question is about generators, which are functions that return an item from a (usually very large or infinite) set on demand, an example from Python is: ...
• 133
1 vote
49 views

### Merge Sort sentinel: What if your array contains Integer.MAX_VALUE?

I'm just getting my head round Merge Sort, and I was wondering whether the use of the sentinel value was considered good practice in the real world, or mostly an algorithmic conceit? I get that it ...
• 11
73 views

### 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 across: https://app-...
34 views

### data structure Q with priotry queue which allow us to find the median in $O(1)$ and the data structure need to support the following operations

I've got this question from an exercise and i'm not sure if it is possible to do so Think of new data structure Q with priotry queue which allow us to find the median in $O(1)$ and the data structure ...
• 211
70 views

### Two-Sum - Range Allowance Algorithm Design

🧩 What is the best way to find if there are two individual capacities that sum to a total capacity within a range of plus and minus the total capacity? Optimize for runtime over memory complexity. ...
• 109
236 views

### Two-Sum - Pre-sort Optimization Algorithm Design

🧩 Is it possible to optimize the runtime of a two-sum solution by receiving a pre-sorted input either in ascending or descending order? 🚀 Original Two-Sum Determine whether there are two items whose ...
• 109
377 views

### Explanation of pseudocode and time complexity analysis

I am trying to work my way through some computer science training and I am not able to properly understand the following pseudo code: ...
• 83
102 views

### Find the intersection point between two sorted arrays with unknown lengths in lesser than O(n)

Two sorted arrays of positive integers, X[] and Y[] are given.But, the array sizes are unknown to us. We may assume that accessing any index beyond the last element of the array returns -1. The ...
1 vote
1k views

### Convention of a += operator in pseudocode

I have to write some algorithm in pseudocode for a paper. For this I have the "$\leftarrow$" to assign a value. $x \leftarrow y^2$ now I want to write a method which adds to the variable. In ...
• 123
51 views

### Minimizing the sum of differences in a pair [duplicate]

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 ...
27 views

### What is the runtime of this pseudocode?

I need help figuring out the runtime of the following pseudocode. I believe it is O(|E| + |V|), but I'm not totally sure... ...
388 views

### pseudocode to split number value to array of numbers

How to write a pseudocode to split a number value to array of numbers? Let's say the number value is 12345. I need to convert it into [1,2,3,4,5].
5k views

This is a pseudocode question in my IGCSE CompSci textbook: Use a CASE statement to display the day of the week if the variable ...
325 views

### 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 ...
• 343
100 views

### 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 ...
20 views

### Run time of pseudo code in big theta notation [duplicate]

I am looking for the run time of the following pseudo code. ...
• 115
296 views

### Tracing BST Pseudocode for Insertion

I'm having real trouble tracing some pseudocode for insetion into a Binary Search Tree. I need to understand this in order to be able to teach it, but I think there are flaws in the material. For ...
1 vote
249 views

### QuickSort of linked lists optimised for duplicates

This is an past year question for a school exam that I do not suggested solutions for. Problem Description Quick Sort is not stable because of need to swap values in array when partition is done. If ...
1 vote
939 views

### dynamic pseudo-code for simplified coin changing algorithm

As a homework exercise our professor presented to us a simplified version of the coin-changing problem in which we do not need to minimize the number of coins used or track the number of possible ...
369 views

### What is the fastest algorithm of generating all possible permutations (within a given set of constraints) of a multidimensional array?

There is D-dimensional array A. The number D and the size Sd of every dimension d=1..D is input from keyboard. There is also 1-dimensional array E of size N. It consists of unique integer numbers 0..N-...
• 11
2k views

### Pseudocode for Userdefined Data Types

In the pseudocode guide for my syllabus, an example of a record data type is given as below: ...
93 views

### Divide and Conquer Algorithm to calculate $a^n$

I am attempting to create an algorithm which given the value of $a \in \mathbb{R}$ and $b \in \mathbb{N}$, calculate $a^n$. So for example, using the Java language pattern, the algorithm will be ...
34 views

### For Loop Range with Smaller Number on Right

Simple question from an algorithm noob... If $i=1$ then the inner loop will include what I believe to be an invalid range. Is this acceptable pseudocode? ...
186 views

### 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....
45 views

### CLRS pseudocode involving both subscripting and property access of a data structure

In Introduction to Algorithms, the stack data structure's enqueue operation has the following pseudocode ...
1 vote
734 views

### 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 ...
1 vote
178 views

### 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: ...
1k views

### Writing pseudocode to be language independent

There exist 5 rules for any pseudocode , one of these rules is : "Keep statements language independent" I don't understand what is this rule is saying. So can someone explain it and then give an ...
• 21
4k views

### 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 ...
1 vote
270 views

### Balance groups based on average, element constraints and size

It's a complex situation, where I want to balance groups of numbers based on the average of these numbers, while keeping the group size unchanged and not breaking elements constraints. Let me explain ...
4k views

### What is the most used way to write for-loop as pseudocode?

for $e\leftarrow1$ to 8 do for $e\in[1,8]$ do for $e\in\{x\in\mathbb{N}|1\le x\le8\}$ do What is more preferred?
1 vote
110 views

### What sort of code is this?

Here is a question I encountered:- Read this section of program code that inputs 10 positive numbers and then outputs the smallest number input. Identify three changes you would need to make to find ...
1 vote
1k views

### Doubt on declaring an array in pseudocode

So here's the code:- DECLARE number as INTEGER PRINT "Enter a number" INPUT number DECLARE randomarray [1:number] AS INTEGER Is this possible? i.e whilst declaring arrays, can we use variables? ...
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 ...