• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/4

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

4 Cards in this Set

  • Front
  • Back
Insertion Sort
(1..numbers.size-1).each do |j|
  key = numbers[j]
  i = j - 1
  while i >= 0 && numbers[i] > key
    numbers[i+1] = numbers[i]
    i -= 1
  end
  numbers[i+1] = key unless j == i+1
end
(1..numbers.size-1).each do |j|
key = numbers[j]
i = j - 1
while i >= 0 && numbers[i] > key
numbers[i+1] = numbers[i]
i -= 1
end
numbers[i+1] = key unless j == i+1
end
Quick Sort
class QuickSort
attr_reader :array

def initialize(array)
@array = array
end

def call
sort(array)
end

def sort(sub_array)
sub_array.length <= 1 ? sub_array : quick_sort(sub_array)
end

private

def quick_sort(sub_array)
pivot = sub_array.pop

less = []
greater = []

sub_array.each do |x|
if x <= pivot
less << x
else
greater << x
end
end

sort(less) + [pivot] + sort(greater)
end
end
Find the missing integers in an array of integers
def missing_int(source_array)
  missing = 0
  source_array.each do |i|
    missing ^= i
  end
  integers.each do |i|
    missing ^= i
  end
  missing
end
def missing_int(source_array)
missing = 0
source_array.each do |i|
missing ^= i
end
integers.each do |i|
missing ^= i
end
missing
end
Find the largest continuous sum of an array of integers
def largest_continuous_sum
  max = integers[0]
  cur = integers[0]

  integers[1..-1].each do |i|
    cur += i
    max = cur if cur >= max
  end

  max
end
def largest_continuous_sum
max = integers[0]
cur = integers[0]

integers[1..-1].each do |i|
cur += i
max = cur if cur >= max
end

max
end