3.1 Elementary Data Structures: Building Blocks Flashcards
What is a data type?
A data type is a set of values and a collection of operations on those values.
What are the different basic data types available in C?
int, short int, long int
char
float, double
Give an example of an expression which uses both implicit and explicit type conversion.
if x and n are integers,
((float) x) / n.
x is converted to float explicitly and n is converted implicitly in order to make both the operands floats before the operation.
Give the formulas for calculating average (mu) and standard deviation (sigma) of a sequence x1, x2, x3…. xn.
average = https://getcalc.com/formula/math/average.png
standard deviation=
https://miro.medium.com/max/264/1*fWLk5NLbJ3X0farGthyxQw.png
How can we rewrite the formula for standard deviation to in order to calculate it in one pass through the data?
https://www.strchr.com/standard_deviation_in_one_pass
According to the principles of software development, what are the three files in which we should split our program?
- Interface - Where we define the data structure to be used and declare functions that are to be used to manipulate the data structure.
- Implementation - Where we define the functions declared in the interface, the actual implementation of the functions in the interface.
- Client - A program that uses the functions declared in the interface to work at a high level of abstraction.
How to make use of the interface-implementation architecture from the client program?
We include the interface as a header file in the client program; and compile the implementation along with the client program before using it.
How can we use pointers to return multiple values?
Create the variables in which the return value is to be stored in the main function and pass them by reference to the given function. In the given function, store the values to be returned in these variables. Since, these values will reflect in the main function since these variables were passed by reference.
What is a Data Structure?
A Data Structure refers to a mechanism for organizing our information to provide convenient and efficient mechanisms for accessing and manipulating it.
Give a basic definition of arrays and lists; what is the difference between them with regards to the ease of access and manipulation?
Arrays are data structures in which we organize objects in a fixed sequential fashion that is more suitable for access than for manipulation.
Lists are data structures in which we organize objects in a logical sequential fashion that is more suitable for manipulation than for access.
What is “Numerical Tolerance”?
How to implement a comparison of floats with numerical tolerance of say upto 10^-4?
Numerical Tolerance means that error upto that value is acceptable.
(int) float1(10000) == (int) float2(10000)