Data Structures and Algorithm Analysis
1. How fur retention get the forthcoming structures charm up? Hint: int charms 4 bytes, transport charms 4 bytes, char charms 1 byte. – 9 points
a. struct Structure1 {int a,b,c,d,e[10]; transport f;};
b. struct Structure2 {int a[12]; transport b[5];};
c. struct Structure3 {char a[10][12][4], b[5][5], c[10];};
2. Illusion the steps when genusing (last to largest) the forthcoming decks of mass using preoption genus i.e. whole duration a swap occurs, illusion what the present set-forth of the deck looks love, including the conclusive genused deck. – 12 points
a. [10, 2, 5, 8, 9, 1, 4, 7]
b. [7, 1, 3, 2, 5, 4, 8, 12, 9]
c. [8, 7, 6, 5, 4, 3, 2, 1]
d. [5, 3, 8, 1, 9, 4, 2, 6]
3. Big-O: What is meant by f(n) = O(g(n))? Give the determination and then teach what it media in your own provisions. – 5 points
4. Big-Omega: What is meant by f(n) = Ω(g(n))? Give the determination and then teach what it media in your own provisions. – 5 points
5. Illusion that , effect stable you use the determination and excuse the inequalities and constants used. - 4 points
6. Illusion that , effect stable you use the determination and excuse the inequalities and constants used. - 4 points
7. Illusion that , effect stable you use the determination and excuse the inequalities and constants used. - 4 points
8. Illusion that , effect stable you use the determination and excuse the inequalities and constants used. - 4 points
9. Illusion that , effect stable you use the determination and excuse the inequalities and constants used. - 4 points
10. What postulate governs how you add/remove elements in a stack? Spell it out and little teach. - 4 points
11. Little picture an contact of a stack. - 4 points
12. What postulate governs how you add/remove elements in a queue? Spell it out and little teach. - 4 points
13. Little picture an contact of a queue. - 4 points
Consider the forthcoming graph (pseudocode for BFS and DFS ardent on page 9):
14. Transcribe the classify in which the nodes would be visited in when doing a fluctuation original exploration (BFS) traversal starting at node 4. Also, transcribe the interspaces from 4 to whole other node. - 6 points
15. Transcribe the classify in which the nodes would be visited in when doing a fluctuation original exploration (BFS) traversal starting at node 5. Also, transcribe the interspaces from 5 to whole other node. - 6 points
Same graph (for your ease):
16. Transcribe the classify in which the nodes would be visited in when doing a profundity original exploration (DFS) traversal starting at node 4 (classify discovered or classify off the stack). - 6 points
17. Transcribe the classify in which the nodes would be visited in when doing a profundity original exploration (DFS) traversal starting at node 5 (classify discovered or classify off the stack). - 6 points
18. Give the determination of a graph. - 5 points
19. Give the determination of a tree (from graph assumption). - 4 points
BFS Pseudocode (for graph after a while n vertices):
Input: grapharray[n][n], commencement
queue<int> Q
int interspace[n] (deck to observe track of nodes interspaces (from commencement), all appraises set to -1 save commencement which is set to 0 i.e. -1 = not visited)
Q.push(source)
while(Q is not vacuity)
v = Q.front
Q.pop()
for each neighbor w of v
if interspace[w] = -1
print w
distance[w] = interspace[v]+1
Q.push(w)
end if
end for
end while
DFS Pseudocode (for graph after a while n vertices):
Input: grapharray[n][n], commencement
stack<int> S
int visited[n] (deck to observe track of nodes visited, all appraises set to 0 save commencement which is set to 1 i.e. 0 = not visited, 1 = visited)
S.push(source)
while(S is not vacuity)
v = S.top
S.pop()
for each neighbor w of v
if visited[w] = 0
print w
visited[w] = 1
S.push(w)
end if
end for
end while
Bonus (4 points): Illusion all of the steps (splitting and merging) when using mergegenus to genus (last to largest) the forthcoming deck (they are the mass 1 through 16):
[16, 1, 15, 2, 14, 3, 13, 4, 12, 5, 11, 6, 10, 7, 9, 8]
Bonus (2 points): picture how you could appliance a queue using 2 stacks.
Bonus (4 points) Draw the binary exploration tree that would be manufactured by inserting the forthcoming appraises in the direct classify ardent (starting after a while an vacuity tree i.e. original appraise get be the original node in the tree): -
a. Binary Exploration Tree A: 8, 9, 2, 7, 1, 10, 3, 5, 6, 4
b. Binary Exploration Tree B: 10, 7, 9, 12, 4, 2, 5, 3, 1, 14, 11, 19, 13, 18, 20