CS paper 1.. Flashcards

1
Q

Subroutines and stack frames

A

-Each time a subroutine Is called the program jumps to a different part
-Once subroutine completes program needs to return to where it left off
-Before program jumps off subroutines needs to know where to return to and restore values of any local variables and parameters when returning
-This is achieved with a stack frame

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

before calling subroutine (what system needs to do)

A

-construct stack frame
-add return address to stack frame
-add local variables to stack frame
-push completed stack from onto stack

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

data structures

A

stacks,queues,graphs,trees,
hash tables,dictionaries ,vectors

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

arrays

A

-variable that can contain more than one data item
-allocating a contiguous part of memory for the purpose of storing that data
-contiguous = data is stored together, 1 elements after the other
-starts at index 0
-static data structure

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

list vs array vs tuple

A

list: mutable,items can be changed or replaced, store
> 1 data type
array: mutable, items can be changed or replaced, only store 1 data type
tuple: immutable, items cannot be changed or replaced, store > 1 data type

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

File handling

A

Refers to the opening, closing, reading from and writing to files by program code

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

Binary file

A

-Contains records with many different data types

A 15 figure number will occupy 15 bytes in standard text, but it would take up less space stored as a pure binary number

Reading binary file is language specific but requires you to know the exact structure of the file e.g. field sizes

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

Static data structure

A

-Is fixed in size and cannot free up memory while program is running
-An array is suitable for storing a fixed number of items e.g. months of the year
-The disadvantage is that the size of the array has to be decided in advance And if items fill up, the array no more can be added
- Also memory, which has been allocated to the array cannot be reallocated
-But no pointers or ther data about structure needs to be stored

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

dynamic data structure

A
  • Collection of data, in memory that can grow or shrink in size
    -Does this with aid of the heap
  • Useful for implementing data structures, e.g. queues when the maximum size of data structure is not know
    -Unused memory reallocated As required while program running
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

stack operation

A

-push(item) = add item
-pop() = remove item
-peek() =return top value without removing
-isEmpty()
-isFull()

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

queue

A
  • First in first out, data structure
    -New element added to end of queue
    -back pointer, point to last item
    -front pointer, poin tto first item
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Queue operations

A
  • enQueue(item) = add new item to rear of queue
  • deQueue() = remove front item from queue and return it
  • isEmpty() = test whether queue is empty
  • isFull() = test whether queue is full
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

circular queues

A
  • When Array Fills up and rear pointer points to last element (e.g. q[5]) It will be made to the first element, (q0), when next person joins queue
    -Requires extra effort for programmer and less flexible than dynamic data structure
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

application of queues

A

-processer schelduling
-Transferring data between processor and printer spooling
-Performing breadth-first searches on graph data structures

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

adding item to stack

A

-check if stack is already full
-increment stack pointer so it points to next available space in array
-push (insert) new items

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

add items to queue

A

-Check if Q is already full
-Increment back pointer so it points to next available space in arrray
-Insert (enqueue) new item at position pointed by back pointer

17
Q

graph

A

data structure consisting of nodes and edges
can have more then 2 edges and point to any vertex
graphs can be weighted with edges givena value
edges can:
point in 1 direction (directed)
not specify a direction (undirected)

18
Q

adjacency matrix

A

-a table that shows the relationship between vertices in a graph
-checking for presence/absence of edge requires accessing corresponding element in matrix
-sparse graph with many nodes but few edges, most cells empty, and bigger graphs means greater potential for wasted memory
-If using static 2D array, it can be harder to delete/add nodes

19
Q

Adjacency list

A
  • a data structure that stores the relationship between vertices in a graph
    -checking for presence/absence of edge requires traversing list of corresponding vertex (O(k) time)
    -space efficient wat to implement sparsely connected graph
    -much less memory used
20
Q

graph applications

A

-mapping road networks for navigation systems
-storing social network data
-resource allocation in operating systems

21
Q
A