reverse polish notation, operations with big numbers ivelin rachev telerik corporation...

19
Equation solving, Big numbers Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy .com “Baba Tonka” High School of Mathematics

Post on 27-Dec-2015

228 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Equation solving,Big numbers

Reverse polish notation, Operations with big numbers

Ivelin Rachev

Telerik Corporationhttp:/telerikacademy.

com

“Baba Tonka” High School of Mathematics

Page 2: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Table of Contents

1. Priority of Operations

Left and Right associatively

2. Reverse Polish notation

Getting reverse polish notation

Calculating reverse polish notation

3. Big Numbers

Comparing

Adding

Subtracting

Multiplying 2

Page 3: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Equation SolvingSolve the equations!

Page 4: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Priority of Operations (1)

Operations have strict priority

Functions

“(“ and “)”

“*” and “/”

“+” and “–”

Page 5: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Priority of Operations (2)

LEFT ASSOCIATIVE

The left operation takes priority!

7-3+2=(7-3)+2=6

5

When operations have the same priority it matters whether they are

left or right associative

RIGHT ASSOCIATIVE

The right operation takes priority!

7-3+2=7-(3+2)=2

Page 6: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Reverse Polish notation (1)

6

Equation written in reverse polish notation has the operations, functions etc. written after the operands. (suffixed)

There are no “(“ and “)” in Reverse Polish notation!5+3*(2-1)-1*4 → 5 3 2 1 - * + 1 4 * -Infixed Suffixed

Page 7: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Reverse Polish notation (2)

Add a zero before each empirical operator.

While there are symbols to be read: Read a symbol

If it is a number add it to the stack

If it is an operator: While the top operator of the stack

has lower priority to the current operator or it is left associated and has the same or lower priority pop it out of the stack and add it the suffixed equation.

Push the current operator into the stack.

If it is a left parenthesis put it in the stack.

7

Page 8: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Reverse Polish notation (3)

If it is a right parenthesis: Until the token at the top of the stack

is a left parenthesis, pop operators off the stack onto the suffixed equation.

Pop the left parenthesis from the stack, but not onto the suffixed equation.

If the stack runs out without finding a left parenthesis, then there are mismatched parentheses

8

Page 9: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Reverse Polish notation (4)

When there are no more symbols to read: While there are still operator tokens

in the stack: If the operator token on the top of

the stack is a parenthesis, then there are mismatched parentheses.

Pop the operator onto the suffixed equation.

9

Page 10: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Reverse Polish notation (5)

10

Page 11: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Reverse Polish notation (6)

Read through the suffixed equation: When you reach an

When you reach an operation do it using the values in your stack and push the answer back in the stack

The only remaining value in your stack is your answer to the equation.

11

Page 12: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

LIVE DEMO

12

Page 13: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Big NumbersHow to?

Page 14: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Big Numbers(1) Big Numbers are usually

represented using a data structure and an logical variable for signed big numbers.

Page 15: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Big Numbers(2)Criteria in comparing big numbers:

By positivity and negativity.

By Length.

By each individual digit.

Note that negative numbers are ordered in reverse order by absolute value.

15

Page 16: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Big Numbers (3)

16

We fallow the same steps as in real life when we add and extract. The maximum that can be transferred is 1.

Multiplying is just adding numbers and moving them rightwards

Page 17: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

LIVE DEMO

17

Page 18: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

форум програмиране, форум уеб дизайнкурсове и уроци по програмиране, уеб дизайн – безплатно

програмиране за деца – безплатни курсове и уроцибезплатен SEO курс - оптимизация за търсачки

уроци по уеб дизайн, HTML, CSS, JavaScript, Photoshop

уроци по програмиране и уеб дизайн за ученициASP.NET MVC курс – HTML, SQL, C#, .NET, ASP.NET MVC

безплатен курс "Разработка на софтуер в cloud среда"

BG Coder - онлайн състезателна система - online judge

курсове и уроци по програмиране, книги – безплатно от Наков

безплатен курс "Качествен програмен код"

алго академия – състезателно програмиране, състезания

ASP.NET курс - уеб програмиране, бази данни, C#, .NET, ASP.NETкурсове и уроци по програмиране – Телерик академия

курс мобилни приложения с iPhone, Android, WP7, PhoneGap

free C# book, безплатна книга C#, книга Java, книга C#Дончо Минков - сайт за програмиранеНиколай Костов - блог за програмиранеC# курс, програмиране, безплатно

?

? ? ??

?? ?

?

?

?

??

?

?

? ?

Questions?

?http://algoacademy.telerik.com

Page 19: Reverse polish notation, Operations with big numbers Ivelin Rachev Telerik Corporation http:/telerikacademy.com “Baba Tonka” High School of Mathematics

Free Trainings @ Telerik Academy

“C# Programming @ Telerik Academy csharpfundamentals.telerik.com

Telerik Software Academy academy.telerik.com

Telerik Academy @ Facebook facebook.com/TelerikAcademy

Telerik Software Academy Forums forums.academy.telerik.com