Purchase Solution

1 label code, 2 determine time complexity of code segments ,

Not what you're looking for?

Ask Custom Question

1. Find one example of each label in the following source code and write the line number of the example next to the label.

a. Instance variable

b. Class variable :

c. Instance method

d. Class method

e. Constant variable

f. Constructor

g. Import statement :

1: package edu.gmu.cs.geom;
2:
3: import edu.gmu.cs.geom.Translatable;
4:
5: public class Point2d implements Translatable {
6:
7: public static int ORIGIN_X = 0;
8: public static int ORIGIN_Y = 0;
9:
10: private int x;
11: private int y;
12:
13: public Point2d() {
14: this.x = Point2d.ORIGIN_X;
15: this.y = Point2d.ORIGIN_Y;
16: }
17:
18: public Point2d(int x, int y) {
19: this.x = x;
20: this.y = y;
21: }
22:
23: public int getX() {
24: return this.x;
25: }
26:
27: public int getY() {
28: return this.y;
29: }
30:
31: public void translate(int xDelta, int yDelta) {
32: this.x += xDelta;
33: this.y += yDelta;
34: }
35:
36: public static Point2d add(Point2d left, Point2d right) {
37: int x = left.getX() + right.getX();
38: int y = left.getY() + right.getY();
39:
40: return new Point2d(x, y);
41: }
42:
43: }

2. Order the following code segments by time complexity in ascending order. For bonus points, show the runtime of each code segment in Big O notation.

a.

for (int y = 0; y < n; y++) {
for (int x = 0; x < n; x++) {
m[y, x] = 0;
}
}

b.

public boolean isOdd(int x) {
return (x % 2) == 0;
}

c.

int x = 0;
int y = 0;

while (x < MAX) {
if (isOdd(x)) {
x++;
y++;
} else {
x++;
}
}

d.

int sum = 0;
for (int i = 0; i < items.size(); i = (i * 2) + 1) {
sum += items.get(i);
}

Purchase this Solution

Solution Summary

The expert determines the time complexity of code segments for a label code are examined.

Solution Preview

Question #1
a. Instance variable
10: private int x;
b. Class variable :
7: public static int ORIGIN_X = 0;
c. Instance method
23: ...

Purchase this Solution


Free BrainMass Quizzes
Javscript Basics

Quiz on basics of javascript programming language.

C# variables and classes

This quiz contains questions about C# classes and variables.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.