Uploaded by belikesayantan12

DSA Major 1

advertisement
Institute of Technical Education and Research
Data Structures and Algorithms
Major Assignment-1
This assignment is to test your knowledge in Array.
******************************************************************************
Problem Statement:
Given a 9*9 board filled with random numbers between -5 to 100. In one try user
randomly choose the row and column number. User need to find in how many tries he/she finds
a negative number in the board.
Description:
User need to create a 9*9 2-D array and store random numbers between -5 to 100 in
each different cells and display the 2-D array. Then in every try he/she need to choose two
random numbers (p,q) between 0 to 9, and check if the specific location contains a negative
number or not. If it is not a negative number, the process should be continued until a -ve number
found. In this process user need to display in how many tries he/she finds a negative number in
the board. Again user should also find the maximum value generated through out all tries.
In the second part of the assignment, user need to store elements found in the board for
all different tries, in a separate 1-D array (choose an array of large size) and find number of
distinct elements generated through out all different tries made above.
In the third part of the assignment, user need to check if the generated array is in
sorted (ascending) order or not.
Points Distribution:
• [3 Points] Creating a 9*9 board.
• [1 Points] Display the board.
• [4 Points] To find in how many tries he/she finds a negative number in the board and
find the maximum value generated through out all tries.
• [1 Points] Creating 1-D array
• [3 Points] To find number of distinct elements generated through out all different tries.
• [3 Points] To check if array is sorted or not.
(More over you can update in the java file provided to you, MajorAssignment_1.java)
Sample Output:
Board
95
70
23
54
36
8
54
98
0
(3,7)
(6,8)
(3,5)
(3,4)
(6,7)
(5,0)
(5,6)
(1,4)
(5,0)
(2,3)
(5,7)
(8,4)
(5,8)
(7,6)
(6,6)
(0,6)
(2,6)
(1,7)
(5,6)
(7,8)
(7,2)
(7,4)
(2,6)
(8,2)
is:
53
12
86
54
3
4
68
31
11
54
-4
45
48
14
66
68
21
-1
location
location
location
location
location
location
location
location
location
location
location
location
location
location
location
location
location
location
location
location
location
location
location
location
1
46
43
91
42
78
44
51
78
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
choosen
85
36
87
20
76
75
8
59
52
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
and
57
-3
47
44
11
93
74
86
62
number
number
number
number
number
number
number
number
number
number
number
number
number
number
number
number
number
number
number
number
number
number
number
number
66
90
57
97
3
89
61
6
13
is 94
is 26
is 44
is 20
is 55
is 8
is 89
is 36
is 8
is 43
is 23
is 52
is 41
is 6
is 61
is 66
is 57
is 95
is 89
is 11
is 68
is 59
is 57
is -1
70
95
6
94
49
23
55
34
53
37
30
62
69
62
41
26
11
70
In 24 try a negative number found.
And maximum value generated in this process is 95
Created array is:
94 26 44 20 55 8 89 36 8 43 23 52 41 6 61 66 57 95 89 11 68 59 57 -1
No. of unique elements in created array x[] is 20
Array is not sorted
Related documents
Download