Skip to content

Instantly share code, notes, and snippets.

View raviteja1452's full-sized avatar

Raviteja Bejgum raviteja1452

View GitHub Profile
@raviteja1452
raviteja1452 / largest_area_under_a_histogram_using_stack.cpp
Created April 3, 2017 07:30
Stack/ Largest Area under a Histogram Problem (using stacks).
// Finding the Largest Area Under a Histogram using Stacks
// p9Scripts
/*
Question:
1) Find the Largest Area Under a Histogram. Each bar of Histogram is considered of width 1.
Algorithm:
Here we use stack for finding Largest Area under a Histogram.
1) Assumptions: Each bar of Histogram is of width 1 unit.
MaxArea = -1 ;
@raviteja1452
raviteja1452 / spans_problem_using_stack.cpp
Created April 3, 2017 07:14
Stack/ Stock Span Problem (using stack)
// Finding the stocks span problems using Stack
// p9Scripts
/*
Question: Find the spans for the given set of values in a list.
Span = count of elements just previous to the element and less than the element's value (consecutive).
Algorithm:
Stacks can be used to solve this problem in a Time complexity of o(n).
@raviteja1452
raviteja1452 / implementation_of_stack_using_queues.cpp
Created April 3, 2017 05:19
Stack/ Implementation of Stack using Queues.
// Implementing a Stack using 2 Queues
// p9Scripts.
/*
Here we use standard c++ stl library.
We use queue stl and Implement a stack using the queues.
*/
/*
Question: Implementation of Stack using Queues
Algorithm:
Let q1 and q2 be two queues.
@raviteja1452
raviteja1452 / implementation_of_queue_using_stacks.cpp
Created April 3, 2017 05:08
Stack/ Implementation of Queue using Two Stacks.
// Implementing a Queue using two Stacks.
// p9Scripts
/*
Q: Implementation of Queue using stacks.
Here we use stack c++ stl to build a queue
Operations that we design for a queue:
Stacks s1 and s2
Enqueue:
@raviteja1452
raviteja1452 / reversing_elements_of_stack_using_stack.cpp
Created April 3, 2017 05:01
Stack/ Reversing elements of Stack (using Recursion).
// Reversing the elements of stack using Recursion
//p9scripts
/*
Q: Reverse the elements of stack using Recursion.
Algorithm:
Given a stack of n elements, we need to reverse the elements of stack.
Here we have two functions.
1) ReverseFunction :
@raviteja1452
raviteja1452 / infix_evaluation_using_two_stacks.cpp
Created April 3, 2017 04:43
Stack/ Evaluating an Infix Expression using two Stacks (Operand and Operator Stacks).
// Evaluation of Infix Expression using Two Stacks
// p9Scripts
/*
Q: Evalution of Infix Expression using Two Stacks.
Algo: Here we have two stacks.
1) Operator Stack
2) Operand Stack.
@raviteja1452
raviteja1452 / postfix_evaluation_using_stacks.cpp
Created April 3, 2017 04:33
Stack/ Evaluating a Postfix Expression (using stacks).
// Evaluation of a Postfix Expression using Stack
// p9Scripts
/*
Q:Evaluation of a Postfix Expressoin using Stack
Algorithm:
We process the Postfix String from List
We use a Stack Stl (Operand Stack) for our Algorithm
If the present character is operand , push to stack.
If the present character is operator, pop top two elements of stack. perform opeartion between them and push to stack.
@raviteja1452
raviteja1452 / infix_to_postfix_coversion_using_stacks.cpp
Created April 3, 2017 04:28
Stack/ Converting an Infix Expression to Postfix Expression (using stacks).
// Conversion from an Infix Expression to Postfix Expression using stacks
// p9Scripts
/*
Q) Convert an Infix Expression to Post Expression using Stack.
Algorithm:
1) We use Stack stl for our purpose.
2) Process the Infix Expression from left to right.
3) For each character in string:
If its an operand, output it and move to next.
@raviteja1452
raviteja1452 / balancing_symbols_using_stacks.cpp
Created April 3, 2017 03:58
Stack/ Checking If the string of symbols is balanced or not (Using Stack).
// Balancing Symbols ---Braces like [],(),{}--- using Stacks
// p9scripts
/*
Q: Find out whether a given string of symbols is balanced or not ?
Algorithm:
We use C++ stack stl.
Move from left to right of the string.
1) Push into stack if you encounter any opening brace [ , { , (
2) When you encounter a closing brace, compare it with the top of stack.
If its matching with its counter opening brace. continue to next by popping the stack.
@raviteja1452
raviteja1452 / stack_using_linkedlists.cpp
Last active September 6, 2022 12:34
Stack/ Stack Using Linkedlists.
// Stack Using a Linkedlists
// p9Scripts
// Implementaion of Stack using a Linkedlists
#include<iostream>
using namespace std;