Advanced Higher Comp coding Flashcards

1
Q

EFFICIENT Bubble Sort

      swapped = False
      -------------------------------------------
                -------------------------------------------
                          ------------------------
                          ---------------------------------
                          ----------------------------
                         -------------------
      stopIndex-=1
A

EFFICIENT BUBBLE SORT

swapped = True
stopIndex = len(array)
while swapped == True and stopIndex >= 0:
swapped = False
for index in range(stopindex-1):
if array[index] > array[index+1]
temp = array[index]
array[index] = array[index+1]
array[index+1] = temp
swapped = True
stopIndex-=1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

INSERTION SORT

  value = array[index]
  --------------------------------------------------------
            -------------------------------------
              index -= 1
   -----------------------------
A

INSERTION SORT

for index in range(1, len(array)):
value = array[index]
while index > 0 and value < array[index-1]:
array[index] = array[index-1]
index -= 1
array[index] = value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

BINARY SEARCH

    ----------------------------
    i---------------------------
          return mid # changes depending on context
    ---------------------------
         -------------------
     ------
             ------------------- return -1 # changes depending on context
A

BINARY SEARCH

low = 0
high = len(array) - 1
while low <= high:
mid = (high+low) // 2
if array[mid] == target:
return mid # changes depending on context
elif array[mid] > target:
high = mid - 1
else:
low = mid + 1
return -1 # changes depending on context

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a constructor? OOP

A

One of the default methods for a class which is used when an object is created. It may give values to none, some, or all of the instance variables for the object when it is created from the class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Encapsulation? OOP

A

Encapsulation is the process of wrapping data and the methods that work on data within one unit.

This is related to setting private/public methods. Private can only be accessed from inside the class, public means it can be directly by any method within any other object in the program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is inheritance? OOP

A

The sharing of characteristics between a class of objects and a newly created subclass. This allows code to be re-used by extending an existing class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Polymorphism? OOP

A

The ability of a subclass to inherit and change the properties and methods from the base class it inherits from.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How do you initialize a 2D Array?

A

array = [[0 for i in range(cols)] for count in range(rows)]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly