0% found this document useful (0 votes)
5 views

Data Structures and Algorithm Assignments

The document outlines an algorithm and pseudocode for searching an item in a 2D array using C programming. It describes the steps to initialize the array, iterate through its elements, and check for the item, setting a flag if found. Finally, it provides conditions to print the item's indices or a message indicating that the item was not found.

Uploaded by

kisakye
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)
5 views

Data Structures and Algorithm Assignments

The document outlines an algorithm and pseudocode for searching an item in a 2D array using C programming. It describes the steps to initialize the array, iterate through its elements, and check for the item, setting a flag if found. Finally, it provides conditions to print the item's indices or a message indicating that the item was not found.

Uploaded by

kisakye
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/ 6

An algorithm and pseudocode to

search for an item in a 2D array


using C programming language:

Algorithm:

Ÿ Start

Ÿ Declare a 2D array of size m x n


and an item to be searched.

Ÿ Initialize a flag variable to indicate


whether the item is found or not.

Ÿ Iterate over the rows and columns


of the array.

Ÿ Check if the current element is


equal to the item to be searched.

Ÿ If yes, set the flag variable to true


and
break the loop.

Ÿ Otherwise, continue iterating.

Ÿ After the loop, check the flag


variable.

Ÿ If it is true, print the indices of the


item found.

Ÿ If it is false, print a message


indicating that the item was not
found.

Ÿ Stop.
1. start
2. declare a 2D array of size m x n
and an item to be searched
3. initialize a flag variable to false
4. for i = 0 to m-1 do
5. for j = 0 to n-1 do
6. if arr[i][j] == item then
7. set flag to true
8. print "Item found at
indices (" i ", " j ")"
9. break out of both loops
10. end if
11. end for
12. if flag == true then
13. break
14. end if
15. end for
16. if flag == false then
17. print "Item not found in the
array"
18. end if
19. stop

You might also like