SlideShare a Scribd company logo
1 of 10
Data Structures and Algorithm Analysis
Spring 2020 Post Midterm Exam – 100 points + 10 bonus
NAME:
1. How much memory will the following structures take up?
Hint: int takes 4 bytes, float takes 4 bytes, char takes 1 byte. – 9
points
a. struct Structure1 {int a,b,c,d,e[10]; float f;};
b. struct Structure2 {int a[12]; float b[5];};
c. struct Structure3 {char a[10][12][4], b[5][5], c[10];};
2. Show the steps when sorting (smallest to largest) the
following arrays of numbers using selection sort i.e. every time
a swap occurs, show what the current state of the array looks
like, including the final sorted array. – 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 definition
and then explain what it means in your own terms. – 5 points
4. Big-Omega: What is meant by f(n) = Ω(g(n))? Give the
definition and then explain what it means in your own terms. –
5 points
5. Show that , make sure you use the definition and justify the
inequalities and constants used. - 4 points
6. Show that , make sure you use the definition and justify the
inequalities and constants used. - 4 points
7. Show that , make sure you use the definition and justify the
inequalities and constants used. - 4 points
8. Show that , make sure you use the definition and justify the
inequalities and constants used. - 4 points
9. Show that , make sure you use the definition and justify the
inequalities and constants used. - 4 points
10. What principle governs how you add/remove elements in a
stack? Spell it out and briefly explain. - 4 points
11. Briefly describe an application of a stack. - 4 points
12. What principle governs how you add/remove elements in a
queue? Spell it out and briefly explain. - 4 points
13. Briefly describe an application of a queue. - 4 points
Consider the following graph (pseudocode for BFS and DFS
given on page 9):
14. Write the order in which the nodes would be visited in when
doing a breadth first search (BFS) traversal starting at node 4.
Also, write the distances from 4 to every other node. - 6 points
15. Write the order in which the nodes would be visited in when
doing a breadth first search (BFS) traversal starting at node 5.
Also, write the distances from 5 to every other node. - 6 points
Same graph (for your convenience):
16. Write the order in which the nodes would be visited in when
doing a depth first search (DFS) traversal starting at node 4
(order discovered or order off the stack). - 6 points
17. Write the order in which the nodes would be visited in when
doing a depth first search (DFS) traversal starting at node 5
(order discovered or order off the stack). - 6 points
18. Give the definition of a graph. - 5 points
19. Give the definition of a tree (from graph theory). - 4 points
BFS Pseudocode (for graph with n vertices):
Input: grapharray[n][n], source
queue<int> Q
int distance[n] (array to keep track of nodes distances (from
source), all values set to -1 except source which is set to 0 i.e. -
1 = not visited)
Q.push(source)
while(Q is not empty)
v = Q.front
Q.pop()
for each neighbor w of v
if distance[w] = -1
print w
distance[w] = distance[v]+1
Q.push(w)
end if
end for
end while
DFS Pseudocode (for graph with n vertices):
Input: grapharray[n][n], source
stack<int> S
int visited[n] (array to keep track of nodes visited, all values set
to 0 except source which is set to 1 i.e. 0 = not visited, 1 =
visited)
S.push(source)
while(S is not empty)
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): Show all of the steps (splitting and merging)
when using mergesort to sort (smallest to largest) the following
array (they are the numbers 1 through 16):
[16, 1, 15, 2, 14, 3, 13, 4, 12, 5, 11, 6, 10, 7, 9, 8]
Bonus (2 points): describe how you could implement a queue
using 2 stacks.
Bonus (4 points) Draw the binary search tree that would be
constructed by inserting the following values in the exact order
given (starting with an empty tree i.e. first value will be the
first node in the tree): -
a. Binary Search Tree A: 8, 9, 2, 7, 1, 10, 3, 5, 6, 4
b. Binary Search Tree B: 10, 7, 9, 12, 4, 2, 5, 3, 1, 14, 11, 19,
13, 18, 20
11

More Related Content

Similar to Data Structures and Algorithm AnalysisSpring 2020 Post Midterm E

2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02Krish_ver2
 
Analysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsAnalysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsSigSegVSquad
 
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docxgraphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docxwhittemorelucilla
 
bfs tree searching ,sortingUntitled presentation.pptx
bfs tree searching ,sortingUntitled presentation.pptxbfs tree searching ,sortingUntitled presentation.pptx
bfs tree searching ,sortingUntitled presentation.pptxsaurabhpandey679381
 
lecture 17
lecture 17lecture 17
lecture 17sajinsc
 
1 Compute and draw the adjacency matrix and adjacency list .pdf
1 Compute and draw the adjacency matrix and adjacency list .pdf1 Compute and draw the adjacency matrix and adjacency list .pdf
1 Compute and draw the adjacency matrix and adjacency list .pdfatwaytvl
 
Building a Functional Stream in Scala
Building a Functional Stream in ScalaBuilding a Functional Stream in Scala
Building a Functional Stream in ScalaDerek Wyatt
 
hospital management
hospital managementhospital management
hospital managementguestbcbbb5c
 
Classical programming interview questions
Classical programming interview questionsClassical programming interview questions
Classical programming interview questionsGradeup
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxcarliotwaycave
 
Breadth first search
Breadth first search Breadth first search
Breadth first search piku das
 

Similar to Data Structures and Algorithm AnalysisSpring 2020 Post Midterm E (20)

DFS and BFS
DFS and BFSDFS and BFS
DFS and BFS
 
2.5 bfs & dfs 02
2.5 bfs & dfs 022.5 bfs & dfs 02
2.5 bfs & dfs 02
 
Graphs
GraphsGraphs
Graphs
 
LEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdfLEC 12-DSALGO-GRAPHS(final12).pdf
LEC 12-DSALGO-GRAPHS(final12).pdf
 
Analysis of Pathfinding Algorithms
Analysis of Pathfinding AlgorithmsAnalysis of Pathfinding Algorithms
Analysis of Pathfinding Algorithms
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docxgraphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
graphin-c1.pnggraphin-c1.txt1 22 3 83 44 5.docx
 
bfs tree searching ,sortingUntitled presentation.pptx
bfs tree searching ,sortingUntitled presentation.pptxbfs tree searching ,sortingUntitled presentation.pptx
bfs tree searching ,sortingUntitled presentation.pptx
 
lecture 17
lecture 17lecture 17
lecture 17
 
Parallel search
Parallel searchParallel search
Parallel search
 
1 Compute and draw the adjacency matrix and adjacency list .pdf
1 Compute and draw the adjacency matrix and adjacency list .pdf1 Compute and draw the adjacency matrix and adjacency list .pdf
1 Compute and draw the adjacency matrix and adjacency list .pdf
 
Graphs bfs dfs
Graphs bfs dfsGraphs bfs dfs
Graphs bfs dfs
 
Building a Functional Stream in Scala
Building a Functional Stream in ScalaBuilding a Functional Stream in Scala
Building a Functional Stream in Scala
 
hospital management
hospital managementhospital management
hospital management
 
Classical programming interview questions
Classical programming interview questionsClassical programming interview questions
Classical programming interview questions
 
Graphs
GraphsGraphs
Graphs
 
Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]Data Structures - Lecture 10 [Graphs]
Data Structures - Lecture 10 [Graphs]
 
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docxINFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
INFORMATIVE ESSAYThe purpose of the Informative Essay assignme.docx
 
Breadth first search
Breadth first search Breadth first search
Breadth first search
 
Bfs and Dfs
Bfs and DfsBfs and Dfs
Bfs and Dfs
 

More from jeniihykdevara

hiExplain what is Hadoop, how its fit into the Data Wareho.docx
hiExplain what is Hadoop, how its fit into the Data Wareho.docxhiExplain what is Hadoop, how its fit into the Data Wareho.docx
hiExplain what is Hadoop, how its fit into the Data Wareho.docxjeniihykdevara
 
Hide Folder InformationThis project is due in about 3 12 hour.docx
Hide Folder InformationThis project is due in about 3 12 hour.docxHide Folder InformationThis project is due in about 3 12 hour.docx
Hide Folder InformationThis project is due in about 3 12 hour.docxjeniihykdevara
 
Hi,  i have a draft of my paper about technology need to be fina.docx
Hi,  i have a draft of my paper about technology need to be fina.docxHi,  i have a draft of my paper about technology need to be fina.docx
Hi,  i have a draft of my paper about technology need to be fina.docxjeniihykdevara
 
Hi,Write a narrative essay.The topic for this essay Write a.docx
Hi,Write a narrative essay.The topic for this essay Write a.docxHi,Write a narrative essay.The topic for this essay Write a.docx
Hi,Write a narrative essay.The topic for this essay Write a.docxjeniihykdevara
 
Hi,The paper is Masters degree level. Must be written in APA styl.docx
Hi,The paper is Masters degree level. Must be written in APA styl.docxHi,The paper is Masters degree level. Must be written in APA styl.docx
Hi,The paper is Masters degree level. Must be written in APA styl.docxjeniihykdevara
 
High and Low Context CommunicationResearch high and low context co.docx
High and Low Context CommunicationResearch high and low context co.docxHigh and Low Context CommunicationResearch high and low context co.docx
High and Low Context CommunicationResearch high and low context co.docxjeniihykdevara
 
Hi,Please answer all three questions below, also attached textbook.docx
Hi,Please answer all three questions below, also attached textbook.docxHi,Please answer all three questions below, also attached textbook.docx
Hi,Please answer all three questions below, also attached textbook.docxjeniihykdevara
 
Hi,Please find attached the article and answer the question below.docx
Hi,Please find attached the article and answer the question below.docxHi,Please find attached the article and answer the question below.docx
Hi,Please find attached the article and answer the question below.docxjeniihykdevara
 
Hi,I want a report about the uploaded case study. These are the .docx
Hi,I want a report about the uploaded case study. These are the .docxHi,I want a report about the uploaded case study. These are the .docx
Hi,I want a report about the uploaded case study. These are the .docxjeniihykdevara
 
Hi,I need someone to implement my paper in part of1.result&discu.docx
Hi,I need someone to implement my paper in part of1.result&discu.docxHi,I need someone to implement my paper in part of1.result&discu.docx
Hi,I need someone to implement my paper in part of1.result&discu.docxjeniihykdevara
 
Hi,I have a book discussion in my literature class, the book is .docx
Hi,I have a book discussion in my literature class, the book is .docxHi,I have a book discussion in my literature class, the book is .docx
Hi,I have a book discussion in my literature class, the book is .docxjeniihykdevara
 
Hi,I got two summaries. Each summary is ONE PAGE.The first.docx
Hi,I got two summaries. Each summary is ONE PAGE.The first.docxHi,I got two summaries. Each summary is ONE PAGE.The first.docx
Hi,I got two summaries. Each summary is ONE PAGE.The first.docxjeniihykdevara
 
Hi, I need this assingment by tomorrow 12415 at 1159PM. I hav.docx
Hi, I need this assingment by tomorrow 12415 at 1159PM. I hav.docxHi, I need this assingment by tomorrow 12415 at 1159PM. I hav.docx
Hi, I need this assingment by tomorrow 12415 at 1159PM. I hav.docxjeniihykdevara
 
Hi, I need this discussion question answered by 1159pm tomorrow Fri.docx
Hi, I need this discussion question answered by 1159pm tomorrow Fri.docxHi, I need this discussion question answered by 1159pm tomorrow Fri.docx
Hi, I need this discussion question answered by 1159pm tomorrow Fri.docxjeniihykdevara
 
Hi,I have three article, what I need is a one page summary of a .docx
Hi,I have three article, what I need is a one page summary of a .docxHi,I have three article, what I need is a one page summary of a .docx
Hi,I have three article, what I need is a one page summary of a .docxjeniihykdevara
 
Hi, I need help writing an art history paper wondering if you could .docx
Hi, I need help writing an art history paper wondering if you could .docxHi, I need help writing an art history paper wondering if you could .docx
Hi, I need help writing an art history paper wondering if you could .docxjeniihykdevara
 
Hi, I need help with my papers but I need someone with experience in.docx
Hi, I need help with my papers but I need someone with experience in.docxHi, I need help with my papers but I need someone with experience in.docx
Hi, I need help with my papers but I need someone with experience in.docxjeniihykdevara
 
Hi, I have an assignment in my religion class, I have uploaded the i.docx
Hi, I have an assignment in my religion class, I have uploaded the i.docxHi, I have an assignment in my religion class, I have uploaded the i.docx
Hi, I have an assignment in my religion class, I have uploaded the i.docxjeniihykdevara
 
Hi, I need a 3-3.5 page paper about 2 books and a text. First book .docx
Hi, I need a 3-3.5 page paper about 2 books and a text. First book .docxHi, I need a 3-3.5 page paper about 2 books and a text. First book .docx
Hi, I need a 3-3.5 page paper about 2 books and a text. First book .docxjeniihykdevara
 
Hi, I have an assignment in my behavior in organization class, its .docx
Hi, I have an assignment in my behavior in organization class, its .docxHi, I have an assignment in my behavior in organization class, its .docx
Hi, I have an assignment in my behavior in organization class, its .docxjeniihykdevara
 

More from jeniihykdevara (20)

hiExplain what is Hadoop, how its fit into the Data Wareho.docx
hiExplain what is Hadoop, how its fit into the Data Wareho.docxhiExplain what is Hadoop, how its fit into the Data Wareho.docx
hiExplain what is Hadoop, how its fit into the Data Wareho.docx
 
Hide Folder InformationThis project is due in about 3 12 hour.docx
Hide Folder InformationThis project is due in about 3 12 hour.docxHide Folder InformationThis project is due in about 3 12 hour.docx
Hide Folder InformationThis project is due in about 3 12 hour.docx
 
Hi,  i have a draft of my paper about technology need to be fina.docx
Hi,  i have a draft of my paper about technology need to be fina.docxHi,  i have a draft of my paper about technology need to be fina.docx
Hi,  i have a draft of my paper about technology need to be fina.docx
 
Hi,Write a narrative essay.The topic for this essay Write a.docx
Hi,Write a narrative essay.The topic for this essay Write a.docxHi,Write a narrative essay.The topic for this essay Write a.docx
Hi,Write a narrative essay.The topic for this essay Write a.docx
 
Hi,The paper is Masters degree level. Must be written in APA styl.docx
Hi,The paper is Masters degree level. Must be written in APA styl.docxHi,The paper is Masters degree level. Must be written in APA styl.docx
Hi,The paper is Masters degree level. Must be written in APA styl.docx
 
High and Low Context CommunicationResearch high and low context co.docx
High and Low Context CommunicationResearch high and low context co.docxHigh and Low Context CommunicationResearch high and low context co.docx
High and Low Context CommunicationResearch high and low context co.docx
 
Hi,Please answer all three questions below, also attached textbook.docx
Hi,Please answer all three questions below, also attached textbook.docxHi,Please answer all three questions below, also attached textbook.docx
Hi,Please answer all three questions below, also attached textbook.docx
 
Hi,Please find attached the article and answer the question below.docx
Hi,Please find attached the article and answer the question below.docxHi,Please find attached the article and answer the question below.docx
Hi,Please find attached the article and answer the question below.docx
 
Hi,I want a report about the uploaded case study. These are the .docx
Hi,I want a report about the uploaded case study. These are the .docxHi,I want a report about the uploaded case study. These are the .docx
Hi,I want a report about the uploaded case study. These are the .docx
 
Hi,I need someone to implement my paper in part of1.result&discu.docx
Hi,I need someone to implement my paper in part of1.result&discu.docxHi,I need someone to implement my paper in part of1.result&discu.docx
Hi,I need someone to implement my paper in part of1.result&discu.docx
 
Hi,I have a book discussion in my literature class, the book is .docx
Hi,I have a book discussion in my literature class, the book is .docxHi,I have a book discussion in my literature class, the book is .docx
Hi,I have a book discussion in my literature class, the book is .docx
 
Hi,I got two summaries. Each summary is ONE PAGE.The first.docx
Hi,I got two summaries. Each summary is ONE PAGE.The first.docxHi,I got two summaries. Each summary is ONE PAGE.The first.docx
Hi,I got two summaries. Each summary is ONE PAGE.The first.docx
 
Hi, I need this assingment by tomorrow 12415 at 1159PM. I hav.docx
Hi, I need this assingment by tomorrow 12415 at 1159PM. I hav.docxHi, I need this assingment by tomorrow 12415 at 1159PM. I hav.docx
Hi, I need this assingment by tomorrow 12415 at 1159PM. I hav.docx
 
Hi, I need this discussion question answered by 1159pm tomorrow Fri.docx
Hi, I need this discussion question answered by 1159pm tomorrow Fri.docxHi, I need this discussion question answered by 1159pm tomorrow Fri.docx
Hi, I need this discussion question answered by 1159pm tomorrow Fri.docx
 
Hi,I have three article, what I need is a one page summary of a .docx
Hi,I have three article, what I need is a one page summary of a .docxHi,I have three article, what I need is a one page summary of a .docx
Hi,I have three article, what I need is a one page summary of a .docx
 
Hi, I need help writing an art history paper wondering if you could .docx
Hi, I need help writing an art history paper wondering if you could .docxHi, I need help writing an art history paper wondering if you could .docx
Hi, I need help writing an art history paper wondering if you could .docx
 
Hi, I need help with my papers but I need someone with experience in.docx
Hi, I need help with my papers but I need someone with experience in.docxHi, I need help with my papers but I need someone with experience in.docx
Hi, I need help with my papers but I need someone with experience in.docx
 
Hi, I have an assignment in my religion class, I have uploaded the i.docx
Hi, I have an assignment in my religion class, I have uploaded the i.docxHi, I have an assignment in my religion class, I have uploaded the i.docx
Hi, I have an assignment in my religion class, I have uploaded the i.docx
 
Hi, I need a 3-3.5 page paper about 2 books and a text. First book .docx
Hi, I need a 3-3.5 page paper about 2 books and a text. First book .docxHi, I need a 3-3.5 page paper about 2 books and a text. First book .docx
Hi, I need a 3-3.5 page paper about 2 books and a text. First book .docx
 
Hi, I have an assignment in my behavior in organization class, its .docx
Hi, I have an assignment in my behavior in organization class, its .docxHi, I have an assignment in my behavior in organization class, its .docx
Hi, I have an assignment in my behavior in organization class, its .docx
 

Recently uploaded

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxEyham Joco
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxDr.Ibrahim Hassaan
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxUnboundStockton
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.arsicmarija21
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 

Recently uploaded (20)

Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Types of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptxTypes of Journalistic Writing Grade 8.pptx
Types of Journalistic Writing Grade 8.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Gas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptxGas measurement O2,Co2,& ph) 04/2024.pptx
Gas measurement O2,Co2,& ph) 04/2024.pptx
 
Blooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docxBlooming Together_ Growing a Community Garden Worksheet.docx
Blooming Together_ Growing a Community Garden Worksheet.docx
 
AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.AmericanHighSchoolsprezentacijaoskolama.
AmericanHighSchoolsprezentacijaoskolama.
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 

Data Structures and Algorithm AnalysisSpring 2020 Post Midterm E

  • 1. Data Structures and Algorithm Analysis Spring 2020 Post Midterm Exam – 100 points + 10 bonus NAME: 1. How much memory will the following structures take up? Hint: int takes 4 bytes, float takes 4 bytes, char takes 1 byte. – 9 points a. struct Structure1 {int a,b,c,d,e[10]; float f;}; b. struct Structure2 {int a[12]; float b[5];}; c. struct Structure3 {char a[10][12][4], b[5][5], c[10];}; 2. Show the steps when sorting (smallest to largest) the following arrays of numbers using selection sort i.e. every time a swap occurs, show what the current state of the array looks like, including the final sorted array. – 12 points a. [10, 2, 5, 8, 9, 1, 4, 7]
  • 2. 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. 3. Big-O: What is meant by f(n) = O(g(n))? Give the definition and then explain what it means in your own terms. – 5 points 4. Big-Omega: What is meant by f(n) = Ω(g(n))? Give the definition and then explain what it means in your own terms. – 5 points 5. Show that , make sure you use the definition and justify the inequalities and constants used. - 4 points 6. Show that , make sure you use the definition and justify the inequalities and constants used. - 4 points 7. Show that , make sure you use the definition and justify the
  • 4. inequalities and constants used. - 4 points 8. Show that , make sure you use the definition and justify the inequalities and constants used. - 4 points 9. Show that , make sure you use the definition and justify the inequalities and constants used. - 4 points 10. What principle governs how you add/remove elements in a stack? Spell it out and briefly explain. - 4 points 11. Briefly describe an application of a stack. - 4 points
  • 5. 12. What principle governs how you add/remove elements in a queue? Spell it out and briefly explain. - 4 points 13. Briefly describe an application of a queue. - 4 points Consider the following graph (pseudocode for BFS and DFS given on page 9): 14. Write the order in which the nodes would be visited in when doing a breadth first search (BFS) traversal starting at node 4. Also, write the distances from 4 to every other node. - 6 points 15. Write the order in which the nodes would be visited in when doing a breadth first search (BFS) traversal starting at node 5. Also, write the distances from 5 to every other node. - 6 points
  • 6. Same graph (for your convenience): 16. Write the order in which the nodes would be visited in when doing a depth first search (DFS) traversal starting at node 4 (order discovered or order off the stack). - 6 points 17. Write the order in which the nodes would be visited in when doing a depth first search (DFS) traversal starting at node 5 (order discovered or order off the stack). - 6 points 18. Give the definition of a graph. - 5 points 19. Give the definition of a tree (from graph theory). - 4 points BFS Pseudocode (for graph with n vertices): Input: grapharray[n][n], source
  • 7. queue<int> Q int distance[n] (array to keep track of nodes distances (from source), all values set to -1 except source which is set to 0 i.e. - 1 = not visited) Q.push(source) while(Q is not empty) v = Q.front Q.pop() for each neighbor w of v if distance[w] = -1 print w distance[w] = distance[v]+1 Q.push(w) end if end for end while DFS Pseudocode (for graph with n vertices): Input: grapharray[n][n], source stack<int> S int visited[n] (array to keep track of nodes visited, all values set to 0 except source which is set to 1 i.e. 0 = not visited, 1 = visited) S.push(source) while(S is not empty)
  • 8. 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): Show all of the steps (splitting and merging) when using mergesort to sort (smallest to largest) the following array (they are the numbers 1 through 16): [16, 1, 15, 2, 14, 3, 13, 4, 12, 5, 11, 6, 10, 7, 9, 8]
  • 9. Bonus (2 points): describe how you could implement a queue using 2 stacks. Bonus (4 points) Draw the binary search tree that would be constructed by inserting the following values in the exact order given (starting with an empty tree i.e. first value will be the first node in the tree): - a. Binary Search Tree A: 8, 9, 2, 7, 1, 10, 3, 5, 6, 4
  • 10. b. Binary Search Tree B: 10, 7, 9, 12, 4, 2, 5, 3, 1, 14, 11, 19, 13, 18, 20 11