algorithms

How and which algorithms I can use to meet this requirements as I am a self leaner I need a help to write a pseudocode for it. thanks

Devise your own setting for storing and searching the data in an array of non-negative integers redundantly. You may just describe the setting without having to give an explicit algorithm to explain the process by which data is stored. You should explain how hardware failures can be detected in your method. Once you have described the setting, complete the
following:
1. Write a pseudocode function to describe an algorithm where the stored data can be searched for a value key: if the data is found, its location in the original array should be returned; -1 should be returned if the data is not found; -2 should be returned if there is a data storage error.

I have tried this pseudocode: where and when data storage get errors and return -2?

A = [], N = length of A , x = number, key
1
2
3
4
5
6
function linearSearch(A, N, x)
    for 0 <= i < N 
        if (A[i] == x)
            return True
    return -1
end function 

Last edited on
explain how hardware failures can be detected

What kind of "hardware failures" are you expecting? I have a feeling this may have been translated from another language. Maybe "hardware failure" just means overflowing the array?

As for searching algorithms, you can either store unordered data and do a linear search, or store ordered data and do a binary search.
@dutch
thanks. I dont know "hardware failure". I have edited my question and i wrote the pseudocode for it. I am not sure that this pseudocode meet the requirements. could you please check it for me ? thanks
Last edited on
-2 should be returned if there is a data storage error.
how is this requirement met, that is what they are asking and its not in your pseudocode.
@jonnin
thanks. How do i fix it ?
it is unclear.
I mean in pseudo code its just
1
2
3
4
5
6
7
8
function linearSearch(A, N, x)
    for 0 <= i < N 
        if (A[i] == x)
            return i; //fixed this too
        if(hardware_error()) 
           return -2;
    return -1
end function 
@jonnin
thank you very much
Topic archived. No new replies allowed.