SCC121: weeks 6-10 Flashcards

(34 cards)

1
Q

Describe a queue data structure

A

-First in First out data structure.
-Items are added to the tail of the list and removed from the head.

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

What are some key processes associated with queues?

A

-Queue()- creates a new queue
-enqueue()- adds a new item to the queue
-dequeue()-removes an item from the list
-isEmpty()- checks if the given queue is empty
-size()- returns the size of the list

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

Why are abstract data types “abstract”??

A

-Abstract data types are theoretical concepts of how data can be stored.
-ADT definitions describe what operations should be performed, not HOW it is implemented/coded.
-when realised/implemented, ADTs become Data Structures.

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

Data Structures vs ADTs

A

-data structures are a physical representation of how data is stored structurally in memory.
-ADT is a theoretical overview of the data structure and the functions needed to manipulate it.

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

describe the concept of byte addressable memory.

A

memory can be seen as an array of bytes. each byte/ cell of the array has a unique address.

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

What is word size?

A

-number of bits the CPU can process at once
-we assume a word is 32 bits in size unless told otherwise
-differs across machines
-memory addresses increase by word size/8 (size of a byte)
-typically ints are word size.

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

What are the 4 pieces of information associated with a variable?

A

-name
-value
-address
-type

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

Why use pointers?

A

-Avoids passing copies of variables, memory efficient
-variables are local to the function they are declared in
-pointers allow programmers to pass memory addresses between functions, pass by value, pass by reference

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

what is a heterogenous data structure?

A

A data structure that can hold data of multiple types.

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

Give an example of a heterogenous data type.

A

-records
-has components of varying types, called fields
-fields are identified by name, not index.

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

How would a 2D array be created in C?

A

int 2dArray[x][y];

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

how would a 2D array be created in java?

A

int [][] rating = new int[x][y];

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

How would you go about populating a 2D array in C?

A
  • a nested loop can be used to traverse every row and cell.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why use an Array?

A

-one word identifier for a group of variables.
-random access, elements don’t need to be sequentially traversed through

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

What are the problems of an Array?

A

-fixed size, does not allow dynamic appending
-insertions and deletions are costly

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

define - what is it used for?

A

-defining constants

17
Q

Why are constants useful?

A

defined in one place- only need to be changed in one place.

18
Q

describe the difference between passing by reference and passing by value.

A

-passing by reference:
a pointer to a variable is passed as a parameter to a function
-passing by value:
the variable itself is passed to the function, not the memory location the value is stored at.

19
Q

describe the key features of a stack

A

-items are inserted and removed from the tail
-a first in last out data structure

20
Q

what are the necessary functions for a stack ADT?

A

-Stack()
-push()
-pop()

21
Q

what are some errors that can occur when using stacks?

A

-overflow error when push() used on a full stack
-underflow error when pop() used on an empty stack

22
Q

what are some common uses of stack ADTs?

A

-program execution: call stack
-syntax applications: evaluating expressions and parentheses matching
-searching/traversal: depth traversal

23
Q

Describe the concept of a doubly linked list

A

-each value/piece of data in the list is stored along with a pointer to the next and previous item in the list.
-If the value of the previous or next pointer is nil or ‘/’ this suggests the item is the first or last in the list.
-allows dynamic appending the data structure, no set size

24
Q

describe a singly linked list

A

-no previous pointer stored along with data, only the pointer to the next value
-cannot be traversed in reverse order
-removing values always requires traversal

25
if storage is quick.....
retrieval will be slow.
26
if storage is slow.........
retrieval will be quick.
27
list the order of big O notation complexity classes, small to large
-O(1) -O(logN) -O(n) -O(n(logn)) -O(n^2) -O(n^3) -O(n^a) -O(2^n) -O(a^n)
28
What is the time complexity of a linear search?
linear time complexity- O(n)
29
what is the time complexity of a binary search?
O(logn)
30
What are key attributes of a recursive algorithm?
-A function that calls itself -input size of parameter passed to recursive function grows smaller each time it is called. -consists of a base case and general case. general case contains recursive call and base case returns result. if base case is never met- overflow error as function never ends
31
Describe the concept of hashing
-method of indexing a storage array. -index is determined by an algorithm we run on the data itself
32
what are some characteristics of a hash table?
-to avoid collisions, may store values in an array at an index- called storing in buckets -elements have unique keys -hash function uses key to generate hash code -hash values map to buckets which contain keys
33
how can collisions be reduced?
-increasing the range of indexes -a hashing algorithm should have a wide output range -using more information from the key usually increases the range
34