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

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
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 

Recently uploaded (20)

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
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 

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]