Book Image

Learning F# Functional Data Structures and Algorithms

By : Adnan Masood
Book Image

Learning F# Functional Data Structures and Algorithms

By: Adnan Masood

Overview of this book

Table of Contents (21 chapters)
Learning F# Functional Data Structures and Algorithms
Credits
Foreword
Foreword
Foreword
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Algorithm – parenthesis matching using stacks


In computer science, stack data structure serves a variety of uses, from operating system function pointer management to compiler construction. We will try to be less ambitious and use the stack to solve the parenthesis matching problem. Instead of using the stack data structure explicitly, we will implicitly use stack operations to show you how to use the stack constructs within the algorithm.

A typical arithmetic expression is usually written as follows:

Here, the parentheses are being used to provide the order in which the operators will be applied in the statement. Also, in various programming languages, we use different types of brackets to represent scope and an incomplete set of brackets will raise a compiler warning.

For the languages which use them, balancing the sets of opening and closing parenthesis is crucial to manage the scope of variables and methods, as well as explaining the execution context for statements and functions. A matching...