SlideShare a Scribd company logo
1 of 3
Download to read offline
National School of Business Management
Algorithms and Data Structures
CS106.3 - 16.1 Sessional Examination
Time: 03Hrs
Answer all Questions Date: 29th Mar 2017
Question 1 – 20 Marks
(a) Briefly explain what an algorithm is in the context of Computing. [5 Marks]
(b) Briefly explain, giving an example, how asymptotic analysis can isolate the algorithm
efficiency from the machine and platform dependency. [5 Marks]
(c) Simplify the following Big-O expressions [5 Marks]
i. O(2n3+5n-10)
ii. O(2n2+102n)+O(n)
iii. O(n)*O(log(n))
iv. O(n)+O(log(n))
v. n*O(1)
(d) Giving reasons, evaluate the time complexity of the following function. [5 Marks]
int fact(int n)
{ if(n==1) return 1;
return n*fact(n-1); }
Question 2 - 20 Marks
Following code segment implements the binary search algorithm.
1 first = 0;
2 last = size -1;
3 found = 0;
4 position = -1;
6 while(!found && first <=last) {
7 middle = (first+last)/2;
8 if(array[middle] == key) { found = 1;
9 position = middle; }
10 else if(key<array[middle]) last = middle – 1;
11 else first = middle + 1;
12 }
13 return position;
(a) If the above code segment to write inside a function called bsearch() what will be the
return type and required arguments for the function? Give your answer by writing the
function header including return data type and argument declarations. [5 marks]
(b) Write down a comment line you would include in the above code against each line to
illustrate the function of each line or statement. You do not have to copy the code - just
put the line number and your comment in your answer script. [5marks]
(c) Copy the following table into your answer script and complete it for each iteration for
the problem scenario given below to carry out a desk-check of the code given above.
Variable initially After
iteration 1
After
iteration 2
After
iteration 3
key 23
size 15
first 0
last 14
found 0
position -1
(!found && first <=last) true
middle NA
array[middle] NA
array[]
2 5 9 10 12 15 18 19 23 25 29 30 35 43 45
key =23 [10 Marks]
Question 3 - 20 Marks
The following is a skeleton of a selection sort implementation in C.
int minIndex(float d[], int size){ // return the index of
... // the min in the given array
}
void swap(float *p1, float* p2) { // swap two vars
...
}
void selectionSort(float d[], int size){
...
}
(a) Write C code to implement the above selection sort algorithm. [10 Marks]
(b) Evaluate step by step, giving reasons, the time complexity of each of the above
functions in terms of the Big-O notation. [10 Marks]
Question 4 - 20 Marks
Following code intends to implement a dynamic stack.
struct node{ float data;
struct node* next; };
struct stack{ struct node* sp; };
struct node* makenode(float item){ // make a new node with item
...
}
void init(struct stack * s){...} // initialize sp
int full(struct stack * s){...} // return 1 if full
int empty(struct stack * s){...} // return 1 if empty
int push(struct stack *s, float item){ ...
}
float pop(struct stack *s){ ...
}
float top(struct stack *s){...}
(a) Write a clear diagram to show the status of the stack structure instance, nodes, stored
values and node linking after pushing the values 2.0, 6.2 and 7.0. [6 marks]
(b) Write code for each function above to complete the stack implementation.
[14 Marks]
Question 5 - 20 Marks
(a) Draw a binary search tree generated by inserting the following items in the given order.
23, 45, 12, 4, 56, 9, 13, 15, 24, 3 [4 Marks]
(b) Draw the sequence of items you process, if the BST is traversed by,
i. pre-order,
ii. in-order,
iii. post-order, tree walking methods. [6 marks]
(c) Write down a node structure in C, suitable to implement the above BST. [2 marks]
(d) Write a C function to display the above BST in pre-order traversal. [4 Marks]
(e) Write a C function to find a value (key) in the BST by traversing the BST in pre-order
manner. [4 Marks]

More Related Content

What's hot

FP305 data structure PAPER FINAL SEM 3
FP305 data structure PAPER FINAL SEM 3FP305 data structure PAPER FINAL SEM 3
FP305 data structure PAPER FINAL SEM 3Syahriha Ruslan
 
Directed Acyclic Graph
Directed Acyclic Graph Directed Acyclic Graph
Directed Acyclic Graph AJAL A J
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphsTilakpoudel2
 
Sample presentation slides template
Sample presentation slides templateSample presentation slides template
Sample presentation slides templateValerii Klymchuk
 
A2 Domain and Range
A2 Domain and RangeA2 Domain and Range
A2 Domain and Rangevhiggins1
 
Block diagram, Transfer Function from block diagram reduction, (8 Rules to re...
Block diagram, Transfer Function from block diagram reduction, (8 Rules to re...Block diagram, Transfer Function from block diagram reduction, (8 Rules to re...
Block diagram, Transfer Function from block diagram reduction, (8 Rules to re...Waqas Afzal
 
09 bsc-17 dsp lab 10-1
09 bsc-17 dsp lab 10-109 bsc-17 dsp lab 10-1
09 bsc-17 dsp lab 10-1Jannat41
 
openMP loop parallelization
openMP loop parallelizationopenMP loop parallelization
openMP loop parallelizationAlbert DeFusco
 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordLakshmi Sarvani Videla
 
Excel macro to generate prime numbers
Excel macro to generate prime numbersExcel macro to generate prime numbers
Excel macro to generate prime numbersUpendra Lele
 
4Developers 2015: Clean JavaScript code - only dream or reality - Sebastian Ł...
4Developers 2015: Clean JavaScript code - only dream or reality - Sebastian Ł...4Developers 2015: Clean JavaScript code - only dream or reality - Sebastian Ł...
4Developers 2015: Clean JavaScript code - only dream or reality - Sebastian Ł...PROIDEA
 
Ec2203 digital electronics questions anna university by www.annaunivedu.org
Ec2203 digital electronics questions anna university by www.annaunivedu.orgEc2203 digital electronics questions anna university by www.annaunivedu.org
Ec2203 digital electronics questions anna university by www.annaunivedu.organnaunivedu
 

What's hot (17)

FP305 data structure PAPER FINAL SEM 3
FP305 data structure PAPER FINAL SEM 3FP305 data structure PAPER FINAL SEM 3
FP305 data structure PAPER FINAL SEM 3
 
Directed Acyclic Graph
Directed Acyclic Graph Directed Acyclic Graph
Directed Acyclic Graph
 
Implementation
ImplementationImplementation
Implementation
 
Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphs
 
Sample presentation slides template
Sample presentation slides templateSample presentation slides template
Sample presentation slides template
 
A2 Domain and Range
A2 Domain and RangeA2 Domain and Range
A2 Domain and Range
 
Ss matlab solved
Ss matlab solvedSs matlab solved
Ss matlab solved
 
Block diagram, Transfer Function from block diagram reduction, (8 Rules to re...
Block diagram, Transfer Function from block diagram reduction, (8 Rules to re...Block diagram, Transfer Function from block diagram reduction, (8 Rules to re...
Block diagram, Transfer Function from block diagram reduction, (8 Rules to re...
 
Lecture two
Lecture twoLecture two
Lecture two
 
09 bsc-17 dsp lab 10-1
09 bsc-17 dsp lab 10-109 bsc-17 dsp lab 10-1
09 bsc-17 dsp lab 10-1
 
openMP loop parallelization
openMP loop parallelizationopenMP loop parallelization
openMP loop parallelization
 
Introduction to Data Science With R Lab Record
Introduction to Data Science With R Lab RecordIntroduction to Data Science With R Lab Record
Introduction to Data Science With R Lab Record
 
Excel macro to generate prime numbers
Excel macro to generate prime numbersExcel macro to generate prime numbers
Excel macro to generate prime numbers
 
Ezmath
EzmathEzmath
Ezmath
 
4Developers 2015: Clean JavaScript code - only dream or reality - Sebastian Ł...
4Developers 2015: Clean JavaScript code - only dream or reality - Sebastian Ł...4Developers 2015: Clean JavaScript code - only dream or reality - Sebastian Ł...
4Developers 2015: Clean JavaScript code - only dream or reality - Sebastian Ł...
 
Permute
PermutePermute
Permute
 
Ec2203 digital electronics questions anna university by www.annaunivedu.org
Ec2203 digital electronics questions anna university by www.annaunivedu.orgEc2203 digital electronics questions anna university by www.annaunivedu.org
Ec2203 digital electronics questions anna university by www.annaunivedu.org
 

Similar to National School of Business Management Algorithms and Data Structures CS106.3 - 16.1 Sessional Examination

Computer science ms
Computer science msComputer science ms
Computer science msB Bhuvanesh
 
09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structures09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structuresjntuworld
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docxjosies1
 
xii-ip-support-material.pdf
xii-ip-support-material.pdfxii-ip-support-material.pdf
xii-ip-support-material.pdfkajalkhorwal106
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentationManchireddy Reddy
 
Sp 1418794917
Sp 1418794917Sp 1418794917
Sp 1418794917lakshmi r
 
Computer Science Sample Paper 2
Computer Science Sample Paper 2Computer Science Sample Paper 2
Computer Science Sample Paper 2kvs
 
CS Sample Paper 1
CS Sample Paper 1CS Sample Paper 1
CS Sample Paper 1kvs
 
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21chinthala Vijaya Kumar
 
11th information practices paper CBSE INDIA 2012 2013
11th information practices paper CBSE INDIA 2012 201311th information practices paper CBSE INDIA 2012 2013
11th information practices paper CBSE INDIA 2012 2013Harish Gyanani
 
Technical aptitude test 2 CSE
Technical aptitude test 2 CSETechnical aptitude test 2 CSE
Technical aptitude test 2 CSESujata Regoti
 
90 Informatics Practices.pdf
90 Informatics Practices.pdf90 Informatics Practices.pdf
90 Informatics Practices.pdfvikas500500
 
MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfahmed8651
 

Similar to National School of Business Management Algorithms and Data Structures CS106.3 - 16.1 Sessional Examination (20)

Doc 20180130-wa0005
Doc 20180130-wa0005Doc 20180130-wa0005
Doc 20180130-wa0005
 
Doc 20180130-wa0004-1
Doc 20180130-wa0004-1Doc 20180130-wa0004-1
Doc 20180130-wa0004-1
 
Computer science ms
Computer science msComputer science ms
Computer science ms
 
09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structures09 a1ec01 c programming and data structures
09 a1ec01 c programming and data structures
 
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
Task4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docxTask4output.txt 2  5  9 13 15 10  1  0  3  7 11 14 1.docx
Task4output.txt 2 5 9 13 15 10 1 0 3 7 11 14 1.docx
 
xii-ip-support-material.pdf
xii-ip-support-material.pdfxii-ip-support-material.pdf
xii-ip-support-material.pdf
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 
Sp 1418794917
Sp 1418794917Sp 1418794917
Sp 1418794917
 
Computer Science Sample Paper 2
Computer Science Sample Paper 2Computer Science Sample Paper 2
Computer Science Sample Paper 2
 
CS Sample Paper 1
CS Sample Paper 1CS Sample Paper 1
CS Sample Paper 1
 
Cs101 endsem 2014
Cs101 endsem 2014Cs101 endsem 2014
Cs101 endsem 2014
 
Cs practical file
Cs practical fileCs practical file
Cs practical file
 
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
CBSE Class 12 Computer Science(083) Sample Question Paper 2020-21
 
11th information practices paper CBSE INDIA 2012 2013
11th information practices paper CBSE INDIA 2012 201311th information practices paper CBSE INDIA 2012 2013
11th information practices paper CBSE INDIA 2012 2013
 
Technical aptitude test 2 CSE
Technical aptitude test 2 CSETechnical aptitude test 2 CSE
Technical aptitude test 2 CSE
 
CS_PQMS.pdf
CS_PQMS.pdfCS_PQMS.pdf
CS_PQMS.pdf
 
6th Semester (June; July-2015) Computer Science and Information Science Engin...
6th Semester (June; July-2015) Computer Science and Information Science Engin...6th Semester (June; July-2015) Computer Science and Information Science Engin...
6th Semester (June; July-2015) Computer Science and Information Science Engin...
 
90 Informatics Practices.pdf
90 Informatics Practices.pdf90 Informatics Practices.pdf
90 Informatics Practices.pdf
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
 
MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdf
 

More from HarithaRanasinghe (20)

Session12 pointers
Session12 pointersSession12 pointers
Session12 pointers
 
Session11 single dimarrays
Session11 single dimarraysSession11 single dimarrays
Session11 single dimarrays
 
Session09 multi dimarrays
Session09 multi dimarraysSession09 multi dimarrays
Session09 multi dimarrays
 
Session07 recursion
Session07 recursionSession07 recursion
Session07 recursion
 
Session06 functions
Session06 functionsSession06 functions
Session06 functions
 
Session05 iteration structure
Session05 iteration structureSession05 iteration structure
Session05 iteration structure
 
Session04 selection structure_b
Session04 selection structure_bSession04 selection structure_b
Session04 selection structure_b
 
Session04 selection structure_a
Session04 selection structure_aSession04 selection structure_a
Session04 selection structure_a
 
Session03 operators
Session03 operatorsSession03 operators
Session03 operators
 
Session02 c intro
Session02 c introSession02 c intro
Session02 c intro
 
Session01 basics programming
Session01 basics programmingSession01 basics programming
Session01 basics programming
 
Program flow charts
Program flow chartsProgram flow charts
Program flow charts
 
Sad -sample_paper
Sad  -sample_paperSad  -sample_paper
Sad -sample_paper
 
Sad sample paper - mcq answers
Sad   sample paper - mcq answersSad   sample paper - mcq answers
Sad sample paper - mcq answers
 
Paper
PaperPaper
Paper
 
Model questions
Model questionsModel questions
Model questions
 
Model paper algorithms and data structures
Model paper  algorithms and data structuresModel paper  algorithms and data structures
Model paper algorithms and data structures
 
Doc 20180208-wa0001
Doc 20180208-wa0001Doc 20180208-wa0001
Doc 20180208-wa0001
 
Doc 20180130-wa0003
Doc 20180130-wa0003Doc 20180130-wa0003
Doc 20180130-wa0003
 
Doc 20180130-wa0002
Doc 20180130-wa0002Doc 20180130-wa0002
Doc 20180130-wa0002
 

Recently uploaded

Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Recently uploaded (20)

Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

National School of Business Management Algorithms and Data Structures CS106.3 - 16.1 Sessional Examination

  • 1. National School of Business Management Algorithms and Data Structures CS106.3 - 16.1 Sessional Examination Time: 03Hrs Answer all Questions Date: 29th Mar 2017 Question 1 – 20 Marks (a) Briefly explain what an algorithm is in the context of Computing. [5 Marks] (b) Briefly explain, giving an example, how asymptotic analysis can isolate the algorithm efficiency from the machine and platform dependency. [5 Marks] (c) Simplify the following Big-O expressions [5 Marks] i. O(2n3+5n-10) ii. O(2n2+102n)+O(n) iii. O(n)*O(log(n)) iv. O(n)+O(log(n)) v. n*O(1) (d) Giving reasons, evaluate the time complexity of the following function. [5 Marks] int fact(int n) { if(n==1) return 1; return n*fact(n-1); } Question 2 - 20 Marks Following code segment implements the binary search algorithm. 1 first = 0; 2 last = size -1; 3 found = 0; 4 position = -1; 6 while(!found && first <=last) { 7 middle = (first+last)/2; 8 if(array[middle] == key) { found = 1; 9 position = middle; } 10 else if(key<array[middle]) last = middle – 1; 11 else first = middle + 1; 12 } 13 return position;
  • 2. (a) If the above code segment to write inside a function called bsearch() what will be the return type and required arguments for the function? Give your answer by writing the function header including return data type and argument declarations. [5 marks] (b) Write down a comment line you would include in the above code against each line to illustrate the function of each line or statement. You do not have to copy the code - just put the line number and your comment in your answer script. [5marks] (c) Copy the following table into your answer script and complete it for each iteration for the problem scenario given below to carry out a desk-check of the code given above. Variable initially After iteration 1 After iteration 2 After iteration 3 key 23 size 15 first 0 last 14 found 0 position -1 (!found && first <=last) true middle NA array[middle] NA array[] 2 5 9 10 12 15 18 19 23 25 29 30 35 43 45 key =23 [10 Marks] Question 3 - 20 Marks The following is a skeleton of a selection sort implementation in C. int minIndex(float d[], int size){ // return the index of ... // the min in the given array } void swap(float *p1, float* p2) { // swap two vars ... } void selectionSort(float d[], int size){ ... }
  • 3. (a) Write C code to implement the above selection sort algorithm. [10 Marks] (b) Evaluate step by step, giving reasons, the time complexity of each of the above functions in terms of the Big-O notation. [10 Marks] Question 4 - 20 Marks Following code intends to implement a dynamic stack. struct node{ float data; struct node* next; }; struct stack{ struct node* sp; }; struct node* makenode(float item){ // make a new node with item ... } void init(struct stack * s){...} // initialize sp int full(struct stack * s){...} // return 1 if full int empty(struct stack * s){...} // return 1 if empty int push(struct stack *s, float item){ ... } float pop(struct stack *s){ ... } float top(struct stack *s){...} (a) Write a clear diagram to show the status of the stack structure instance, nodes, stored values and node linking after pushing the values 2.0, 6.2 and 7.0. [6 marks] (b) Write code for each function above to complete the stack implementation. [14 Marks] Question 5 - 20 Marks (a) Draw a binary search tree generated by inserting the following items in the given order. 23, 45, 12, 4, 56, 9, 13, 15, 24, 3 [4 Marks] (b) Draw the sequence of items you process, if the BST is traversed by, i. pre-order, ii. in-order, iii. post-order, tree walking methods. [6 marks] (c) Write down a node structure in C, suitable to implement the above BST. [2 marks] (d) Write a C function to display the above BST in pre-order traversal. [4 Marks] (e) Write a C function to find a value (key) in the BST by traversing the BST in pre-order manner. [4 Marks]