0% found this document useful (0 votes)
3 views15 pages

Object-Oriented Programming Array Problems

The document outlines various programming practice problems focused on one-dimensional and two-dimensional arrays, categorized into easy, medium, and advanced levels. Each problem includes specific tasks such as finding maximum and minimum values, calculating sums and averages, rotating arrays, and implementing sorting algorithms. The document serves as a comprehensive guide for students to enhance their skills in object-oriented programming through practical exercises.

Uploaded by

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

Object-Oriented Programming Array Problems

The document outlines various programming practice problems focused on one-dimensional and two-dimensional arrays, categorized into easy, medium, and advanced levels. Each problem includes specific tasks such as finding maximum and minimum values, calculating sums and averages, rotating arrays, and implementing sorting algorithms. The document serves as a comprehensive guide for students to enhance their skills in object-oriented programming through practical exercises.

Uploaded by

abbas.ahmed2036
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Fast National University of computing and Emerging Sciences Peshawar Campus

if
Ka
Object Oriented Programming
Practice Problem

ad One-Dimensional Arrays (1D Arrays)

🔹 Easy (Basic Level)


m
am

1. Find the Maximum and Minimum in an Array

●​ Write a program that reads N numbers into an array and finds the maximum and
minimum values.
uh

2. Sum and Average of Elements

●​ Take N integers in an array and calculate the sum and average of the elements.
M

3. Reverse an Array

●​ Store N integers in an array and print the reverse of the array.

4. Count Even and Odd Numbers

Muhammad Kaif
Teacher Assistant | Proctor
●​ Count how many even and odd numbers exist in the array.

5. Search an Element in an Array

●​ Implement a linear search algorithm to check if a number exists in the array.

6. Copy Elements from One Array to Another

●​ Take an array and copy its elements into a new array.

if
Ka
7. Remove Duplicates from an Array

●​ Remove duplicate elements from an array and print the unique values.

8. Find the Second Largest Number

ad
●​ Write a program to find the second largest number in an array.

9. Count Occurrences of a Number


m
●​ Given an array and a target number, count how many times the number appears.
am

10. Merge Two Sorted Arrays into a Single Sorted Array

●​ Take two sorted arrays and merge them into one sorted array.
uh

Medium Level
M

11. Left Rotate an Array by K Positions

●​ Rotate an array left by K positions.

12. Right Rotate an Array by K Positions

●​ Rotate an array right by K positions.


Muhammad Kaif
Teacher Assistant | Proctor
13. Find the First and Last Occurrence of a Number

●​ Find the first and last occurrence of a given number in an array.

14. Sort an Array Using Selection Sort

●​ Implement Selection Sort to sort an array in ascending order.

15. Find the Intersection of Two Arrays

if
Ka
●​ Given two arrays, find their common elements.

16. Find the Union of Two Arrays

●​ Given two arrays, return an array containing their union (unique elements).

ad
17. Find the Missing Number in a Sequence

●​ Given a range of numbers (e.g., 1 to N), find the missing number.


m
18. Check if an Array is Palindromic
am

●​ Check if the given array reads the same forward and backward.

19. Remove an Element from an Array


uh

●​ Take an array and a target element, remove it from the array, and shift elements.

20. Implement Binary Search on a Sorted Array


M

●​ Search for a number using the binary search algorithm.

🔹 Advanced Level
21. Find the Majority Element
Muhammad Kaif
Teacher Assistant | Proctor
●​ An element is a majority element if it appears more than N/2 times. Find it!

22. Find the Kth Largest Element in an Array

●​ Given an array, find the Kth largest element efficiently.

23. Implement Bubble Sort on an Array

if
●​ Sort an array using the Bubble Sort algorithm.

Ka
24. Implement QuickSort Algorithm

●​ Sort an array using QuickSort.

25. Find the Subarray with the Maximum Sum (Kadane’s Algorithm)

ad
●​ Find the maximum sum subarray using Kadane’s algorithm.

26. Find Pairs with a Given Sum


m
●​ Given an array and a number K, find all pairs whose sum equals K.
am

27. Find the Smallest and Second Smallest Element

●​ Write a program to find the smallest and second smallest element.


uh

28. Rearrange Array in Alternate Positive and Negative Order

●​ Given an array, rearrange it so that positive and negative numbers alternate.


M

29. Find the Longest Consecutive Subsequence

●​ Find the longest sequence of consecutive numbers in an unsorted array.

30. Rearrange Array Such That A[i] Becomes A[A[i]]

●​ Modify an array such that each element at index i becomes arr[arr[i]].


Muhammad Kaif
Teacher Assistant | Proctor
Two-Dimensional Arrays (2D Arrays)

🔹 Easy (Basic Level)


1. Input and Display a 2D Array

if
●​ Take a 2D matrix input from the user and print it in matrix form.

Ka
2. Sum of All Elements in a Matrix

●​ Compute the sum of all elements in a MxN matrix.

ad
3. Find the Largest Element in a Matrix

●​ Find the largest number in a given MxN matrix.


m
4. Print the Diagonal Elements of a Square Matrix
am

●​ Print both primary and secondary diagonals.

5. Transpose of a Matrix

●​ Convert a matrix such that A[i][j] becomes A[j][i].


uh

6. Sum of Each Row in a Matrix


M

●​ Find the sum of each row and print it.

7. Sum of Each Column in a Matrix

●​ Find the sum of each column and print it.

8. Check if a Matrix is Symmetric

Muhammad Kaif
Teacher Assistant | Proctor
●​ A matrix is symmetric if A[i][j] == A[j][i].

9. Convert a Matrix to Its Upper Triangular Form

●​ Convert a square matrix to upper triangular form.

10. Find the Row with the Maximum Sum

if
●​ Identify the row with the largest sum.

Ka
Medium Level

11. Multiply Two Matrices


ad
●​ Implement matrix multiplication of MxN and NxP matrices.
m
12. Check if a Matrix is an Identity Matrix

●​ An identity matrix has 1s on the main diagonal and 0s elsewhere.


am

13. Spiral Print of a Matrix

●​ Print a matrix in spiral order.


uh

14. Sort Each Row of a Matrix

●​ Sort all rows in ascending order.


M

15. Find the Saddle Point in a Matrix

●​ A saddle point is the minimum in its row but maximum in its column.

16. Rotate a Matrix by 90 Degrees

●​ Rotate a matrix clockwise by 90°.


Muhammad Kaif
Teacher Assistant | Proctor
17. Find the Maximum Element in Each Row

●​ Print the largest element in each row.

18. Replace All Zeroes in a Matrix with Ones

●​ If a matrix has zeroes, replace them with ones.

19. Convert a Matrix to Its Lower Triangular Form

if
Ka
●​ Convert a square matrix to lower triangular form.

20. Count the Number of Negative Numbers in a Matrix

●​ Count all negative numbers in a MxN matrix.

ad
🔹Advanced Level
m
21. Find the Determinant of a Matrix
am

●​ Compute the determinant of a NxN matrix.

22. Compute the Inverse of a Matrix


uh

●​ Compute the inverse of a NxN matrix.

23. Check if Two Matrices are Equal


M

●​ Determine if two MxN matrices are identical.

24. Find the Shortest Path in a 2D Grid

●​ Implement BFS or DFS to find the shortest path.

Muhammad Kaif
Teacher Assistant | Proctor
25. Rotate a Matrix by 180 Degrees

●​ Rotate a NxN matrix by 180°.

26. Find the Rank of a Matrix

●​ Compute the rank of a matrix.

if
27. Implement Gaussian Elimination

Ka
●​ Solve linear equations using Gaussian elimination.

28. Find the Trace of a Square Matrix

●​ The trace of a matrix is the sum of its diagonal elements.

ad
29. Find the Sum of Two Matrices

●​ Compute the sum of two MxN matrices.


m
30. Implement the Floyd-Warshall Algorithm for All-Pairs Shortest Path
am

●​ Solve the all-pairs shortest path problem.


uh

One-Dimensional Arrays (1D Arrays)

🔹 Easy (Basic Level)


M

1. Find the Maximum and Minimum in an Array

●​ Write a program that reads N numbers into an array and finds the maximum and
minimum values.

2. Sum and Average of Elements


Muhammad Kaif
Teacher Assistant | Proctor
●​ Take N integers in an array and calculate the sum and average of the elements.

3. Reverse an Array

●​ Store N integers in an array and print the reverse of the array.

4. Count Even and Odd Numbers

if
●​ Count how many even and odd numbers exist in the array.

Ka
5. Search an Element in an Array

●​ Implement a linear search algorithm to check if a number exists in the array.

6. Copy Elements from One Array to Another


ad
●​ Take an array and copy its elements into a new array.
m
7. Remove Duplicates from an Array

●​ Remove duplicate elements from an array and print the unique values.
am

8. Find the Second Largest Number

●​ Write a program to find the second largest number in an array.


uh

9. Count Occurrences of a Number

●​ Given an array and a target number, count how many times the number appears.
M

10. Merge Two Sorted Arrays into a Single Sorted Array

●​ Take two sorted arrays and merge them into one sorted array.

🔹 Medium Level
11. Left Rotate an Array by K Positions
Muhammad Kaif
Teacher Assistant | Proctor
●​ Rotate an array left by K positions.

12. Right Rotate an Array by K Positions

●​ Rotate an array right by K positions.

13. Find the First and Last Occurrence of a Number

if
●​ Find the first and last occurrence of a given number in an array.

Ka
14. Sort an Array Using Selection Sort

●​ Implement Selection Sort to sort an array in ascending order.

15. Find the Intersection of Two Arrays


ad
●​ Given two arrays, find their common elements.
m
16. Find the Union of Two Arrays

●​ Given two arrays, return an array containing their union (unique elements).
am

17. Find the Missing Number in a Sequence

●​ Given a range of numbers (e.g., 1 to N), find the missing number.


uh

18. Check if an Array is Palindromic

●​ Check if the given array reads the same forward and backward.
M

19. Remove an Element from an Array

●​ Take an array and a target element, remove it from the array, and shift elements.

20. Implement Binary Search on a Sorted Array

●​ Search for a number using the binary search algorithm.


Muhammad Kaif
Teacher Assistant | Proctor
🔹 Advanced Level
21. Find the Majority Element

●​ An element is a majority element if it appears more than N/2 times. Find it!

if
22. Find the Kth Largest Element in an Array

Ka
●​ Given an array, find the Kth largest element efficiently.

23. Implement Bubble Sort on an Array

●​ Sort an array using the Bubble Sort algorithm.


ad
24. Implement QuickSort Algorithm
m
●​ Sort an array using QuickSort.

25. Find the Subarray with the Maximum Sum (Kadane’s Algorithm)
am

●​ Find the maximum sum subarray using Kadane’s algorithm.

26. Find Pairs with a Given Sum


uh

●​ Given an array and a number K, find all pairs whose sum equals K.

27. Find the Smallest and Second Smallest Element


M

●​ Write a program to find the smallest and second smallest element.

28. Rearrange Array in Alternate Positive and Negative Order

●​ Given an array, rearrange it so that positive and negative numbers alternate.

29. Find the Longest Consecutive Subsequence


Muhammad Kaif
Teacher Assistant | Proctor
●​ Find the longest sequence of consecutive numbers in an unsorted array.

30. Rearrange Array Such That A[i] Becomes A[A[i]]

●​ Modify an array such that each element at index i becomes arr[arr[i]].

if
2️⃣ Two-Dimensional Arrays (2D Arrays)

🔹 Easy (Basic Level)

Ka
1. Input and Display a 2D Array

ad
●​ Take a 2D matrix input from the user and print it in matrix form.

2. Sum of All Elements in a Matrix


m
●​ Compute the sum of all elements in a MxN matrix.
am

3. Find the Largest Element in a Matrix

●​ Find the largest number in a given MxN matrix.

4. Print the Diagonal Elements of a Square Matrix


uh

●​ Print both primary and secondary diagonals.


M

5. Transpose of a Matrix

●​ Convert a matrix such that A[i][j] becomes A[j][i].

6. Sum of Each Row in a Matrix

●​ Find the sum of each row and print it.

Muhammad Kaif
Teacher Assistant | Proctor
7. Sum of Each Column in a Matrix

●​ Find the sum of each column and print it.

8. Check if a Matrix is Symmetric

●​ A matrix is symmetric if A[i][j] == A[j][i].

if
9. Convert a Matrix to Its Upper Triangular Form

Ka
●​ Convert a square matrix to upper triangular form.

10. Find the Row with the Maximum Sum

●​ Identify the row with the largest sum.

ad
🔹 Medium Level
m
11. Multiply Two Matrices
am

●​ Implement matrix multiplication of MxN and NxP matrices.

12. Check if a Matrix is an Identity Matrix


uh

●​ An identity matrix has 1s on the main diagonal and 0s elsewhere.

13. Spiral Print of a Matrix


M

●​ Print a matrix in spiral order.

14. Sort Each Row of a Matrix

●​ Sort all rows in ascending order.

15. Find the Saddle Point in a Matrix


Muhammad Kaif
Teacher Assistant | Proctor
●​ A saddle point is the minimum in its row but maximum in its column.

16. Rotate a Matrix by 90 Degrees

●​ Rotate a matrix clockwise by 90°.

17. Find the Maximum Element in Each Row

●​ Print the largest element in each row.

if
Ka
18. Replace All Zeroes in a Matrix with Ones

●​ If a matrix has zeroes, replace them with ones.

19. Convert a Matrix to Its Lower Triangular Form

ad
●​ Convert a square matrix to lower triangular form.

20. Count the Number of Negative Numbers in a Matrix


m
●​ Count all negative numbers in a MxN matrix.
am

🔹 Advanced Level
uh

21. Find the Determinant of a Matrix

●​ Compute the determinant of a NxN matrix.


M

22. Compute the Inverse of a Matrix

●​ Compute the inverse of a NxN matrix.

23. Check if Two Matrices are Equal

Muhammad Kaif
Teacher Assistant | Proctor
●​ Determine if two MxN matrices are identical.

24. Find the Shortest Path in a 2D Grid

●​ Implement BFS or DFS to find the shortest path.

25. Rotate a Matrix by 180 Degrees

if
●​ Rotate a NxN matrix by 180°.

Ka
26. Find the Rank of a Matrix

●​ Compute the rank of a matrix.

27. Implement Gaussian Elimination


ad
●​ Solve linear equations using Gaussian elimination.
m
28. Find the Trace of a Square Matrix

●​ The trace of a matrix is the sum of its diagonal elements.


am

29. Find the Sum of Two Matrices

●​ Compute the sum of two MxN matrices.


uh

30. Implement the Floyd-Warshall Algorithm for All-Pairs Shortest Path

●​ Solve the all-pairs shortest path problem.


M

Muhammad Kaif
Teacher Assistant | Proctor

You might also like