1050_Lab8_Worksheet

.docx

School

Langara College *

*We aren’t endorsed by this school

Course

1050

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

5

Uploaded by CaptainGalaxyWasp15

Report
CPSC 1050 – Lab 8 – Worksheet (32 marks) Abstract Data Types For each of the following questions write your complete work. The first 3 questions are from "Lab 9 Abstract Data Types" (Lab9_Manual.pdf). You may write your answers in a document, save as PDF, and submit on D2L. 1. (4 marks) Lab 9 / Exercise 1. Ans- 1,2- Alice 3- while(more data) read value push(stack,value) while(NOT empty(stack)) pop(stack,value) write value ========================================================================================== 2. (4 marks) Lab 9 / Exercise 4. Ans- 1,2,3,4- The structure of the tree looks like linear. The each and every node of the tree being the child one after another. 5- It will remain sorted until and unless we change it. 6- It is a stick. 7- 1
The order is: Daisy Echinacea Fern Aster Bluebell Coreopsis Gladiolus 8- Yes many orders are possible. Because it is inserted alphabetically ========================================================================================== 3. (4 marks) Lab 9 / Exercise 5. Ans- 1,2,3- 4- The name inserts after the old duplicate name. 5- making new name of child of another node / making new name in its own node 6- no the app gets confused. It turns to red. ========================================================================================== 2
4. (4 marks) What is the output of the following stack algorithm? Push(myStack, 2) Push(myStack, 7) Push(myStack, 8) Push(myStack, 5) Push(myStack, 9) Push(myStack, 1) Pop(myStack, item) Pop(myStack, item) Pop(myStack, item) Push(myStack, item) Push(myStack, item) WHILE(NOT IsEmtpy(myStack)) Pop(myStack, item) Write item, ", " 2 is the output of the Stack and Queues of the Code. ======================================================================== 5. (4 marks) What is the output of the following queue algorithm? Enque(myQueue, 2) Enque(myQueue, 7) Enque(myQueue, 8) Enque(myQueue, 5) Enque(myQueue, 9) Enque(myQueue, 1) Deque(myQueue, item) Deque(myQueue, item) Deque(myQueue, item) Enque(myQueue, item) WHILE(NOT IsEmtpy(myQueue)) Deque(myQueue, item) Write item, ", " 5918 is the output ======================================================================== 6. (4 marks) Write an algorithm that sets variable bottom equal to the last element in a stack: a. leaving the stack empty. ANS- WHILE (NOT IsEmpty(myStack)) Pop(myStack, bottom) 3
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help