Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lynn Trickey's Finished questions #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
### Problems for you

Snippet 1 - Big O:

I would define this as 0(n) linear because the efficiency
will be directly related to how long the array is,
Since you're iterating over each item in the array.

```ruby
def largest?(array, value)
array.each do |item|
Expand All @@ -25,6 +30,12 @@ end
```

Snippet 2 - Big O:

I would also define this as 0(n) linear, because, again,
it's going to depend on how long the (assumed) array of
customers is. Although we technically are iterating
over it twice, I believe we'd simplify 0(2n) to 0(n).

```ruby
def info_dump(customers)
puts "Customer Names: "
Expand All @@ -39,13 +50,23 @@ end
```

Snippet 3 - Big O:

I'd say 0(1) constant, because no matter how large the
data set, since we're only checking the first element,
it's always going to take the same amount of time.

```ruby
def first_element_is_red?(array)
array[0] == 'red' ? true : false
end
```

Snippet 4 - Big O:

0(n^2) quadratic because the loops are nested.
Depending on the length of the data set, the
efficiency would decrease exponentially.

```ruby
def duplicates?(array)
array.each_with_index do |item1, index1|
Expand All @@ -59,6 +80,13 @@ end
```

Snippet 5 - Big O:

This one is a little confusing to me. I'd say it's
constant because the arrays of words and endings are set
with three items each, so the efficiency shouldn't change.
However if we could change those arrays, I'd say it
was 0(n*m) because the loops are nested.

```ruby
words = [chocolate, coconut, rainbow]
endings = [cookie, pie, waffle]
Expand All @@ -71,6 +99,14 @@ end
```

Snippet 6 - Big O:

0(n) linear, because even though this each loop is within
a method, it doesn't affect it - it's not like
nesting two each loops. The efficiency will directly
relate to the size of the data set. I'm assuming here
that you would call the method print_array on the array
numbers.

```ruby
numbers = # some array (you don't know contents)

Expand All @@ -80,6 +116,12 @@ end
```

Snippet 7 - Big O:

Since there are nested loops - an each loop and a while
loop - I'm going to assume that this is 0(n)
exponential. The sort will take longer depending on
the length of the set for both loops.

```ruby
# this is insertion sort
(2...num.length).each do |j|
Expand All @@ -94,6 +136,11 @@ end
```

Snippet 8 - Big O:

Again I'm going to assume 0(n) because of
looped statements here. The length/size of data set
affects both do/end block.

```ruby
# this is selection sort
n.times do |i|
Expand Down