Abstraction Flashcards

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

State what is meant by an abstract data type

A

Is a collection of data. When we want to use an abstract data type, we need a set of basic operations

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

List the basic operations that abstract data types have to follow

A
  1. Create a new instance of the data structure
  2. Find an element in the data structure
  3. Insert a new element into the data structure
  4. Delete an element from the data structure
  5. Access all elements stored in the data structure in a systematic manner
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Give examples of abstract data types

A
  1. Stacks
  2. Queues
  3. Linked Lists
  4. Binary Trees
  5. Hash Tables
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How does a stack work

A

Items are piled on items on top. The item that is accessible is the one on top of the stack. If we try to find an item in the stack and take it out, we are likely to cause pile to collapse.
The baseofstackpointer will always point to the first slot in the stack.
The topofstackpointer will point to the last element pushed onto the stack.
When an element is removed from the stack, the topofstackpointer will decrease to point to the element now at the top of the stack.

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

Explain how a queue works

A

Items added to the queue, get added to the end (endofqueuepointer)
When the item at the front of the queue leaves, we need to move all the other items one step forward. This creates a circular queue where we adjust the frontofqueuepointer

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

Explain how an insertion sort works

A

Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. At each iteration, insertion sort removes one element from the input data, finds the location it belongs within the sorted list, and inserts it there. It repeats until no input elements remain.

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

State the advantages of insertion sort

A
  1. Simple
  2. Efficient in practice compared to bubble sort
  3. Only requires a constant memory space
  4. Can sort the list as it receives it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

State the disadvantages of insertion sort

A

1.Less efficient for large lists

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

State how a binary search works

A

Repeated checking of the middle item in an ordered search list and discarding the half of the list which does not contain the search item

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

What are the advantages of binary search?

A
  1. Faster to search for items than other algorithms

2. Simple algorithm

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

What are the disadvantages of binary search?

A
  1. Not needed for small amount of elements
  2. Works on lists already sorted
  3. Lacks efficiency is the list doesn’t have direct access
  4. Hash lookups are faster
How well did you know this?
1
Not at all
2
3
4
5
Perfectly