Questions tagged [pseudocode]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
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: ...
user avatar
0 votes
1 answer
37 views

A* pseudocode problem

What is the difference between this two pseudocode and which one should i implement? ...
user avatar
1 vote
0 answers
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 ...
user avatar
-1 votes
3 answers
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 ...
user avatar
  • 11
0 votes
1 answer
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? ...
user avatar
2 votes
2 answers
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 ...
user avatar
0 votes
1 answer
78 views

I'm studying a trie tree, where I want to delete a word, Please make me understand the algorithm

...
user avatar
0 votes
0 answers
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 ...
user avatar
  • 1
0 votes
2 answers
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: ...
user avatar
2 votes
1 answer
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 ...
user avatar
0 votes
0 answers
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 ...
user avatar
  • 101
1 vote
1 answer
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: ...
user avatar
  • 11
0 votes
1 answer
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 ...
user avatar
2 votes
1 answer
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$ ...
user avatar
0 votes
2 answers
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-...
user avatar
  • 25
1 vote
1 answer
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: ...
user avatar
  • 133
1 vote
0 answers
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 ...
user avatar
  • 11
2 votes
1 answer
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-...
user avatar
0 votes
0 answers
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 ...
user avatar
  • 211
0 votes
2 answers
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. ...
user avatar
0 votes
2 answers
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 ...
user avatar
0 votes
1 answer
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: ...
user avatar
  • 83
0 votes
1 answer
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 ...
user avatar
1 vote
1 answer
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 ...
user avatar
  • 123
3 votes
0 answers
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 ...
user avatar
0 votes
0 answers
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... ...
user avatar
0 votes
1 answer
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].
user avatar
0 votes
2 answers
5k views

Please check my answer to a pseudocode CASE statement question

This is a pseudocode question in my IGCSE CompSci textbook: Use a CASE statement to display the day of the week if the variable ...
user avatar
2 votes
1 answer
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 ...
user avatar
  • 343
2 votes
0 answers
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 ...
user avatar
0 votes
0 answers
20 views

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

I am looking for the run time of the following pseudo code. ...
user avatar
  • 115
0 votes
0 answers
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 ...
user avatar
1 vote
1 answer
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 ...
user avatar
1 vote
1 answer
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 ...
user avatar
0 votes
1 answer
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-...
user avatar
  • 11
0 votes
0 answers
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: ...
user avatar
0 votes
1 answer
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 ...
user avatar
0 votes
1 answer
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? ...
user avatar
2 votes
1 answer
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....
user avatar
0 votes
1 answer
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 ...
user avatar
1 vote
1 answer
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 ...
user avatar
1 vote
1 answer
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: ...
user avatar
-2 votes
2 answers
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 ...
user avatar
  • 21
14 votes
2 answers
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 ...
user avatar
1 vote
1 answer
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 ...
user avatar
0 votes
3 answers
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?
user avatar
1 vote
1 answer
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 ...
user avatar
1 vote
1 answer
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? ...
user avatar
2 votes
1 answer
38 views

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 ...
user avatar
  • 141
-1 votes
1 answer
414 views

How does this algorithm expressed in pseudo-code work?

On a website it gives you questions and answers for computer science, yet does not explain the answer. I was hoping if someone could explain the pseudo-code (answer) for me, as I do not understand it. ...
user avatar
  • 1