In: Computer Science
Course name : Algorithm and Data Structure-I
Write a brief note about dependent structure.
Compare between tree and qraph.
Explain What we means by "Data encapsulation"? And give example.
Explain the concept of interface in java with example.
Calculate T(n) and Big O notation for the following algorithm:
Initialize sum to 0.
Initialize index variable i to 0
While i<n do the following
Calculate and return mean = sum / n .
*Please answer these with no pics or hand writing
Dependent Structure :
Two structures, say A and B, are called mutually dependent if one of members of each refers to other structure.
code example :
struct A {
struct B b;
int value;
};
struct B {
struct A a;
float wool;
};
Difference between tree and graph:
A tree is simply a hierachical graph with a root node. Tree data structures will not be as intricately connected as graphs, trees tend to have a single path between nodes and they never ever have loops or circuits.
Tree has exactly one root node. Graph doesn't have a root node.
No loops are permitted in tree, but graph can have loops.
Data encapsulation :
Data encapsulation is also referred as bundling data. It keeps data safe from outside inferences and misuse.
encapsulation is used in abstraction, which leads to data hiding.The concept of data encapsulation is supported in C++ through the use of the public, protected and private keywords
Example :
class Box {
public:
double getVolume(void) {
return length * breadth * height;
}
private:
double length;
double breadth;
double height;
};
Interface in JAVA:
Big -O Notation for Algorithm :
Like, if this helped ??.