Data Abstraction - Formula Sheet
While Data Abstraction is a conceptual programming methodology, it uses specific mathematical and indexing formulas to define and manipulate abstract data structures.
1. Distance Calculation Formula between Abstract City Objects
The distance between two cities represented as abstract data objects with latitude and longitude coordinates is determined using the Euclidean distance formula:
\[Distance(city_{1}, city_{2}) = \\sqrt{(lt_{1} - lt_{2})^{2} + (lg_{1} - lg_{2})^{2}}\]
Where each term is defined as follows:
- \(lt_{1}\): Latitude of the first city, obtained using the selector getlat(city1).
- \(lg_{1}\): Longitude of the first city, obtained using the selector getlon(city1).
- \(lt_{2}\): Latitude of the second city, obtained using the selector getlat(city2).
- \(lg_{2}\): Longitude of the second city, obtained using the selector getlon(city2).
2. Compound Data Indexing Formulas (Pairs)
When implementing a Pair ADT using Python lists or tuples, individual elements are retrieved using zero-based offset indexing formulas:
- First Element Indexing: \(x_{0} = Pair\) (Retrieves the first element of the pair).
- Second Element Indexing: \(x_{1} = Pair\) (Retrieves the second element of the pair).
3. Rational Number Representation
A rational number is exact when represented as a pair of integers consisting of a numerator and a denominator:
\[Rational = \\frac{n}{d}\]
Where:
- \(n\): Numerator, selected using the selector numer(x).
- \(d\): Denominator, selected using the selector denom(x) (where \(d \\neq 0\)).
More for this chapter
Book Back Questions10 textbook MCQs · solved
Additional MCQs15 extra MCQs · solved
Practice TestInteractive · instant score
Book Back TestTest yourself on the textbook set
Additional MCQ TestTest yourself on the extra set
Study NotesConcepts & methods
More chapters in Computer Science
View all
1 Function
3 Scoping
4 Algorithmic Strategies
5 Python -Variables and Operators
6 Control Structures
7 Python functions
8 Strings and String manipulation
9 Lists, Tuples, Sets and Dictionary
10 Python Classes and objects
11 Database Concepts
12 Structured Query Language (SQL)
13 Python and CSV files
14 Importing C++ programs in Python.
15 Data manipulation through SQL
16 Data visualization using pyplot: line chart, pie chart and bar chart