0% found this document useful (0 votes)
19 views4 pages

Data Structures and Algorithms Coursework

This document provides instructions for a coursework assignment on data structures and algorithms programming. It includes 8 questions to be answered related to pointers, structures, stacks, queues, and expressions. Students must complete the assignment as a pair, and submit handwritten work by June 17th, 2017 at 1:00pm for 40% of the course marks. The lecturer is Serunjogi Ismail.

Uploaded by

Ismail Wizzy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views4 pages

Data Structures and Algorithms Coursework

This document provides instructions for a coursework assignment on data structures and algorithms programming. It includes 8 questions to be answered related to pointers, structures, stacks, queues, and expressions. Students must complete the assignment as a pair, and submit handwritten work by June 17th, 2017 at 1:00pm for 40% of the course marks. The lecturer is Serunjogi Ismail.

Uploaded by

Ismail Wizzy
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Course Unit: Data structures and Algorithms Programming Course Work

1
Course: DIT/ DCS
Group Work: Each Two Members
Deadline: 17th /06/2017 Before 1:00pm
Marks: 40%
Mode: Handwritten (Good Handwriting)

2. Let us consider the following statements:


int *p;
int num;
In these statements, p is a pointer variable of type int and num is a variable of type int.
Let us assume that memory location 1200 is allocated for p and memory location 1800 is for
num. (See Figure 3-1.)

With illustrations, explain the values of each variable after execution

Lecturer: Serunjogi Ismail


2
4. Write C Language Statements to do the following

5. Consider the following statements:

Lecturer: Serunjogi Ismail


struct stackType stack;

3
int x, y;
Show what is output by the following segment of code:
x = 4;
y = 0;
[Link](7);
[Link](x);
[Link](x + 5);
y = [Link]();
[Link]();
[Link](x + y);
[Link](y - 2);
[Link](3);
x = [Link]();
[Link]();
printf("x = %d\n", x);
printf("y = %d\n", y);
while (![Link]())
{
printf("%d\n", [Link]());
[Link]();
}
6. Evaluate the following postfix expressions:

7. Convert the following infix expressions to postfix

8. Consider the following statements:


struct queueType queue;
int x, y;
Show what output by the following segment of code is:
x = 4;
y = 5;
[Link](x);
Lecturer: Serunjogi Ismail
[Link](y);

4
x = [Link]();
[Link]();
[Link](x + 5);
[Link](16);
[Link](x);
[Link](y - 3);
printf("Queue Elements: ");
while (![Link]())
{
printf("%d ", [Link]());
[Link]();
}
printf("\n");

Lecturer: Serunjogi Ismail

Common questions

Powered by AI

Including theoretical concepts and hands-on practice ensures that students not only understand the underlying principles of programming but also develop practical skills by applying these concepts. Handwritten assignments particularly aid in reinforcing understanding through active participation, encouraging cognitive engagement and memory retention .

Converting infix expressions to postfix involves using a stack to reorder operators in accordance with the precedence and associativity rules. Operators are pushed onto the stack and only output when lower precedence operators are to be processed or at the end of the expression, allowing operand order to be maintained while ensuring operators appear in correct sequence relative to their operands .

Illustrative diagrams help students visualize relationships and operations within data structures, reinforcing abstract concepts with concrete representations. For pointers and stacks, diagrams clarify memory management and data flow, bridging gaps between theoretical understanding and practical application .

Postfix expression evaluation involves reading from left to right without operator precedence, using a stack to facilitate operations as operands become available. This eliminates the complexity of nested operations, enhancing efficiency and reducing error-prone operators precedence compared to infix evaluation, which requires frequent context switching and look ahead .

In the given examples, the pointer variable 'p' is allocated memory at location 1200 and holds the address of another integer. The integer variable 'num' is allocated at 1800 and directly holds an integer value. Pointers store memory addresses rather than raw data, allowing dynamic memory management and data structure manipulation .

In the provided code segment, initially, x is set to 4 and y to 0. The stack operations sequence is as follows: push 7 onto the stack; push x (4); push x + 5 (9); set y to the top of the stack (9) and then pop the stack; push x + y (13); push y - 2 (7); push 3; set x to the top of the stack (3) and then pop the stack. After these operations and popping values while printing, y retains the value 9. The stack outputs: 13, 7, 4, 7 .

The code segment demonstrates the LIFO property through push and pop operations: items are added (pushed) onto the stack, and later retrieved in reverse order. The most recently added item (3) is accessed first when popped. This property is crucial for algorithms needing backtracking or reverse traversals, such as parsing expressions or undo mechanisms in applications .

Handwritten assignments in programming may limit students' experience with debugging, syntax checking, and real-time feedback provided by digital tools. This could delay the identification and correction of errors, reducing the opportunity for iterative learning and practice in coding environments .

The queue operations begin with x = 4 and y = 5. Sequence: enqueue x (4); enqueue y (5); dequeue front of queue, x still references 4; enqueue x + 5 (9); enqueue 16; enqueue x (4); enqueue y - 3 (2). This results in a queue with elements 5, 9, 16, 4, and 2. Printing these in sequence as the queue is emptied results in the output: 5 9 16 4 2 .

Stacks and queues offer structured ways to manage data access and modification, aligning with specific access patterns like LIFO for stacks and FIFO for queues. They simplify tasks such as function call management, expression processing, and scheduling by encapsulating these patterns, making algorithms clearer and more efficient .

You might also like