SlideShare a Scribd company logo
Page | 1
PART 1 – Multiple Choice Questions
1. Which of the following is FALSE about linked lists
A. The data structure includes the link to another object of the same type
B. The data set are stored in contiguous order in memory
C. The size is dynamic during run-time
D. Memory is allocated at run-time
2. The advantage of arrays over linked lists is
A. Direct access
B. Less memory usage
C. Easier to implement
D. Dynamic memory allocation
3. Which of the following structures is suitable to keep track of a sequence printing jobs
sent to a network printer?
A. Trees
B. Stack
C. Queues
D. Lists
4. The following problems best solved using stack structures, EXCEPT
A. Balancing of parenthesis
B. Evaluation of postfix expressions
C. Removal of items in random order
D. Evaluation of functions containing recursive calls
5. Given the following sequence of operations performed on a stack:
push (5.0), push (9.5), pop, push (27.5), push (12.7), push (0), pop, pop, push
(31.2)
What will be the sequence of items in the stack as a result?
A. 31.2 0.0 12.7 27.5 9.5 5.0
B. 27.5 9.5 5.0
C. 3.12 27.5 5.0
D. Stack is empty
Page | 2
6. Suppose myList is an object of List data structure, and myList.displayList() produces the
following output:
28 7 76 48 70
What would be the output when the following statements are executed?
myList.InsertNode(2, 10);
myList.DisplayList();
A. 10 28 7 76 48 70
B. 28 7 76 10 48 70
C. 28 7 76 48 70 10
D. 28 7 10 76 48 70
7. Suppose an array myArr contains the following sequences of integers:
28 7 76 48 70
What would be resulting sequence of MyArr when the following statement is executed?
myArr [2] = 10;
A. 10 28 7 76 48
B. 28 7 76 10 48
C. 28 7 10 48 70
D. 7 10 76 48 70
8. Which of the following is FALSE when using recursion
A. The recursions must be assumed to work all the time
B. You must have a base case which can be solved without recursion
C. The recursive call must always make progress towards the base case
D. The recursive calls must always be compounded in multiple recursive calls
9. How many times will the symbol ‘#’ be printed by the call foo (4)?
void foo (int i) {
if (i > 1) {
foo (i/2);
foo (i/2);
}
cout << "#";
}
A. 6
B. 7
C. 8
D. 9
Page | 3
10. Which of the following statements about QUEUES is FALSE ?
A. New items can only be inserted at the end position
B. The items are processed in a queue on a First in First out basis
C. The main operations of a queue is enqueueing and dequeueing
D. Items cannot be removed from a queue at the beginning of queue
11. In linked lists, there are no NULL links in
A. linear doubly linked list
B. circular linked list
C. single linked list
D. All of the above
12. The range of 4-bits unsigned integer is between:
A. 0 to 15
B. 1 to 16
C. -7 to 8
D. -15 to 14
13. When a new node is inserted in between a linked list, which of these is TRUE:
A. nodes appearing after the new node needs to be moved
B. nodes appearing before the new node needs to be moved
C. nodes appearing before and after the new node need to be moved
D. None of the above
14. One DIFFERENCE between a queue and a stack is:
A. Queues require linked lists, but stacks require array
B. Stacks require linked lists, but queues require array
C. Queues use two ends of the structure; stacks use only one.
D. Stacks use two ends of the structure; queues use only one.
15. The address of an element [i, j] in a m × n matrix based on the column-wise order can be ______
A. m * ( i – 2 ) + j
B. m * ( j – 2 ) + i
C. n* ( i – 1 ) + j
D. n* ( i – 1) + (j – 1)
Page | 4
PART 2 – Short Answer Questions
1. Given the following code:
#include <iostream>
using namespace std;
int myfunction(int);
int main () {
int input, answer;
cout <<"Enter an integer: ";
cin >> input;
answer = myfunction(input);
cout << endl<<"The answer "<<input<< "! is " << answer;
return 0;
}
int myfunction (int num) {
cout <<"Fib " << num<< " is " ;
if (num == 0)
return 0;
else (num == 1)
return 1;
else
return myfunction (num-1) + myfunction (num-2);
}
Write the output of the program if the user types 4 as input?
2. Discuss the pros and cons of choosing linked list implementation for lists, stacks
and queues.
3. Suppose a queue called myQueue is implemented using a circular array of
MAXSIZE = 7. Illustrate to show the step-by-step effects in myQueue if the following
sequence of statements is executed:
myQueue.enqueue (‘F’)
myQueue.enqueue (‘C’)
myQueue.enqueue (‘Q’)
myQueue.dequeue
myQueue.enqueue (‘X’)
myQueue.enqueue (‘Z’)
myQueue.dequeue
myQueue.enqueue (‘L’)
myQueue.enqueue (‘S’)
myQueue.enqueue (‘W’)
myQueue.enqueue (‘C’)
myQueue.dequeue
Page | 5
4. In C++, a variable that stores integer values can be declared as short (2 bytes or
16 bits) or int (bytes or 32 bits). Furthermore, floating-point numbers can be
declared as float (4 bytes or 32 bits) or double (8 bytes or 64 bits) based on the
IEEE Standard for Floating Point Arithmetic (IEEE-754).
Determine the corresponding binary values that are stored in the computer for the
following variable declarations:
a. unsigned short a = 15;
b. short b = -15;
c. float c = -52.25
5. Use stacks to show the step-by-step evaluation of the post-fix expression given
below:
5.2 2.0 1.5 * + 4.0 2.0 2.0 ^ * -
6. Given below is a recursive method of function f for the value x. Write an equivalent
program segment using iterative method.
int f (int x){
if (x == 0)
return 0;
else
return 2 * f (x – 1) + x * x;
}
7. The elements in an array may be stored based on a row-wise or column-wise
arrangement depending on the programming language used.
Suppose the dimensions of an array myGoodArray are 7X9X8.
Given the address of myGoodArray [4, z, 3] based on the column-wise method is
438, when the base address (B) is 10, with size of each element (W) is 2, and lowest
index of each dimension is 0,
a. Find z.
b. Determine the address of the same element if it is implemented in row-wise
method.
8. Write an algorithm which checks if the brackets in an expression are balanced and
reports an error if the matching brackets is missing.

More Related Content

What's hot

Class xi sample paper (Computer Science)
Class xi sample paper (Computer Science)Class xi sample paper (Computer Science)
Class xi sample paper (Computer Science)
MountAbuRohini
 
CDAC CCAT examination important question
CDAC CCAT examination important questionCDAC CCAT examination important question
CDAC CCAT examination important question
prabhatjon
 

What's hot (19)

Class xi sample paper (Computer Science)
Class xi sample paper (Computer Science)Class xi sample paper (Computer Science)
Class xi sample paper (Computer Science)
 
Cplus plus abd datastructure
Cplus plus abd datastructureCplus plus abd datastructure
Cplus plus abd datastructure
 
Directed Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocksDirected Acyclic Graph Representation of basic blocks
Directed Acyclic Graph Representation of basic blocks
 
important C questions and_answers praveensomesh
important C questions and_answers praveensomeshimportant C questions and_answers praveensomesh
important C questions and_answers praveensomesh
 
Assignment
AssignmentAssignment
Assignment
 
Core java
Core javaCore java
Core java
 
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
 
Aloha paper for cdac ccpp
Aloha paper  for  cdac ccppAloha paper  for  cdac ccpp
Aloha paper for cdac ccpp
 
CDAC CCAT examination important question
CDAC CCAT examination important questionCDAC CCAT examination important question
CDAC CCAT examination important question
 
Assignment week0 c++
Assignment  week0 c++Assignment  week0 c++
Assignment week0 c++
 
Computer science ms
Computer science msComputer science ms
Computer science ms
 
6th Semester (Dec-2015; Jan-2016) Computer Science and Information Science En...
6th Semester (Dec-2015; Jan-2016) Computer Science and Information Science En...6th Semester (Dec-2015; Jan-2016) Computer Science and Information Science En...
6th Semester (Dec-2015; Jan-2016) Computer Science and Information Science En...
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guide
 
Oops Paper
Oops PaperOops Paper
Oops Paper
 
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...
 
C and data structure
C and data structureC and data structure
C and data structure
 
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
 
CLASS XII COMPUTER SCIENCE MONTHLY TEST PAPER
CLASS XII COMPUTER SCIENCE MONTHLY TEST  PAPERCLASS XII COMPUTER SCIENCE MONTHLY TEST  PAPER
CLASS XII COMPUTER SCIENCE MONTHLY TEST PAPER
 
Sample paper i.p
Sample paper i.pSample paper i.p
Sample paper i.p
 

Similar to Redo midterm

Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
maxinesmith73660
 
Data structure using c bcse 3102 pcs 1002
Data structure using c bcse 3102 pcs 1002Data structure using c bcse 3102 pcs 1002
Data structure using c bcse 3102 pcs 1002
SANTOSH RATH
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
rosemarybdodson23141
 

Similar to Redo midterm (20)

Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
 
Computer science sqp
Computer science sqpComputer science sqp
Computer science sqp
 
Ds qb 2021 rma
Ds qb 2021 rmaDs qb 2021 rma
Ds qb 2021 rma
 
MATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdfMATLAB Questions and Answers.pdf
MATLAB Questions and Answers.pdf
 
Cs101 endsem 2014
Cs101 endsem 2014Cs101 endsem 2014
Cs101 endsem 2014
 
CBSE XI COMPUTER SCIENCE
CBSE XI COMPUTER SCIENCECBSE XI COMPUTER SCIENCE
CBSE XI COMPUTER SCIENCE
 
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
 
Gate Previous Years Papers
Gate Previous Years PapersGate Previous Years Papers
Gate Previous Years Papers
 
Topic 2_revised.pptx
Topic 2_revised.pptxTopic 2_revised.pptx
Topic 2_revised.pptx
 
Data structure using c bcse 3102 pcs 1002
Data structure using c bcse 3102 pcs 1002Data structure using c bcse 3102 pcs 1002
Data structure using c bcse 3102 pcs 1002
 
Adobe
AdobeAdobe
Adobe
 
Dat 305 dat305 dat 305 education for service uopstudy.com
Dat 305 dat305 dat 305 education for service   uopstudy.comDat 305 dat305 dat 305 education for service   uopstudy.com
Dat 305 dat305 dat 305 education for service uopstudy.com
 
Cbse marking scheme 2006 2011
Cbse marking scheme 2006  2011Cbse marking scheme 2006  2011
Cbse marking scheme 2006 2011
 
1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional1z0 851 exam-java standard edition 6 programmer certified professional
1z0 851 exam-java standard edition 6 programmer certified professional
 
MCQs on Stacks.pdf
MCQs on Stacks.pdfMCQs on Stacks.pdf
MCQs on Stacks.pdf
 
MCQs on Stacks.pdf
MCQs on Stacks.pdfMCQs on Stacks.pdf
MCQs on Stacks.pdf
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
 
Technical aptitude questions_e_book1
Technical aptitude questions_e_book1Technical aptitude questions_e_book1
Technical aptitude questions_e_book1
 

More from IIUM (20)

How to use_000webhost
How to use_000webhostHow to use_000webhost
How to use_000webhost
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Kreydle internship-multimedia
Kreydle internship-multimediaKreydle internship-multimedia
Kreydle internship-multimedia
 
03phpbldgblock
03phpbldgblock03phpbldgblock
03phpbldgblock
 
Chap2 practice key
Chap2 practice keyChap2 practice key
Chap2 practice key
 
Group p1
Group p1Group p1
Group p1
 
Tutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seoTutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seo
 
Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009
 
03 the htm_lforms
03 the htm_lforms03 the htm_lforms
03 the htm_lforms
 
Exercise on algo analysis answer
Exercise on algo analysis   answerExercise on algo analysis   answer
Exercise on algo analysis answer
 
Heaps
HeapsHeaps
Heaps
 
Report format
Report formatReport format
Report format
 
Edpuzzle guidelines
Edpuzzle guidelinesEdpuzzle guidelines
Edpuzzle guidelines
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
 
Group assignment 1 s21516
Group assignment 1 s21516Group assignment 1 s21516
Group assignment 1 s21516
 
Avl tree-rotations
Avl tree-rotationsAvl tree-rotations
Avl tree-rotations
 
Week12 graph
Week12   graph Week12   graph
Week12 graph
 
Vpn
VpnVpn
Vpn
 

Recently uploaded

Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
Avinash Rai
 

Recently uploaded (20)

Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptxslides CapTechTalks Webinar May 2024 Alexander Perry.pptx
slides CapTechTalks Webinar May 2024 Alexander Perry.pptx
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdfDanh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
Danh sách HSG Bộ môn cấp trường - Cấp THPT.pdf
 
How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17How to the fix Attribute Error in odoo 17
How to the fix Attribute Error in odoo 17
 
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
GIÁO ÁN DẠY THÊM (KẾ HOẠCH BÀI BUỔI 2) - TIẾNG ANH 8 GLOBAL SUCCESS (2 CỘT) N...
 
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
UNIT – IV_PCI Complaints: Complaints and evaluation of complaints, Handling o...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17How to Manage Notification Preferences in the Odoo 17
How to Manage Notification Preferences in the Odoo 17
 
Keeping Your Information Safe with Centralized Security Services
Keeping Your Information Safe with Centralized Security ServicesKeeping Your Information Safe with Centralized Security Services
Keeping Your Information Safe with Centralized Security Services
 
Sectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdfSectors of the Indian Economy - Class 10 Study Notes pdf
Sectors of the Indian Economy - Class 10 Study Notes pdf
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
The Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational ResourcesThe Benefits and Challenges of Open Educational Resources
The Benefits and Challenges of Open Educational Resources
 
size separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceuticssize separation d pharm 1st year pharmaceutics
size separation d pharm 1st year pharmaceutics
 
[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation[GDSC YCCE] Build with AI Online Presentation
[GDSC YCCE] Build with AI Online Presentation
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx2024_Student Session 2_ Set Plan Preparation.pptx
2024_Student Session 2_ Set Plan Preparation.pptx
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 

Redo midterm

  • 1. Page | 1 PART 1 – Multiple Choice Questions 1. Which of the following is FALSE about linked lists A. The data structure includes the link to another object of the same type B. The data set are stored in contiguous order in memory C. The size is dynamic during run-time D. Memory is allocated at run-time 2. The advantage of arrays over linked lists is A. Direct access B. Less memory usage C. Easier to implement D. Dynamic memory allocation 3. Which of the following structures is suitable to keep track of a sequence printing jobs sent to a network printer? A. Trees B. Stack C. Queues D. Lists 4. The following problems best solved using stack structures, EXCEPT A. Balancing of parenthesis B. Evaluation of postfix expressions C. Removal of items in random order D. Evaluation of functions containing recursive calls 5. Given the following sequence of operations performed on a stack: push (5.0), push (9.5), pop, push (27.5), push (12.7), push (0), pop, pop, push (31.2) What will be the sequence of items in the stack as a result? A. 31.2 0.0 12.7 27.5 9.5 5.0 B. 27.5 9.5 5.0 C. 3.12 27.5 5.0 D. Stack is empty
  • 2. Page | 2 6. Suppose myList is an object of List data structure, and myList.displayList() produces the following output: 28 7 76 48 70 What would be the output when the following statements are executed? myList.InsertNode(2, 10); myList.DisplayList(); A. 10 28 7 76 48 70 B. 28 7 76 10 48 70 C. 28 7 76 48 70 10 D. 28 7 10 76 48 70 7. Suppose an array myArr contains the following sequences of integers: 28 7 76 48 70 What would be resulting sequence of MyArr when the following statement is executed? myArr [2] = 10; A. 10 28 7 76 48 B. 28 7 76 10 48 C. 28 7 10 48 70 D. 7 10 76 48 70 8. Which of the following is FALSE when using recursion A. The recursions must be assumed to work all the time B. You must have a base case which can be solved without recursion C. The recursive call must always make progress towards the base case D. The recursive calls must always be compounded in multiple recursive calls 9. How many times will the symbol ‘#’ be printed by the call foo (4)? void foo (int i) { if (i > 1) { foo (i/2); foo (i/2); } cout << "#"; } A. 6 B. 7 C. 8 D. 9
  • 3. Page | 3 10. Which of the following statements about QUEUES is FALSE ? A. New items can only be inserted at the end position B. The items are processed in a queue on a First in First out basis C. The main operations of a queue is enqueueing and dequeueing D. Items cannot be removed from a queue at the beginning of queue 11. In linked lists, there are no NULL links in A. linear doubly linked list B. circular linked list C. single linked list D. All of the above 12. The range of 4-bits unsigned integer is between: A. 0 to 15 B. 1 to 16 C. -7 to 8 D. -15 to 14 13. When a new node is inserted in between a linked list, which of these is TRUE: A. nodes appearing after the new node needs to be moved B. nodes appearing before the new node needs to be moved C. nodes appearing before and after the new node need to be moved D. None of the above 14. One DIFFERENCE between a queue and a stack is: A. Queues require linked lists, but stacks require array B. Stacks require linked lists, but queues require array C. Queues use two ends of the structure; stacks use only one. D. Stacks use two ends of the structure; queues use only one. 15. The address of an element [i, j] in a m × n matrix based on the column-wise order can be ______ A. m * ( i – 2 ) + j B. m * ( j – 2 ) + i C. n* ( i – 1 ) + j D. n* ( i – 1) + (j – 1)
  • 4. Page | 4 PART 2 – Short Answer Questions 1. Given the following code: #include <iostream> using namespace std; int myfunction(int); int main () { int input, answer; cout <<"Enter an integer: "; cin >> input; answer = myfunction(input); cout << endl<<"The answer "<<input<< "! is " << answer; return 0; } int myfunction (int num) { cout <<"Fib " << num<< " is " ; if (num == 0) return 0; else (num == 1) return 1; else return myfunction (num-1) + myfunction (num-2); } Write the output of the program if the user types 4 as input? 2. Discuss the pros and cons of choosing linked list implementation for lists, stacks and queues. 3. Suppose a queue called myQueue is implemented using a circular array of MAXSIZE = 7. Illustrate to show the step-by-step effects in myQueue if the following sequence of statements is executed: myQueue.enqueue (‘F’) myQueue.enqueue (‘C’) myQueue.enqueue (‘Q’) myQueue.dequeue myQueue.enqueue (‘X’) myQueue.enqueue (‘Z’) myQueue.dequeue myQueue.enqueue (‘L’) myQueue.enqueue (‘S’) myQueue.enqueue (‘W’) myQueue.enqueue (‘C’) myQueue.dequeue
  • 5. Page | 5 4. In C++, a variable that stores integer values can be declared as short (2 bytes or 16 bits) or int (bytes or 32 bits). Furthermore, floating-point numbers can be declared as float (4 bytes or 32 bits) or double (8 bytes or 64 bits) based on the IEEE Standard for Floating Point Arithmetic (IEEE-754). Determine the corresponding binary values that are stored in the computer for the following variable declarations: a. unsigned short a = 15; b. short b = -15; c. float c = -52.25 5. Use stacks to show the step-by-step evaluation of the post-fix expression given below: 5.2 2.0 1.5 * + 4.0 2.0 2.0 ^ * - 6. Given below is a recursive method of function f for the value x. Write an equivalent program segment using iterative method. int f (int x){ if (x == 0) return 0; else return 2 * f (x – 1) + x * x; } 7. The elements in an array may be stored based on a row-wise or column-wise arrangement depending on the programming language used. Suppose the dimensions of an array myGoodArray are 7X9X8. Given the address of myGoodArray [4, z, 3] based on the column-wise method is 438, when the base address (B) is 10, with size of each element (W) is 2, and lowest index of each dimension is 0, a. Find z. b. Determine the address of the same element if it is implemented in row-wise method. 8. Write an algorithm which checks if the brackets in an expression are balanced and reports an error if the matching brackets is missing.