Question

In: Computer Science

Course name : Algorithm and Data Structure-I Write a brief note about dependent structure. Compare between...

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

  1. Add x[i] to sum.
  2.   Increment i by 1.

          Calculate and return mean = sum / n .

*Please answer these with no pics or hand writing

Solutions

Expert Solution

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 :

  • Most time consumig statement is While loop. it runs n times.
  • other statement are simple assignment, initialization, increment or arithmatic operations, which takes constant running time.
  • So overall time complexity is O(N).

Like, if this helped ??.


Related Solutions

Course: DSA Data Structure and Algorithm What is an AVL Tree, what are its different types...
Course: DSA Data Structure and Algorithm What is an AVL Tree, what are its different types of rotation, Illustrate with examples.
write a brief about teva pharmaceuticals . also write about its size , type, structure, operation...
write a brief about teva pharmaceuticals . also write about its size , type, structure, operation , etc
1.You are required to form a business and to write a brief introduction about it (name,...
1.You are required to form a business and to write a brief introduction about it (name, services or products, legal form, merchandising or manufacturing, retail or wholesale, size, industry, etc…) 2. In deciding on the legal form for your business, discuss the reasons for your choice. 3. Discuss the different financing options to set up your business and the reasons for your choice (s). 4. Identify the users of accounting information for your business and briefly discuss on how each...
1.You are required to form a business and to write a brief introduction about it (name,...
1.You are required to form a business and to write a brief introduction about it (name, services or products, legal form, merchandising or manufacturing, retail or wholesale, size, industry, etc…) -250 words 2. In deciding on the legal form for your business, discuss the reasons for your choice. -250 words 3. Discuss the different financing options to set up your business and the reasons for your choice (s). -250 words 4. Identify the users of accounting information for your business...
Write a brief note about the type of fits and tolerances in machine elements subject under...
Write a brief note about the type of fits and tolerances in machine elements subject under mechanical engineering
Write a brief note on Breton woods conference
Write a brief note on Breton woods conference
write down a brief note on urinary bladder cancer? Note: No plagiarism.
write down a brief note on urinary bladder cancer? Note: No plagiarism.
write reflection about data mining theory and applications course
write reflection about data mining theory and applications course
Write a class Roster that is identified by the course name, course code, number of credits,...
Write a class Roster that is identified by the course name, course code, number of credits, instructor name, and contains a list of students stored in an array. For now you can use stack allocated array of MAX_CAPACITY=10 (define MAX_CAPACITY as a macro in the .h file). Later we will make this array dynamic to allow it to grow. Provide necessary constructors, accessor functions for each member, and mutator functions for each member. Provide a function to add a student...
I have to write an initial algorithm and a refined algorithm for the following problem: Display...
I have to write an initial algorithm and a refined algorithm for the following problem: Display the square of numbers from 0 to some user inputted value. For example if the user enters 3 then the program will need to display the square of 0, 1, 2 and 3. Must use a counter loop. Must use 2 methods. One method that gets the number from the user and returns it. A second method is passed that number as a parameter...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT