0% found this document useful (0 votes)
8 views2 pages

Lab 07

The lab focuses on enhancing students' understanding of stacks through two tasks: removing k digits from a number to achieve the smallest possible result and evaluating a boolean expression. Each task is worth 15 marks and must be solved efficiently without using built-in stack libraries, adhering to O(n) time complexity. Students are required to work individually and avoid any collaboration or plagiarism.

Uploaded by

mz8640073
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)
8 views2 pages

Lab 07

The lab focuses on enhancing students' understanding of stacks through two tasks: removing k digits from a number to achieve the smallest possible result and evaluating a boolean expression. Each task is worth 15 marks and must be solved efficiently without using built-in stack libraries, adhering to O(n) time complexity. Students are required to work individually and avoid any collaboration or plagiarism.

Uploaded by

mz8640073
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
You are on page 1/ 2

Data Structures and Algorithms Lab

CS‐F23
LAB‐07 Issue Date: March 17, 2025
Start Time: 11:45 AM
Total Marks: 30 Submission Time: 12:45 AM

The objective of this lab is to:


This lab aims to enhance students' understanding of stacks and their applications in solving real-world
problems efficiently.
Instructions:
1) Use stacks to solve both tasks efficiently.
2) Do not use built-in stack libraries
3) Ensure correctness by testing with multiple input cases.
4) Implement each function efficiently to minimize time and space complexity.
Task 01(Remove K Digits to Get the Smallest Number) 15 Marks

Given a non-negative integer represented as a string num, and an integer k, remove k digits from the number so
that the resulting number is the smallest possible.

If the resulting number is empty, return "0.

Example:

Input: "1432219", k = 3

Process:

 Remove 4 → "132219"
 Remove 3 → "12219"
 Remove 2 → "1219"

Output: "1219"

Constraints : Solve the problem O(n) time complexity

Function Prototype: string removeKdigits(string num, int k)

Task 02 (Evaluate Boolean Expression) 15 Marks

You are given a valid boolean expression as a string. The expression follows these rules:

1. 't' → Represents true.


2. 'f' → Represents false.
3. '!(subExpr)' → Represents logical NOT of subExpr.
4. '&(subExpr1, subExpr2, ..., subExprn)' → Represents logical AND of n subexpressions (n ≥ 1).
5. '|(subExpr1, subExpr2, ..., subExprn)' → Represents logical OR of n subexpressions (n ≥ 1).

Return the boolean result (true or false) after evaluating the expression.

Example:
Input: expression = "&(t, !(f), t)"

Output: true

Explanation:

 !(f) → true
 &(t, true, t) → AND of (true, true, true) → true

Constraints : Solve the problem O(n) time complexity

Function Prototype: bool evaluateBooleanExpression(string expression);

Good Luck!

------------------------------------------------------

Note: You must complete all your tasks individually. Absolutely NO collaboration is allowed. Any case of
plagiarism/cheating would result in 0 marks in sessional activities.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy