Green University of Bangladesh
Department of Computer Science and Engineering (CSE)
Faculty of Sciences and Engineering
Semester: Spring, Year:2024), B.Sc. in CSE (Day)
Lab Report NO # 01
Course Title: Artificial Intelligence Lab
Course Code: CSE 316 Section: 221_D4
Lab Experiment Name:
1. Write a program that takes an input string of parentheses ()[]{} and
determines whether the expression is balanced or not.
2. Write a program to find the second-highest number in a given set of
numbers.
Student Details
Name ID
1. Nur Hasan Hasib 221902247
Lab Date : 15/01/25
Submission Date : 22/01/25
Course Teacher’s Name : Mahjabin Rahman Oishe
Lab Report Status
Marks: ………………………………… Signature:.....................
Comments:.............................................. Date:..............................
1. TITLE OF THE LAB REPORT EXPERIMENT
1. Write a program that takes an input string of parentheses ()[]{} and determines whether the
expression is balanced or not.
2. Write a program to find the second-highest number in a given set of numbers.
2. OBJECTIVES
To develop efficient algorithms for solving common computational problems, such as
balanced parentheses checking and finding the second-highest number.
To implement stack-based and numerical comparison techniques for handling different
problem scenarios.
To optimize the programs for accuracy, efficiency, and robustness against edge cases.
To ensure user-friendly input handling and clear output messages for better usability.
To validate and test the solutions with various input cases, ensuring correctness and
reliability.
3. PROCEDURE AND IMPLEMENTATION
Problem 01:
1. Input: Read the string containing parentheses.
2. Check Pairs: Repeatedly remove matching pairs (), {}, and [].
3. Loop Until Stable: Continue until no more pairs can be removed.
4. Final Check: If the string is empty, it's balanced; otherwise, it's not.
5. Output Result: Print "balance" if empty, else "not balance".
Problem 02:
1. Initialize List: Define an array of numbers.
2. Sort the List: Arrange numbers in ascending order.
3. Find Second-Highest: Retrieve the second-last element of the sorted list.
4. Output Result: Print the second-highest number.
4. TEST RESULT / OUTPUT
Problem 01:
Problem 02:
5. ANALYSIS AND DISCUSSION
In this lab, these two problems focus on essential computational techniques: string processing and
numerical analysis. The first problem checks for balanced parentheses by repeatedly removing
matching pairs until none remain. While simple, a stack-based approach would be more efficient
for large inputs. The second problem finds the second-highest number by sorting the array and
selecting the second-last element. Though effective, a more optimized approach would track the
highest and second-highest numbers in a single pass (O(n)). Both problems highlight fundamental
problem-solving concepts and the importance of algorithm efficiency.
6. Summary
These problems demonstrate key computational techniques string processing and numerical analysis. The
balanced parentheses checker removes matching pairs iteratively, though a stack-based method is more
efficient. The second-highest number finder sorts the list, but a single-pass approach is optimal. Both
emphasize algorithm efficiency and problem-solving skills.