Algorithm to find smallest element

  • Thread starter Thread starter Bucs44
  • Start date Start date
  • Tags Tags
    Algorithm Element
Click For Summary

Homework Help Overview

The discussion revolves around creating an algorithm to find the smallest element among three variables, a, b, and c. Participants are examining the structure and correctness of the proposed algorithm.

Discussion Character

  • Exploratory, Conceptual clarification, Problem interpretation

Approaches and Questions Raised

  • The original poster attempts to define an algorithm but questions whether their wording constitutes a valid algorithm. Other participants raise concerns about the algorithm's logic and initialization of variables.

Discussion Status

Participants are actively discussing the clarity and correctness of the algorithm. Some have provided feedback on the structure, while others are questioning the assumptions made in the problem statement and the algorithm's setup.

Contextual Notes

There is a noted ambiguity regarding the initialization of the variables a, b, and c, as well as the transition from problem statement to algorithm. Participants are considering how punctuation might clarify this distinction.

Bucs44
Messages
57
Reaction score
0
I'm working on an algorithm that finds the smallest element among a, b, and c.

Here is what I have so far:

Input: a,b,c
Output: small; smallest element in the sequence a,b,c
a = 2, b = 4, c = 3
Small = a
If b < small, then small = b
If c < small, then small = c

Is this right?
 
Physics news on Phys.org
How could it be wrong?
 
I'm just wondering if I worded it correct and it constitutes as an algorithm?
 
It's perfect.
 
Well, except for one thing: According to the algorithm, it gets a, b, c as input and then immediately sets a= 2, b= 4, c= 3. No matter what a, b, c are, this algorithm outputs 2!
 
Depends on where you think the problem statement ends and the algorithm starts. Maybe we need a new punctuation symbol here.
 
I actually added the a = 2, b = 4, c = 3 portion as I thought that was what was needed in order to perform the algorithm
 

Similar threads

  • · Replies 4 ·
Replies
4
Views
1K
Replies
1
Views
2K
Replies
3
Views
2K
  • · Replies 17 ·
Replies
17
Views
2K
Replies
4
Views
1K
Replies
2
Views
2K
Replies
3
Views
1K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
9
Views
3K