Writing Pseudocode Algorithms Flashcards

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

Describe the pseudocode for a Bubble Sort

A

A = ​Array of data

Swapped = True

While Swapped = True Do

Swapped = False

for i = 0 to A.length - 1

if A[i] > A[i+1]

temp = A[i]

A[i] = A[i+1]

A[i+1] = temp

Swapped = True

End if

Next Count

End while

Return A

End function

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

Describe the pseudocode for an Insertion Sort

A

A = ​Array of data

for i = 0 to A.length - 1

currentData = A[i]

position = i

while position > 0 AND A[position - 1] > currentData

temp = A[position]

A[position] = A[position - 1]

A[position - 1] = temp

End While

A[position] = currentData

Next Count

return A

end function

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

Describe the pseudocode for a Linear Search

A

A ​= Array of data

x ​= Desired element

for i = 0 to A.length - 1

if A[i] == x then

position = i

return position

break

else

return “Position not found”

End if

next count

end function

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

Describe the pseudocode for a Binary Search

A

A ​= Array of data

x ​= Desired element

low = 0

high = A.length -1

while low <= high

mid = (low + high) / 2

if A[mid] == x

return mid

else if A[mid] > x

high = mid -1

else

low = mid + 1

endif

endwhile

return “Not found in data”

end function

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

Describe the Stack Operations and Names

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

Describe the Queue Operations and Names

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

Describe the pseudocode for a stack isEmpty

A

if(top == -1)

return true

else

return false

end if

end function

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

Describe the pseudocode for a stack isFull

A

if top = maxSize then

return True

else

return False

end if

end function

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

Describe the pseudocode for a stack push

A

If isFull() then

Print “The stack is full”

Else

top = top + 1

arrStack[top]=newValue

End if

End function

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

Describe the pseudocode for a stack pop

A

if isEmpty() then

Print “The stack is empty”

else

item = arrStack[top]

top = top -1

Return item

End if

End function

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

Describe the pseudocode for a stack peek

A

if isEmpty()

Print “Stack is empty”

Else

return arrStack[top]

endif

end function

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

Describe the pseudocode for a Queue Enqueue

A

if(isFull() then

Print “The queue is full”

Else

rear = (rear+1) % maxSize

arrQueue[rear] = newValue

size = size + 1

Endif

End function

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

Describe the pseudocode for a Queue Dequeue

A

int item

if(isEmpty()) then

Print “The queue is empty”

Else

item = arrQueue[front]

front = (front+1) % maxSize

size = size -1

Endif

End function

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

Explain the advantages of writing an application using a modular approach

A
  • Work is easier to divide between a team
  • Each team member just needs to know what values go into their subroutine and the expected functionality
  • Saves time as work takes place in parallel
  • Easier to test/ debug/ read
  • Each subroutine can be tested before being passed on
  • Code can be reused in the project/ future projects
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is a Stack

A

-A data structure that operates on a first in last out basis

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

What is a queue

A

A data structure that acts on a first in first out bias