Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  A function f defined on stacks of integers sa... Start Learning for Free
A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i. 
If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?
  • a)
    6
  • b)
    4
  • c)
    3
  • d)
    2
Correct answer is option 'C'. Can you explain this answer?
Verified Answer
A function f defined on stacks of integers satisfies the following pro...
i Element to be pushed
Initial State f(φ) = 0 For Empty Stack F(S) is 0.
Then we push each element ( )one by one and calculate f(s)for each insertion as given
Is the function to compute F(s) for each insertions
1. INSERT 2 into Stack
Similarly ,
The value of F(s) after inserting all elements into stack is 3 
View all questions of this test
Most Upvoted Answer
A function f defined on stacks of integers satisfies the following pro...
Solution:

Given, f() = 0 and f(push(S, i)) = max(f(S), 0) + i for all stacks S and integers i.

Let's calculate f(S) for the given stack S containing the integers 2, -3, 2, -1, 2 in order from bottom to top.

1. Pushing 2 onto the empty stack:
f(push({}, 2)) = max(f({}), 0) + 2
= max(0, 0) + 2
= 2

2. Pushing -3 onto the stack:
f(push({2}, -3)) = max(f({2}), 0) - 3
= max(2, 0) - 3
= -1

3. Pushing 2 onto the stack:
f(push({2, -3}, 2)) = max(f({2, -3}), 0) + 2
= max(2, 0) + 2
= 4

4. Pushing -1 onto the stack:
f(push({2, -3, 2}, -1)) = max(f({2, -3, 2}), 0) - 1
= max(4, 0) - 1
= 3

5. Pushing 2 onto the stack:
f(push({2, -3, 2, -1}, 2)) = max(f({2, -3, 2, -1}), 0) + 2
= max(3, 0) + 2
= 5

Therefore, f(S) = 3 for the given stack S containing the integers 2, -3, 2, -1, 2 in order from bottom to top.

Hence, the correct answer is option (c) 3.
Explore Courses for Computer Science Engineering (CSE) exam

Similar Computer Science Engineering (CSE) Doubts

Top Courses for Computer Science Engineering (CSE)

A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i.If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?a)6b)4c)3d)2Correct answer is option 'C'. Can you explain this answer?
Question Description
A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i.If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?a)6b)4c)3d)2Correct answer is option 'C'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i.If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?a)6b)4c)3d)2Correct answer is option 'C'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i.If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?a)6b)4c)3d)2Correct answer is option 'C'. Can you explain this answer?.
Solutions for A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i.If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?a)6b)4c)3d)2Correct answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i.If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?a)6b)4c)3d)2Correct answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i.If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?a)6b)4c)3d)2Correct answer is option 'C'. Can you explain this answer?, a detailed solution for A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i.If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?a)6b)4c)3d)2Correct answer is option 'C'. Can you explain this answer? has been provided alongside types of A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i.If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?a)6b)4c)3d)2Correct answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice A function f defined on stacks of integers satisfies the following properties. f(∅) = 0 and f (push (S, i)) = max (f(S), 0) + i for all stacks S and integers i.If a stack S contains the integers 2, -3, 2, -1, 2 in order from bottom to top, what is f(S)?a)6b)4c)3d)2Correct answer is option 'C'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev