0% found this document useful (0 votes)
34 views

Data Structures Practice Questions: Program#1

The document provides algorithms for several data structures practice problems involving linked lists, including returning a value at a given index, counting occurrences of a number, removing duplicate nodes from a sorted list, calculating the sum of all nodes, finding the minimum/maximum in a stack or queue, converting a decimal number to binary using a stack, and finding the middle element in a stack or queue. It also notes that students in section A should study the topic of array implementation of queues on their own.

Uploaded by

Engr Umar Ashraf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Data Structures Practice Questions: Program#1

The document provides algorithms for several data structures practice problems involving linked lists, including returning a value at a given index, counting occurrences of a number, removing duplicate nodes from a sorted list, calculating the sum of all nodes, finding the minimum/maximum in a stack or queue, converting a decimal number to binary using a stack, and finding the middle element in a stack or queue. It also notes that students in section A should study the topic of array implementation of queues on their own.

Uploaded by

Engr Umar Ashraf
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Data Structures Practice Questions

Program#1
Write a function that takes a linked list and an integer index and returns the data value stored in
the node at that index position.
Algorithm:
1. initialize count = 0
2. Loop through the link list
a. If count is equal to the passed index then return current node
b. Increment count
c. Change current in order to point to the next of the current node.

Program#2
Write a function that counts the number of times a given int occurs in a Linked List
Algorithm:
1. initialize count = 0
2. Loop through each element of the link list
a. If element value is equal to the passed number then increment the count
b. Return count

Progrma#3
Write a removeDuplicates() function which takes a sorted list in ascending order and deletes any
duplicate nodes from the list. The list should only be traversed once.
For example if the linked list is 11->11->11->21->43->43->60 then removeDuplicates() function
should convert the list to 11->21->43->60.
Algorithm:
1. Traverse the list from the head (or start) node
2. Compare each node with its next node. If data of next node is same as current node then
delete the next node, Before we delete a node, we need to store next pointer of the node

Program#4
Write a function which calculates the sum of all the nodes present in the singly linked list.

Program#5
Write a function which finds the minimum / maximum number in the stack / queue using array
implementation.

Program#6
Write a program to convert a decimal number into its binary form using stack implementation.

Program#7
Write a function which finds the middle element in the stack / queue using array implementation.

Note: Students of section (A), Please study the topic Array Implementation of Queue by
yourselves.

You might also like