pseudocode

Pseudo code example [closed]

我与影子孤独终老i 提交于 2019-12-13 11:29:47
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago . I am new to programming in general and I am trying to learn the basics of it. Could someone explain me the concept of Pseudo code. I have already done some research but an additional help would be great. As an example, what would pseudo code for making a peanut butter and jelly

Pseudo code to check if binary tree is a binary search tree - not sure about the recursion

浪子不回头ぞ 提交于 2019-12-13 04:38:51
问题 I have homeowork to write pseudo code to check if a valid binary tree is a search binary tree. I created an array to hold the in-order values of the tree. if the in-order values are in decreasing order it means it is indeed BST. However I've got some problem with the recursion in the method InOverArr. I need to update the index of the array in order to submit the values to the array in the order they are at the tree. I'm not sure the index is really updated properly during the recursion.. is

Having an array of points that form a circle how to randomize one coordinate?

一曲冷凌霜 提交于 2019-12-13 03:43:49
问题 We have an array or points (double's X, Y, Z) they form a circle, starting from default rotation angles Xa, Ya, Za. We want to extend each point in our circle by one axes (say Z) on some random variable. How to do such thing in pseudocode? 回答1: Do you mean something like this (pseudocode): void randomize(Point[] points, Axis axis, double scale) { RandomNumberGenerator rng = new RandomNumberGenerator(); for (Point point : points) { point[axis] += scale * rng.nextRandom(); } } If you need to

Knapsack - save time and memory

老子叫甜甜 提交于 2019-12-12 23:05:30
问题 According to Wikipedia and other sources I had went through, you need matrix m[n][W] ; n - number of items and W - total capacity of knapsack. This matrix get really big, sometimes too big to handle it in C program. I know that dynamic programming is based on saving time for memory but still, is there any solution where can you save time and memory? Pseudo-code for Knapsack problem: // Input: // Values (stored in array v) // Weights (stored in array w) // Number of distinct items (n) //

MIPS Pseudo istructions, replacements

本秂侑毒 提交于 2019-12-12 21:12:26
问题 After making research what is it, I found out that it is simply replacment of way of getting same result. Correct me please if I'm wrong. example: move $s0, $t1 can be replaced with: add $s0, $zero, $t1 Questions: How can be replaced lw , la , sw , bne ? 回答1: Yes, the move instruction can and is replaced with an add instruction. Some background on pseudo instructions: MIPS is a RISC (Reduced Instruction Set Computer) architecture, meaning there is a relatively small number of instructions

Write pseudocode of a program that prints such a pattern

淺唱寂寞╮ 提交于 2019-12-12 19:56:28
问题 Analyze output pattern and write algorithm of a program that prints such a pattern. Input 4 Pattern: 55555 4444 333 22 1 Input 3 Pattern: 333 22 1 Process (what I have come up with) n = input (“Enter a positive integer”) r= 0 while r < n c = (n – r) + 1 while c > 0 s = n – r print s c = c – 1 end r = r + 1 n = n – 1 print end l end Problem: I have used r for rows, and c for columns. The problem rises in c = (n – r) + 1 for first row. It makes the first row n+1, works for following rows. On

Simple algorithm (pseudo-code) for line segment intersection

随声附和 提交于 2019-12-12 19:53:47
问题 I am trying to solve this question, but I am stuck on how to make this work. I will post the question, and then explain where I am in it. Given a set of horizontal line segments and vertical lines of total size n, we want to compute the number of horizontal segments intersected by each vertical line. The algorithm should be of complexity O(n*logn), and should be achieved by sorting, following by a linear scan. A horizontal segment is specified by two x-coordinates and a y-coordinate, while a

How to initialise a 2D array in Python?

孤人 提交于 2019-12-12 11:09:59
问题 I've been given the pseudo-code: for i= 1 to 3 for j = 1 to 3 board [i] [j] = 0 next j next i How would I create this in python? (The idea is to create a 3 by 3 array with all of the elements set to 0 using a for loop). 回答1: If you really want to use for -loops: >>> board = [] >>> for i in range(3): ... board.append([]) ... for j in range(3): ... board[i].append(0) ... >>> board [[0, 0, 0], [0, 0, 0], [0, 0, 0]] But Python makes this easier for you: >>> board = [[0]*3 for _ in range(3)] >>>

Potential for Race Conditions in Reader/Writer Pseudocode

微笑、不失礼 提交于 2019-12-12 05:25:33
问题 I'm analysing the following pseudocode for race conditions (a bit of self practise) and looking at where the possibilities are. The pseudocode describes a vague asynchronous reader/writer. Writer Thread r = 0; w = 1; l = 2; //assign start slot numbers while(1) { write_slot(w); l = w; //last written slot is w w = not(r,l) //assigns next slot so that w is neither r or l } Reader Thread while(1) { r = l; //read from latest write read(r); } The possibilities of corruption/race conditions I've

Generate all permutations of several lists in Java

▼魔方 西西 提交于 2019-12-12 01:49:06
问题 I have n lists, for example: L_1 = [a_11, a_12, ...] L_2 = [a_21, a_22, ...] ... L_n = [a_n1, a_n2, ...] where i th list has k_i elements. And now, I want to generate all n -elements list, where i th element is from L_i , I mean: [a_11, a_21, ..., a_n1] [a_11, a_21, ..., a_n2] ... [a_11, a_22, ..., a_n1] [a_11, a_22, ..., a_n2] ... [a_12, a_21, ..., a_n1] [a_12, a_21, ..., a_n2] ... [a_12, a_22, ..., a_n1] [a_12, a_22, ..., a_n2] ... The total number of lists shoulbe be equal to k_1*k_2*...k