0% found this document useful (0 votes)
2 views1 page

DSA1 Tutorial: Algorithm Design Exercises

The document outlines a tutorial for Data Structure & Algorithms 1, focusing on algorithm design and problem-solving through three programming exercises. Each exercise requires analyzing a problem, planning an algorithm, and validating it with test data, including calculating the cost of a TV, determining salary increases, and computing airline revenue. The tutorial aims to enhance students' skills in algorithmic thinking and validation techniques.

Uploaded by

maria-ines.raheb
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)
2 views1 page

DSA1 Tutorial: Algorithm Design Exercises

The document outlines a tutorial for Data Structure & Algorithms 1, focusing on algorithm design and problem-solving through three programming exercises. Each exercise requires analyzing a problem, planning an algorithm, and validating it with test data, including calculating the cost of a TV, determining salary increases, and computing airline revenue. The tutorial aims to enhance students' skills in algorithmic thinking and validation techniques.

Uploaded by

maria-ines.raheb
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

Data Structure & Algorithms 1 (DSA1)

Tutorial 1 - Algorithmic and Problem Solving


2024 - 2025

02 October 2024

Objectives
In this tutorial, you will practice algorithm design and validation by solving the following programming
exercises. Each exercise requires you to analyze a specific problem, plan an algorithm, and validate it with
test data.

Exercise 1
A TV manufacturer is in need of a program that calculates and displays the cost of a 4K Ultra HD TV
currently on sale at one of their local stores. The program should determine the cost by multiplying the sale
price by the state sales tax rate and then adding the result to the sale price.
Tasks:
1. Analyze the TV manufacturer’s problem and define the input and output.
2. Plan an algorithm to solve the specified problem (use concise English statements).
3. Represent the proposed algorithm with a flowchart.
4. Validate the algorithm with your own data sets.

Exercise 2
An employee anticipates a specific percentage increase in her/his salary for the next year. She/He want a
program to calculate and display her/his raise and new salary amounts.
Tasks:
1. After analyzing this problem, create the corresponding algorithm.
2. Verify the algorithm’s correctness using a set of test data.

Exercise 3
An airplane offers both first-class and coach seats, with first-class tickets priced higher than coach tickets.
The airline requires a program to compute and present the total revenue generated from a particular flight.
Tasks:
1. Develop the airline’s algorithm for calculating total revenue.
2. Test the algorithm’s accuracy using appropriate data.
∗ This document is copyrighted © 2023 by [Dr. Noureddine Lasla and Dr. Fouzia Anguel]. All rights reserved.

Common questions

Powered by AI

To validate an algorithm for calculating a TV's cost using a flowchart, represent the algorithm steps in a visual format, showing the logical flow from input to output. Test various scenarios with different sale prices and tax rates using the flowchart to ensure all paths lead to correct computations, which can also be tested against manual calculations .

To define the input for calculating the cost of a 4K Ultra HD TV with state sales tax, you need the sale price of the TV and the state sales tax rate as inputs. The output should be the total cost, which is calculated by multiplying the sale price by the state sales tax rate and adding the result to the sale price .

The steps in the algorithm for calculating an anticipated salary increase would include: 1) Input the current salary and anticipated increase percentage. 2) Calculate the salary raise by multiplying the current salary by the increase percentage. 3) Compute the new salary by adding the raise to the current salary. 4) Output the raise and the new salary amounts .

The process includes: 1) Begin with identifying the input variables: sale price and tax rate. 2) Establish a computational step to multiply the sale price by the tax rate. 3) Add the result to the initial sale price to get the total cost. 4) End by defining output as the total cost. This structured approach ensures all components are considered for accurate calculations .

To test the accuracy of an algorithm for calculating total flight revenue, you can use a set of test data that includes various combinations of first-class and coach ticket sales. Calculate expected revenues manually or using simple arithmetic checks, then compare those results with the outputs generated by the algorithm to ensure consistency and correctness .

Using test data is critical for verifying an algorithm’s correctness because it provides a way to predict the outcome and compare it against expected results. This process helps uncover mistakes in the logic like incorrect percentage calculations or mishandled arithmetic operations, ensuring the algorithm works as intended under various real-world scenarios .

Flowcharts assist in the validation of an algorithm by providing a visual representation of the process, thus making it easier to trace the logic and identify potential errors. When calculating flight revenue, a flowchart can help ensure that each step from input (ticket sales) to output (total revenue) functions correctly under different scenarios, reinforcing logical integrity and facilitating debug processes .

Planning an algorithm using concise English statements is crucial as it helps clarify the logical steps required to solve a problem, ensuring nothing is overlooked. It also facilitates communication of the algorithm's logic to others, potentially uncovering flaws in reasoning before implementation. This approach reduces complexity by breaking down the problem into understandable segments, ensuring a more robust transition to coding .

Design a flowchart by first including elements that represent starting and ending points. Use process boxes for calculations such as multiplying the current salary by the raise percentage and adding this to the original salary. Decision boxes can handle branching paths if conditions apply, like cap limits on raises. Flow lines ensure the correct sequence and logical progression, ultimately leading to output boxes presenting the salary and raise .

Challenges could include accurately accounting for diverse ticket categories with distinct pricing and variable input sizes depending on flight occupancy. Address these by designing flexible input parsing that can handle different classes uniformly and ensure that logic accounts for the differential pricing. Implement rigorous error handling to manage potential anomalies like missing data .

You might also like