SlideShare uma empresa Scribd logo
1 de 4
Baixar para ler offline
National School of Business Management
Algorithms and Data Structures
CS106.3 - 16.2 Examination
Time: 03Hrs
Answer all Questions Date: 2017
Question 1 – 20 Marks
(a) What is asymptotic analysis in the context of evaluation of Algorithms? [5 Marks]
(b) Simplify the following Big-O expressions [10 Marks]
i. O(10n4-n2-10)
ii. O(2n3+102n) * O(n)
iii. O(n2) + O(5*log(n))
iv. O(n2) * O(5*log(n))
v. n2*O(n2)
(c) Giving reasons, evaluate the time complexity of the following function. [5 Marks]
int swapping;
do {
for(i=0,swapping=0;i<size-1;i++)
if(data[i]>data[i+1]) { temp=data[i];
data[i]=data[i+1];
data[i+1]=temp;
swapping=1;
}
} while(swapping)
Question 2 - 20 Marks
Following loop implements the insertion sort algorithm.
1 for(k=1; k<size; k++){
2 for(i=0; i<k && d[i]<=d[k]; i++);
3 temp=d[k];
4 for(l=k;l>i;l--) d[l]=d[l-1];
5 d[i]=temp;
6 }
(a) Write a complete C function to implement the insertion sort algorithm. [5 marks]
(b) Write down a comment line for each and every line in the above C function in part (a). If
necessary number the lines in the C function and write the comments separately with
the line numbers. [5marks]
(c) Copy the following table into your answer script and complete it for each iteration of the
outer loop (loop using k) 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
After
iteration
4
…
Array d[] 12,25,9,2,
20,15,8
size 7
k 1
d[k] 25
i NA
d[i] NA
Problem Scenario:
array[]
12 25 9 2 20 15 8
[10 Marks]
Question 3 - 20 Marks
(a) Show diagrammatically, the operation of a queue implemented via a circular array
assuming the array size to be 8. Draw diagrams to show the status of the queue for the
following, clearly indicating the position of the head/front and tail/rear.
i. empty queue
ii. after enqueueing 4 items; 12, 23, 8 and 15
iii. full queue [6 Marks]
(b) Suggest a method to differentiate an empty queue (in section (a) above) from a full
queue by comparing the values of head and tail. [5 Marks]
(c) Implement 3 functions, including either enqueue() or dequeue(), of the queue
specification given below. Utilize your suggestion in part (b) above. [9 Marks]
struct queue { int head, tail;
int data[size]; };
int enqueue(struct queue *q, int item);
int dequeue(struct queue*q);
int init(struct queue* q); // set head and tail
int full(struct queue* q); // return 1 if full
int empty(struct queue* q); // return 1 if empty
Question 4 - 20 Marks
Following incomplete code segment intends to implement the linear search algorithm.
int lsearch(float data[], int size, float key){
int found = 0;
int position = –1;
int index = 0;
(a) Complete the above code to using appropriate syntax. [6 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. [4 marks]
Following lines were extracted from a typical linked list implementation prototype in C.
// data structure for a node
struct node { float data;
struct node* next;};
//creates a node with data value (item) & returns the node address
struct node* makeNode(float item);
// add a new node to the head
struct node* addHead(struct node** list, float item);
// add a new node to the tail
struct node* addTail(struct node** list, float item);
(c) Write code for the above three functions to derive the linked list implementation.
[10 marks]
Question 5 - 20 Marks
(a) Draw a binary search tree (BST) generated by inserting the following items in the given
order.
54, 15, 12, 64, 51, 9, 85, 15, 24, 3 [6 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 return the minimum value stored in a BST. [4 Marks]
(e) Explain the use of tree data structure in a computer application. [2 Marks]

Mais conteúdo relacionado

Mais procurados

Mais procurados (19)

Implementation
ImplementationImplementation
Implementation
 
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
 
Chapter 6 Matrices in MATLAB
Chapter 6 Matrices in MATLABChapter 6 Matrices in MATLAB
Chapter 6 Matrices in MATLAB
 
Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)Counting sort(Non Comparison Sort)
Counting sort(Non Comparison Sort)
 
X10707 (me8691)
X10707 (me8691)X10707 (me8691)
X10707 (me8691)
 
chapter-8.ppt
chapter-8.pptchapter-8.ppt
chapter-8.ppt
 
Cs101 endsem 2014
Cs101 endsem 2014Cs101 endsem 2014
Cs101 endsem 2014
 
Data Structures- Hashing
Data Structures- Hashing Data Structures- Hashing
Data Structures- Hashing
 
Digital logic design1
Digital logic design1Digital logic design1
Digital logic design1
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Lumpkin Graphing functions
Lumpkin Graphing functionsLumpkin Graphing functions
Lumpkin Graphing functions
 
EC202 SIGNALS & SYSTEMS PREVIOUS QUESTION PAPER
EC202 SIGNALS & SYSTEMS PREVIOUS QUESTION PAPEREC202 SIGNALS & SYSTEMS PREVIOUS QUESTION PAPER
EC202 SIGNALS & SYSTEMS PREVIOUS QUESTION PAPER
 
Data Visualization With R: Learn To Combine Multiple Graphs
Data Visualization With R: Learn To Combine Multiple GraphsData Visualization With R: Learn To Combine Multiple Graphs
Data Visualization With R: Learn To Combine Multiple Graphs
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
Graphing functions
Graphing functionsGraphing functions
Graphing functions
 
Queue
QueueQueue
Queue
 
[Question Paper] Introduction To C++ Programming (Revised Course) [January / ...
[Question Paper] Introduction To C++ Programming (Revised Course) [January / ...[Question Paper] Introduction To C++ Programming (Revised Course) [January / ...
[Question Paper] Introduction To C++ Programming (Revised Course) [January / ...
 
Quiz 10 cp_sol
Quiz 10 cp_solQuiz 10 cp_sol
Quiz 10 cp_sol
 
Ch3
Ch3Ch3
Ch3
 

Semelhante a Doc 20180130-wa0004

pleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfpleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdf
wasemanivytreenrco51
 
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
jntuworld
 

Semelhante a Doc 20180130-wa0004 (20)

Computer science ms
Computer science msComputer science ms
Computer science ms
 
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...
 
Computer Science Sample Paper 2
Computer Science Sample Paper 2Computer Science Sample Paper 2
Computer Science Sample Paper 2
 
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov"Optimization of a .NET application- is it simple ! / ?",  Yevhen Tatarynov
"Optimization of a .NET application- is it simple ! / ?", Yevhen Tatarynov
 
Data structure manual
Data structure manualData structure manual
Data structure manual
 
Sp 1418794917
Sp 1418794917Sp 1418794917
Sp 1418794917
 
CS Sample Paper 1
CS Sample Paper 1CS Sample Paper 1
CS Sample Paper 1
 
Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”Rainer Grimm, “Functional Programming in C++11”
Rainer Grimm, “Functional Programming in C++11”
 
7th Semester (Dec-2015; Jan-2016) Computer Science and Information Science En...
7th Semester (Dec-2015; Jan-2016) Computer Science and Information Science En...7th Semester (Dec-2015; Jan-2016) Computer Science and Information Science En...
7th Semester (Dec-2015; Jan-2016) Computer Science and Information Science En...
 
Bcsl 033 solve assignment
Bcsl 033 solve assignmentBcsl 033 solve assignment
Bcsl 033 solve assignment
 
pleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdfpleaase I want manual solution forData Structures and Algorithm An.pdf
pleaase I want manual solution forData Structures and Algorithm An.pdf
 
Vtu cs 7th_sem_question_papers
Vtu cs 7th_sem_question_papersVtu cs 7th_sem_question_papers
Vtu cs 7th_sem_question_papers
 
Lab-2.4 101.pdf
Lab-2.4 101.pdfLab-2.4 101.pdf
Lab-2.4 101.pdf
 
8th Semester (June; July-2015) Computer Science and Information Science Engin...
8th Semester (June; July-2015) Computer Science and Information Science Engin...8th Semester (June; July-2015) Computer Science and Information Science Engin...
8th Semester (June; July-2015) Computer Science and Information Science Engin...
 
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
 
FSOFT - Test Java Exam
FSOFT - Test Java ExamFSOFT - Test Java Exam
FSOFT - Test Java Exam
 
Adobe
AdobeAdobe
Adobe
 
CS_PQMS.pdf
CS_PQMS.pdfCS_PQMS.pdf
CS_PQMS.pdf
 
Ds important questions
Ds important questionsDs important questions
Ds important questions
 
5th Semester (June; July-2015) Computer Science and Information Science Engin...
5th Semester (June; July-2015) Computer Science and Information Science Engin...5th Semester (June; July-2015) Computer Science and Information Science Engin...
5th Semester (June; July-2015) Computer Science and Information Science Engin...
 

Mais de 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-wa0005
Doc 20180130-wa0005Doc 20180130-wa0005
Doc 20180130-wa0005
 
Doc 20180130-wa0004-1
Doc 20180130-wa0004-1Doc 20180130-wa0004-1
Doc 20180130-wa0004-1
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

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
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Doc 20180130-wa0004

  • 1. National School of Business Management Algorithms and Data Structures CS106.3 - 16.2 Examination Time: 03Hrs Answer all Questions Date: 2017 Question 1 – 20 Marks (a) What is asymptotic analysis in the context of evaluation of Algorithms? [5 Marks] (b) Simplify the following Big-O expressions [10 Marks] i. O(10n4-n2-10) ii. O(2n3+102n) * O(n) iii. O(n2) + O(5*log(n)) iv. O(n2) * O(5*log(n)) v. n2*O(n2) (c) Giving reasons, evaluate the time complexity of the following function. [5 Marks] int swapping; do { for(i=0,swapping=0;i<size-1;i++) if(data[i]>data[i+1]) { temp=data[i]; data[i]=data[i+1]; data[i+1]=temp; swapping=1; } } while(swapping) Question 2 - 20 Marks Following loop implements the insertion sort algorithm. 1 for(k=1; k<size; k++){ 2 for(i=0; i<k && d[i]<=d[k]; i++); 3 temp=d[k]; 4 for(l=k;l>i;l--) d[l]=d[l-1]; 5 d[i]=temp; 6 }
  • 2. (a) Write a complete C function to implement the insertion sort algorithm. [5 marks] (b) Write down a comment line for each and every line in the above C function in part (a). If necessary number the lines in the C function and write the comments separately with the line numbers. [5marks] (c) Copy the following table into your answer script and complete it for each iteration of the outer loop (loop using k) 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 After iteration 4 … Array d[] 12,25,9,2, 20,15,8 size 7 k 1 d[k] 25 i NA d[i] NA Problem Scenario: array[] 12 25 9 2 20 15 8 [10 Marks] Question 3 - 20 Marks (a) Show diagrammatically, the operation of a queue implemented via a circular array assuming the array size to be 8. Draw diagrams to show the status of the queue for the following, clearly indicating the position of the head/front and tail/rear. i. empty queue ii. after enqueueing 4 items; 12, 23, 8 and 15 iii. full queue [6 Marks] (b) Suggest a method to differentiate an empty queue (in section (a) above) from a full queue by comparing the values of head and tail. [5 Marks] (c) Implement 3 functions, including either enqueue() or dequeue(), of the queue specification given below. Utilize your suggestion in part (b) above. [9 Marks]
  • 3. struct queue { int head, tail; int data[size]; }; int enqueue(struct queue *q, int item); int dequeue(struct queue*q); int init(struct queue* q); // set head and tail int full(struct queue* q); // return 1 if full int empty(struct queue* q); // return 1 if empty Question 4 - 20 Marks Following incomplete code segment intends to implement the linear search algorithm. int lsearch(float data[], int size, float key){ int found = 0; int position = –1; int index = 0; (a) Complete the above code to using appropriate syntax. [6 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. [4 marks] Following lines were extracted from a typical linked list implementation prototype in C. // data structure for a node struct node { float data; struct node* next;}; //creates a node with data value (item) & returns the node address struct node* makeNode(float item); // add a new node to the head struct node* addHead(struct node** list, float item); // add a new node to the tail struct node* addTail(struct node** list, float item); (c) Write code for the above three functions to derive the linked list implementation. [10 marks]
  • 4. Question 5 - 20 Marks (a) Draw a binary search tree (BST) generated by inserting the following items in the given order. 54, 15, 12, 64, 51, 9, 85, 15, 24, 3 [6 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 return the minimum value stored in a BST. [4 Marks] (e) Explain the use of tree data structure in a computer application. [2 Marks]