Question

In: Computer Science

Question 3 You should form the list of integers with your student ID. The numbers are...

Question 3

You should form the list of integers with your student ID. The numbers are generated as follows:

Number

Based on your student ID number, formed by its …

a

1 st and 2nd digits

b

2 nd and 3rd digits

c

3rd and 4th digits

d

4th and 5th digits

e

5th and 6th digits

f

6th and 7th digits

g

7th and 8th digits

For example, the student ID is 19563755A.

Values of a to g are: 19, 95, 56, 63, 37, 75, 55

Sort them using insertion sort. Show all the steps.

Solutions

Expert Solution

#Note:

For this problem using Python language.

All work has done it creates number only alphabets never assign.

Theory

List:

The list is a collection of element which is ordered also unordered and changeable. It also allow duplicate values.

Solution:

Algorithm:

1. Start

2. Get input from user

3. Seperate the user id and store into list namely values.

4. Create function for concate the adjecent numbers in values list.

5. After concatenation add this numbers in numbers list.

6. display numbers list

6. Create function for insertion sort of numbers list

7. After sorting display sorting list.

8. End

Code:

#get input from user

studentID=input("Enter student id ")
# Its seperate the user id and 
values=[int(i) for i in studentID]
numbers=[]
i=0
j=1
# function for concate numbers
def numConcat(num1, num2):
    # find number of digits in num2
    digits = len(str(num2))
    # add zeroes to the end of num1
    num1 = num1 * (10 ** digits)
    #condition check for first element 
    if(num1==0):
        pass
    # add num2 to num1
    else:
        num3= num1 + num2
        #add concated numbers in numbers list
        numbers.append(num3)
# function for insertion sorting of numbers list
def insertionSort(arr):
    # Traverse through 1 to len(arr)
    for i in range(1, len(arr)):

        key = arr[i]

        # Move elements of arr[0..i-1], that are
        # greater than key, to one position ahead
        # of their current position
        j = i - 1
        while j >= 0 and key < arr[j]:
            arr[j + 1] = arr[j]
            j -= 1
        arr[j + 1] = key
    #print sorted list
    print("Sorted list is:")
    print(arr)
#i is for first and j is for next element
while(i<j and j<len(values)):
    first=values[i]
    second=values[j]
    #pass adjecent numbers to function
    numConcat(first, second)
    i=i+1
    j=j+1
print("The values are:")
print(numbers)
#call insertionSort() method
insertionSort(numbers)

Output:


Related Solutions

Reconsider your student ID in a binary format (as explained in the previous question) as the...
Reconsider your student ID in a binary format (as explained in the previous question) as the dataword. 2.1) Find the codeword corresponding to this dataword using the CRC error detection technique, and the divisor polynomial g(x) = x3+x2+1. Do Binary division with 0s and 1s. 2.2) Compute now the codeword corresponding to this dataword assuming that the divisor polynomial that is used is f(x) = x5+1. Do Polynomial division. 2.3) Assume that an error corrupted the first two bits of...
Reconsider your student ID in a binary format (as explained in the previous question) as the...
Reconsider your student ID in a binary format (as explained in the previous question) as the dataword. 2.1) Find the codeword corresponding to this dataword using the CRC error detection technique, and the divisor polynomial g(x) = x3 +x2 +1. Do Binary division with 0s and 1s. 2.2) Compute now the codeword corresponding to this dataword assuming that the divisor polynomial that is used is f(x) = x5+1. Do Polynomial division. 2.3) Assume that an error corrupted the first two...
Consider you student ID as a decimal number (Example: MIT123456 should be ‘123456’) and covert to...
Consider you student ID as a decimal number (Example: MIT123456 should be ‘123456’) and covert to binary digits. You may use any online decimal to binary converter to convert this. Now draw the message signal for the binary numbers (consider this as your bit stream) and show ASK, BFSK and BPSK signal accordingly.
Consider the middle 3 digits of your student ID composed of seven digits. Convert it to...
Consider the middle 3 digits of your student ID composed of seven digits. Convert it to binary format (each digit is represented by a maximum of 3bits). For example, 1060385 is simplified to 603 and then converted to 110 000 011. Assume now that we want to send your student ID while being able to detect and correct single bit errors. 1.1) Using two-dimensional parity check show what will be transmitted codeword using datawords of size 3bits. 1.2) Using the...
In Python syntax, create a list of 10 numbers (any numbers). Create your list 3 times,...
In Python syntax, create a list of 10 numbers (any numbers). Create your list 3 times, each time using a different syntax to define the list. Write a while loop that prints the numbers from 1 to 10. Convert your previous loop into a for loop. Rewrite your for loop to only have one number in the range. Write a for loop to print out each item of your list of 10 numbers, all on the same line, separated by...
Change program linkedListClass to the linked list for student items (a student item contains id, name...
Change program linkedListClass to the linked list for student items (a student item contains id, name and score, where the id is used as key) and test it in the main method. You can define a student item using a class of student. given the following codes; import java.util.*; public class linkedListClass {    public Node header;    public linkedListClass()    {        header = null;    }    public final Node Search(int key)    {        Node...
8.26 LAB: Output numbers in reverse Write a program that reads a list of integers, and...
8.26 LAB: Output numbers in reverse Write a program that reads a list of integers, and outputs those integers in reverse. The input begins with an integer indicating the number of integers that follow. For coding simplicity, follow each output integer by a space, including the last one. Assume that the list will always contain fewer than 20 integers. Ex: If the input is: 5 2 4 6 8 10 the output is: 10 8 6 4 2 To achieve...
Write a Java program that reads a list of integers into an array. The program should...
Write a Java program that reads a list of integers into an array. The program should read this array from the file “input.txt”. You may assume that there are fewer than 50 entries in the array. Your program determines how many entries there are. The output is a two-column list. The first column is the list of the distinct array elements; the second column is the number of occurrences of each element. The list should be sorted on entries in...
Please write your name and student ID number clearly at the top of your answer paper....
Please write your name and student ID number clearly at the top of your answer paper. 1. Production Possibilities Frontier gives us the information about the combinations of goods and services that can be produced by a country given its resources and production technology. a. Assume that China can only produce 2 goods: toys and computers. Draw China’s PPF and clearly specify the axes. b. In class we learned about China’s demographic challenge. Describe this challenge in a few sentences....
Question 1 - Create a class named Student that has fields for an ID number, number...
Question 1 - Create a class named Student that has fields for an ID number, number of credit hours earned, and number of points earned. (For example, many schools compute grade point averages based on a scale of 4, so a three-credit-hour class in which a student earns an A is worth 12 points.) Include methods to assign values to all fields. A Student also has a field for grade point average. Include a method to compute the grade point...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT