0% found this document useful (0 votes)
67 views2 pages

Smallest Element in An Array

1. The algorithm finds the smallest element in an array by initializing the first element as the accumulator value, comparing each subsequent element to the accumulator, and updating the accumulator if a smaller value is found. 2. It iterates through each element by decrementing a counter with the total number of elements, and increments the memory pointer to the next element for comparison. 3. Once all elements are compared, the final accumulator value is the smallest element in the array.

Uploaded by

mohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views2 pages

Smallest Element in An Array

1. The algorithm finds the smallest element in an array by initializing the first element as the accumulator value, comparing each subsequent element to the accumulator, and updating the accumulator if a smaller value is found. 2. It iterates through each element by decrementing a counter with the total number of elements, and increments the memory pointer to the next element for comparison. 3. Once all elements are compared, the final accumulator value is the smallest element in the array.

Uploaded by

mohan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

SMALLEST ELEMENT IN AN ARRAY

AIM:
To find the smallest element in an array.
ALGORITHM:
1. Place all the elements of an array in the consecutive memory
locations.
2. Fetch the first element from the memory location and load it in the
accumulator.
3. Initialize a counter (register) with the total number of elements in an
array.
4. Decrement the counter by 1.
5. Increment the memory pointer to point to the next element.
6. Compare the accumulator content with the memory content (next
element).
7. If the accumulator content is smaller, then move the memory content
(largest element) to the accumulator. Else continue.
8. Decrement the counter by 1.
9. Repeat steps 5 to 8 until the counter reaches zero
10. Store the result (accumulator content) in the specified memory location.
OBSERVATION:

INPUT OUTPUT
ADDRESS DATA ADDRESS DATA
8100 8105
8101
8102
8103
8104

RESULT: Thus the smallest number in the given array is found out.

38
FLOW CHART:
START


[HL] [8100H]


[B] 04H


[A] [HL]


[HL [HL] + 1

YES IS
[A] < [HL]?

NO


[A] [HL]


[B] [B]-1

IS NO
[B] = 0?

YES

[8105] [A]

STOP

You might also like