2. Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What are the three programming constructs?

A

Sequence - executing one statement after another.
Iteration - repeating a section of code while a Boolean expression is true. This is with a for loop, while loop, do… while loop.
Branching (selection) - branching to a different place in the program according to the value of a Boolean expression. This is with if statements or switch/case.

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

What is the Linear Search in pseudocode?

A

array names[6] = [“Dave”, “Richard”, “Astrid”, “Dima”, “Charlie”, “Paul”]
found = false
for i = 0 to names.length - 1
if (names[i] == “Roberto”) then
print(“Found at index “ + i)
found = true
break // stops the for loop
endIf
next i
if (found == false) then
print(“No matching item is found”)
endIf

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

How do you use sign and magnitude to represent numbers?

A

Positive numbers - Same as unsigned binary except the left most bit has to be a 0.
Negative numbers - Same as unsigned binary except the most significant digit has to be 1.

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

How do you use 2s compliment to represent number?

A

Positive numbers - Same as unsigned binary except the left most bit has to be a 0.
Negative numbers - Take the positive version of the number and then keep it same up to and keep the first 1, then start to flip the rest. Right to Left.

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

When subtracting numbers what can you do?

A

Convert the number to a negative number and then add them and IGNORE ANY OVERFLOW.

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

What is the Binary Search in pseudocode?

A

array myIntegers[5] = [12, 16, 19, 22, 25]
start = 0
end = 4
found = false
input searchItem(“Please enter search item”)
midPoint = 0
while (found == false AND START <= END)
MIDPOINT = (START + END) DIV 2
if (myIntegers[midPoint] == searchItem) then
found = true
elseif (myIntegers[midPoint] > searchItem)
end = midPoint - 1
else
start = midPoint +1
endif
endwhile

if (found == true) then
print(“Item found at “ + midPoint)
endif

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

What are the pros and cons of the binary search?

A

+ Efficient on large sorted data.
+ Can use strings.
- Slow on small list that is unlikely to grow.

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

What are the positives of global scope?

A

Once defined once, it can be used anywhere again and again.
If the value is changed somewhere it is changed for every place in the program (might be desired).

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

What are the negatives of global scope?

A

Makes code harder to read as it is harder to follow the data between subroutines. Memory for the variable is locked up for the entire time the program is running.

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

What are the positives of local scope?

A

Can reuse the variable name in other subroutines.
Once the subroutine has finished the local variable is no longer needed so the memory is freed up.
This also makes the subroutine more reusable.
Harder to make a mistake by changing the value accidently.

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

What are the negatives of local scope?

A

Need to be passed into subroutines or you need to redefine the variable.
Can’t be used outside of scope, needs knowledge of the scope.

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

What is the difference between passing in the variable ByRef and ByVal?

A

ByRef or By Reference passes in the memory address, updaring it in memory.
ByVal or By Value copies the value and allows a new variable to be used. It doesn’t change the value if used outside it’s scope. Acts as a local variable then.

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

When do you not pass in the variable as a parameter?

A

It is a global variable.

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

What is a bubble sort?

A

A sorting algorithm that orders data in a list or an array in any order that you desire by moving through the lists from end to end swapping in necessary.

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

What is the pseudocode for bubble sort?

A

array myNumbers[6]

for (i = 0 to myNumbers.length - 2)
swapped = false
for (j = 1 to myNumbers.length - 1 - i)
if (myNumbers[j-1] > myNumbers[j])
temp = myNumbers[j-1]
myNumbers[j-1] = myNumbers[j]
myNumbers[j] = temp
swapped = true
endif
next j
if (swapped == false) then
break //breaks out of loop
endif
next i

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

What are the pros of a bubble sort?

A

Easy to implement.
Good for small data sets that are almost sorted.

17
Q

What are the cons of a bubble sort?

A

Inefficient as it may continue to make passes through the list if sorted already.
Avoided by using a swaps variable changing the Boolean value of it.

18
Q

What does it mean when you think abstractly?

A

Hiding details and identifying and highlioghting key elements.

19
Q

What does it mean when you think ahead?

A

What inputs/outputs will you need.

20
Q

What does it mean when you think procedurely?

A

Order of events/subproblems.

21
Q

What does it mean when you think logically?

A

Decisions to be made.

22
Q

What does it mean by computational thinking?

A

It is an approach to problem-solving combining critical thinking and computer processes.
5 key elements to it.

23
Q

What does it mean when you think concurrently?

A

What can be done at the same time.

24
Q

Pros of thinking abstractly?

A

Easier to understand.
Reduces time to find a solution, design and programming time and memory/processing power. (Costs less<).
Focuses on the main program.